Re: need a quicker way to read ascii file w/a structure [message #25336] |
Wed, 06 June 2001 12:22  |
dirk
Messages: 15 Registered: March 1998
|
Junior Member |
|
|
In article <003701c0ee21$447c6b70$d938a8c0@hadfield>,
Mark Hadfield <m.hadfield@niwa.cri.nz> wrote:
> From: "Lucas Miller" <differentiable@hotmail.com>
>> OK. I've got an ascii file laid out in columns with a string in the
>> first column, like this
>>
>> yyyy-ddd // hh:mm:ss.ms 0 12 -1.00 -1.00 -1.00 -1.00
>> (lots and lots of rows)
>>
>> I defined a structure
>> mystruct = {utctime: ' ',mpos: 0, sector: 0,$
>> arate: 0.0, brate: 0.0, crate: 0.0, drate: 0.0}
>>
>> I know the number of rows so I replicate,
>> data = replicate(mystruct,num_of_rows)
>>
[snip]
>
> Yes, because mystruct.utctime is a string and strings are "greedy" in read
> operations unless the field width is specified explicitly.
>
> yyyy-ddd // hh:mm:ss.ms 0 12 -1.00 -1.00 -1.00 -1.00
>
[snip]
> I have written a lot of routines to process text data files and I have found
> that the formats are so variable and loosely defined that a general solution
> is not possible and not worth attempting.
I have had a lot of success with the function readcol.pro found on the
idlastro archives. http://idlastro.gsfc.nasa.gov/contents.html
Get all the supporting programs for this, it's worth it.
Basically, it will separate each line into tokens of various type and
stick those values in arrays that you speciify. It will be easy to put
them in the structure from there. Since it is based on the token idea, it
can deal with varying formats, as long as there are spaces between the
tokens.
Good luck.
- Dirk
|
|
|