source: trunk/SRC/ToBeReviewed/HOPE/createhopestruct.pro @ 114

Last change on this file since 114 was 114, checked in by smasson, 18 years ago

new compilation options (compile_opt idl2, strictarrsubs) in each routine

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