Extract a sub-structure from a structure [message #47181] |
Thu, 26 January 2006 07:29 |
L. Testut
Messages: 16 Registered: January 2006
|
Junior Member |
|
|
; Dear all,
; I have a big structure st={lat:FLTARR(N), lon:FLTARR(N),
para1:FLTARR(N),..., paraN:INTARR(N)} with many parameters
; Lat and lon represent coordinates of an altimetric point above the
sea surface and concern let's the entire globe.
; What I want to do is to extract a sub-region from this struture, I've
seen that there is at least two solutions :
; 1) I create a new structure of the new size
; 2) or I use pointer to change the size of my field whitout defining a
new structure
;
;
; I prefer the second solution but I only manage to do the first one
!!!
;*******SOLUTION 1***************
; I define stn "normal" structure
stn = {x:findgen(100),y:findgen(100),z:(indgen(100)+500.),
para1:LONARR(100), para2:INTARR(100)}
help,stn,/str
; I select a sub-region of interest
IDN = WHERE((stn.x LT 50) AND (stn.y LT 50),count)
print,count
plot,stn.x[ID],stn.y[ID]
; Now if I want to work with a struture representative of the
sub-region which is smaller
; and needs less computing time I have to do some contorsions like :
tag = tag_names(stn)
NewStn = CREATE_STRUCT(tag[0], FINDGEN(count))
FOR i=1,N_ELEMENTS(tag)-1 DO NewStn=CREATE_STRUCT(NewStn, tag[i],
FINDGEN(count))
help,NewStn,/str
; ! It seems to be OK ! (unless the field type have changed ! ) Now I
tried the second solution
;*******SOLUTION 2***************
; I define stp "pointer" struture
stp =
{x:ptr_new(findgen(100)),y:ptr_new(findgen(100)),z:ptr_new(( indgen(100)+500.)),
para1:ptr_new(LONARR(100)), para2:ptr_new(INTARR(100))}
help,stp, /str
; I select a sub-region of interest
IDP = WHERE((*stp.x LT 50) AND (*stp.y LT 50),count)
print,count
; it works ok until now
; Then as I am very optimistic I want to do that:
tag = tag_names(stp)
FOR i=1,N_ELEMENTS(tag)-1 DO *stp.(i)=*stp.(i)[IDP]
;but it doesnt' work ? is there somebody that can tell me what is the
;right way to replace in my structure the total region with the
;sub-region for all the parameter of course !
; Thanks a lot !
; Laurent
|
|
|