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

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