source: trunk/ToBeReviewed/HOPE/createhopestruct.pro @ 53

Last change on this file since 53 was 53, checked in by pinsard, 18 years ago

upgrade of ToBeReviewed?/HOPE according to cerbere.lodyc.jussieu.fr: /usr/home/smasson/SAXO_RD/

  • Property svn:executable set to *
File size: 5.4 KB
Line 
1FUNCTION createhopestruct, event
2   widget_control, event.top, get_uvalue=top_uvalue
3; find the selected variable
4   selected = *top_uvalue[1, findline(top_uvalue, 'selected')]
5; get the variable id
6   varid=(*top_uvalue[1, findline(top_uvalue, 'datavarid')])[selected]
7; get the section type
8   type = (*top_uvalue[1, findline(top_uvalue, 'sectype')])[selected]
9; get its dimension
10   dimsvar=(*top_uvalue[1, findline(top_uvalue, 'dimvar')])[*,selected]
11   tosort=sortdim(completetype(type))
12   dimsvar=dimsvar[tosort]
13; get the specified spatial domain and build reading parameters
14   linetype =(*top_uvalue[1, findline(top_uvalue, 'linetype')])[selected]
15   case linetype of
16      'odd':domainid = widget_info(event.top,find_by_uname = 'basedomainodd')
17      'even':domainid = widget_info(event.top,find_by_uname = 'basedomaineven')
18      'odd-even':domainid = widget_info(event.top,find_by_uname = 'basedomainodd-even')
19   endcase
20   allaxes=*top_uvalue[1, findline(top_uvalue, 'dimlist')]
21   xaxis=allaxes.(dimsvar[0])
22   xlimits = *top_uvalue[1, findline(top_uvalue, 'xlimits')]
23   if NOT keyword_set(xlimits) then begin
24      xid=widget_info(domainid,find_by_uname = 'xinterval')
25      widget_control, xid, get_value=xint
26   endif ELSE xint = xaxis[where(xaxis GE xlimits[0] AND xaxis LE xlimits[1])]
27   yaxis=allaxes.(dimsvar[1])
28   yaxis = reverse(yaxis)       ; latitudes from the south to the north
29   ylimits = *top_uvalue[1, findline(top_uvalue, 'ylimits')]
30   if NOT keyword_set(ylimits) then begin
31      yid=widget_info(domainid,find_by_uname = 'yinterval')
32      widget_control, yid, get_value=yint
33   endif ELSE yint = yaxis[where(yaxis GE ylimits[0] AND yaxis LE ylimits[1])]
34   zaxis=allaxes.(dimsvar[2])
35   zlimits = *top_uvalue[1, findline(top_uvalue, 'zlimits')]
36   if NOT keyword_set(zlimits) then begin
37      zid=widget_info(domainid,find_by_uname = 'zinterval')
38      widget_control, zid, get_value=zint
39   endif ELSE zint = zaxis[where(zaxis GE zlimits[0] AND zaxis LE zlimits[1])]
40; time axis and time interval
41   time=allaxes.(dimsvar[3])
42   yyyymmdd = vairdate(time)
43   tlimits = *top_uvalue[1, findline(top_uvalue, 'tlimits')]
44   if NOT keyword_set(tlimits) then BEGIN
45      date1id = widget_info(event.top, find_by_uname = 'date1')
46      widget_control, date1id, get_value = date1
47      date2id = widget_info(event.top, find_by_uname = 'date2')
48      widget_control, date2id, get_value = date2
49      tlimits = [date1, date2]
50   ENDIF
51   tint = time[where(yyyymmdd GE tlimits[0] AND yyyymmdd LE tlimits[1])]
52;
53; limits of the domain
54;
55   nxt = n_elements(xint)
56   nyt = n_elements(yint)
57   nzt = n_elements(zint)
58   jpt = n_elements(tint)
59;
60   firstx = (where(xaxis GE xint[0]))[0]
61   firsty = (where(yaxis GE yint[0]))[0]
62   lasty = firsty+nyt-1
63   firstz = (where(zaxis GE zint[0]))[0]
64   firstt = (where(time GE tint[0]))[0]
65;
66; read the array
67;
68   cdfid=ncdf_open(*top_uvalue[1, findline(top_uvalue, 'filename')])
69   offset=[firstx,n_elements(yaxis)-lasty-1,firstz,firstt]
70   count=[nxt,nyt,nzt,jpt]
71   tosortinv=sortdim(completetype(type),/inv)
72; sort the offset and count for the case of the array is not written
73; as a xyzt array but for example as a yzxt array....
74   offset=offset[tosortinv]
75   count=count[tosortinv]
76; call to ncdf_varget
77   ncdf_varget, cdfid, varid, array, offset=offset, count=count ;
78; force to keep the dimension equal to 1
79   if count[3] eq 1 then array=reform(array,count[0],count[1],count[2],count[3],/over)
80   if not (array_equal(tosort, lindgen(4))) then array=transpose(temporary(array),tosort)
81   count=[nxt,nyt,nzt,jpt]
82   if jpt eq 1 then array=reform(array,count[0],count[1],count[2],count[3],/over)
83   array=reverse(array, 2, /over)
84; if there is no longitude zoom, shift the array to obtain longitude
85; between 20 and 380
86   if nxt EQ 128 OR nxt EQ 256 then begin
87      key_shift = -(where(xaxis GE 20))[0]
88      xaxis = shift(temporary(xaxis), key_shift)
89      xaxis[where(xaxis LT 20)] = xaxis[where(xaxis LT 20)]+360
90      array = shift(temporary(array), key_shift, 0, 0, 0)
91   ENDIF ELSE key_shift = 0
92; get some informations about the array
93   insidevar=ncdf_varinq(cdfid,varid)
94   if insidevar.natts NE 0 then begin
95      attnames = strarr(insidevar.natts)
96      for attiq=0,insidevar.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,varid,attiq))
97; get the name
98      if (where(attnames EQ 'long_name'))[0] EQ -1 then value = '' $
99      ELSE ncdf_attget,cdfid,varid,'long_name',value
100      varname = strtrim(string(value), 2)
101; get the units
102      if (where(attnames EQ 'units'))[0] EQ -1 then value = '' $
103      ELSE ncdf_attget,cdfid,varid,'units',value
104      varunit = strtrim(string(value), 2)
105; get the 'missing_value'
106      if (where(attnames EQ 'missing_value'))[0] EQ -1 then valmask = 1e20 $
107      ELSE ncdf_attget,cdfid,varid,'missing_value', valmask
108   ENDIF ELSE BEGIN
109      varunit = ''
110      valmask = 1e20
111      varname = ''
112   ENDELSE
113   varexp = ''
114;
115; build arguments to use computehopegrid and put it together in a structure
116   firsts = [firstx,firsty,firstz]
117   lasts = [firstx+nxt-1,firsty+nyt-1,firstz+nzt-1]
118   vargrid = (*top_uvalue[1, findline(top_uvalue, 'pointtype')])[selected]
119   hopegrid = {xaxis:xaxis, yaxis:yaxis, zaxis:zaxis, firsts:firsts, lasts:lasts, type:type, linetype:linetype, pttype:vargrid}
120   hopestru = {array:array, unit:varunit, name:varname, date:time[firstt:firstt+jpt-1], grid:vargrid, hopegrid:hopegrid}
121; we close the netcdf file before living!
122   ncdf_close,  cdfid
123   return, hopestru
124end
Note: See TracBrowser for help on using the repository browser.