;+
;
; @file_comments
;
; @categories
;
; @param EVENT
;
; @returns
;
; @restrictions
;
; @examples
;
; @history
;
; @version
; $Id$
;
;-
;
PRO read_hope_event, event
;
compile_opt idl2, strictarrsubs
;
widget_control, event.id, get_uvalue=uval
widget_control, event.top, get_uvalue=top_uvalue
case uval.name OF
;---------------------------------
'cancel':begin
; close the file
cdfid=*top_uvalue[1, findline(top_uvalue, 'cdfid')]
ncdf_close, cdfid
; clear the pointer
for i=0,n_elements(top_uvalue)-1 do ptr_free, top_uvalue[i]
; kill the widget
widget_control,event.top,/destroy
end
;---------------------------------
'type choice':begin
; find the new type of selected section
typeindex=widget_info(event.id,/droplist_select)
selectedtype=(*top_uvalue[1, findline(top_uvalue, 'type choice')])[typeindex]
; find the available variables for this type of section
sectype = *top_uvalue[1, findline(top_uvalue, 'sectype')]
goodvar = where(sectype EQ selectedtype)
namevar = *top_uvalue[1, findline(top_uvalue, 'namevar')]
goodnamevar = namevar[goodvar]
; find the selected var name
varchoiceid = widget_info(event.top,find_by_uname = 'var choice')
varindex = widget_info(varchoiceid,/droplist_select)
varchoice = *top_uvalue[1, findline(top_uvalue, 'var choice')]
selectedvarname=varchoice[varindex]
; do we change the variable?
if (where(goodnamevar EQ selectedvarname))[0] EQ -1 then begin
selectedvarname = goodnamevar[0]
varindex = (where(varchoice EQ selectedvarname))[0]
widget_control, varchoiceid, set_droplist_select = varindex
ENDIF
; displays the different domains
selected = goodvar[where(goodnamevar EQ selectedvarname)]
rh_alldomains, event.top, selected
end
;---------------------------------
'var choice':BEGIN
; find the new variable
varindex=widget_info(event.id,/droplist_select)
selectedvar=(*top_uvalue[1, findline(top_uvalue, 'var choice')])[varindex]
; find the available variables for this type of section
namevar = *top_uvalue[1, findline(top_uvalue, 'namevar')]
goodvar = where(namevar EQ selectedvar)
sectype = *top_uvalue[1, findline(top_uvalue, 'sectype')]
goodtype = sectype[goodvar]
; find the selected type of section
typechoiceid = widget_info(event.top,find_by_uname = 'type choice')
typeindex = widget_info(typechoiceid,/droplist_select)
typechoice = *top_uvalue[1, findline(top_uvalue, 'type choice')]
selectedtype=typechoice[typeindex]
; do we change the type of section ?
if (where(goodtype EQ selectedtype))[0] EQ -1 then begin
selectedtype = goodtype[0]
typeindex = (where(typechoice EQ selectedtype))[0]
widget_control, typechoiceid, set_droplist_select = typeindex
ENDIF
; displays the different domains
selected = goodvar[where(goodtype EQ selectedtype)]
rh_alldomains, event.top, selected
END
;---------------------------------
'plot':BEGIN
; plot the array
res = createhopestruct(event)
; type of section
selected = *top_uvalue[1, findline(top_uvalue, 'selected')]
type = (*top_uvalue[1, findline(top_uvalue, 'sectype')])[selected]
; get the informations of cw_specifie
specifieid=widget_info(event.top,find_by_uname = 'specifie')
widget_control, specifieid, get_value = specifie
specifie = struct2string(specifie,/direct2string)
case type of
'x':command = 'plt1d,res,''x'','+specifie
'y':command = 'plt1d,res,''y'','+specifie
'z':command = 'plt1d,res,''z'','+specifie
't':command = 'pltt,res,''t'' ,'+specifie
'xy':command = 'plt, res,'+specifie
'xz':command = 'pltz, res,''xz'','+specifie
'yz':command = 'pltz, res,''yz'','+specifie
'xt':command = 'pltt,res,''xt'','+specifie
'yt':command = 'pltt,res,''yt'','+specifie
'zt':command = 'pltt,res,''zt'','+specifie
'xyz':
'xyt':
'yzt':
'xyzt':
ENDCASE
test = execute(command)
if test EQ 0 then stop
end
;---------------------------------
'linechoice':BEGIN
if event.select EQ 1 then begin
sensitive = bytarr(3)
sensitive[where(['odd', 'even', 'odd-even'] eq event.value)] = 1
basedomainodd=widget_info(event.top,find_by_uname = 'basedomainodd')
widget_control, basedomainodd, sensitive = sensitive[0]
basedomaineven=widget_info(event.top,find_by_uname = 'basedomaineven')
widget_control, basedomaineven, sensitive = sensitive[1]
basedomainoddeven=widget_info(event.top,find_by_uname = 'basedomainodd-even')
widget_control, basedomainoddeven, sensitive = sensitive[2]
case (where(sensitive EQ 1))[0] of
0:BEGIN
widget_control, basedomainodd, get_uvalue = oddsecchoice
oddsecchoiceid=widget_info(event.top,find_by_uname = 'oddsecchoice')
if oddsecchoiceid NE 0 then $
index = widget_info(oddsecchoiceid, /droplist_select) $
ELSE index = 0
*top_uvalue[1, findline(top_uvalue, 'selected')] = oddsecchoice[index]
END
1:BEGIN
widget_control, basedomaineven, get_uvalue = evensecchoice
evensecchoiceid=widget_info(event.top,find_by_uname = 'evensecchoice')
if evensecchoiceid NE 0 then $
index = widget_info(evensecchoiceid, /droplist_select) $
ELSE index = 0
*top_uvalue[1, findline(top_uvalue, 'selected')] = evensecchoice[index]
END
2:BEGIN
widget_control, basedomainodd, get_uvalue = oddevensecchoice
oddevensecchoiceid=widget_info(event.top,find_by_uname = 'odd-evensecchoice')
if oddevensecchoiceid NE 0 then $
index = widget_info(oddevensecchoiceid, /droplist_select) $
ELSE index = 0
*top_uvalue[1, findline(top_uvalue, 'selected')] = oddevensecchoice[index]
END
endcase
endif
END
;---------------------------------
'oddsecchoice':BEGIN
widget_control, event.top, update=0
basedomainodd=widget_info(event.top,find_by_uname = 'basedomainodd')
widget_control, basedomainodd, get_uvalue = oddsecchoice
domainpart, top_uvalue, basedomainodd, oddsecchoice[event.index]
*top_uvalue[1, findline(top_uvalue, 'selected')] = oddsecchoice[event.index]
widget_control, event.top, update=1
END
;---------------------------------
'evensecchoice':BEGIN
widget_control, event.top, update=0
basedomaineven=widget_info(event.top,find_by_uname = 'basedomaineven')
widget_control, basedomaineven, get_uvalue = evensecchoice
domainpart, top_uvalue, basedomaineven, evensecchoice[event.index]
*top_uvalue[1, findline(top_uvalue, 'selected')] = evensecchoice[event.index]
widget_control, event.top, update=1
END
;---------------------------------
'odd-evensecchoice':BEGIN
widget_control, event.top, update=0
basedomainoddeven=widget_info(event.top,find_by_uname = 'basedomainodd-even')
widget_control, basedomainoddeven, get_uvalue = oddevensecchoice
domainpart, top_uvalue, basedomainoddeven, oddevensecchoice[event.index]
*top_uvalue[1, findline(top_uvalue, 'selected')] = oddevensecchoice[event.index]
widget_control, event.top, update=1
END
;---------------------------------
'date1':BEGIN
date2id = widget_info(event.top, find_by_uname = 'date2')
widget_control, date2id, get_value = date2
if event.value GT date2 then widget_control, date2id, set_value = event.value
END
;---------------------------------
'date2':BEGIN
date1id = widget_info(event.top, find_by_uname = 'date1')
widget_control, date1id, get_value = date1
if event.value LT date1 then widget_control, date1id, set_value = event.value
END
;---------------------------------
else:
endcase
return
end
;
;+
;
; @file_comments
; Read the Hope grid file converted in NetCdf by xconv
;
; @categories
; Reading
;
; @param TYPEIN {in}{required}{type=string}
; A string specifying from which type of section the 4D
; array based: 'xy, 'xz', 'yz'
;
; @param VARNAMEIN {in}{required}{type=string}
; A string the name of the variable to be read (in
; lower or upper case)
;
; @keyword FILENAME {type=string}
; The name of the file to be read
;
; @keyword XLIMITS {type=vector}
; A two elements vector [lonmin, lonmax]]
; the boundary of the longitudes (from 0 to 360)
;
; @keyword YLIMITS {type=vector}
; A two elements vector [latmin, latmax]]
; the boundary of the latitudes (from -90 to 90)
;
; @keyword ZLIMITS {type=vector}
; A two elements vector [depthmin, depthmax]]
; the boundary of the depth
;
; @keyword TLIMITS {type=vector}
; A two elements vector [date1, date2]]
; the boundary of the calendar with date1 and date2
; following the syntax yyyymmdd
;
; @keyword ODDPT
; Activate to read only the sections located on ODD
; points
;
; @keyword EVENPT
; Activate to read only the sections located on even
; points
;
; @keyword ODDEVENPT
; Activate to read only the sections located on
; both even and odd points (horizontal sections)
;
; @keyword _EXTRA
; Used to pass keywords
;
; @returns
; -1 if typein and varnamein are undefined (this is the widget
; version)
;
; A structure which but be read by litchamp and is
; necessary to complete the grid associated to the data (see
; the example).
;
; @uses
; common.pro (useful only for the definition of iodir)
;
; @restrictions
; 'x', 'y', 'z', 't', 'xt', 'yt' and 'zt' section not coded, xconv
; must be able to works with this kind of function.
; The grid file has no zoom possibilities on horizontal dimensions.
;
; @restrictions
;
; When typein and varnamein are defined, the method to find the
; good variable is:
; 1) find the variables which are available on this type of
; sections with this name
; 2) if ODDPT, EVENPT or ODDEVENPT are specified, consider only
; these types of sections
; 3) For an XY section the chosen variable is the one which has
; the most level in the vertical domain specified by ZLIMITS.
; For an XZ section the chosen variable is the one which has
; the most points in the latitude domain specified by YLIMITS.
; For an YZ section the chosen variable is the one which has
; the most points in the longitude domain specified by XLIMITS.
;
;
; @examples
;
; IDL> a=read_hope('xy','ocpt',filename='CLIM_CNT_1993-1998.nc')
; IDL> help, a,/struct
; ** Structure <82ec344>, 6 tags, length=1860176, refs=1:
; ARRAY FLOAT Array[128, 242, 15]
; UNIT STRING 'deg C'
; NAME STRING 'Ocean potential temperature'
; DATE FLOAT Array[1]
; GRID STRING 'T'
; HOPEGRID STRUCT -> Array[1]
; IDL> help, a.hopegrid,/struct
; ** Structure <82eb9cc>, 8 tags, length=1588, refs=2:
; XAXIS FLOAT Array[128]
; YAXIS FLOAT Array[242]
; ZAXIS FLOAT Array[15]
; FIRSTS LONG Array[3]
; LASTS LONG Array[3]
; TYPE STRING 'xy'
; LINETYPE STRING 'odd-even'
; PTTYPE STRING 'T'
; IDL> help, litchamp(a)
; FLOAT = Array[128, 242, 15]
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; June 2001
;
; @version
; $Id$
;
;-
;
FUNCTION read_hope, typein, varnamein, FILENAME = filename, XLIMITS = xlimits, YLIMITS = ylimits, ZLIMITS = zlimits, TLIMITS = tlimits, ODDPT = oddpt, ODDEVENPT = oddevenpt, EVENPT = evenpt, _EXTRA = ex
;
compile_opt idl2, strictarrsubs
;
@common ; usefull only for the definition of iodir
if n_elements(filename) EQ 0 then filename = isafile(iodirectory = iodir, _extra = ex)
IF size(filename, /type) NE 7 THEN return, -1
filename = isafile(filename = filename, iodirectory = iodir, _extra = ex)
;
cdfid = ncdf_open(filename) ; id of the netcdf file
wathinside = ncdf_inquire(cdfid) ; structure with global informations
;-------------------------------
; dimensions
;-------------------------------
namedim = strarr(wathinside.ndims) ; name of the dimensions
typedim = strarr(wathinside.ndims) ; type of the dimensions (x,y,z,t)
sizedim = lonarr(wathinside.ndims) ; size of each dimension
; loop on the dimensions to get the names and sizes
for dimiq = 0, wathinside.ndims-1 do begin
ncdf_diminq, cdfid, dimiq, name, value
namedim[dimiq] = name
case 1 of
STRCMP(name, 'lon', 3, /FOLD_CASE):typedim[dimiq] = 'x'
STRCMP(name, 'lat', 3, /FOLD_CASE):typedim[dimiq] = 'y'
STRCMP(name, 'z', 1, /FOLD_CASE):typedim[dimiq] = 'z'
STRCMP(name, 't', 1, /FOLD_CASE):typedim[dimiq] = 't'
ELSE:BEGIN
ncdf_close, cdfid
return, report('Unknown name of dimension')
END
endcase
sizedim[dimiq] = value
endfor
; dimlist: structure which contains the name and the value of each
; dimension
; we suppose that there is always a variable which has the
; same name that the dimension and which gives the values of
; this dimension
ncdf_varget, cdfid, namedim[0], value
dimlist = create_struct(namedim[0], value)
for dimiq = 1, wathinside.ndims-1 do begin
ncdf_varget, cdfid, namedim[dimiq], value ;get the value
dimlist = create_struct(dimlist, namedim[dimiq], value)
endfor
;-------------------------------
; variables
;-------------------------------
namevar = strarr(wathinside.nvars) ; names of the variables
ndimsvar = lonarr(wathinside.nvars) ; number of dim for each variable
dimvar = replicate(-1, wathinside.ndims, wathinside.nvars) ; dims of each variables
; loop over the variable ids to fill namevar, ndimsvar and dimvar
for varid = 0, wathinside.nvars-1 do begin
res = ncdf_varinq(cdfid, varid)
namevar[varid] = res.name
namevar[varid] = strjoin(strsplit(namevar[varid], '_[0-99]', /EXTRACT, /REGEX))
ndimsvar[varid] = res.ndims
dimvar[0:res.ndims-1, varid] = res.dim
ENDFOR
; we cut dimvar to select only the interessant part
dimvar = dimvar[0:max(ndimsvar)-1, *]
; selection of the data variables which are different from the
; dimension variables
; we suppose that that data variables are 4D array (with sometime
; dimensions equal to 1). they must be different from dimension
; variables which have only 1 dimension
datavarid = where(ndimsvar eq 4)
numberofvar = n_elements(datavarid)
namevar = namevar[datavarid]
ndimsvar = ndimsvar[datavarid]
dimvar = dimvar[*, datavarid]
;
sectype = strarr(numberofvar) ; the type of section for each variable :'xy', 'xz', 'yz'...
linetype = strarr(numberofvar) ; the line of the points : odd, even or odd-even
pointtype = strarr(numberofvar) ; the type of variable : scalar ('T') or vector ('U')
for i = 0, numberofvar-1 do begin
dimofthevar = dimvar[*, i]
sectype[i] = typedim[dimofthevar[0]]+typedim[dimofthevar[1]]
xaxisid = dimofthevar[where(typedim[dimofthevar] EQ 'x')]
yaxisid = dimofthevar[where(typedim[dimofthevar] EQ 'y')]
lineandpt = findlineandpointtype(sectype[i], dimlist.(xaxisid[0]), dimlist.(yaxisid[0]), iodir)
linetype[i] = lineandpt.linetype
pointtype[i] = lineandpt.pointtype
endfor
;
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
; definition of the widget
;---------------------------------------------------
;---------------------------------------------------
;---------------------------------------------------
base = widget_base(/column)
;---------------------------------------------------
; first base:
; droplist to select the type of section
; droplist to select the variable
; button to select type of line : odd, even or odd-even
;---------------------------------------------------
base1 = widget_base(base, /row, /frame)
typechoice = sectype[uniq(sectype, sort(sectype))]
if n_elements(typechoice) GT 1 then typechoice = typechoice[sortdim(typechoice)]
base11 = widget_droplist(base1, title = 'Type of section', value = typechoice, uvalue = {name:'type choice'}, uname = 'type choice')
if n_elements(typein) NE 0 then BEGIN
selectedtype = strmid(typein, 0, 2)
widget_control, base11, set_droplist_select $
= 0L > (where(typechoice EQ selectedtype))[0]
ENDIF ELSE selectedtype = typechoice[0]
;
varchoice = namevar[uniq(namevar, sort(namevar))]
base12 = widget_droplist(base1, title = 'Available data', value = varchoice, uvalue = {name:'var choice'}, uname = 'var choice')
if n_elements(varnamein) NE 0 THEN BEGIN
selectedname = varnamein
widget_control, base12, set_droplist_select $
= 0L > (where(strlowcase(varchoice) EQ strlowcase(varnamein)))[0]
ENDIF ELSE selectedname = varchoice[0]
;
base13 = widget_base(base1, /row, uname = 'linechoicebase')
;---------------------------------------------------
; base 2: base to select the domain of the odd points
;---------------------------------------------------
base2 = widget_base(base, /column, uname = 'basedomainodd', /frame)
;---------------------------------------------------
; base 3: base to select the domain of the even points
;---------------------------------------------------
base3 = widget_base(base, /column, uname = 'basedomaineven', /frame)
;---------------------------------------------------
; base 4: base to select the domain of the odd-even points
;---------------------------------------------------
base4 = widget_base(base, /column, uname = 'basedomainodd-even', /frame)
;---------------------------------------------------
; base 5: calendar
;---------------------------------------------------
base5 = widget_base(base, /row, uname = 'baset', /frame)
timename = strlowcase((tag_names(dimlist))[wathinside.recdim])
; read the time axis in julina days
time = ncdf_gettime(filename, cdfid)
; update the dimlist structure
dimlist.(wathinside.recdim) = time
base51 = cw_calendar(base5, time, uname = 'date1', uvalue = {name:'date1'})
base52 = cw_calendar(base5, time, uname = 'date2', uvalue = {name:'date2'})
;---------------------------------------------------
; base 6: base to select the min, max, ... and others keywords
;---------------------------------------------------
base6 = cw_specifie(base, /column, uname = 'specifie', uvalue = {name:'specifie'})
;---------------------------------------------------
; base 7: last base with the action buttons
;---------------------------------------------------
base7 = widget_base(base, /row, uname = 'finalaction')
base71 = widget_button(base7, value = 'Plot', uvalue = {name:'plot'})
base72 = widget_button(base7, value = 'Cancel', uvalue = {name:'cancel'})
;---------------------------------------------------
; determination of the selected variable ......
;---------------------------------------------------
goodname = 0 > where(strlowcase(namevar) EQ strlowcase(selectedname))
goodtype = 0 > where(sectype EQ selectedtype)
selected = inter(goodname, goodtype)
if selected[0] EQ -1 then BEGIN
widget_control, base, /destroy
ncdf_close, cdfid
return, report('impossible combinaison : type of section '+selectedtype+', variable name '+selectedname)
ENDIF
if n_elements(typein) NE 0 then BEGIN
if NOT keyword_set(xlimits) then xlimits = [-1e9, 1e9]
if NOT keyword_set(ylimits) then ylimits = [-1e9, 1e9]
if NOT keyword_set(zlimits) then zlimits = [-1e9, 1e9]
if NOT keyword_set(tlimits) then tlimits = [-1e9, 1e9]
ENDIF
if n_elements(typein) NE 0 AND n_elements(selected) NE 1 then BEGIN
if keyword_set(oddpt) then selected = inter(selected, where(linetype EQ 'odd'))
if keyword_set(evenpt) then selected = inter(selected, where(linetype EQ 'even'))
if keyword_set(oddevenpt) then selected = inter(selected, where(linetype EQ 'odd-even'))
if selected[0] EQ -1 then BEGIN
widget_control, base, /destroy
ncdf_close, cdfid
return, report('impossible combinaison : type of section '+selectedtype+', variable name '+selectedname+' and line type ')
endif
if n_elements(selected) NE 1 then begin
case selectedtype of
'xy':BEGIN
; choice on the vertical axis
; choice based on the variable which has the most available levels
; between the zlimits.
if NOT keyword_set(zlimits) then begin
print, 'case not coded...'
stop
ENDIF
number = lonarr(n_elements(selected))
for i = 0, n_elements(selected)-1 do begin
zdim = dimvar[2, selected[i]]
zaxis = dimlist.(zdim)
nothing = where(zaxis GE zlimits[0] AND zaxis LE zlimits[1], count)
number[i] = count
ENDFOR
selected = selected[where(number EQ max(number))]
if n_elements(selected) NE 1 then begin
print, 'case not coded...'
stop
endif
END
'xz':BEGIN
; choice on the latitude axis
if NOT keyword_set(ylimits) then begin
print, 'case not coded...'
stop
ENDIF
number = lonarr(n_elements(selected))
for i = 0, n_elements(selected)-1 do begin
ydim = dimvar[2, selected[i]]
yaxis = dimlist.(ydim)
nothing = where(yaxis GE ylimits[0] AND yaxis LE ylimits[1], count)
number[i] = count
ENDFOR
selected = selected[where(number EQ max(number))]
if n_elements(selected) NE 1 then begin
print, 'case not coded...'
stop
endif
END
'yz':BEGIN
; choice on the longitude axis
if NOT keyword_set(xlimits) then begin
print, 'case not coded...'
stop
ENDIF
number = lonarr(n_elements(selected))
for i = 0, n_elements(selected)-1 do begin
xdim = dimvar[2, selected[i]]
xaxis = dimlist.(xdim)
nothing = where(xaxis GE xlimits[0] AND xaxis LE xlimits[1], count)
number[i] = count
ENDFOR
selected = selected[where(number EQ max(number))]
if n_elements(selected) NE 1 then begin
print, 'case not coded...'
stop
endif
END
endcase
endif
ENDIF
;---------------------------------------------------
; definition of the uvalue of the base which allows to share the
; variables between programs.
;---------------------------------------------------
top_uvalue = ptrarr(2, 18, /allocate_heap)
*top_uvalue[0, 0] = 'type choice' & *top_uvalue[1, 0] = temporary(typechoice)
*top_uvalue[0, 1] = 'var choice' & *top_uvalue[1, 1] = temporary(varchoice)
*top_uvalue[0, 2] = 'namevar' & *top_uvalue[1, 2] = temporary(namevar)
*top_uvalue[0, 3] = 'dimvar' & *top_uvalue[1, 3] = temporary(dimvar)
*top_uvalue[0, 4] = 'sectype' & *top_uvalue[1, 4] = temporary(sectype)
*top_uvalue[0, 5] = 'linetype' & *top_uvalue[1, 5] = temporary(linetype)
*top_uvalue[0, 6] = 'pointtype' & *top_uvalue[1, 6] = temporary(pointtype)
*top_uvalue[0, 7] = 'dimlist' & *top_uvalue[1, 7] = temporary(dimlist)
*top_uvalue[0, 8] = 'typedim' & *top_uvalue[1, 8] = temporary(typedim)
*top_uvalue[0, 9] = 'sizedim' & *top_uvalue[1, 9] = temporary(sizedim)
*top_uvalue[0, 10] = 'cdfid' & *top_uvalue[1, 10] = cdfid
*top_uvalue[0, 11] = 'datavarid' & *top_uvalue[1, 11] = datavarid
*top_uvalue[0, 12] = 'selected' & *top_uvalue[1, 12] = selected
*top_uvalue[0, 13] = 'filename' & *top_uvalue[1, 13] = filename
*top_uvalue[0, 14] = 'xlimits' & *top_uvalue[1, 14] = testvar(var = xlimits)
*top_uvalue[0, 15] = 'ylimits' & *top_uvalue[1, 15] = testvar(var = ylimits)
*top_uvalue[0, 16] = 'zlimits' & *top_uvalue[1, 16] = testvar(var = zlimits)
*top_uvalue[0, 17] = 'tlimits' & *top_uvalue[1, 17] = testvar(var = tlimits)
widget_control, base, set_uvalue = top_uvalue
rh_alldomains, base, selected
if n_params() EQ 0 then BEGIN
; we use the widget
widget_control, base, /REALIZE
xmanager, 'read_hope', base, /no_block
return, -1
ENDIF
; get the output
output = createhopestruct({top:base})
; clear the pointer
for i = 0, n_elements(top_uvalue)-1 do ptr_free, top_uvalue[i]
; close the file
ncdf_close, cdfid
return, output
end