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

Home » Public Forums » archive » READ_ASCII - accessing data from structures
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
READ_ASCII - accessing data from structures [message #39371] Wed, 12 May 2004 10:14 Go to next message
m.doyle is currently offline  m.doyle
Messages: 6
Registered: January 2004
Junior Member
Hello all,

I wonder if anyone might be able to help me with this?

I'm using the IDL READ_ASCII function to read in a semicolon seperated
file, after which I'd like to access individual elements of that data
file. From the RSI website, I see that I can access the data fields
(i.e. each column of data) by using, for example;

print, mydata.(4)

using the Variable_Name.(Tag_Index) method.

Could someone tell me how to get to the individual elements of
mydata.(4)?? Using the above I can only get a large stream of numbers,
I need to use them one by one.

Many thanks for your help!

Martin
Re: read_ascii [message #41754 is a reply to message #39371] Wed, 08 December 2004 13:21 Go to previous messageGo to next message
Rick Towler is currently offline  Rick Towler
Messages: 821
Registered: August 1998
Senior Member
> The problem is that sometimes the array is contained in field01,
> sometimes in field01.

> How come it varies ?

You mean "field1" and "field01".

When confronted with less than 10 fields, READ_ASCII will return
field1-field9, when you have more than 10, field01-field99.

It is unfortunate that READ_ASCII behaves this way but David's
suggestion of addressing the structure by tag index instead of tag name
will solve your problem.

-Rick
Re: read_ascii [message #41755 is a reply to message #39371] Wed, 08 December 2004 12:54 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Francois writes:

> I use the following code to read an ascii file:
>> filename = dialog_pickfile(path='c:\')
>> data = READ_ASCII(filename, DATA_START=1, DELIMITER= ',')
>> data = data.field1
>
> I want data to become an array instead of a structure.
>
> The problem is that sometimes the array is contained in field01,
> sometimes in field01.
> How come it varies ?

I'm not sure I see the variation in the question,
but in any case I don't know why it varies. If it
*is* varying, why not try this:

data = READ_ASCII(filename, DATA_START=1, DELIMITER= ',')
data = data.(0)

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: read_ascii [message #41992 is a reply to message #41754] Thu, 09 December 2004 05:52 Go to previous message
Benjamin Tupper is currently offline  Benjamin Tupper
Messages: 1
Registered: December 2004
Junior Member
Rick Towler wrote:

>
>> The problem is that sometimes the array is contained in field01,
>> sometimes in field01.
>
>
>> How come it varies ?
>
>
> You mean "field1" and "field01".
>
> When confronted with less than 10 fields, READ_ASCII will return
> field1-field9, when you have more than 10, field01-field99.
>
> It is unfortunate that READ_ASCII behaves this way but David's
> suggestion of addressing the structure by tag index instead of tag name
> will solve your problem.
>

Hi,

You could define the names of the fields using ASCII_TEMPLATE before
calling READ_ASCII. You can define the template without using
ASCII_TEMPLATE - a little study of the structure returned by
ASCII_TEMPLATE should help.

Alternatively, you could modify READ_ASCII (call it something else,
though, like MY_READ_ASCII). You can force the routine to always use N
digits in the field names by modifying the following line (line 874 in
my version) ....

digits_str = $
strtrim(string(strlen(strtrim(string(fieldCountUse),2))),2)

to something like this...

my_dig_len = fieldCountUse > 2
digits_str = $
strtrim(string(strlen(strtrim(string(my_dig_len),2))),2)



On a related note, I have drifted away from treating columnated ASCII
data files as nColumns of vectors. Instead, I treat them as vectors of
structures where each row is a record and each column is a field of the
record. This works fine for flatly organized data and I find a vector
of structures MUCH easier to manage in IDL than a structure of vectors.
If you are interested seeing my version of READ_ASCII then shoot me an
email.

Cheers,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Flip Matrix
Next Topic: number of decimals?

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

Current Time: Fri Oct 10 07:03:30 PDT 2025

Total time taken to generate the page: 0.32352 seconds