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

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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