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

Home » Public Forums » archive » Re: Reading string data from binary f77 files?
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: Reading string data from binary f77 files? [message #1636] Fri, 07 January 1994 01:00
walsteyn is currently offline  walsteyn
Messages: 3
Registered: December 1993
Junior Member
In <thompson.757898339@serts.gsfc.nasa.gov> thompson@serts.gsfc.nasa.gov (William Thompson) writes:

> scott@abyss.ATMOS.ColoState.Edu (Scott Denning) writes:

>> I have binary files of model output that are set up with a bunch of header
>> info, including a list of the names of the fields contained in the file.
>> The files are written in IEEE binary by fortran 77 programs. I can read
>> everything just fine into IDL by opening the file code like
>> ..
>> ARRAY1 = FLTARR(im,jm,lm)
>> OPENR, 1, 'model.output', /F77_UNFORMATTED
>> READU, 1, ARRAY1
>> ..
>> etc.
>> The only trouble seems to be in reading the strings which are supposed to
>> be the names of the fields (titles for the plots I make with IDL). I have
>> been trying variations on
>> title = StrArr(100)
>> readu, 1, title
>> All I get is an array of 100 nulls.
>> Even reading a single character string like this:
>> name = '123'
>> readu, 1, header
>> doesn't work.
>> Any ideas?


> The way to do this is to create a byte array with the correct number of
> characters, read this into IDL, and then convert it to string. Assuming that
> you're trying to read a title string with 100 characters in your example above,
> this should do the trick:
> title = bytarr(100)
> readu, 1, title
> title = string(title)
> Bill Thompson


Another trick is to make sure that the title string is already
*filled* with an arbitrary character string that is as long as the record
you want to read. (This is mentioned in the manual somewhere.)
Example:
title = string(' ',format='(A100)')
readu, 1, title

Fred Walsteijn.
Re: Reading string data from binary f77 files? [message #1637 is a reply to message #1636] Thu, 06 January 1994 15:18 Go to previous message
thompson is currently offline  thompson
Messages: 584
Registered: August 1991
Senior Member
scott@abyss.ATMOS.ColoState.Edu (Scott Denning) writes:

> I have binary files of model output that are set up with a bunch of header
> info, including a list of the names of the fields contained in the file.
> The files are written in IEEE binary by fortran 77 programs. I can read
> everything just fine into IDL by opening the file code like

> ..
> ARRAY1 = FLTARR(im,jm,lm)
> OPENR, 1, 'model.output', /F77_UNFORMATTED
> READU, 1, ARRAY1
> ..

> etc.

> The only trouble seems to be in reading the strings which are supposed to
> be the names of the fields (titles for the plots I make with IDL). I have
> been trying variations on

> title = StrArr(100)
> readu, 1, title

> All I get is an array of 100 nulls.

> Even reading a single character string like this:

> name = '123'
> readu, 1, header

> doesn't work.

> Any ideas?

The way to do this is to create a byte array with the correct number of
characters, read this into IDL, and then convert it to string. Assuming that
you're trying to read a title string with 100 characters in your example above,
this should do the trick:

title = bytarr(100)
readu, 1, title
title = string(title)

Bill Thompson
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: How to use fewer colors for Widget-app-window?
Next Topic: IDL color palette and tvrd

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

Current Time: Wed Oct 08 19:13:28 PDT 2025

Total time taken to generate the page: 0.00752 seconds