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

Home » Public Forums » archive » Create a structure in IDL
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
Create a structure in IDL [message #94248] Mon, 06 March 2017 11:53 Go to next message
francisco.pozon is currently offline  francisco.pozon
Messages: 2
Registered: March 2017
Junior Member
Hello everyone:

I would like to create a structure in IDL and put the information from my ASCII file. The problem is that I have several ASCII files and always the number of columns and rows are different. For example, I have the ASCII file "data.dat" and has 50 lines and 2040 columns. I know that we can define the data structure (if we assume I have only 5 columns):

datastruct = { col1:0L, col2:0.0, col3:0.0, col4:0.0, col5:0.0}

I can read my file and then replicate the structure:

file = 'data.dat'
nrows = file_line(file) ; to estimate the number of rows
data = replicate(datastruct, nrows)
openr, lun, file, /GET_LUN
readF, lun, data
free_lun, lun

I can do: print, data.col1 or print, data.col2 and so on... but this will give me only the first 5 columns. How I can do the same but for 2040 columns and also when we don't know in advance the number of columns in the file. Thanks for your help!
Re: Create a structure in IDL [message #94250 is a reply to message #94248] Mon, 06 March 2017 16:00 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
You can make repeated calls to the intrinsic CREATE_STRUCT() function to build up your structure. For example, to make a structure with 10 tags of scalar floats

IDL> name = 'col' + strtrim(indgen(10),2)
IDL> struct = create_struct(name[0],0.)
IDL> for i=1,9 do struct= create_struct(temporary(struct),name[i],0.0)
IDL> help,/str,struct
** Structure <23013f8>, 10 tags, length=40, data length=40, refs=1:
COL0 FLOAT 0.00000
COL1 FLOAT 0.00000
COL2 FLOAT 0.00000
COL3 FLOAT 0.00000
COL4 FLOAT 0.00000
COL5 FLOAT 0.00000
COL6 FLOAT 0.00000
COL7 FLOAT 0.00000
COL8 FLOAT 0.00000
COL9 FLOAT 0.00000

You can also use https://idlastro.gsfc.nasa.gov/ftp/pro/structure/mrd_struct. pro
which is a wrapper for building a structure this way, e.g.

IDL> str = mrd_struct(name,replicate('0.',10),1)
IDL> help,/str,str
** Structure <2216d78>, 10 tags, length=40, data length=40, refs=1:
COL0 FLOAT 0.00000
COL1 FLOAT 0.00000
COL2 FLOAT 0.00000
COL3 FLOAT 0.00000
COL4 FLOAT 0.00000
COL5 FLOAT 0.00000
COL6 FLOAT 0.00000
COL7 FLOAT 0.00000
COL8 FLOAT 0.00000
COL9 FLOAT 0.00000

--Wayne

On Monday, March 6, 2017 at 2:53:55 PM UTC-5, Francisco wrote:
> Hello everyone:
>
> I would like to create a structure in IDL and put the information from my ASCII file. The problem is that I have several ASCII files and always the number of columns and rows are different. For example, I have the ASCII file "data.dat" and has 50 lines and 2040 columns. I know that we can define the data structure (if we assume I have only 5 columns):
>
> datastruct = { col1:0L, col2:0.0, col3:0.0, col4:0.0, col5:0.0}
>
> I can read my file and then replicate the structure:
>
> file = 'data.dat'
> nrows = file_line(file) ; to estimate the number of rows
> data = replicate(datastruct, nrows)
> openr, lun, file, /GET_LUN
> readF, lun, data
> free_lun, lun
>
> I can do: print, data.col1 or print, data.col2 and so on... but this will give me only the first 5 columns. How I can do the same but for 2040 columns and also when we don't know in advance the number of columns in the file. Thanks for your help!
Re: Create a structure in IDL [message #94252 is a reply to message #94250] Tue, 07 March 2017 12:23 Go to previous message
francisco.pozon is currently offline  francisco.pozon
Messages: 2
Registered: March 2017
Junior Member
Thank you very much! This helps a lot to understand the use of structures!
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: P-value, DF, Variance
Next Topic: Undefined procedure/function: 'REVERSE'

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

Current Time: Wed Oct 08 07:06:45 PDT 2025

Total time taken to generate the page: 0.00379 seconds