[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: writeu, printf, readu/f 2 file
Without delving into too much detail about your specific program, I
can say that you should pay a lot more attention to your output
formatting. Don't assume, simply because you print it out one way, it
can be read the same way. For example:
IDL> openw, 50, 'test.dat'
IDL> printf, 50, 1, '2 3', 4
IDL> close, 50
IDL> openr, 50, 'test.dat'
IDL> a = 0 & b = '' & c = 0
IDL> readf, 50, a, b, c
% READF: End of file encountered. Unit: 50
File: test.dat
% Execution halted at: $MAIN$
Hmmm, why did this fail? Well, the string B is very greedy and it
consumes everything to the end of the line, including the "4".
Mixing formatted and unformatted data in a file can be tricky. The
problem is that when you read formatted data the file pointer can
advance unpredictably. Better to read and write the data
intermediately to a string buffer.
Craig
"Sean Heukels" <sean77=cuthere=@dds.nl> writes:
> Can writeu, and printf be combined ?? in one write action.
> Or is it the one or the other ?
> I've been trying everything. The whole day and it still doesn't work.
>
> What I want to do is write some txt and variables, that define
> the following data block and ofcourse the time and location, etc
> In the header. But somehow, the firt line reads fine, but after that
> everything is garbled.
> I think it has something to do with the different write/read statements
>
> See sample code that is not working
... deleted ...
--
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------