comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: writeu, printf, readu/f 2 file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: writeu, printf, readu/f 2 file [message #24136] Tue, 13 March 2001 12:13 Go to next message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
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
------------------------------------------------------------ --------------
Re: writeu, printf, readu/f 2 file [message #24261 is a reply to message #24136] Mon, 19 March 2001 07:45 Go to previous message
Martin Schultz is currently offline  Martin Schultz
Messages: 515
Registered: August 1997
Senior Member
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 [[
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: BETTER FONTS
Next Topic: Writing large [x,x,x,x] files

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sat Oct 11 14:44:16 PDT 2025

Total time taken to generate the page: 1.21323 seconds