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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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