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

Home » Public Forums » archive » defining structure after ascii template
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
defining structure after ascii template [message #85878] Mon, 16 September 2013 08:56 Go to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
Hello,

As far as I can see, it is not possible to define a structure using a template as the one built via ascii_template(). Essentially, extract a sub-structure from the template returned by ascii_template, containing the column names as tags and the field type. What is the proper way to do this?

Thanks,
Seb
Re: defining structure after ascii template [message #85879 is a reply to message #85878] Mon, 16 September 2013 09:02 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
spluque@gmail.com writes:

> As far as I can see, it is not possible to define a structure using a template as the one built via ascii_template(). Essentially, extract a sub-structure from the template returned by ascii_template, containing the column names as tags and the field type. What is the proper way to do this?

I honestly have no idea what this question means. Why don't you explain
to us what you are trying to do.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: defining structure after ascii template [message #85880 is a reply to message #85879] Mon, 16 September 2013 10:02 Go to previous messageGo to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
On Monday, September 16, 2013 11:02:11 AM UTC-5, David Fanning wrote:
> spluque@gmail.com writes:
>
>
>
>> As far as I can see, it is not possible to define a structure using a template as the one built via ascii_template(). Essentially, extract a sub-structure from the template returned by ascii_template, containing the column names as tags and the field type. What is the proper way to do this?
>
>
>
> I honestly have no idea what this question means. Why don't you explain
>
> to us what you are trying to do.

Sorry for the terse initial post. Here is what I am trying to do:

1. I've prepared a template with ascii_template() for reading in an ASCII file via read_ascii().

2. Before reading the data with read_ascii(), I need to prepare an *array* of structures, where each element is a record (row) in a number of files to be read with the template in (1).

3. read_ascii() creates a structure that looks like this:

help, data, /structures
** Structure <57e3008>, 23 tags, length=7800864, data length=7800864, refs=1:
FIELD01 LONG Array[84792]
FIELD02 FLOAT Array[84792]
FIELD03 LONG Array[84792]
...[many more fields]

So the array of structures to be created would like this (abbreviating the number of fields for brevity here):

p={'foo', FIELD01:0L, FIELD02:0.0, FIELD03:0L}
replicate(p, n_recs)

where n_recs is the total number of records expected.

So the question is how can p be created from the information already there in the template created in (1)?

Thanks,
Seb
Re: defining structure after ascii template [message #85882 is a reply to message #85880] Mon, 16 September 2013 10:24 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
spluque@gmail.com writes:

>
> On Monday, September 16, 2013 11:02:11 AM UTC-5, David Fanning wrote:
>> spluque@gmail.com writes:
>>
>>
>>
>>> As far as I can see, it is not possible to define a structure using a template as the one built via ascii_template(). Essentially, extract a sub-structure from the template returned by ascii_template, containing the column names as tags and the field type. What is the proper way to do this?
>>
>>
>>
>> I honestly have no idea what this question means. Why don't you explain
>>
>> to us what you are trying to do.
>
> Sorry for the terse initial post. Here is what I am trying to do:
>
> 1. I've prepared a template with ascii_template() for reading in an ASCII file via read_ascii().
>
> 2. Before reading the data with read_ascii(), I need to prepare an *array* of structures, where each element is a record (row) in a number of files to be read with the template in (1).
>
> 3. read_ascii() creates a structure that looks like this:
>
> help, data, /structures
> ** Structure <57e3008>, 23 tags, length=7800864, data length=7800864, refs=1:
> FIELD01 LONG Array[84792]
> FIELD02 FLOAT Array[84792]
> FIELD03 LONG Array[84792]
> ...[many more fields]
>
> So the array of structures to be created would like this (abbreviating the number of fields for brevity here):
>
> p={'foo', FIELD01:0L, FIELD02:0.0, FIELD03:0L}
> replicate(p, n_recs)
>
> where n_recs is the total number of records expected.
>
> So the question is how can p be created from the information already there in the template created in (1)?

Well, p *is* the structure you obtained. I guess I don't see the
problem:

IDL> struct = ascii_template()
IDL> help, struct
** Structure <701c24d0>, 10 tags, length=320, data length=313, refs=1:
VERSION FLOAT 1.00000
DATASTART LONG 0
DELIMITER BYTE 32
MISSINGVALUE FLOAT NaN
COMMENTSYMBOL STRING ''
FIELDCOUNT LONG 10
FIELDTYPES LONG Array[10]
FIELDNAMES STRING Array[10]
FIELDLOCATIONS LONG Array[10]
FIELDGROUPS LONG Array[10]
IDL> data = Replicate(struct, 100)

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: defining structure after ascii template [message #85884 is a reply to message #85882] Mon, 16 September 2013 10:51 Go to previous messageGo to next message
spluque is currently offline  spluque
Messages: 33
Registered: September 2013
Member
On Monday, September 16, 2013 12:24:29 PM UTC-5, David Fanning wrote:
> spluque@gmail.com writes:
>
>
>
>>
>
>> On Monday, September 16, 2013 11:02:11 AM UTC-5, David Fanning wrote:
>
>>> spluque@gmail.com writes:
>
>>>
>
>>>
>
>>>
>
>>>> As far as I can see, it is not possible to define a structure using a template as the one built via ascii_template(). Essentially, extract a sub-structure from the template returned by ascii_template, containing the column names as tags and the field type. What is the proper way to do this?
>
>>>
>
>>>
>
>>>
>
>>> I honestly have no idea what this question means. Why don't you explain
>
>>>
>
>>> to us what you are trying to do.
>
>>
>
>> Sorry for the terse initial post. Here is what I am trying to do:
>
>>
>
>> 1. I've prepared a template with ascii_template() for reading in an ASCII file via read_ascii().
>
>>
>
>> 2. Before reading the data with read_ascii(), I need to prepare an *array* of structures, where each element is a record (row) in a number of files to be read with the template in (1).
>
>>
>
>> 3. read_ascii() creates a structure that looks like this:
>
>>
>
>> help, data, /structures
>
>> ** Structure <57e3008>, 23 tags, length=7800864, data length=7800864, refs=1:
>
>> FIELD01 LONG Array[84792]
>
>> FIELD02 FLOAT Array[84792]
>
>> FIELD03 LONG Array[84792]
>
>> ...[many more fields]
>
>>
>
>> So the array of structures to be created would like this (abbreviating the number of fields for brevity here):
>
>>
>
>> p={'foo', FIELD01:0L, FIELD02:0.0, FIELD03:0L}
>
>> replicate(p, n_recs)
>
>>
>
>> where n_recs is the total number of records expected.
>
>>
>
>> So the question is how can p be created from the information already there in the template created in (1)?
>
>
>
> Well, p *is* the structure you obtained. I guess I don't see the
>
> problem:
>
>
>
> IDL> struct = ascii_template()
>
> IDL> help, struct
>
> ** Structure <701c24d0>, 10 tags, length=320, data length=313, refs=1:
>
> VERSION FLOAT 1.00000
>
> DATASTART LONG 0
>
> DELIMITER BYTE 32
>
> MISSINGVALUE FLOAT NaN
>
> COMMENTSYMBOL STRING ''
>
> FIELDCOUNT LONG 10
>
> FIELDTYPES LONG Array[10]
>
> FIELDNAMES STRING Array[10]
>
> FIELDLOCATIONS LONG Array[10]
>
> FIELDGROUPS LONG Array[10]
>
> IDL> data = Replicate(struct, 100)


Thanks for your patience David. The problem is that the template structure is not quite the same as the one created by read_ascii(); compare the output you got with the one in point (2) of my previous message. In other words, what I need to replicate is an element of the output of read_ascii(), but without having to call it first. Hopefully, this is clearer.

Cheers,
Seb
Re: defining structure after ascii template [message #85886 is a reply to message #85884] Mon, 16 September 2013 10:58 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
spluque@gmail.com writes:

> Thanks for your patience David. The problem is that the template structure is not quite the same as the one created by read_ascii(); compare the output you got with the one in point (2) of my previous message. In other words, what I need to replicate is an element of the output of read_ascii(), but without having to call it first. Hopefully, this is clearer.

Sorry, it's just not getting through to me. Maybe someone else will have
some luck. :-)

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: defining structure after ascii template [message #85916 is a reply to message #85878] Wed, 18 September 2013 03:14 Go to previous message
markb77 is currently offline  markb77
Messages: 217
Registered: July 2006
Senior Member
I think the structure you get back from ascii_template is actually correct - you just use it with the read_ascii command. You don't need to create a new structure.

Mark
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Merits of different ways of 'extending' arrays
Next Topic: Import data in IDL from other source

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

Current Time: Wed Oct 08 13:34:30 PDT 2025

Total time taken to generate the page: 0.00523 seconds