Re: "shrink" structures [message #69723] |
Tue, 09 February 2010 23:43  |
Johannes Korn
Messages: 5 Registered: January 2010
|
Junior Member |
|
|
David Fanning wrote:
> Johannes Korn writes:
>
>> Hi,
>>
>> I usually read ascii tables using read_ascii with a ascii template which
>> gives me an anonymous structure with fields of the same length.
>>
>> for example
>> d=READ_ASCII('file', TEMPLATE=templ)
>>
>> afterwards d is d.date, d.time and d.value
>>
>> I would like to "shrink" d to contain only a specific date.
>>
>> Something like
>> ind=where(d.date eq '10052000')
>> d = d[ind]
>>
>> This doesn't work of course but I thought at least d.date = d.date[ind]
>> should. But this doesn't resize d.date but only fills all locations with
>> the values of d.date[ind].
>>
>> Is there any other way than to copy everything to arrays?
>
> How about a shrunken structure? Consider this function:
>
> ;*********************************************************** ************
> Function ShrinkStruct, struct, indices
>
> tags = N_Tags(struct)
> fieldNames = Tag_Names(struct)
>
> newStruct = Create_Struct(fieldNames[0], $
> (struct.(0))[indices])
> FOR j=1,tags-1 DO BEGIN
> newStruct = Create_Struct(newStruct, fieldnames[j], $
> (struct.(j))[indices])
> ENDFOR
>
> RETURN, newStruct
>
> END
> ;*********************************************************** ************
That's what I was looking for. Thanks a lot!
Johannes
|
|
|