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

Last change on this file since 142 was 142, checked in by navarro, 18 years ago

english and nicer header (2a)

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