;+ ; ; @file_comments ; ; @categories ; ; @param EVENT ; ; @returns ; ; @uses ; ; @restrictions ; ; @examples ; ; @history ; ; @version ; $Id$ ; ; @todo seb ; ;- FUNCTION createhopestruct, event ; compile_opt idl2, strictarrsubs ; widget_control, event.top, get_uvalue=top_uvalue ; find the selected variable selected = *top_uvalue[1, findline(top_uvalue, 'selected')] ; get the variable id varid=(*top_uvalue[1, findline(top_uvalue, 'datavarid')])[selected] ; get the section type type = (*top_uvalue[1, findline(top_uvalue, 'sectype')])[selected] ; get its dimension dimsvar=(*top_uvalue[1, findline(top_uvalue, 'dimvar')])[*,selected] tosort=sortdim(completetype(type)) dimsvar=dimsvar[tosort] ; get the specified spatial domain and build reading parameters linetype =(*top_uvalue[1, findline(top_uvalue, 'linetype')])[selected] case linetype of 'odd':domainid = widget_info(event.top,find_by_uname = 'basedomainodd') 'even':domainid = widget_info(event.top,find_by_uname = 'basedomaineven') 'odd-even':domainid = widget_info(event.top,find_by_uname = 'basedomainodd-even') endcase allaxes=*top_uvalue[1, findline(top_uvalue, 'dimlist')] xaxis=allaxes.(dimsvar[0]) xlimits = *top_uvalue[1, findline(top_uvalue, 'xlimits')] if NOT keyword_set(xlimits) then begin xid=widget_info(domainid,find_by_uname = 'xinterval') widget_control, xid, get_value=xint endif ELSE xint = xaxis[where(xaxis GE xlimits[0] AND xaxis LE xlimits[1])] yaxis=allaxes.(dimsvar[1]) yaxis = reverse(yaxis) ; latitudes from the south to the north ylimits = *top_uvalue[1, findline(top_uvalue, 'ylimits')] if NOT keyword_set(ylimits) then begin yid=widget_info(domainid,find_by_uname = 'yinterval') widget_control, yid, get_value=yint endif ELSE yint = yaxis[where(yaxis GE ylimits[0] AND yaxis LE ylimits[1])] zaxis=allaxes.(dimsvar[2]) zlimits = *top_uvalue[1, findline(top_uvalue, 'zlimits')] if NOT keyword_set(zlimits) then begin zid=widget_info(domainid,find_by_uname = 'zinterval') widget_control, zid, get_value=zint endif ELSE zint = zaxis[where(zaxis GE zlimits[0] AND zaxis LE zlimits[1])] ; time axis and time interval time=allaxes.(dimsvar[3]) yyyymmdd = vairdate(time) tlimits = *top_uvalue[1, findline(top_uvalue, 'tlimits')] if NOT keyword_set(tlimits) then BEGIN date1id = widget_info(event.top, find_by_uname = 'date1') widget_control, date1id, get_value = date1 date2id = widget_info(event.top, find_by_uname = 'date2') widget_control, date2id, get_value = date2 tlimits = [date1, date2] ENDIF tint = time[where(yyyymmdd GE tlimits[0] AND yyyymmdd LE tlimits[1])] ; ; limits of the domain ; nxt = n_elements(xint) nyt = n_elements(yint) nzt = n_elements(zint) jpt = n_elements(tint) ; firstx = (where(xaxis GE xint[0]))[0] firsty = (where(yaxis GE yint[0]))[0] lasty = firsty+nyt-1 firstz = (where(zaxis GE zint[0]))[0] firstt = (where(time GE tint[0]))[0] ; ; read the array ; cdfid=ncdf_open(*top_uvalue[1, findline(top_uvalue, 'filename')]) offset=[firstx,n_elements(yaxis)-lasty-1,firstz,firstt] count=[nxt,nyt,nzt,jpt] tosortinv=sortdim(completetype(type),/inv) ; sort the offset and count for the case of the array is not written ; as a xyzt array but for example as a yzxt array.... offset=offset[tosortinv] count=count[tosortinv] ; call to ncdf_varget ncdf_varget, cdfid, varid, array, offset=offset, count=count ; ; force to keep the dimension equal to 1 if count[3] eq 1 then array=reform(array,count[0],count[1],count[2],count[3],/over) if not (array_equal(tosort, lindgen(4))) then array=transpose(temporary(array),tosort) count=[nxt,nyt,nzt,jpt] if jpt eq 1 then array=reform(array,count[0],count[1],count[2],count[3],/over) array=reverse(array, 2, /over) ; if there is no longitude zoom, shift the array to obtain longitude ; between 20 and 380 if nxt EQ 128 OR nxt EQ 256 then begin key_shift = -(where(xaxis GE 20))[0] xaxis = shift(temporary(xaxis), key_shift) xaxis[where(xaxis LT 20)] = xaxis[where(xaxis LT 20)]+360 array = shift(temporary(array), key_shift, 0, 0, 0) ENDIF ELSE key_shift = 0 ; get some informations about the array insidevar=ncdf_varinq(cdfid,varid) if insidevar.natts NE 0 then begin attnames = strarr(insidevar.natts) for attiq=0,insidevar.natts-1 do attnames[attiq]=strlowcase(ncdf_attname(cdfid,varid,attiq)) ; get the name if (where(attnames EQ 'long_name'))[0] EQ -1 then value = '' $ ELSE ncdf_attget,cdfid,varid,'long_name',value varname = strtrim(string(value), 2) ; get the units if (where(attnames EQ 'units'))[0] EQ -1 then value = '' $ ELSE ncdf_attget,cdfid,varid,'units',value varunit = strtrim(string(value), 2) ; get the 'missing_value' if (where(attnames EQ 'missing_value'))[0] EQ -1 then valmask = 1e20 $ ELSE ncdf_attget,cdfid,varid,'missing_value', valmask ENDIF ELSE BEGIN varunit = '' valmask = 1e20 varname = '' ENDELSE varexp = '' ; ; build arguments to use computehopegrid and put it together in a structure firsts = [firstx,firsty,firstz] lasts = [firstx+nxt-1,firsty+nyt-1,firstz+nzt-1] vargrid = (*top_uvalue[1, findline(top_uvalue, 'pointtype')])[selected] hopegrid = {xaxis:xaxis, yaxis:yaxis, zaxis:zaxis, firsts:firsts, lasts:lasts, type:type, linetype:linetype, pttype:vargrid} hopestru = {array:array, unit:varunit, name:varname, date:time[firstt:firstt+jpt-1], grid:vargrid, hopegrid:hopegrid} ; we close the netcdf file before living! ncdf_close, cdfid return, hopestru end