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

Home » Public Forums » archive » Re: Reading both strings and floats from an ASCII 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: Reading both strings and floats from an ASCII file [message #47786] Tue, 28 February 2006 00:37
Juan Arrieta is currently offline  Juan Arrieta
Messages: 6
Registered: February 2006
Junior Member
Thanks a lot David, it works like a charm.
Have a great day,
Juan
Re: Reading both strings and floats from an ASCII file [message #47788 is a reply to message #47786] Mon, 27 February 2006 20:28 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Juan Arrieta writes:

> The output of a trajectory optimization routine looks as follows:
> COLS: 5
> ROWS: 110
> NAMES: <U1><U2><STATE 1><STATE 2><FINAL STATE>
> 6.0000E+00 -3.3333E-01 -1.8329E+00 5.0000E-01
> -3.6879E-01
> 1.2000E+01 -3.3333E-01 -1.1517E+00 5.0000E-01
> -2.1062E+00
> ... (more rows)
>
> I would like to read the NAMES into an array so I can, say, create the
> plot labesl in a more efficient manner. The names can change from a few
> letters to a few word (i.e. unknown width). Also, the number of columns
> (thus names) can change drastically.
>
> I know how to read the number of columns, rows, and the data itself.
> Only the names are giving me a headache. Any pointers, IDL experts?

Off-hand, I would try something like this:

; Read the first three lines of the file into a string array.
OpenR, lun, filename, /Get_Lun
header = StrArr(3)
ReadF, lun, header

; Parse the header for information.
cols = Fix(StrMid(header[0],5))
rows = Fix(StrMid(header[1],5))
namestr = StrMid(header[2], 6)
names = StrSplit(namestr, '[><]', /RegEx, /Extract)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL source editor :)
Next Topic: Problem concerning accessing external library in IDL6.0

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

Current Time: Fri Oct 10 01:30:55 PDT 2025

Total time taken to generate the page: 1.19788 seconds