[13] | 1 | ;+ |
---|
| 2 | ; |
---|
[231] | 3 | ; @file_comments |
---|
| 4 | ; read NetCDF meshmask file created by OPA |
---|
[13] | 5 | ; |
---|
[226] | 6 | ; @categories |
---|
[157] | 7 | ; Grid |
---|
[13] | 8 | ; |
---|
[103] | 9 | ; @examples |
---|
| 10 | ; IDL> ncdf_meshread [,' filename'] |
---|
[121] | 11 | ; |
---|
[172] | 12 | ; @param filename {in}{optional}{default='meshmask.nc'}{type=scalar string} |
---|
| 13 | ; Name of the meshmask file to read. If this name does not contain any "/" |
---|
| 14 | ; and if iodirectory keyword is not specify, then the common variable |
---|
[264] | 15 | ; iodir will be used to define the mesh file path. |
---|
[13] | 16 | ; |
---|
[172] | 17 | ; @keyword GLAMBOUNDARY {default=those defined in the file}{type=2 elements vector} |
---|
| 18 | ; Longitude boundaries that should be used to visualize the data. |
---|
[13] | 19 | ; lon2 > lon1 |
---|
| 20 | ; lon2 - lon1 le 360 |
---|
[172] | 21 | ; By default, the common (cm_4mesh) variable key_shift will be automatically |
---|
| 22 | ; defined according to GLAMBOUNDARY. |
---|
[13] | 23 | ; |
---|
[231] | 24 | ; @keyword CHECKDAT |
---|
[264] | 25 | ; Suppressed. Use <pro>micromeshmask</pro> to create an appropriate meshmask. |
---|
[13] | 26 | ; |
---|
[172] | 27 | ; @keyword ONEARTH {default=1}{type=scalar: 0 or 1} |
---|
| 28 | ; Force the manual definition of data localization on the earth or not |
---|
| 29 | ; 0) if the data are not on the earth |
---|
| 30 | ; 1) if the data are on earth (in that case we can for example use |
---|
| 31 | ; the labels 'longitude', 'latitude' in plots). |
---|
| 32 | ; The resulting value will be stored in the common (cm_4mesh) variable key_onearth |
---|
| 33 | ; ONEARTH = 0 forces PERIODIC = 0, SHIFT = 0 and is cancelling GLAMBOUNDARY |
---|
[13] | 34 | ; |
---|
[172] | 35 | ; @keyword GETDIMENSIONS {default=0}{type=scalar: 0 or 1} |
---|
[155] | 36 | ; Activate this keywords if you only want to know the dimension |
---|
[264] | 37 | ; of the domain stored in the mesh file. This dimension will be |
---|
[155] | 38 | ; defined in jpiglo, jpjglo, jpkglo (cm_4mesh common variables) |
---|
[118] | 39 | ; |
---|
[172] | 40 | ; @keyword PERIODIC {default=computed by using the first line of glamt}{type=scalar: 0 or 1} |
---|
| 41 | ; Force the manual definition of the grid zonal periodicity. |
---|
| 42 | ; The resulting value will be stored in the common (cm_4mesh) variable key_periodic |
---|
| 43 | ; PERIODIC = 0 forces SHIFT = 0 |
---|
[13] | 44 | ; |
---|
[172] | 45 | ; @keyword SHIFT {default=computed according to glamboundary}{type=scalar} |
---|
[226] | 46 | ; Force the manual definition of the zonal shift that must be apply to the data. |
---|
[172] | 47 | ; The resulting value will be stored in the common (cm_4mesh) variable key_shift |
---|
| 48 | ; Note that if key_periodic=0 then in any case key_shift = 0. |
---|
[13] | 49 | ; |
---|
[172] | 50 | ; @keyword STRCALLING {type=scalar string} |
---|
[264] | 51 | ; the calling command used to call <pro>computegrid</pro> (this is used by <pro>xxx</pro>) |
---|
[69] | 52 | ; |
---|
[172] | 53 | ; @keyword STRIDE {default=[1, 1, 1]}{type=3 elements vector} |
---|
| 54 | ; Specify the stride in x, y and z direction. The resulting |
---|
| 55 | ; value will be stored in the common (cm_4mesh) variable key_stride |
---|
[13] | 56 | ; |
---|
[231] | 57 | ; @keyword _EXTRA |
---|
| 58 | ; Used to pass keywords to <pro>isafile</pro> |
---|
[118] | 59 | ; |
---|
[231] | 60 | ; @uses |
---|
| 61 | ; cm_4mesh |
---|
| 62 | ; cm_4data |
---|
| 63 | ; cm_4cal |
---|
[13] | 64 | ; |
---|
[103] | 65 | ; @restrictions |
---|
[264] | 66 | ; ixminmesh, ixmaxmesh, iyminmesh, iymaxmesh, izminmesh, izmaxmesh must |
---|
| 67 | ; be defined before calling ncdf_meshread. If some of those values |
---|
[231] | 68 | ; are equal to -1 they will be automatically defined |
---|
[13] | 69 | ; |
---|
[226] | 70 | ; @history |
---|
| 71 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[13] | 72 | ; 12/1999 |
---|
| 73 | ; July 2004, Sebastien Masson: Several modifications (micromeshmask, |
---|
| 74 | ; clean partial steps, clean use of key_stride, automatic definition |
---|
| 75 | ; of key_shift, ...) |
---|
| 76 | ; Oct. 2004, Sebastien Masson: add PERIODIC and SHIFT |
---|
[121] | 77 | ; Aug. 2005, Sebastien Masson: some cleaning + english |
---|
[118] | 78 | ; |
---|
[226] | 79 | ; @version |
---|
| 80 | ; $Id$ |
---|
[118] | 81 | ; |
---|
[13] | 82 | ;- |
---|
[231] | 83 | ; |
---|
[13] | 84 | PRO ncdf_meshread, filename, GLAMBOUNDARY = glamboundary, CHECKDAT = checkdat $ |
---|
| 85 | , ONEARTH = onearth, GETDIMENSIONS = getdimensions $ |
---|
| 86 | , PERIODIC = periodic, SHIFT = shift, STRIDE = stride $ |
---|
[69] | 87 | , STRCALLING = strcalling, _EXTRA = ex |
---|
[13] | 88 | ; |
---|
[114] | 89 | compile_opt idl2, strictarrsubs |
---|
| 90 | ; |
---|
[13] | 91 | @cm_4mesh |
---|
| 92 | @cm_4data |
---|
| 93 | @cm_4cal |
---|
| 94 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
| 95 | @updatenew |
---|
| 96 | @updatekwd |
---|
| 97 | ENDIF |
---|
| 98 | ;--------------------------------------------------------- |
---|
| 99 | ; |
---|
| 100 | tempsun = systime(1) ; for key_performance |
---|
| 101 | IF keyword_set(CHECKDAT) THEN BEGIN |
---|
[240] | 102 | ras = report([' The keyword CHECKDAT has been suppressed (it could create bugs).', $ |
---|
| 103 | ' Remove it from the call of ncdf_meshread', $ |
---|
| 104 | ' Please use smallmeshmask.pro or micromeshmask.pro to create a', $ |
---|
| 105 | ' meshmask that has manageable size']) |
---|
[13] | 106 | return |
---|
| 107 | ENDIF |
---|
| 108 | ;------------------------------------------------------- |
---|
| 109 | ; find meshfile name and open it! |
---|
| 110 | ;------------------------------------------------------- |
---|
[121] | 111 | ; def of filename by default |
---|
[13] | 112 | IF n_params() EQ 0 then filename = 'meshmask.nc' |
---|
| 113 | meshname = isafile(file = filename, iodirectory = iodir, _EXTRA = ex) |
---|
| 114 | meshname = meshname[0] |
---|
| 115 | ; |
---|
| 116 | noticebase = xnotice('Reading file !C '+meshname+'!C ...') |
---|
| 117 | ; if the meshmask is on tape archive ... get it back |
---|
| 118 | IF !version.OS_FAMILY EQ 'unix' THEN spawn, '\file '+meshname+' > /dev/null' |
---|
| 119 | cdfid = ncdf_open(meshname) |
---|
[273] | 120 | inq = ncdf_inquire(cdfid) |
---|
[13] | 121 | ;------------------------------------------------------------ |
---|
| 122 | ; dimensions |
---|
| 123 | ;------------------------------------------------------------ |
---|
| 124 | ncdf_diminq, cdfid, 'x', name, jpiglo |
---|
| 125 | ncdf_diminq, cdfid, 'y', name, jpjglo |
---|
| 126 | listdims = strlowcase(ncdf_listdims(cdfid)) |
---|
[121] | 127 | IF (where(listdims EQ 'z'))[0] NE -1 THEN ncdf_diminq, cdfid, 'z', name, jpkglo ELSE BEGIN |
---|
[13] | 128 | dimid = (where(strmid(listdims, 0, 5) EQ 'depth'))[0] |
---|
[121] | 129 | IF dimid NE -1 THEN ncdf_diminq, cdfid, dimid, name, jpkglo ELSE BEGIN |
---|
[114] | 130 | dummy = report('We could not find the vertical dimension..., its name must be z or start with depth') |
---|
[13] | 131 | stop |
---|
[121] | 132 | ENDELSE |
---|
| 133 | ENDELSE |
---|
[13] | 134 | ; |
---|
| 135 | if keyword_set(getdimensions) then begin |
---|
| 136 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
| 137 | ncdf_close, cdfid |
---|
| 138 | return |
---|
| 139 | endif |
---|
| 140 | ;------------------------------------------------------- |
---|
| 141 | ; check that all i[xyz]min[ax]mesh are well defined |
---|
| 142 | ;------------------------------------------------------- |
---|
| 143 | if n_elements(ixminmesh) EQ 0 THEN ixminmesh = 0 |
---|
| 144 | if n_elements(ixmaxmesh) EQ 0 then ixmaxmesh = jpiglo-1 |
---|
| 145 | if ixminmesh EQ -1 THEN ixminmesh = 0 |
---|
| 146 | IF ixmaxmesh EQ -1 then ixmaxmesh = jpiglo-1 |
---|
| 147 | if n_elements(iyminmesh) EQ 0 THEN iyminmesh = 0 |
---|
| 148 | IF n_elements(iymaxmesh) EQ 0 then iymaxmesh = jpjglo-1 |
---|
| 149 | if iyminmesh EQ -1 THEN iyminmesh = 0 |
---|
| 150 | IF iymaxmesh EQ -1 then iymaxmesh = jpjglo-1 |
---|
| 151 | if n_elements(izminmesh) EQ 0 THEN izminmesh = 0 |
---|
| 152 | IF n_elements(izmaxmesh) EQ 0 then izmaxmesh = jpkglo-1 |
---|
| 153 | if izminmesh EQ -1 THEN izminmesh = 0 |
---|
| 154 | IF izmaxmesh EQ -1 then izmaxmesh = jpkglo-1 |
---|
| 155 | ; definition of jpi,jpj,jpj |
---|
[172] | 156 | jpi = long(ixmaxmesh-ixminmesh+1) |
---|
| 157 | jpj = long(iymaxmesh-iyminmesh+1) |
---|
| 158 | jpk = long(izmaxmesh-izminmesh+1) |
---|
[13] | 159 | ;------------------------------------------------------- |
---|
| 160 | ; check onearth and its consequences |
---|
| 161 | ;------------------------------------------------------- |
---|
| 162 | IF n_elements(onearth) EQ 0 THEN key_onearth = 1 $ |
---|
[121] | 163 | ELSE key_onearth = keyword_set(onearth) |
---|
[13] | 164 | IF NOT key_onearth THEN BEGIN |
---|
| 165 | periodic = 0 |
---|
| 166 | shift = 0 |
---|
| 167 | ENDIF |
---|
| 168 | ;------------------------------------------------------- |
---|
| 169 | ; automatic definition of key_periodic |
---|
| 170 | ;------------------------------------------------------- |
---|
| 171 | IF n_elements(periodic) EQ 0 THEN BEGIN |
---|
| 172 | IF jpi GT 1 THEN BEGIN |
---|
| 173 | varinq = ncdf_varinq(cdfid, 'glamt') |
---|
| 174 | CASE varinq.ndims OF |
---|
| 175 | 2:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 176 | , offset = [ixminmesh, iyminmesh], count = [jpi, 1] |
---|
| 177 | 3:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 178 | , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1] |
---|
| 179 | 4:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 180 | , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1] |
---|
| 181 | ENDCASE |
---|
| 182 | xaxis = (xaxis+720) MOD 360 |
---|
| 183 | xaxis = xaxis[sort(xaxis)] |
---|
| 184 | key_periodic = (xaxis[jpi-1]+2*(xaxis[jpi-1]-xaxis[jpi-2])) $ |
---|
| 185 | GE (xaxis[0]+360) |
---|
| 186 | ENDIF ELSE key_periodic = 0 |
---|
| 187 | ENDIF ELSE key_periodic = keyword_set(periodic) |
---|
| 188 | ;------------------------------------------------------- |
---|
| 189 | ; automatic definition of key_shift |
---|
| 190 | ;------------------------------------------------------- |
---|
| 191 | IF n_elements(shift) EQ 0 THEN BEGIN |
---|
| 192 | key_shift = long(testvar(var = key_shift)) |
---|
| 193 | ; key_shift will be defined according to the first line of glamt. |
---|
| 194 | if keyword_set(glamboundary) AND jpi GT 1 AND key_periodic EQ 1 $ |
---|
| 195 | THEN BEGIN |
---|
| 196 | varinq = ncdf_varinq(cdfid, 'glamt') |
---|
| 197 | CASE varinq.ndims OF |
---|
| 198 | 2:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 199 | , offset = [ixminmesh, iyminmesh], count = [jpi, 1] |
---|
| 200 | 3:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 201 | , offset = [ixminmesh, iyminmesh, 0], count = [jpi, 1, 1] |
---|
| 202 | 4:ncdf_varget, cdfid, 'glamt', xaxis $ |
---|
| 203 | , offset = [ixminmesh, iyminmesh, 0, 0], count = [jpi, 1, 1, 1] |
---|
| 204 | ENDCASE |
---|
| 205 | ; xaxis between glamboundary[0] and glamboundary[1] |
---|
| 206 | xaxis = xaxis MOD 360 |
---|
| 207 | smaller = where(xaxis LT glamboundary[0]) |
---|
| 208 | if smaller[0] NE -1 then xaxis[smaller] = xaxis[smaller]+360 |
---|
| 209 | bigger = where(xaxis GE glamboundary[1]) |
---|
| 210 | if bigger[0] NE -1 then xaxis[bigger] = xaxis[bigger]-360 |
---|
[121] | 211 | ; |
---|
[13] | 212 | key_shift = (where(xaxis EQ min(xaxis)))[0] |
---|
[121] | 213 | IF key_shift NE 0 THEN BEGIN |
---|
[13] | 214 | key_shift = jpi-key_shift |
---|
| 215 | xaxis = shift(xaxis, key_shift) |
---|
| 216 | ENDIF |
---|
| 217 | ; |
---|
| 218 | IF array_equal(sort(xaxis), lindgen(jpi)) NE 1 THEN BEGIN |
---|
[240] | 219 | ras = report(['the x axis (1st line of glamt) is not sorted in the increasing order after the automatic definition of key_shift', $ |
---|
| 220 | 'please use the keyword shift (and periodic) to suppress the automatic definition of key_shift (and key_periodic) and define by hand a more suitable value...']) |
---|
[13] | 221 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
| 222 | return |
---|
[121] | 223 | ENDIF |
---|
[13] | 224 | ; |
---|
| 225 | ENDIF ELSE key_shift = 0 |
---|
| 226 | ENDIF ELSE key_shift = long(shift)*(key_periodic EQ 1) |
---|
| 227 | ;------------------------------------------------------- |
---|
| 228 | ; check key_stride and related things |
---|
| 229 | ;------------------------------------------------------- |
---|
| 230 | if n_elements(stride) eq 3 then key_stride = stride |
---|
| 231 | if n_elements(key_stride) LE 2 then key_stride = [1, 1, 1] |
---|
| 232 | key_stride = 1l > long(key_stride) |
---|
| 233 | IF total(key_stride) NE 3 THEN BEGIN |
---|
| 234 | IF key_shift NE 0 THEN BEGIN |
---|
| 235 | ; for explanation, see header of read_ncdf_varget.pro |
---|
| 236 | jpiright = key_shift |
---|
| 237 | jpileft = jpi - key_shift - ( (key_stride[0]-1)-((key_shift-1) MOD key_stride[0]) ) |
---|
| 238 | jpi = ((jpiright-1)/key_stride[0]+1) + ((jpileft-1)/key_stride[0]+1) |
---|
| 239 | ENDIF ELSE jpi = (jpi-1)/key_stride[0]+1 |
---|
| 240 | jpj = (jpj-1)/key_stride[1]+1 |
---|
| 241 | jpk = (jpk-1)/key_stride[2]+1 |
---|
| 242 | ENDIF |
---|
| 243 | ;------------------------------------------------------- |
---|
| 244 | ; default definitions to be able to use read_ncdf_varget |
---|
| 245 | ;------------------------------------------------------- |
---|
| 246 | ; default definitions to be able to use read_ncdf_varget |
---|
| 247 | ixmindtasauve = testvar(var = ixmindta) |
---|
| 248 | iymindtasauve = testvar(var = iymindta) |
---|
| 249 | izmindtasauve = testvar(var = izmindta) |
---|
| 250 | ; |
---|
| 251 | ixmindta = 0l |
---|
| 252 | iymindta = 0l |
---|
| 253 | izmindta = 0l |
---|
| 254 | ; |
---|
| 255 | jpt = 1 |
---|
| 256 | time = 1 |
---|
| 257 | firsttps = 0 |
---|
| 258 | ; |
---|
| 259 | firstx = 0 |
---|
| 260 | lastx = jpi-1 |
---|
| 261 | firsty = 0 |
---|
| 262 | lasty = jpj-1 |
---|
| 263 | firstz = 0 |
---|
| 264 | lastz = jpk-1 |
---|
| 265 | nx = jpi |
---|
| 266 | ny = jpj |
---|
| 267 | nz = 1 |
---|
| 268 | izminmeshsauve = izminmesh |
---|
| 269 | izminmesh = 0 |
---|
[212] | 270 | ; |
---|
| 271 | key_yreverse = 0 |
---|
| 272 | key_zreverse = 0 |
---|
[216] | 273 | key_gridtype = 'c' |
---|
[13] | 274 | ;------------------------------------------------------- |
---|
| 275 | ; 2d arrays: |
---|
| 276 | ;------------------------------------------------------- |
---|
| 277 | ; list the 2d variables that must be read |
---|
| 278 | namevar = ['glamt', 'glamu', 'glamv', 'glamf' $ |
---|
| 279 | , 'gphit', 'gphiu', 'gphiv', 'gphif' $ |
---|
| 280 | , 'e1t', 'e1u', 'e1v', 'e1f' $ |
---|
| 281 | , 'e2t', 'e2u', 'e2v', 'e2f'] |
---|
| 282 | ; for the variables related to the partial steps |
---|
| 283 | allvarname = ncdf_listvars(cdfid) |
---|
| 284 | IF (where(allvarname EQ 'hdept'))[0] NE -1 THEN BEGIN |
---|
| 285 | key_partialstep = 1 |
---|
| 286 | namevar = [namevar, 'hdept', 'hdepw'] |
---|
| 287 | ENDIF ELSE BEGIN |
---|
| 288 | key_partialstep = 0 |
---|
| 289 | hdept = -1 |
---|
| 290 | hdepw = -1 |
---|
| 291 | ENDELSE |
---|
| 292 | ; for compatibility with old versions of meshmask/partial steps |
---|
| 293 | IF (where(allvarname EQ 'e3tp'))[0] NE -1 THEN $ |
---|
[121] | 294 | namevar = [namevar, 'e3tp', 'e3wp'] ELSE BEGIN |
---|
[13] | 295 | e3t_ps = -1 |
---|
| 296 | e3w_ps = -1 |
---|
| 297 | ENDELSE |
---|
| 298 | IF (where(allvarname EQ 'e3t_ps'))[0] NE -1 $ |
---|
[121] | 299 | THEN namevar = [namevar, 'e3t_ps', 'e3w_ps' ]ELSE BEGIN |
---|
[13] | 300 | e3t_ps = -1 |
---|
| 301 | e3w_ps = -1 |
---|
| 302 | ENDELSE |
---|
| 303 | IF (where(allvarname EQ 'e3u_ps'))[0] NE -1 $ |
---|
[121] | 304 | THEN namevar = [namevar, 'e3u_ps', 'e3v_ps'] ELSE BEGIN |
---|
[13] | 305 | e3u_ps = -1 |
---|
| 306 | e3v_ps = -1 |
---|
| 307 | ENDELSE |
---|
| 308 | ; |
---|
| 309 | ; read all the 2d variables |
---|
| 310 | ; |
---|
| 311 | for i = 0, n_elements(namevar)-1 do begin |
---|
[273] | 312 | varinq = ncdf_varinq(cdfid, namevar[i]) |
---|
| 313 | name = varinq.name |
---|
[13] | 314 | @read_ncdf_varget |
---|
[172] | 315 | command = namevar[i]+'=float(temporary(res))' |
---|
[121] | 316 | nothing = execute(command) |
---|
[13] | 317 | ENDFOR |
---|
| 318 | ; for compatibility with old versions of meshmask/partial steps |
---|
| 319 | ; change e3[tw]p to e3[tw]_ps |
---|
| 320 | IF n_elements(e3tp) NE 0 THEN e3t_ps = temporary(e3tp) |
---|
| 321 | IF n_elements(e3wp) NE 0 THEN e3w_ps = temporary(e3wp) |
---|
[121] | 322 | ; in the case of key_stride ne [1, 1, 1] redefine f points |
---|
[13] | 323 | ; coordinates: they must be in the middle of 3 T points |
---|
| 324 | if key_stride[0] NE 1 OR key_stride[1] NE 1 then BEGIN |
---|
| 325 | ; we must recompute glamf and gphif... |
---|
[121] | 326 | IF jpi GT 1 THEN BEGIN |
---|
[13] | 327 | if (keyword_set(key_onearth) AND keyword_set(xnotsorted)) $ |
---|
| 328 | OR (keyword_set(key_periodic) AND key_irregular) then BEGIN |
---|
| 329 | stepxf = (glamt + 720) MOD 360 |
---|
| 330 | stepxf = shift(stepxf, -1, -1) - stepxf |
---|
| 331 | stepxf = [ [[stepxf]], [[stepxf + 360]], [[stepxf - 360]] ] |
---|
| 332 | stepxf = min(abs(stepxf), dimension = 3) |
---|
| 333 | IF NOT keyword_set(key_periodic) THEN $ |
---|
| 334 | stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
| 335 | ENDIF ELSE BEGIN |
---|
| 336 | stepxf = shift(glamt, -1, -1) - glamt |
---|
| 337 | IF keyword_set(key_periodic) THEN $ |
---|
| 338 | stepxf[jpi-1, *] = 360 + stepxf[jpi-1, *] $ |
---|
| 339 | ELSE stepxf[jpi-1, *] = stepxf[jpi-2, *] |
---|
| 340 | ENDELSE |
---|
[121] | 341 | IF jpj GT 1 THEN BEGIN |
---|
[13] | 342 | stepxf[*, jpj-1] = stepxf[*, jpj-2] |
---|
| 343 | stepxf[jpi-1, jpj-1] = stepxf[jpi-2, jpj-2] |
---|
| 344 | ENDIF |
---|
| 345 | glamf = glamt + 0.5 * stepxf |
---|
| 346 | ENDIF ELSE glamf = glamt + 0.5 |
---|
[121] | 347 | IF jpj GT 1 THEN BEGIN |
---|
[13] | 348 | ; we must compute stepyf: y distance between T(i,j) T(i+1,j+1) |
---|
| 349 | stepyf = shift(gphit, -1, -1) - gphit |
---|
| 350 | stepyf[*, jpj-1] = stepyf[*, jpj-2] |
---|
| 351 | IF jpi GT 1 THEN BEGIN |
---|
| 352 | if NOT keyword_set(key_periodic) THEN $ |
---|
| 353 | stepyf[jpi-1, *] = stepyf[jpi-2, *] |
---|
| 354 | stepyf[jpi-1, jpj-1] = stepyf[jpi-2, jpj-2] |
---|
[121] | 355 | ENDIF |
---|
[13] | 356 | gphif = gphit + 0.5 * stepyf |
---|
| 357 | ENDIF ELSE gphif = gphit + 0.5 |
---|
| 358 | ENDIF |
---|
| 359 | ;------------------------------------------------------- |
---|
| 360 | ; 3d arrays: |
---|
| 361 | ;------------------------------------------------------- |
---|
| 362 | nz = jpk |
---|
| 363 | izminmesh = izminmeshsauve |
---|
| 364 | ; |
---|
| 365 | listdims = ncdf_listdims(cdfid) |
---|
| 366 | micromask = (where(listdims EQ 'y_m'))[0] |
---|
| 367 | ; |
---|
[273] | 368 | varinq = ncdf_varinq(cdfid, 'tmask') |
---|
| 369 | name = varinq.name |
---|
[13] | 370 | IF micromask NE -1 THEN BEGIN |
---|
| 371 | ; keep original values |
---|
| 372 | iyminmeshtrue = iyminmesh |
---|
| 373 | key_stridetrue = key_stride |
---|
| 374 | yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue |
---|
| 375 | yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue |
---|
| 376 | ; the mask is stored as the bit values of the byte array (along the y |
---|
| 377 | ; dimension, see micromeshmask.pro)... |
---|
[121] | 378 | ; we must modify several parameters... |
---|
[13] | 379 | iyminmesh = 0L |
---|
| 380 | firsty = yyy1/8 |
---|
| 381 | lasty = yyy2/8 |
---|
| 382 | ny = lasty-firsty+1 |
---|
| 383 | key_stride = [key_stride[0], 1, key_stride[2]] |
---|
| 384 | @read_ncdf_varget |
---|
| 385 | tmask = bytarr(jpi, jpj, jpk) |
---|
| 386 | ; now we must get back the mask |
---|
| 387 | ; loop on the level to save memory (the loop is short and, thus, |
---|
| 388 | ; should be fast enough) |
---|
| 389 | FOR k = 0, jpk-1 DO BEGIN |
---|
| 390 | zzz = transpose(res[*, *, k]) |
---|
| 391 | zzz = reform(binary(zzz), 8*ny, nx, /over) |
---|
| 392 | zzz = transpose(temporary(zzz)) |
---|
| 393 | zzz = zzz[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8] |
---|
[121] | 394 | IF key_stridetrue[1] NE 1 THEN BEGIN |
---|
[13] | 395 | ; IF float(strmid(!version.release,0,3)) LT 5.6 THEN BEGIN |
---|
| 396 | nnny = (size(zzz))[2] |
---|
| 397 | yind = key_stridetrue[1]*lindgen((nnny-1)/key_stridetrue[1]+1) |
---|
| 398 | tmask[*, *, k] = temporary(zzz[*, yind]) |
---|
| 399 | ; ENDIF ELSE tmask[*, *, k] = temporary(zzz[*, 0:*:key_stridetrue[1]]) |
---|
| 400 | ENDIF ELSE tmask[*, *, k] = temporary(zzz) |
---|
| 401 | ENDFOR |
---|
| 402 | ENDIF ELSE BEGIN |
---|
| 403 | @read_ncdf_varget |
---|
| 404 | tmask = byte(res) |
---|
| 405 | ENDELSE |
---|
[226] | 406 | ; boundary conditions used to compute umask. |
---|
[273] | 407 | varinq = ncdf_varinq(cdfid, 'umask') |
---|
| 408 | name = varinq.name |
---|
[13] | 409 | nx = 1L |
---|
| 410 | firstx = jpi-1 |
---|
| 411 | lastx = jpi-1 |
---|
| 412 | IF micromask NE -1 THEN BEGIN |
---|
| 413 | @read_ncdf_varget |
---|
| 414 | umaskred = reform(binary(res), 8*ny, jpk, /over) |
---|
| 415 | umaskred = umaskred[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *] |
---|
| 416 | IF key_stridetrue[1] NE 1 THEN umaskred = temporary(umaskred[yind, *]) |
---|
| 417 | ENDIF ELSE BEGIN |
---|
| 418 | @read_ncdf_varget |
---|
| 419 | umaskred = reform(byte(res), /over) |
---|
| 420 | ENDELSE |
---|
[226] | 421 | ; boundary conditions used to compute fmask (1). |
---|
[273] | 422 | varinq = ncdf_varinq(cdfid, 'fmask') |
---|
| 423 | name = varinq.name |
---|
[13] | 424 | IF micromask NE -1 THEN BEGIN |
---|
| 425 | @read_ncdf_varget |
---|
| 426 | fmaskredy = reform(binary(res), 8*ny, jpk, /over) |
---|
| 427 | fmaskredy = fmaskredy[yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *] |
---|
| 428 | IF key_stridetrue[1] NE 1 THEN fmaskredy = temporary(fmaskredy[yind, *]) |
---|
| 429 | ENDIF ELSE BEGIN |
---|
| 430 | @read_ncdf_varget |
---|
| 431 | fmaskredy = reform(byte(res), /over) |
---|
| 432 | fmaskredy = temporary(fmaskredy) MOD 2 |
---|
| 433 | ENDELSE |
---|
[226] | 434 | ; boundary conditions used to compute vmask |
---|
[273] | 435 | varinq = ncdf_varinq(cdfid, 'vmask') |
---|
| 436 | name = varinq.name |
---|
[13] | 437 | nx = jpi |
---|
| 438 | firstx = 0L |
---|
| 439 | lastx = jpi-1L |
---|
| 440 | ny = 1L |
---|
| 441 | firsty = jpj-1 |
---|
| 442 | lasty = jpj-1 |
---|
| 443 | IF micromask NE -1 THEN BEGIN |
---|
| 444 | yyy1 = firsty*key_stridetrue[1]+iyminmeshtrue |
---|
| 445 | yyy2 = lasty*key_stridetrue[1]+iyminmeshtrue |
---|
| 446 | iyminmesh = 0L |
---|
| 447 | firsty = yyy1/8 |
---|
| 448 | lasty = yyy2/8 |
---|
| 449 | ny = lasty-firsty+1 |
---|
| 450 | @read_ncdf_varget |
---|
[98] | 451 | IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over) |
---|
[13] | 452 | vmaskred = transpose(temporary(res), [1, 0, 2]) |
---|
| 453 | vmaskred = reform(binary(vmaskred), 8*ny, nx, nz, /over) |
---|
| 454 | vmaskred = transpose(temporary(vmaskred), [1, 0, 2]) |
---|
| 455 | vmaskred = reform(vmaskred[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]) |
---|
| 456 | ENDIF ELSE BEGIN |
---|
| 457 | @read_ncdf_varget |
---|
| 458 | vmaskred = reform(byte(res), /over) |
---|
| 459 | ENDELSE |
---|
[226] | 460 | ; boundary conditions used to compute fmask (2). |
---|
[273] | 461 | varinq = ncdf_varinq(cdfid, 'fmask') |
---|
| 462 | name = varinq.name |
---|
[13] | 463 | IF micromask NE -1 THEN BEGIN |
---|
| 464 | @read_ncdf_varget |
---|
[98] | 465 | IF jpk EQ 1 THEN res = reform(res, jpi, 1, jpk, /over) |
---|
[13] | 466 | fmaskredx = transpose(temporary(res), [1, 0, 2]) |
---|
| 467 | fmaskredx = reform(binary(fmaskredx), 8*ny, nx, nz, /over) |
---|
| 468 | fmaskredx = transpose(temporary(fmaskredx), [1, 0, 2]) |
---|
| 469 | fmaskredx = reform(fmaskredx[*, yyy1 MOD 8: 8*ny - 8 + yyy2 MOD 8, *]) |
---|
| 470 | ; |
---|
| 471 | iyminmesh = iyminmeshtrue |
---|
| 472 | key_stride = key_stridetrue |
---|
| 473 | ENDIF ELSE BEGIN |
---|
| 474 | @read_ncdf_varget |
---|
| 475 | fmaskredx = reform(byte(res), /over) |
---|
| 476 | fmaskredx = fmaskredx MOD 2 |
---|
| 477 | ENDELSE |
---|
| 478 | ;------------------------------------------------------- |
---|
| 479 | ; 1d arrays |
---|
| 480 | ;------------------------------------------------------- |
---|
| 481 | namevar = ['e3t', 'e3w', 'gdept', 'gdepw'] |
---|
| 482 | for i = 0, n_elements(namevar)-1 do begin |
---|
[273] | 483 | varinq = ncdf_varinq(cdfid, namevar[i]) |
---|
| 484 | CASE n_elements(varinq.dim) OF |
---|
[13] | 485 | 4:BEGIN |
---|
[121] | 486 | command = 'ncdf_varget,cdfid,namevar[i],'+namevar[i] $ |
---|
[13] | 487 | +',offset = [0,0,izminmesh,0], count = [1,1,jpk,1]' |
---|
[121] | 488 | if key_stride[2] NE 1 then command = command+', stride=[1,1,key_stride[2],1]' |
---|
| 489 | END |
---|
[13] | 490 | 2:BEGIN |
---|
[121] | 491 | command = 'ncdf_varget,cdfid,namevar[i],'+namevar[i] $ |
---|
[13] | 492 | +',offset = [izminmesh,0], count = [jpk,1]' |
---|
[121] | 493 | if key_stride[2] NE 1 then command = command+', stride=key_stride[2]' |
---|
| 494 | END |
---|
[13] | 495 | 1:BEGIN |
---|
[121] | 496 | command = 'ncdf_varget,cdfid,namevar[i],'+namevar[i] $ |
---|
[13] | 497 | +',offset = [izminmesh], count = [jpk]' |
---|
[121] | 498 | if key_stride[2] NE 1 then command = command+', stride=key_stride[2]' |
---|
[13] | 499 | END |
---|
| 500 | ENDCASE |
---|
[121] | 501 | nothing = execute(command) |
---|
| 502 | command = namevar[i]+'=float('+namevar[i]+')' |
---|
| 503 | nothing = execute(command) |
---|
| 504 | command = 'if size('+namevar[i]+', /n_dimension) gt 0 then '+namevar[i]+' = reform('+namevar[i]+', /over)' |
---|
| 505 | nothing = execute(command) |
---|
[13] | 506 | ENDFOR |
---|
| 507 | ;------------------------------------------------------- |
---|
| 508 | ncdf_close, cdfid |
---|
| 509 | ;------------------------------------------------------- |
---|
[226] | 510 | ; Apply Glamboundary |
---|
[13] | 511 | ;------------------------------------------------------- |
---|
| 512 | if keyword_set(glamboundary) AND key_onearth then BEGIN |
---|
| 513 | if glamboundary[0] NE glamboundary[1] then BEGIN |
---|
[172] | 514 | glamt = temporary(glamt) MOD 360 |
---|
[13] | 515 | smaller = where(glamt LT glamboundary[0]) |
---|
| 516 | if smaller[0] NE -1 then glamt[smaller] = glamt[smaller]+360 |
---|
| 517 | bigger = where(glamt GE glamboundary[1]) |
---|
| 518 | if bigger[0] NE -1 then glamt[bigger] = glamt[bigger]-360 |
---|
[172] | 519 | glamu = temporary(glamu) MOD 360 |
---|
[13] | 520 | smaller = where(glamu LT glamboundary[0]) |
---|
| 521 | if smaller[0] NE -1 then glamu[smaller] = glamu[smaller]+360 |
---|
| 522 | bigger = where(glamu GE glamboundary[1]) |
---|
| 523 | if bigger[0] NE -1 then glamu[bigger] = glamu[bigger]-360 |
---|
[172] | 524 | glamv = temporary(glamv) MOD 360 |
---|
[13] | 525 | smaller = where(glamv LT glamboundary[0]) |
---|
| 526 | if smaller[0] NE -1 then glamv[smaller] = glamv[smaller]+360 |
---|
| 527 | bigger = where(glamv GE glamboundary[1]) |
---|
| 528 | if bigger[0] NE -1 then glamv[bigger] = glamv[bigger]-360 |
---|
[172] | 529 | glamf = temporary(glamf) MOD 360 |
---|
[13] | 530 | smaller = where(glamf LT glamboundary[0]) |
---|
| 531 | if smaller[0] NE -1 then glamf[smaller] = glamf[smaller]+360 |
---|
| 532 | bigger = where(glamf GE glamboundary[1]) |
---|
| 533 | if bigger[0] NE -1 then glamf[bigger] = glamf[bigger]-360 |
---|
| 534 | toosmall = where(glamu EQ glamboundary[0]) |
---|
| 535 | IF toosmall[0] NE -1 THEN glamu[toosmall] = glamu[toosmall] + 360 |
---|
| 536 | toosmall = where(glamf EQ glamboundary[0]) |
---|
| 537 | IF toosmall[0] NE -1 THEN glamf[toosmall] = glamf[toosmall] + 360 |
---|
| 538 | endif |
---|
| 539 | endif |
---|
| 540 | ;------------------------------------------------------- |
---|
[74] | 541 | ; make sure we do have 2d arrays when jpj eq 1 |
---|
| 542 | ;------------------------------------------------------- |
---|
[121] | 543 | IF jpj EQ 1 THEN BEGIN |
---|
[74] | 544 | glamt = reform(glamt, jpi, jpj, /over) |
---|
| 545 | gphit = reform(gphit, jpi, jpj, /over) |
---|
| 546 | e1t = reform(e1t, jpi, jpj, /over) |
---|
| 547 | e2t = reform(e2t, jpi, jpj, /over) |
---|
| 548 | glamu = reform(glamu, jpi, jpj, /over) |
---|
| 549 | gphiu = reform(gphiu, jpi, jpj, /over) |
---|
| 550 | e1u = reform(e1u, jpi, jpj, /over) |
---|
| 551 | e2u = reform(e2u, jpi, jpj, /over) |
---|
| 552 | glamv = reform(glamv, jpi, jpj, /over) |
---|
| 553 | gphiv = reform(gphiv, jpi, jpj, /over) |
---|
| 554 | e1v = reform(e1v, jpi, jpj, /over) |
---|
| 555 | e2v = reform(e2v, jpi, jpj, /over) |
---|
| 556 | glamf = reform(glamf, jpi, jpj, /over) |
---|
| 557 | gphif = reform(gphif, jpi, jpj, /over) |
---|
| 558 | e1f = reform(e1f, jpi, jpj, /over) |
---|
| 559 | e2f = reform(e2f, jpi, jpj, /over) |
---|
| 560 | IF keyword_set(key_partialstep) THEN BEGIN |
---|
| 561 | hdept = reform(hdept, jpi, jpj, /over) |
---|
| 562 | hdepw = reform(hdepw, jpi, jpj, /over) |
---|
| 563 | e3t_ps = reform(e3t_ps, jpi, jpj, /over) |
---|
| 564 | e3w_ps = reform(e3w_ps, jpi, jpj, /over) |
---|
[121] | 565 | ENDIF |
---|
[74] | 566 | ENDIF |
---|
| 567 | ;------------------------------------------------------- |
---|
[13] | 568 | ixmindta = ixmindtasauve |
---|
| 569 | iymindta = iymindtasauve |
---|
| 570 | izmindta = izmindtasauve |
---|
| 571 | ;------------------------------------------------------- |
---|
| 572 | widget_control, noticebase, bad_id = nothing, /destroy |
---|
| 573 | ; |
---|
[69] | 574 | ;==================================================== |
---|
| 575 | ; grid parameters used by xxx |
---|
| 576 | ;==================================================== |
---|
| 577 | ; |
---|
[121] | 578 | IF NOT keyword_set(strcalling) THEN BEGIN |
---|
[69] | 579 | IF n_elements(ccmeshparameters) EQ 0 THEN strcalling = 'ncdf_meshread' $ |
---|
| 580 | ELSE strcalling = ccmeshparameters.filename |
---|
[121] | 581 | ENDIF |
---|
[74] | 582 | IF n_elements(glamt) GE 2 THEN BEGIN |
---|
| 583 | glaminfo = moment(glamt) |
---|
| 584 | IF finite(glaminfo[2]) EQ 0 THEN glaminfo = glaminfo[0:1] |
---|
| 585 | gphiinfo = moment(gphit) |
---|
| 586 | IF finite(gphiinfo[2]) EQ 0 THEN gphiinfo = gphiinfo[0:1] |
---|
[121] | 587 | ENDIF ELSE BEGIN |
---|
[74] | 588 | glaminfo = glamt |
---|
| 589 | gphiinfo = gphit |
---|
[121] | 590 | ENDELSE |
---|
[172] | 591 | romszinfos = {h:-1, zeta:-1, theta_s:-1, theta_b:-1, hc:-1} |
---|
[69] | 592 | ccmeshparameters = {filename:strcalling $ |
---|
[74] | 593 | , glaminfo:float(string(glaminfo, format = '(E11.4)')) $ |
---|
| 594 | , gphiinfo:float(string(gphiinfo, format = '(E11.4)')) $ |
---|
[69] | 595 | , jpiglo:jpiglo, jpjglo:jpjglo, jpkglo:jpkglo $ |
---|
| 596 | , jpi:jpi, jpj:jpj, jpk:jpk $ |
---|
| 597 | , ixminmesh:ixminmesh, ixmaxmesh:ixmaxmesh $ |
---|
| 598 | , iyminmesh:iyminmesh, iymaxmesh:iymaxmesh $ |
---|
| 599 | , izminmesh:izminmesh, izmaxmesh:izmaxmesh $ |
---|
| 600 | , key_shift:key_shift, key_periodic:key_periodic $ |
---|
| 601 | , key_stride:key_stride, key_gridtype:key_gridtype $ |
---|
| 602 | , key_yreverse:key_yreverse, key_zreverse:key_zreverse $ |
---|
| 603 | , key_partialstep:key_partialstep, key_onearth:key_onearth} |
---|
| 604 | ; |
---|
[13] | 605 | if keyword_set(key_performance) THEN $ |
---|
[121] | 606 | print, 'time ncdf_meshread', systime(1)-tempsun |
---|
[13] | 607 | |
---|
| 608 | ;------------------------------------------------------- |
---|
| 609 | @updateold |
---|
| 610 | ;------------------------------------------------------- |
---|
| 611 | return |
---|
| 612 | end |
---|