[2] | 1 | ;------------------------------------------------------------ |
---|
| 2 | ;------------------------------------------------------------ |
---|
| 3 | ;------------------------------------------------------------ |
---|
| 4 | ;+ |
---|
| 5 | ; |
---|
[223] | 6 | ; @file_comments |
---|
[142] | 7 | ; averages a 2- or 3-d field over a selected |
---|
[2] | 8 | ; geographical area and along one ore more |
---|
| 9 | ; selected axes (x, y or z) |
---|
| 10 | ; |
---|
[142] | 11 | ; @categories |
---|
[2] | 12 | ; |
---|
[163] | 13 | ; @param TAB {in}{required} |
---|
[142] | 14 | ; 2 or 3d field |
---|
[2] | 15 | ; |
---|
[142] | 16 | ; @param DIREC {in}{required} |
---|
| 17 | ; 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz' |
---|
[2] | 18 | ; |
---|
[223] | 19 | ; @keyword BOXZOOM |
---|
[142] | 20 | ; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see domdef |
---|
[223] | 21 | ; boxzoom can have 5 forms: |
---|
[163] | 22 | ; [vert2], |
---|
| 23 | ; [vert1, vert2], |
---|
[223] | 24 | ; [lon1, lon2, lat1, lat2], |
---|
[163] | 25 | ; [lon1, lon2, lat1, lat2, vert2], |
---|
| 26 | ; [lon1, lon2, lat1, lat2, vert1,vert2] |
---|
[2] | 27 | ; |
---|
[223] | 28 | ; @keyword NAN |
---|
[142] | 29 | ; not a number, we activate it if we want to average without considerate some masked values of TAB. |
---|
[163] | 30 | ; If masked values of TAB are values consecrated by IDL(!values.f_nan), we just have to put NAN. |
---|
[142] | 31 | ; If masked values of TAB are valued a (a must be different of 1, corresponding to nan = |
---|
[223] | 32 | ; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a. |
---|
[163] | 33 | ; Comment: In output, result points which are NAN will be valued a or !values.f_nan. |
---|
[223] | 34 | ; |
---|
[142] | 35 | ; @keyword NODOMDEF |
---|
[223] | 36 | ; We activate it if we do not want to pass in domdef even if the keyword boxzoom |
---|
[142] | 37 | ; is present (like when grossemoyenne is called via checkfield) |
---|
[2] | 38 | ; |
---|
[223] | 39 | ; @keyword INTEGRATION |
---|
[142] | 40 | ; To make an integral rather than an average |
---|
[223] | 41 | ; |
---|
| 42 | ; @keyword WDEPTH |
---|
| 43 | ; to specify that the field is at W depth instead of T |
---|
| 44 | ; depth (automatically activated if vargrid eq 'W') |
---|
| 45 | ; |
---|
[142] | 46 | ; @returns |
---|
[223] | 47 | ; An array |
---|
[2] | 48 | ; |
---|
[142] | 49 | ; @uses |
---|
| 50 | ; common |
---|
| 51 | ; domdef |
---|
[2] | 52 | ; |
---|
[223] | 53 | ; @restrictions |
---|
| 54 | ; Put values corresponding to land at 1.e20 |
---|
[2] | 55 | ; |
---|
[142] | 56 | ; @history |
---|
[157] | 57 | ; Jerome Vialard (jv\@lodyc.jussieu.fr) |
---|
[2] | 58 | ; 2/7/98 |
---|
[157] | 59 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
[2] | 60 | ; 14/8/98 |
---|
| 61 | ; 15/1/98 |
---|
[142] | 62 | ; 11/3/99 adaptation for NAN |
---|
| 63 | ; 28/7/99 Averages 1d arrays |
---|
| 64 | ; |
---|
| 65 | ; @version |
---|
| 66 | ; $Id$ |
---|
| 67 | ; |
---|
[2] | 68 | ;- |
---|
[142] | 69 | |
---|
[25] | 70 | function moyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $ |
---|
| 71 | , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $ |
---|
| 72 | , _extra = ex |
---|
| 73 | ;--------------------------------------------------------- |
---|
[114] | 74 | ; |
---|
| 75 | compile_opt idl2, strictarrsubs |
---|
| 76 | ; |
---|
[25] | 77 | @cm_4mesh |
---|
| 78 | @cm_4data |
---|
| 79 | @cm_4cal |
---|
| 80 | IF NOT keyword_set(key_forgetold) THEN BEGIN |
---|
| 81 | @updatenew |
---|
| 82 | @updatekwd |
---|
| 83 | ENDIF |
---|
| 84 | ;--------------------------------------------------------- |
---|
[142] | 85 | tempsun = systime(1) ; To key_performance |
---|
[2] | 86 | ;------------------------------------------------------------ |
---|
[142] | 87 | ;I) preliminaries |
---|
[2] | 88 | ;------------------------------------------------------------ |
---|
[25] | 89 | dirt = 0 |
---|
| 90 | dirx = 0 |
---|
| 91 | diry = 0 |
---|
| 92 | dirz = 0 |
---|
[2] | 93 | ;------------------------------------------------------------ |
---|
[142] | 94 | ; I.1) Directions(s) we follow to integrate |
---|
[2] | 95 | ;------------------------------------------------------------ |
---|
[25] | 96 | if ( strpos(direc, 't') ge 0 ) then dirt = 1 |
---|
| 97 | if ( strpos(direc, 'x') ge 0 ) then dirx = 1 |
---|
| 98 | if ( strpos(direc, 'y') ge 0 ) then diry = 1 |
---|
| 99 | if ( strpos(direc, 'z') ge 0 ) then dirz = 1 |
---|
| 100 | if (dirx eq 0 and diry eq 0 and dirz eq 0) then return, tab |
---|
[2] | 101 | ;------------------------------------------------------------ |
---|
[142] | 102 | ; I.2) verification of the input array's size |
---|
[2] | 103 | ;------------------------------------------------------------ |
---|
[25] | 104 | taille = size(tab) |
---|
| 105 | case 1 of |
---|
| 106 | taille[0] eq 1 :dim = '1d' |
---|
| 107 | taille[0] eq 2 :BEGIN |
---|
| 108 | dim = '2d' |
---|
| 109 | if dirx eq 0 and diry eq 0 then return, tab |
---|
| 110 | END |
---|
| 111 | taille[0] eq 3 :BEGIN |
---|
| 112 | dim = '3d' |
---|
| 113 | if dirx eq 0 and diry eq 0 and dirz eq 0 then return, tab |
---|
| 114 | END |
---|
[223] | 115 | else : return, report('Array must have 2 or 3 dimensions if there is a time dimension use grossemoyenne') |
---|
[25] | 116 | endcase |
---|
[2] | 117 | ;------------------------------------------------------------ |
---|
[142] | 118 | ; I.3) Obtainment of scale's factors and of the mask on the subdomain concernedby the average. |
---|
| 119 | ; Redefinition of the domain ajusted at boxzoom (at 6 elements) |
---|
| 120 | ; This will allowed us to calculate only in the domain concerned by the average. |
---|
[223] | 121 | ; Domdef, followed by grid give us all arrays of the grid on the subdomain |
---|
[2] | 122 | ;------------------------------------------------------------ |
---|
[223] | 123 | if keyword_set(boxzoom) then BEGIN |
---|
[25] | 124 | Case 1 Of |
---|
| 125 | N_Elements(Boxzoom) Eq 1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]] |
---|
| 126 | N_Elements(Boxzoom) Eq 2:bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]] |
---|
| 127 | N_Elements(Boxzoom) Eq 4:bte = [Boxzoom, vert1, vert2] |
---|
| 128 | N_Elements(Boxzoom) Eq 5:bte = [Boxzoom[0:3], 0, Boxzoom[4]] |
---|
| 129 | N_Elements(Boxzoom) Eq 6:bte = Boxzoom |
---|
[223] | 130 | Else: return, report('Bad definition of Boxzoom') |
---|
[25] | 131 | endcase |
---|
[223] | 132 | if NOT keyword_set(nodomdef) then BEGIN |
---|
[25] | 133 | savedbox = 1b |
---|
| 134 | saveboxparam, 'boxparam4moyenne.dat' |
---|
| 135 | domdef, bte, GRIDTYPE = vargrid, _extra = ex |
---|
[223] | 136 | ENDIF |
---|
| 137 | ENDIF |
---|
[2] | 138 | ;--------------------------------------------------------------- |
---|
[142] | 139 | ; attribution of the mask and of longitude and latitude arrays... |
---|
[2] | 140 | ;--------------------------------------------------------------- |
---|
[25] | 141 | IF vargrid EQ 'W' THEN wdepth = 1 |
---|
| 142 | grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz, e1, e2, e3, WDEPTH = wdepth |
---|
[2] | 143 | ;------------------------------------------------------------ |
---|
| 144 | ;------------------------------------------------------------ |
---|
[142] | 145 | ; II) Case of the 1d array |
---|
[2] | 146 | ;------------------------------------------------------------ |
---|
| 147 | ;------------------------------------------------------------ |
---|
[25] | 148 | if dim EQ '1d' then BEGIN |
---|
| 149 | if n_elements(tab) NE nx*ny AND n_elements(tab) NE nx*ny*nz then BEGIN |
---|
| 150 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 151 | return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') |
---|
| 152 | ENDIF |
---|
| 153 | case 1 of |
---|
[142] | 154 | nx EQ 1 AND ny EQ 1:BEGIN ;vector following z |
---|
[25] | 155 | case n_elements(tab) of |
---|
| 156 | jpk:res = tab[firstz:lastz] |
---|
| 157 | nz:res = tab |
---|
[223] | 158 | ELSE:BEGIN |
---|
[25] | 159 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 160 | return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') |
---|
| 161 | END |
---|
| 162 | ENDCASE |
---|
[223] | 163 | if dirz EQ 1 then BEGIN |
---|
| 164 | dim = '3d' |
---|
[25] | 165 | taille = size(reform(res, nx, ny, nz)) |
---|
| 166 | ENDIF ELSE BEGIN |
---|
| 167 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 168 | return, res |
---|
[223] | 169 | ENDELSE |
---|
[25] | 170 | END |
---|
[142] | 171 | ny EQ 1:BEGIN ;vector following x |
---|
[25] | 172 | case n_elements(tab) of |
---|
| 173 | jpi:res = tab[firstx:lastx] |
---|
| 174 | nx:res = tab |
---|
[223] | 175 | ELSE:BEGIN |
---|
[25] | 176 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 177 | return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') |
---|
| 178 | END |
---|
| 179 | ENDCASE |
---|
[223] | 180 | if dirx EQ 1 then BEGIN |
---|
| 181 | dim = '2d' |
---|
[25] | 182 | taille = size(reform(res, nx, ny)) |
---|
[223] | 183 | ENDIF ELSE BEGIN |
---|
[25] | 184 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 185 | return, res |
---|
| 186 | ENDELSE |
---|
| 187 | END |
---|
[142] | 188 | nx EQ 1:BEGIN ;vector following y |
---|
[25] | 189 | case n_elements(tab) of |
---|
| 190 | jpj:res = tab[firsty:lasty] |
---|
| 191 | ny:res = tab |
---|
[223] | 192 | ELSE:BEGIN |
---|
[25] | 193 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 194 | return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') |
---|
| 195 | END |
---|
| 196 | ENDCASE |
---|
| 197 | if diry EQ 1 then BEGIN |
---|
| 198 | dim = '2d' |
---|
| 199 | taille = size(reform(res, nx, ny)) |
---|
[223] | 200 | ENDIF ELSE BEGIN |
---|
[25] | 201 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 202 | return, res |
---|
[223] | 203 | ENDELSE |
---|
[25] | 204 | END |
---|
| 205 | endcase |
---|
| 206 | endif |
---|
[2] | 207 | ;------------------------------------------------------------ |
---|
| 208 | ;------------------------------------------------------------ |
---|
[142] | 209 | ; II) Case of the 2d array |
---|
[2] | 210 | ;------------------------------------------------------------ |
---|
| 211 | ;------------------------------------------------------------ |
---|
[25] | 212 | if (dim eq '2d') then begin |
---|
[2] | 213 | ;--------------------------------------------------------------- |
---|
[142] | 214 | ; II.1) verification of the coherence of the array's size to average |
---|
| 215 | ; Verification of the coherence between the array's size and the domain defined by domdef |
---|
[223] | 216 | ; The input array must have either the total domain's size (jpi,jpj) or this |
---|
[142] | 217 | ; one of the reduced domain (nx,ny) |
---|
[2] | 218 | ;--------------------------------------------------------------- |
---|
[25] | 219 | case 1 of |
---|
| 220 | taille[1] eq jpi and taille[2] eq jpj: $ |
---|
| 221 | res = tab[firstx:lastx, firsty:lasty] |
---|
| 222 | taille[1] eq nx and taille[2] eq ny:res = tab |
---|
[223] | 223 | else:BEGIN |
---|
[25] | 224 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 225 | return, report('Probleme d''adequation entre les tailles du domaine nx*ny '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)) |
---|
| 226 | END |
---|
| 227 | ENDCASE |
---|
[223] | 228 | if keyword_set(nan) NE 0 then BEGIN |
---|
| 229 | if nan NE 1 then BEGIN ; If nan is not !values.f_nan |
---|
[142] | 230 | ; we put it at !values.f_nan |
---|
[25] | 231 | if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ |
---|
| 232 | ELSE notanumber = where(abs(res) GT abs(nan)/10.) |
---|
| 233 | if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan |
---|
[2] | 234 | ENDIF |
---|
[25] | 235 | ENDIF |
---|
[2] | 236 | ;--------------------------------------------------------------- |
---|
[223] | 237 | ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, |
---|
| 238 | ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN |
---|
[142] | 239 | ; LOOK USELESS AT THE BEGINNING |
---|
[2] | 240 | ;--------------------------------------------------------------- |
---|
[223] | 241 | if nx EQ 1 OR ny EQ 1 then BEGIN |
---|
[25] | 242 | res = reform(res, nx, ny, /over) |
---|
| 243 | e1 = reform(e1, nx, ny, /over) |
---|
| 244 | e2 = reform(e2, nx, ny, /over) |
---|
| 245 | endif |
---|
| 246 | if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $ |
---|
| 247 | mask = reform(mask, nx, ny, nz, /over) |
---|
[2] | 248 | ;--------------------------------------------------------------- |
---|
[142] | 249 | ; II.3) Different types of average |
---|
[2] | 250 | ;--------------------------------------------------------------- |
---|
[25] | 251 | mask = mask[*, *, 0] |
---|
| 252 | if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1 |
---|
| 253 | case 1 of |
---|
| 254 | (dirx eq 1) and (diry eq 0) : begin |
---|
| 255 | e = e1*mask |
---|
| 256 | if keyword_set(integration) then divi = 1 $ |
---|
[223] | 257 | else begin |
---|
[25] | 258 | divi = e |
---|
| 259 | IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan |
---|
| 260 | if ny EQ 1 then divi = reform(divi, nx, ny, /over) |
---|
| 261 | divi = total(divi, 1) |
---|
| 262 | endelse |
---|
| 263 | res = res*e |
---|
| 264 | if ny EQ 1 then res = reform(res, nx, ny, /over) |
---|
| 265 | res = total(res, 1, nan = nan)/(divi > 1.) |
---|
| 266 | if msknan[0] NE -1 then begin |
---|
| 267 | testnan = msknan*mask |
---|
| 268 | if ny EQ 1 then testnan = reform(testnan, nx, ny, /over) |
---|
| 269 | testnan = total(testnan, 1)+(total(mask, 1) EQ 0) |
---|
| 270 | endif |
---|
| 271 | end |
---|
| 272 | (dirx eq 0) and (diry eq 1) : begin |
---|
| 273 | e = e2*mask |
---|
| 274 | if keyword_set(integration) then divi = 1 $ |
---|
[223] | 275 | else begin |
---|
[25] | 276 | divi = e |
---|
| 277 | IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan |
---|
| 278 | if ny EQ 1 then divi = reform(divi, nx, ny, /over) |
---|
| 279 | divi = total(divi, 2) |
---|
| 280 | endelse |
---|
| 281 | res = res*e |
---|
| 282 | if ny EQ 1 then res = reform(res, nx, ny, /over) |
---|
| 283 | res = total(res, 2, nan = nan)/(divi > 1.) |
---|
| 284 | if msknan[0] NE -1 then begin |
---|
| 285 | testnan = msknan*mask |
---|
| 286 | if ny EQ 1 then testnan = reform(testnan, nx, ny, /over) |
---|
| 287 | testnan = total(testnan, 2)+(total(mask, 2) EQ 0) |
---|
| 288 | endif |
---|
| 289 | end |
---|
| 290 | (dirx eq 1) and (diry eq 1) : begin |
---|
[223] | 291 | if keyword_set(integration) then divi = 1 else BEGIN |
---|
[25] | 292 | IF msknan[0] NE -1 THEN divi = total(e1*e2*mask*msknan) $ |
---|
| 293 | ELSE divi = total(e1*e2*mask) |
---|
[223] | 294 | ENDELSE |
---|
[25] | 295 | res = total(res*e1*e2*mask, nan = nan)/(divi > 1.) |
---|
| 296 | if msknan[0] NE -1 then begin |
---|
| 297 | testnan = msknan*mask |
---|
| 298 | testnan = total(testnan)+(total(mask) EQ 0) |
---|
| 299 | endif |
---|
| 300 | end |
---|
| 301 | endcase |
---|
| 302 | endif |
---|
[2] | 303 | ;------------------------------------------------------------ |
---|
| 304 | ;------------------------------------------------------------ |
---|
[142] | 305 | ; III) Case 3d arrays series (tab4d) |
---|
[2] | 306 | ;------------------------------------------------------------ |
---|
| 307 | ;------------------------------------------------------------ |
---|
[25] | 308 | if (dim eq '3d') then begin |
---|
[2] | 309 | ;--------------------------------------------------------------- |
---|
[223] | 310 | ; III.1) Verification of the coherence of the array to average size |
---|
| 311 | ; Verification of the coherence between the array's size and the domain |
---|
| 312 | ; defind by domdef |
---|
| 313 | ; The input array must have either the total domain size (jpi,jpj,jpk) |
---|
[142] | 314 | ; or this one of the reduced domain (nx,ny,ny) |
---|
[2] | 315 | ;--------------------------------------------------------------- |
---|
[25] | 316 | case 1 of |
---|
| 317 | taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpk: $ |
---|
| 318 | res = tab[firstx:lastx, firsty:lasty, firstz:lastz] |
---|
| 319 | taille[1] eq jpi and taille[2] eq jpj and taille[3] eq nz: $ |
---|
| 320 | res = tab[firstx:lastx, firsty:lasty, *] |
---|
| 321 | taille[1] EQ nx and taille[2] eq ny and taille[3] eq nz :res = tab |
---|
| 322 | taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpk : $ |
---|
| 323 | res = tab[*, *, firstz:lastz] |
---|
[223] | 324 | else:BEGIN |
---|
[25] | 325 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
| 326 | return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(nz, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1)) |
---|
| 327 | END |
---|
| 328 | endcase |
---|
[223] | 329 | if keyword_set(nan) NE 0 then BEGIN |
---|
| 330 | if nan NE 1 then BEGIN ; if nan is not !values.f_nan |
---|
[142] | 331 | ; we put it at !values.f_nan |
---|
[25] | 332 | if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ |
---|
| 333 | ELSE notanumber = where(abs(res) GT abs(nan)/10.) |
---|
| 334 | if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan |
---|
[2] | 335 | ENDIF |
---|
[25] | 336 | ENDIF |
---|
[2] | 337 | ;--------------------------------------------------------------- |
---|
[223] | 338 | ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, |
---|
| 339 | ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN |
---|
[142] | 340 | ; LOOK USELESS AT THE BEGINNING |
---|
[2] | 341 | ;--------------------------------------------------------------- |
---|
[223] | 342 | if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN |
---|
[25] | 343 | res = reform(res, nx, ny, nz, /over) |
---|
| 344 | e1 = reform(e1, nx, ny, /over) |
---|
| 345 | e2 = reform(e2, nx, ny, /over) |
---|
| 346 | endif |
---|
| 347 | if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $ |
---|
| 348 | mask = reform(mask, nx, ny, nz, /over) |
---|
| 349 | IF keyword_set(key_partialstep) THEN BEGIN |
---|
| 350 | ; the top of the ocean floor is |
---|
| 351 | IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $ |
---|
[223] | 352 | ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3) |
---|
| 353 | ; we suppress columns with only ocean or land |
---|
[25] | 354 | good = where(bottom NE 0 AND bottom NE nz) |
---|
| 355 | ; the bottom of the ocean in 3D index is: |
---|
| 356 | bottom = lindgen(nx*ny)+(temporary(bottom)-1L)*nx*ny |
---|
| 357 | IF good[0] NE -1 THEN bottom = bottom[good] $ |
---|
| 358 | ELSE bottom = -1 |
---|
| 359 | ENDIF ELSE bottom = -1 |
---|
[2] | 360 | ;--------------------------------------------------------------- |
---|
[142] | 361 | ; III.2) different average types |
---|
[2] | 362 | ;--------------------------------------------------------------- |
---|
[25] | 363 | if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1 |
---|
| 364 | case 1 of |
---|
| 365 | (dirx eq 1) and (diry eq 0) and (dirz eq 0) : begin |
---|
| 366 | e13 = e1[*]#replicate(1., nz) |
---|
| 367 | e13 = reform(e13, nx, ny, nz, /over) |
---|
| 368 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ |
---|
| 369 | AND nx NE 1 THEN BEGIN |
---|
[223] | 370 | IF msknan[0] EQ -1 THEN BEGIN |
---|
[25] | 371 | msknan = replicate(1b, nx, ny, nz) |
---|
| 372 | nan = 1 |
---|
| 373 | endif |
---|
| 374 | msknan[bottom] = 0 |
---|
| 375 | res[bottom] = !values.f_nan |
---|
| 376 | ENDIF |
---|
| 377 | if keyword_set(integration) then divi = 1 else begin |
---|
| 378 | divi = e13*mask |
---|
| 379 | IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan |
---|
| 380 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 381 | divi = total(divi, 1) |
---|
| 382 | ENDELSE |
---|
| 383 | res = res*e13*mask |
---|
| 384 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 385 | res = total(res, 1, nan = nan)/(divi > 1.) |
---|
| 386 | e13 = 1 |
---|
| 387 | if msknan[0] NE -1 then begin |
---|
| 388 | testnan = msknan*mask |
---|
| 389 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 390 | testnan = total(testnan, 1)+(total(mask, 1) EQ 0) |
---|
| 391 | endif |
---|
| 392 | end |
---|
| 393 | (dirx eq 0) and (diry eq 1) and (dirz eq 0) : begin |
---|
| 394 | e23 = e2[*]#replicate(1., nz) |
---|
| 395 | e23 = reform(e23, nx, ny, nz, /over) |
---|
| 396 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ |
---|
| 397 | AND ny NE 1 THEN BEGIN |
---|
[223] | 398 | IF msknan[0] EQ -1 THEN BEGIN |
---|
[25] | 399 | msknan = replicate(1b, nx, ny, nz) |
---|
| 400 | nan = 1 |
---|
| 401 | endif |
---|
| 402 | msknan[bottom] = 0 |
---|
| 403 | res[bottom] = !values.f_nan |
---|
| 404 | ENDIF |
---|
| 405 | if keyword_set(integration) then divi = 1 else begin |
---|
| 406 | divi = e23*mask |
---|
| 407 | IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan |
---|
| 408 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 409 | divi = total(divi, 2) |
---|
| 410 | ENDELSE |
---|
| 411 | res = res*e23*mask |
---|
| 412 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 413 | res = total(res, 2, nan = nan)/(divi > 1.) |
---|
| 414 | e23 = 1 |
---|
| 415 | if msknan[0] NE -1 then begin |
---|
| 416 | testnan = msknan*mask |
---|
| 417 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 418 | testnan = total(testnan, 2)+(total(mask, 2) EQ 0) |
---|
| 419 | endif |
---|
| 420 | end |
---|
| 421 | (dirx eq 0) and (diry eq 0) and (dirz eq 1) : begin |
---|
| 422 | e33 = replicate(1, 1.*nx*ny)#e3 |
---|
| 423 | e33 = reform(e33, nx, ny, nz, /over) |
---|
| 424 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN |
---|
| 425 | IF keyword_set(wdepth) THEN $ |
---|
| 426 | e33[bottom] = (e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ |
---|
| 427 | ELSE e33[bottom] = (e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] |
---|
| 428 | ENDIF |
---|
| 429 | if keyword_set(integration) then divi = 1 else begin |
---|
| 430 | divi = e33*mask |
---|
| 431 | if msknan[0] NE -1 then divi = temporary(divi)*msknan |
---|
| 432 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 433 | divi = total(divi, 3) |
---|
| 434 | ENDELSE |
---|
| 435 | res = res*e33*mask |
---|
| 436 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 437 | res = total(res, 3, nan = nan)/(divi > 1.) |
---|
| 438 | e33 = 1 |
---|
| 439 | if msknan[0] NE -1 then begin |
---|
| 440 | testnan = msknan*mask |
---|
| 441 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 442 | testnan = total(testnan, 3)+(total(mask, 3) EQ 0) |
---|
| 443 | endif |
---|
| 444 | end |
---|
| 445 | (dirx eq 1) and (diry eq 1) and (dirz eq 0) : begin |
---|
| 446 | e123 = (e1*e2)[*]#replicate(1., nz) |
---|
| 447 | e123 = reform(e123, nx, ny, nz, /over) |
---|
| 448 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ |
---|
| 449 | AND nx*ny NE 1 THEN BEGIN |
---|
[223] | 450 | IF msknan[0] EQ -1 THEN BEGIN |
---|
[25] | 451 | msknan = replicate(1b, nx, ny, nz) |
---|
| 452 | nan = 1 |
---|
| 453 | endif |
---|
| 454 | msknan[bottom] = 0 |
---|
| 455 | res[bottom] = !values.f_nan |
---|
| 456 | ENDIF |
---|
[223] | 457 | if keyword_set(integration) then divi = 1 else BEGIN |
---|
[25] | 458 | divi = e123*mask |
---|
| 459 | IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan |
---|
| 460 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 461 | divi = total(total(divi, 1), 1) |
---|
| 462 | ENDELSE |
---|
| 463 | res = res*e123*mask |
---|
| 464 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 465 | res = total(total(res, 1, nan = nan), 1, nan = nan) / (divi > 1.) |
---|
| 466 | e123 = 1 |
---|
| 467 | if msknan[0] NE -1 then begin |
---|
| 468 | testnan = msknan*mask |
---|
| 469 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 470 | testnan = total(total(testnan, 1), 1)+(total(total(mask, 1), 1) EQ 0) |
---|
| 471 | endif |
---|
| 472 | end |
---|
| 473 | (dirx eq 1) and (diry eq 0) and (dirz eq 1) : begin |
---|
| 474 | e133 = e1[*]#e3 |
---|
| 475 | e133 = reform(e133, nx, ny, nz, /over) |
---|
| 476 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN |
---|
| 477 | IF keyword_set(wdepth) THEN $ |
---|
| 478 | e133[bottom] = (e1*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ |
---|
| 479 | ELSE e133[bottom] = (e1*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] |
---|
| 480 | ENDIF |
---|
[223] | 481 | if keyword_set(integration) then divi = 1 else BEGIN |
---|
[25] | 482 | divi = e133*mask |
---|
| 483 | if msknan[0] NE -1 then divi = temporary(divi)*msknan |
---|
| 484 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 485 | divi = total(total(divi, 1), 2) |
---|
| 486 | ENDELSE |
---|
| 487 | res = res*e133*mask |
---|
| 488 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 489 | res = total(total(res, 1, nan = nan), 2, nan = nan) / (divi > 1.) |
---|
| 490 | e133 = 1 |
---|
| 491 | if msknan[0] NE -1 then begin |
---|
| 492 | testnan = msknan*mask |
---|
| 493 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 494 | testnan = total(total(testnan, 1), 2)+(total(total(mask, 1), 2) EQ 0) |
---|
| 495 | endif |
---|
| 496 | end |
---|
| 497 | (dirx eq 0) and (diry eq 1) and (dirz eq 1) : begin |
---|
| 498 | e233 = e2[*]#e3 |
---|
| 499 | e233 = reform(e233, nx, ny, nz, /over) |
---|
| 500 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN |
---|
| 501 | IF keyword_set(wdepth) THEN $ |
---|
| 502 | e233[bottom] = (e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ |
---|
| 503 | ELSE e233[bottom] = (e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] |
---|
| 504 | ENDIF |
---|
[223] | 505 | if keyword_set(integration) then divi = 1 else BEGIN |
---|
[25] | 506 | divi = e233*mask |
---|
| 507 | if msknan[0] NE -1 then divi = temporary(divi)*msknan |
---|
| 508 | if nz EQ 1 then divi = reform(divi, nx, ny, nz, /over) |
---|
| 509 | divi = total(total(divi, 2), 2) |
---|
| 510 | ENDELSE |
---|
| 511 | res = res*e233*mask |
---|
| 512 | if nz EQ 1 then res = reform(res, nx, ny, nz, /over) |
---|
| 513 | res = total(total(res, 2, nan = nan), 2, nan = nan) / (divi > 1.) |
---|
| 514 | e233 = 1 |
---|
| 515 | if msknan[0] NE -1 then begin |
---|
| 516 | testnan = msknan*mask |
---|
| 517 | if nz EQ 1 then testnan = reform(testnan, nx, ny, nz, /over) |
---|
| 518 | testnan = total(total(testnan, 2), 2)+(total(total(mask, 2), 2) EQ 0) |
---|
| 519 | endif |
---|
| 520 | end |
---|
| 521 | (dirx eq 1) and (diry eq 1) and (dirz eq 1) : begin |
---|
| 522 | e1233 = (e1*e2)[*]#e3 |
---|
| 523 | e1233 = reform(e1233, nx, ny, nz, /over) |
---|
| 524 | IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN |
---|
| 525 | IF keyword_set(wdepth) THEN $ |
---|
| 526 | e1233[bottom] = (e1*e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ |
---|
| 527 | ELSE e1233[bottom] = (e1*e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] |
---|
| 528 | ENDIF |
---|
[223] | 529 | if keyword_set(integration) then divi = 1 else BEGIN |
---|
[25] | 530 | if msknan[0] NE -1 then divi = total(e1233*mask*msknan) $ |
---|
| 531 | ELSE divi = total(e1233*mask) |
---|
| 532 | ENDELSE |
---|
| 533 | res = total(res*e1233*mask, nan = nan) / (divi > 1.) |
---|
| 534 | e1233 = 1 |
---|
| 535 | if msknan[0] NE -1 then begin |
---|
| 536 | testnan = msknan*mask |
---|
| 537 | testnan = total(testnan)+(total(mask) EQ 0) |
---|
| 538 | endif |
---|
| 539 | end |
---|
| 540 | endcase |
---|
| 541 | endif |
---|
[2] | 542 | ;------------------------------------------------------------ |
---|
| 543 | ;------------------------------------------------------------ |
---|
[142] | 544 | ;IV ) finishing |
---|
[2] | 545 | ;------------------------------------------------------------ |
---|
| 546 | ;------------------------------------------------------------ |
---|
[142] | 547 | ; IV.1) We mask land by a value equal to 1.e+20 |
---|
[2] | 548 | ;------------------------------------------------------------ |
---|
[25] | 549 | valmask = 1e+20 |
---|
| 550 | terre = where(divi EQ 0) |
---|
| 551 | IF terre[0] NE -1 THEN BEGIN |
---|
[114] | 552 | res[terre] = 1e+20 |
---|
[223] | 553 | ENDIF |
---|
[2] | 554 | ;------------------------------------------------------------ |
---|
[142] | 555 | ; IV.2) We replace, when nan equal 1, !values.f_nan by nan |
---|
[2] | 556 | ;------------------------------------------------------------ |
---|
[223] | 557 | if keyword_set(nan) NE 0 then BEGIN |
---|
[25] | 558 | puttonan = where(testnan EQ 0) |
---|
| 559 | if puttonan[0] NE -1 then res[puttonan] = !values.f_nan |
---|
[223] | 560 | if nan NE 1 then BEGIN |
---|
[25] | 561 | notanumber = where(finite(res) eq 0) |
---|
| 562 | if notanumber[0] NE -1 then res[notanumber] = nan |
---|
| 563 | ENDIF |
---|
| 564 | ENDIF |
---|
[2] | 565 | ;------------------------------------------------------------ |
---|
[142] | 566 | ; IV.3) We replace in the domain whch was defined at the entry of average |
---|
[2] | 567 | ;------------------------------------------------------------ |
---|
[25] | 568 | if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' |
---|
[2] | 569 | ;------------------------------------------------------------ |
---|
[223] | 570 | if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun |
---|
[25] | 571 | return, res |
---|
[2] | 572 | ;------------------------------------------------------------ |
---|
| 573 | ;------------------------------------------------------------ |
---|
| 574 | end |
---|