Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
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 ------------------------------------------------------------ --------------
Craig Markwardt wrote: > > 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 > ... or use a byte array to represent strings in a binary file. I have a little utility program available that will convert strings (or string arrays) to byte arrays. To go back, you can simply use String(thearray). The program is here: http://www.mpimet.mpg.de/~schultz.martin/idl/html/src/martin _schultz/str2byte.pro Cheers, Martin -- [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[ [[ Dr. Martin Schultz Max-Planck-Institut fuer Meteorologie [[ [[ Bundesstr. 55, 20146 Hamburg [[ [[ phone: +49 40 41173-308 [[ [[ fax: +49 40 41173-298 [[ [[ martin.schultz@dkrz.de [[ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[