|
Re: Reading both strings and floats from an ASCII file [message #47788 is a reply to message #47786] |
Mon, 27 February 2006 20:28  |
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/
|
|
|