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

Last change on this file since 231 was 231, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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