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

Home » Public Forums » archive » Re: String Data file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: String Data file [message #35861 is a reply to message #35859] Wed, 30 July 2003 16:30 Go to previous message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
"Karthikayan Balakrishnan" wrote...

> I have a data file that looks like this:
> abc 1 2
> def 3 4.5
> ghij 2.3 23.44
> ...
> ...
> The first column is string, the next two are
> floating point. Is there any way I can read such a file?

You have a couple of options depending on how strict a format your data file
adheres to.

If your file has a strict format (which it doesn't look like it does) you
can use the FORMAT keyword to READF to specify exactly how your data is
read. For example:

OPENR, lun, 'yourfile.dat', /GET_LUN
while (not EOF(lun)) do begin
READF, lun, str, fl1, fl2, FORMAT='(a5,1x,f3.1,1x,f5.2)'
PRINT, str, fl1, fl2
endwhile
FREE_LUN, lun

would print your file to the screen, assuming your format was fixed.


If you don't have a strict format for your file, and it starts with a
string, then you'll need to read the entire line in as a string and parse
the line for your data. Something like this:

OPENR, lun, 'yourfile.dat', /GET_LUN
str = ''
while (not EOF(lun)) do begin
READF, lun, str
data = STRSPLIT(str, ' ', /EXTRACT)
str = data[0]
fl1 = FLOAT(data[1])
fl2 = FLOAT(data[2])
PRINT, str, fl1, fl2
endwhile
FREE_LUN, lun


Hope this helps!

-Rick
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: BOX_CURSOR
Next Topic: minor glitch in total()

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

Current Time: Sat Nov 29 00:31:52 PST 2025

Total time taken to generate the page: 1.28424 seconds