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

Home » Public Forums » archive » Re: need a quicker way to read ascii file w/a structure
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: need a quicker way to read ascii file w/a structure [message #25353 is a reply to message #25350] Tue, 05 June 2001 17:40 Go to previous message
m.hadfield is currently offline  m.hadfield
Messages: 36
Registered: April 2001
Member
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)
>
> and I read,
> readf, myfilelun, data
>
> and find out that the entire row is read into my mystruct.utctime
> string variable.

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

> I don't want to use an
> explicit format statement because the format varies....

That's a pity. If the widths of the fields were fixed then an explicit
format would work.

Have you considered going to the person who generated the text files and
suggesting she produce them with fixed widths. While you're at it, ask her
why she couldn't have done that in the first place.

> ...The only thing I can think of doing at
> this point is reading my file in as a string array, separating it into
> variables, and feeding it into my structure.

Well, you don't have to load the entire file into an array, you can read
each line into a scalar string, get the data you want and load it into the
output array, then discard the line.

> This would
> take a LOT of time...

Not all that much in my experience. Read each line, split off the time
string, read the numbers out of the remainder with a reads statement--it
wouldn't take much longer to write the code than to describe it.

> ...and besides isn't there a more elegant way to do
> it?

Not that I can think of.

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.

---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research



--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: resizing an array of structures (uugh)
Next Topic: Specific cross platform IDL problem...

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

Current Time: Wed Oct 08 17:34:46 PDT 2025

Total time taken to generate the page: 0.00425 seconds