[33] | 1 | ;+ |
---|
| 2 | ; |
---|
[142] | 3 | ; @file_comments |
---|
[495] | 4 | ; Initfile for netCDF file. define all the grid parameters through |
---|
[365] | 5 | ; an appropriate call to <pro>computegrid</pro> |
---|
[33] | 6 | ; |
---|
[142] | 7 | ; @categories |
---|
[172] | 8 | ; Grid |
---|
[231] | 9 | ; |
---|
[325] | 10 | ; @param ncfilein {in}{required}{type=scalar string} |
---|
[495] | 11 | ; A string giving the name of the netCDF file |
---|
[33] | 12 | ; |
---|
[172] | 13 | ; @keyword START1 {default=0}{type=scalar: 0 or 1} |
---|
[142] | 14 | ; Index the axis from 1 instead of 0 when using |
---|
[221] | 15 | ; /xyindex and/or /zindex |
---|
[33] | 16 | ; |
---|
[172] | 17 | ; @keyword ZAXISNAME {default='z', 'level', 'lev', 'depth...'}{type=scalar string} |
---|
[231] | 18 | ; A string giving the name of the variable in the file |
---|
| 19 | ; that contains the [xyz]axis. |
---|
[33] | 20 | ; |
---|
[172] | 21 | ; @keyword XYINDEX {default=0}{type=scalar: 0 or 1} |
---|
[142] | 22 | ; To define the x/y axis with index instead of using |
---|
[231] | 23 | ; the values contained in X/YAXISNAME. |
---|
| 24 | ; x/yaxis = keyword_set(start1) + findgen(jpi/jpj) |
---|
[142] | 25 | ; this forces key_onearth = 0 |
---|
[33] | 26 | ; |
---|
[421] | 27 | ; @keyword XMINMESH {default=0L}{type=scalar} |
---|
| 28 | ; Define common (cm_4mesh) variables ixminmesh used to define the localization |
---|
| 29 | ; of the first point of the grid along the x direction in a zoom of the original grid |
---|
| 30 | ; |
---|
| 31 | ; @keyword YMINMESH {default=0L}{type=scalar} |
---|
| 32 | ; Define common (cm_4mesh) variables iyminmesh used to define the localization |
---|
| 33 | ; of the first point of the grid along the y direction in a zoom of the original grid |
---|
| 34 | ; |
---|
| 35 | ; @keyword XMAXMESH {default=jpiglo-1}{type=scalar} |
---|
| 36 | ; Define common (cm_4mesh) variables ixmaxmesh used to define the localization |
---|
| 37 | ; of the last point of the grid along the x direction in a zoom of the original grid |
---|
| 38 | ; Note that if XMAXMESH < 0 then ixmaxmesh is defined as ixmaxmesh = jpiglo -1 + xmaxmesh |
---|
| 39 | ; |
---|
| 40 | ; @keyword YMAXMESH {default=jpjglo-1}{type=scalar} |
---|
| 41 | ; Define common (cm_4mesh) variables iymaxmesh used to define the localization |
---|
| 42 | ; of the last point of the grid along the y direction in a zoom of the original grid |
---|
| 43 | ; Note that if YMAXMESH < 0 then iymaxmesh is defined as iymaxmesh = jpjglo -1 + ymaxmesh |
---|
| 44 | ; |
---|
[172] | 45 | ; @keyword ZINDEX {default=0}{type=scalar: 0 or 1} |
---|
[142] | 46 | ; To define the z axis with index instead of using |
---|
[231] | 47 | ; the values contained in ZAXISNAME. |
---|
| 48 | ; zaxis = keyword_set(start1) + findgen(jpk) |
---|
| 49 | ; |
---|
[142] | 50 | ; @keyword _EXTRA |
---|
[495] | 51 | ; Used to pass keywords to <pro>computegrid</pro>, |
---|
[271] | 52 | ; <pro>ncdf_getaxis</pro>, <pro>ncdf_getmask</pro> and <pro>isafile</pro> |
---|
[33] | 53 | ; |
---|
[142] | 54 | ; @uses |
---|
[370] | 55 | ; <pro>common</pro> |
---|
[33] | 56 | ; |
---|
[142] | 57 | ; @restrictions |
---|
[231] | 58 | ; Change the grid parameters (see <pro>computegrid</pro>) |
---|
[33] | 59 | ; |
---|
[226] | 60 | ; the file must contain an x and an y axis. (1 ou 2 dimensional array) |
---|
[33] | 61 | ; |
---|
[142] | 62 | ; @examples |
---|
[33] | 63 | ; |
---|
[371] | 64 | ; IDL> initncdf,'toto.nc',glam=[-180,180] |
---|
| 65 | ; |
---|
[142] | 66 | ; @history |
---|
[157] | 67 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[142] | 68 | ; 8 May 2002 |
---|
[33] | 69 | ; |
---|
[142] | 70 | ; @version |
---|
| 71 | ; $Id$ |
---|
[33] | 72 | ; |
---|
| 73 | ;- |
---|
[221] | 74 | PRO initncdf, ncfilein $ |
---|
[327] | 75 | , ZAXISNAME=zaxisname, START1=start1 $ |
---|
[508] | 76 | , XYINDEX=xyindex, ZINDEX=zindex, ABSZ = absz $ |
---|
[327] | 77 | , _EXTRA=ex |
---|
[33] | 78 | ; |
---|
[114] | 79 | compile_opt idl2, strictarrsubs |
---|
| 80 | ; |
---|
[33] | 81 | @common |
---|
| 82 | ;---------------------------------------------------------- |
---|
| 83 | ; check the name of the file |
---|
| 84 | ncfile = isafile(FILENAME = ncfilein, IODIRECTORY = iodir, _extra = ex) |
---|
| 85 | if size(ncfile, /type) NE 7 then BEGIN |
---|
[236] | 86 | ras = report( 'initncdf cancelled') |
---|
[33] | 87 | return |
---|
| 88 | endif |
---|
| 89 | ; if the file is stored on tape |
---|
[231] | 90 | if !version.os_family EQ 'unix' then spawn, 'file '+ncfile+' > /dev/null' |
---|
[33] | 91 | ;---------------------------------------------------------- |
---|
| 92 | ; open the file |
---|
| 93 | cdfid = ncdf_open(ncfile) |
---|
| 94 | ; what is inside the file |
---|
| 95 | inside = ncdf_inquire(cdfid) |
---|
| 96 | ;---------------------------------------------------------- |
---|
| 97 | ; name of the variables |
---|
| 98 | namevar = strarr(inside.nvars) |
---|
| 99 | for varid = 0, inside.nvars-1 do begin |
---|
| 100 | invar = ncdf_varinq(cdfid, varid) |
---|
| 101 | namevar[varid] = strlowcase(invar.name) |
---|
| 102 | ENDFOR |
---|
| 103 | ;---------------------------------------------------------- |
---|
[221] | 104 | ; find the x/yaxis |
---|
| 105 | ncdf_getaxis, cdfid, dimidx, dimidy, xaxis, yaxis $ |
---|
| 106 | , START1 = start1, XYINDEX = xyindex, ROMSGRID = romsgrid, _extra = ex |
---|
[33] | 107 | ;---------------------------------------------------------- |
---|
| 108 | ; find the zaxis |
---|
[172] | 109 | IF keyword_set(romsgrid) THEN BEGIN |
---|
[231] | 110 | FOR i = 0, inside.ndims-1 DO BEGIN |
---|
[172] | 111 | ncdf_diminq, cdfid, i, name, size |
---|
| 112 | CASE strlowcase(name) OF |
---|
| 113 | 's_rho':zaxis = reverse(indgen(size)) |
---|
| 114 | 's_u':zaxis = reverse(indgen(size)) |
---|
| 115 | 's_v':zaxis = reverse(indgen(size)) |
---|
| 116 | 's_psi':zaxis = reverse(indgen(size)) |
---|
| 117 | 's_w':zaxis = reverse(indgen(size-1)) |
---|
| 118 | ELSE: |
---|
| 119 | ENDCASE |
---|
[231] | 120 | ENDFOR |
---|
[172] | 121 | IF (where(namevar EQ 'h'))[0] NE -1 THEN BEGIN |
---|
| 122 | ncdf_varget, cdfid, 'h', romsh |
---|
| 123 | ENDIF ELSE romsh = -1 |
---|
[231] | 124 | ENDIF ELSE BEGIN |
---|
[172] | 125 | if keyword_set(zaxisname) then zaxisname = strlowcase(zaxisname) ELSE zaxisname = 'z' |
---|
| 126 | 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] |
---|
| 127 | if zvarid EQ -1 AND inside.ndims GT 3 then begin |
---|
[297] | 128 | ras = report( 'initncdf: the zaxis was not found..., check the use of ZAXISNAME keyword if you want to find one...') |
---|
[33] | 129 | ; stop |
---|
[172] | 130 | endif |
---|
[33] | 131 | ; read the zaxis |
---|
[172] | 132 | if zvarid NE -1 THEN ncdf_varget, cdfid, zvarid, zaxis |
---|
[231] | 133 | ENDELSE |
---|
[172] | 134 | IF keyword_set(zindex) AND keyword_set(zaxis) THEN $ |
---|
| 135 | zaxis = keyword_set(start1) + findgen(n_elements(zaxis)) |
---|
[508] | 136 | IF keyword_set(absz) AND n_elements(zaxis) NE 0 THEN zaxis = abs(zaxis) |
---|
[33] | 137 | ;---------------------------------------------------------- |
---|
| 138 | ; mask |
---|
[271] | 139 | tmask = ncdf_getmask(cdfid, _extra = ex) |
---|
| 140 | ;---------------------------------------------------------- |
---|
[172] | 141 | ; |
---|
[33] | 142 | ncdf_close, cdfid |
---|
[271] | 143 | ;---------------------------------------------------------- |
---|
[465] | 144 | IF keyword_set(romsgrid) THEN BEGIN ; remove last column/row |
---|
| 145 | sz = size(tmask) |
---|
| 146 | nx = sz[1] & ny = sz[2] |
---|
| 147 | xaxis = xaxis[0:nx-2, 0:ny-2] |
---|
| 148 | yaxis = yaxis[0:nx-2, 0:ny-2] |
---|
| 149 | romsh = romsh[0:nx-2, 0:ny-2] |
---|
| 150 | CASE sz[0] OF |
---|
| 151 | 2:tmask = tmask[0:nx-2, 0:ny-2] |
---|
| 152 | 3:tmask = tmask[0:nx-2, 0:ny-2, *] |
---|
| 153 | ENDCASE |
---|
| 154 | ENDIF |
---|
| 155 | ;---------------------------------------------------------- |
---|
[271] | 156 | ; call compute the grid |
---|
[231] | 157 | if NOT keyword_set(zaxis) then BEGIN |
---|
[33] | 158 | computegrid, xaxis = xaxis, yaxis = yaxis $ |
---|
[231] | 159 | , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex |
---|
| 160 | ENDIF ELSE BEGIN |
---|
[33] | 161 | computegrid, xaxis = xaxis, yaxis = yaxis, zaxis = zaxis $ |
---|
[172] | 162 | , mask = tmask, onearth = 1b - keyword_set(xyindex), ROMSH = romsh, _EXTRA = ex |
---|
[231] | 163 | ENDELSE |
---|
[33] | 164 | IF n_elements(time) EQ 0 THEN time = 0 |
---|
[231] | 165 | jpt = n_elements(time) |
---|
[33] | 166 | ;---------------------------------------------------------- |
---|
| 167 | |
---|
| 168 | return |
---|
| 169 | end |
---|