;+
;
; @file_comments
; Initfile for netCDF file. define all the grid parameters through
; an appropriate call to computegrid
;
; @categories
; Grid
;
; @param ncfilein {in}{required}{type=scalar string}
; A string giving the name of the netCDF file
;
; @keyword START1 {default=0}{type=scalar: 0 or 1}
; Index the axis from 1 instead of 0 when using
; /xyindex and/or /zindex
;
; @keyword ZAXISNAME {default='z', 'level', 'lev', 'depth...'}{type=scalar string}
; A string giving the name of the variable in the file
; that contains the [xyz]axis.
;
; @keyword XYINDEX {default=0}{type=scalar: 0 or 1}
; To define the x/y axis with index instead of using
; the values contained in X/YAXISNAME.
; x/yaxis = keyword_set(start1) + findgen(jpi/jpj)
; this forces key_onearth = 0
;
; @keyword XMINMESH {default=0L}{type=scalar}
; Define common (cm_4mesh) variables ixminmesh used to define the localization
; of the first point of the grid along the x direction in a zoom of the original grid
;
; @keyword YMINMESH {default=0L}{type=scalar}
; Define common (cm_4mesh) variables iyminmesh used to define the localization
; of the first point of the grid along the y direction in a zoom of the original grid
;
; @keyword XMAXMESH {default=jpiglo-1}{type=scalar}
; Define common (cm_4mesh) variables ixmaxmesh used to define the localization
; of the last point of the grid along the x direction in a zoom of the original grid
; Note that if XMAXMESH < 0 then ixmaxmesh is defined as ixmaxmesh = jpiglo -1 + xmaxmesh
;
; @keyword YMAXMESH {default=jpjglo-1}{type=scalar}
; Define common (cm_4mesh) variables iymaxmesh used to define the localization
; of the last point of the grid along the y direction in a zoom of the original grid
; Note that if YMAXMESH < 0 then iymaxmesh is defined as iymaxmesh = jpjglo -1 + ymaxmesh
;
; @keyword ZINDEX {default=0}{type=scalar: 0 or 1}
; To define the z axis with index instead of using
; the values contained in ZAXISNAME.
; zaxis = keyword_set(start1) + findgen(jpk)
;
; @keyword _EXTRA
; Used to pass keywords to computegrid,
; ncdf_getaxis, ncdf_getmask and isafile
;
; @uses
; common
;
; @restrictions
; Change the grid parameters (see computegrid)
;
; the file must contain an x and an y axis. (1 ou 2 dimensional array)
;
; @examples
;
; IDL> initncdf,'toto.nc',glam=[-180,180]
;
; @history
; Sebastien Masson (smasson\@lodyc.jussieu.fr)
; 8 May 2002
;
; @version
; $Id$
;
;-
PRO initncdf, ncfilein $
, ZAXISNAME=zaxisname, START1=start1 $
, XYINDEX=xyindex, ZINDEX=zindex, ABSZ = absz $
, _EXTRA=ex
;
compile_opt idl2, strictarrsubs
;
@common
;----------------------------------------------------------
; check the name of the file
ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex)
if size(ncfile, /type) NE 7 then BEGIN
ras = report( 'initncdf cancelled')
return
endif
; if the file is stored on tape
if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null'
;----------------------------------------------------------
; open the file
cdfid = ncdf_open(ncfile)
; what is inside the file
inside = ncdf_inquire(cdfid)
;----------------------------------------------------------
; name of the variables
namevar = strarr(inside.nvars)
for varid = 0, inside.nvars-1 do begin
invar = ncdf_varinq(cdfid, varid)
namevar[varid] = strlowcase(invar.name)
ENDFOR
;----------------------------------------------------------
; find the x/yaxis
ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $
, START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex
;----------------------------------------------------------
; find the zaxis
IF keyword_set(romsgrid) THEN BEGIN
FOR i = 0, inside.ndims-1 DO BEGIN
ncdf_diminq, cdfid, i, name, size
CASE strlowcase(name) OF
's_rho':zaxis = reverse(indgen(size))
's_u':zaxis = reverse(indgen(size))
's_v':zaxis = reverse(indgen(size))
's_psi':zaxis = reverse(indgen(size))
's_w':zaxis = reverse(indgen(size-1))
ELSE:
ENDCASE
ENDFOR
IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN
ncdf_varget, cdfid, 'h', romsh
ENDIF ELSE romsh = -1
ENDIF ELSE BEGIN
if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z'
zvarid = (where(namevar EQ 'nav_lev' or namevar EQ zaxisname OR namevar EQ 'level' OR namevar EQ 'lev' OR strmid(namevar, 0, 5) EQ 'depth'))[0]
if zvarid EQ -1 AND inside.ndims GT 3 then begin
ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...')
; stop
endif
; read the zaxis
if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis
ENDELSE
IF keyword_set(zindex) AND keyword_set(zaxis) THEN $
zaxis = keyword_set(start1) + findgen(n_elements(zaxis))
IF keyword_set(absz) AND n_elements(zaxis) NE 0 THEN zaxis = abs(zaxis)
;----------------------------------------------------------
; mask
tmask = ncdf_getmask(cdfid, _extra = ex)
;----------------------------------------------------------
;
ncdf_close, cdfid
;----------------------------------------------------------
IF keyword_set(romsgrid) THEN BEGIN ; remove last column/row
sz = size(tmask)
nx = sz[1] & ny = sz[2]
xaxis = xaxis[0:nx-2, 0:ny-2]
yaxis = yaxis[0:nx-2, 0:ny-2]
romsh = romsh[0:nx-2, 0:ny-2]
CASE sz[0] OF
2:tmask = tmask[0:nx-2, 0:ny-2]
3:tmask = tmask[0:nx-2, 0:ny-2, *]
ENDCASE
ENDIF
;----------------------------------------------------------
; call compute the grid
if NOT keyword_set(zaxis) then BEGIN
computegrid, xaxis = xaxis, yaxis = yaxis $
, mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
ENDIF ELSE BEGIN
computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $
, mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex
ENDELSE
IF n_elements(time) EQ 0 THEN time = 0
jpt = n_elements(time)
;----------------------------------------------------------
return
end