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