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

Home » Public Forums » archive » Re: converting to array
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: converting to array [message #24129] Wed, 14 March 2001 09:06
Pavel A. Romashkin is currently offline  Pavel A. Romashkin
Messages: 531
Registered: November 2000
Senior Member
Norbert Hahn wrote:

> 1) If the data is written by a program that I can put my
> hand on, I usually read the data under format control.
>
> 2) If the data comes from some unknown source I prefer to
> read the data into a string at first and analyze that
> string. This is to prevent program breaks due to wrong
> data.

I am sorry, but I am not with you on this one.

I deal with bizarre file formats all the time. None of them are written
by programs I can get my hand on. Most have over 100,000 data records,
some have more. If I read all that via string parsing, I still would be
reading the files, months after I started :-(

My approach is, if I can comprehend the file format, I use a formatted
read as close to the data structure as possible. IDL can read a 10
column by 100,000 rows numeric array from a file in split second. But to
loop through 100,000 rows, read a string each time ans READS will take
minutes at least.

The drawback is, it might take effort to figure out the optimal way to
create the format itself. But it pays off tenfold, if you have more than
one file to read.

But, like everything else, it is all the matter of personal preference.

Cheers,
Pavel
Re: converting to array [message #24132 is a reply to message #24129] Wed, 14 March 2001 02:32 Go to previous message
hahn is currently offline  hahn
Messages: 108
Registered: November 1993
Senior Member
davidf@dfanning.com (David Fanning) wrote:

> Norbert Hahn (hahn@hrz.tu-darmstadt.de) writes:
>
>> This is the shortest solution. However, I would read these
>> values into a string, count the words there and then use
>> ReadS to retrieve the data from the string.
>
> Why, for Heaven's sake!?

There are several ways to read numeric data and the method
to read them should be base on how they are written.

1) If the data is written by a program that I can put my
hand on, I usually read the data under format control.

2) If the data comes from some unknown source I prefer to
read the data into a string at first and analyze that
string. This is to prevent program breaks due to wrong
data.

I prefer a program break and some meaningful messages
over a quietly reading program that calmly digests wrong
data.

Norbert
Re: converting to array [message #24142 is a reply to message #24132] Tue, 13 March 2001 06:19 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Norbert Hahn (hahn@hrz.tu-darmstadt.de) writes:

> This is the shortest solution. However, I would read these
> values into a string, count the words there and then use
> ReadS to retrieve the data from the string.

Why, for Heaven's sake!?

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: converting to array [message #24143 is a reply to message #24142] Tue, 13 March 2001 05:18 Go to previous message
hahn is currently offline  hahn
Messages: 108
Registered: November 1993
Senior Member
davidf@dfanning.com (David Fanning) wrote:

> array = FltArr(5) ; Or, however many values you have.
> OPENR, lun, 'myfile.dat', /Get_LUN
> READF, lun, array
> FREE_LUN, lun

This is the shortest solution. However, I would read these
values into a string, count the words there and then use
ReadS to retrieve the data from the string.

Norbert
Re: converting to array [message #24150 is a reply to message #24143] Mon, 12 March 2001 11:53 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Martin Skou Andersen (skou@fys.ku.dk) writes:

> I have some data from a file...
> example:
> file start
> 10.5 30.5 40.8 57.9 90.8
>
> end of file
> I would like to read these data from a file, and these should be placed
> in a array...
> But when I read the file the datas are placed in a string. How do i get
> these data converted to a array?

array = FltArr(5) ; Or, however many values you have.
OPENR, lun, 'myfile.dat', /Get_LUN
READF, lun, array
FREE_LUN, lun

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: plot structured data II
Next Topic: linkimage query

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

Current Time: Sun Oct 12 00:01:39 PDT 2025

Total time taken to generate the page: 0.01244 seconds