;+
;
; @file_comments
; Initfile for Netcdf file. define all the grid parameters through
; an appropriate call to computegid
;
; @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 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.pro
;
; @restrictions
; Change the grid parameters (see computegrid)
;
; @restrictions
; 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 $
, _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))
;----------------------------------------------------------
; mask
tmask = ncdf_getmask(cdfid, _extra = ex)
;----------------------------------------------------------
;
ncdf_close, cdfid
;
;----------------------------------------------------------
; 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