Changeset 223 for trunk/SRC/ToBeReviewed/CALCULS/moyenne.pro
- Timestamp:
- 03/14/07 18:13:39 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/CALCULS/moyenne.pro
r163 r223 4 4 ;+ 5 5 ; 6 ; @file_comments 6 ; @file_comments 7 7 ; averages a 2- or 3-d field over a selected 8 8 ; geographical area and along one ore more … … 17 17 ; 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz' 18 18 ; 19 ; @keyword BOXZOOM 19 ; @keyword BOXZOOM 20 20 ; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see domdef 21 ; boxzoom can have 5 forms: 21 ; boxzoom can have 5 forms: 22 22 ; [vert2], 23 23 ; [vert1, vert2], 24 ; [lon1, lon2, lat1, lat2], 24 ; [lon1, lon2, lat1, lat2], 25 25 ; [lon1, lon2, lat1, lat2, vert2], 26 26 ; [lon1, lon2, lat1, lat2, vert1,vert2] 27 27 ; 28 ; @keyword NAN 28 ; @keyword NAN 29 29 ; not a number, we activate it if we want to average without considerate some masked values of TAB. 30 30 ; If masked values of TAB are values consecrated by IDL(!values.f_nan), we just have to put NAN. 31 31 ; If masked values of TAB are valued a (a must be different of 1, corresponding to nan = 32 ; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a. 32 ; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a. 33 33 ; Comment: In output, result points which are NAN will be valued a or !values.f_nan. 34 ; 34 ; 35 35 ; @keyword NODOMDEF 36 ; We activate it if we do not want to pass in domdef even if the keyword boxzoom 36 ; We activate it if we do not want to pass in domdef even if the keyword boxzoom 37 37 ; is present (like when grossemoyenne is called via checkfield) 38 38 ; 39 ; @keyword INTEGRATION 39 ; @keyword INTEGRATION 40 40 ; To make an integral rather than an average 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 ; 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 ; 46 46 ; @returns 47 ; An array 47 ; An array 48 48 ; 49 49 ; @uses … … 51 51 ; domdef 52 52 ; 53 ; @restrictions Put values corresponding to land at 1.e20 53 ; @restrictions 54 ; Put values corresponding to land at 1.e20 54 55 ; 55 56 ; @history … … 112 113 if dirx eq 0 and diry eq 0 and dirz eq 0 then return, tab 113 114 END 114 else : return, report(' Le tableau d''entree doit etre a 2 ou 3 dimensions s''il contient une dim temporelle utilisergrossemoyenne')115 else : return, report('Array must have 2 or 3 dimensions if there is a time dimension use grossemoyenne') 115 116 endcase 116 117 ;------------------------------------------------------------ … … 118 119 ; Redefinition of the domain ajusted at boxzoom (at 6 elements) 119 120 ; This will allowed us to calculate only in the domain concerned by the average. 120 ; Domdef, followed by grid give us all arrays of the grid on the subdomain 121 ;------------------------------------------------------------ 122 if keyword_set(boxzoom) then BEGIN 121 ; Domdef, followed by grid give us all arrays of the grid on the subdomain 122 ;------------------------------------------------------------ 123 if keyword_set(boxzoom) then BEGIN 123 124 Case 1 Of 124 125 N_Elements(Boxzoom) Eq 1:bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]] … … 127 128 N_Elements(Boxzoom) Eq 5:bte = [Boxzoom[0:3], 0, Boxzoom[4]] 128 129 N_Elements(Boxzoom) Eq 6:bte = Boxzoom 129 Else: return, report(' Mauvaise Definition deBoxzoom')130 Else: return, report('Bad definition of Boxzoom') 130 131 endcase 131 if NOT keyword_set(nodomdef) then BEGIN 132 if NOT keyword_set(nodomdef) then BEGIN 132 133 savedbox = 1b 133 134 saveboxparam, 'boxparam4moyenne.dat' 134 135 domdef, bte, GRIDTYPE = vargrid, _extra = ex 135 ENDIF 136 ENDIF 136 ENDIF 137 ENDIF 137 138 ;--------------------------------------------------------------- 138 139 ; attribution of the mask and of longitude and latitude arrays... … … 155 156 jpk:res = tab[firstz:lastz] 156 157 nz:res = tab 157 ELSE:BEGIN 158 ELSE:BEGIN 158 159 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 159 160 return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') 160 161 END 161 162 ENDCASE 162 if dirz EQ 1 then BEGIN 163 dim = '3d' 163 if dirz EQ 1 then BEGIN 164 dim = '3d' 164 165 taille = size(reform(res, nx, ny, nz)) 165 166 ENDIF ELSE BEGIN 166 167 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 167 168 return, res 168 ENDELSE 169 ENDELSE 169 170 END 170 171 ny EQ 1:BEGIN ;vector following x … … 172 173 jpi:res = tab[firstx:lastx] 173 174 nx:res = tab 174 ELSE:BEGIN 175 ELSE:BEGIN 175 176 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 176 177 return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') 177 178 END 178 179 ENDCASE 179 if dirx EQ 1 then BEGIN 180 dim = '2d' 180 if dirx EQ 1 then BEGIN 181 dim = '2d' 181 182 taille = size(reform(res, nx, ny)) 182 ENDIF ELSE BEGIN 183 ENDIF ELSE BEGIN 183 184 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 184 185 return, res … … 189 190 jpj:res = tab[firsty:lasty] 190 191 ny:res = tab 191 ELSE:BEGIN 192 ELSE:BEGIN 192 193 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 193 194 return, report('Probleme d''adequation entre les tailles du domaine et de la boxzoom.') … … 197 198 dim = '2d' 198 199 taille = size(reform(res, nx, ny)) 199 ENDIF ELSE BEGIN 200 ENDIF ELSE BEGIN 200 201 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 201 202 return, res 202 ENDELSE 203 ENDELSE 203 204 END 204 205 endcase … … 213 214 ; II.1) verification of the coherence of the array's size to average 214 215 ; Verification of the coherence between the array's size and the domain defined by domdef 215 ; The input array must have either the total domain's size (jpi,jpj) or this 216 ; The input array must have either the total domain's size (jpi,jpj) or this 216 217 ; one of the reduced domain (nx,ny) 217 218 ;--------------------------------------------------------------- … … 220 221 res = tab[firstx:lastx, firsty:lasty] 221 222 taille[1] eq nx and taille[2] eq ny:res = tab 222 else:BEGIN 223 else:BEGIN 223 224 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 224 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)) 225 226 END 226 227 ENDCASE 227 if keyword_set(nan) NE 0 then BEGIN 228 if nan NE 1 then BEGIN ; If nan is not !values.f_nan 228 if keyword_set(nan) NE 0 then BEGIN 229 if nan NE 1 then BEGIN ; If nan is not !values.f_nan 229 230 ; we put it at !values.f_nan 230 231 if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ … … 234 235 ENDIF 235 236 ;--------------------------------------------------------------- 236 ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 237 ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 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 238 239 ; LOOK USELESS AT THE BEGINNING 239 240 ;--------------------------------------------------------------- 240 if nx EQ 1 OR ny EQ 1 then BEGIN 241 if nx EQ 1 OR ny EQ 1 then BEGIN 241 242 res = reform(res, nx, ny, /over) 242 243 e1 = reform(e1, nx, ny, /over) … … 254 255 e = e1*mask 255 256 if keyword_set(integration) then divi = 1 $ 256 else begin 257 else begin 257 258 divi = e 258 259 IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan … … 272 273 e = e2*mask 273 274 if keyword_set(integration) then divi = 1 $ 274 else begin 275 else begin 275 276 divi = e 276 277 IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan … … 288 289 end 289 290 (dirx eq 1) and (diry eq 1) : begin 290 if keyword_set(integration) then divi = 1 else BEGIN 291 if keyword_set(integration) then divi = 1 else BEGIN 291 292 IF msknan[0] NE -1 THEN divi = total(e1*e2*mask*msknan) $ 292 293 ELSE divi = total(e1*e2*mask) 293 ENDELSE 294 ENDELSE 294 295 res = total(res*e1*e2*mask, nan = nan)/(divi > 1.) 295 296 if msknan[0] NE -1 then begin … … 307 308 if (dim eq '3d') then begin 308 309 ;--------------------------------------------------------------- 309 ; III.1) Verification of the coherence of the array to average size 310 ; Verification of the coherence between the array's size and the domain 311 ; defind by domdef 312 ; The input array must have either the total domain size (jpi,jpj,jpk) 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) 313 314 ; or this one of the reduced domain (nx,ny,ny) 314 315 ;--------------------------------------------------------------- … … 321 322 taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpk : $ 322 323 res = tab[*, *, firstz:lastz] 323 else:BEGIN 324 else:BEGIN 324 325 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 325 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)) 326 327 END 327 328 endcase 328 if keyword_set(nan) NE 0 then BEGIN 329 if nan NE 1 then BEGIN ; if nan is not !values.f_nan 329 if keyword_set(nan) NE 0 then BEGIN 330 if nan NE 1 then BEGIN ; if nan is not !values.f_nan 330 331 ; we put it at !values.f_nan 331 332 if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ … … 335 336 ENDIF 336 337 ;--------------------------------------------------------------- 337 ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 338 ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 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 339 340 ; LOOK USELESS AT THE BEGINNING 340 341 ;--------------------------------------------------------------- 341 if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN 342 if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN 342 343 res = reform(res, nx, ny, nz, /over) 343 344 e1 = reform(e1, nx, ny, /over) … … 349 350 ; the top of the ocean floor is 350 351 IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $ 351 ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3) 352 ; we suppress columns with only ocean or land 352 ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3) 353 ; we suppress columns with only ocean or land 353 354 good = where(bottom NE 0 AND bottom NE nz) 354 355 ; the bottom of the ocean in 3D index is: … … 367 368 IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ 368 369 AND nx NE 1 THEN BEGIN 369 IF msknan[0] EQ -1 THEN BEGIN 370 IF msknan[0] EQ -1 THEN BEGIN 370 371 msknan = replicate(1b, nx, ny, nz) 371 372 nan = 1 … … 395 396 IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ 396 397 AND ny NE 1 THEN BEGIN 397 IF msknan[0] EQ -1 THEN BEGIN 398 IF msknan[0] EQ -1 THEN BEGIN 398 399 msknan = replicate(1b, nx, ny, nz) 399 400 nan = 1 … … 447 448 IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ 448 449 AND nx*ny NE 1 THEN BEGIN 449 IF msknan[0] EQ -1 THEN BEGIN 450 IF msknan[0] EQ -1 THEN BEGIN 450 451 msknan = replicate(1b, nx, ny, nz) 451 452 nan = 1 … … 454 455 res[bottom] = !values.f_nan 455 456 ENDIF 456 if keyword_set(integration) then divi = 1 else BEGIN 457 if keyword_set(integration) then divi = 1 else BEGIN 457 458 divi = e123*mask 458 459 IF msknan[0] NE -1 THEN divi = temporary(divi)*msknan … … 478 479 ELSE e133[bottom] = (e1*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] 479 480 ENDIF 480 if keyword_set(integration) then divi = 1 else BEGIN 481 if keyword_set(integration) then divi = 1 else BEGIN 481 482 divi = e133*mask 482 483 if msknan[0] NE -1 then divi = temporary(divi)*msknan … … 502 503 ELSE e233[bottom] = (e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] 503 504 ENDIF 504 if keyword_set(integration) then divi = 1 else BEGIN 505 if keyword_set(integration) then divi = 1 else BEGIN 505 506 divi = e233*mask 506 507 if msknan[0] NE -1 then divi = temporary(divi)*msknan … … 526 527 ELSE e1233[bottom] = (e1*e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] 527 528 ENDIF 528 if keyword_set(integration) then divi = 1 else BEGIN 529 if keyword_set(integration) then divi = 1 else BEGIN 529 530 if msknan[0] NE -1 then divi = total(e1233*mask*msknan) $ 530 531 ELSE divi = total(e1233*mask) … … 550 551 IF terre[0] NE -1 THEN BEGIN 551 552 res[terre] = 1e+20 552 ENDIF 553 ENDIF 553 554 ;------------------------------------------------------------ 554 555 ; IV.2) We replace, when nan equal 1, !values.f_nan by nan 555 556 ;------------------------------------------------------------ 556 if keyword_set(nan) NE 0 then BEGIN 557 if keyword_set(nan) NE 0 then BEGIN 557 558 puttonan = where(testnan EQ 0) 558 559 if puttonan[0] NE -1 then res[puttonan] = !values.f_nan 559 if nan NE 1 then BEGIN 560 if nan NE 1 then BEGIN 560 561 notanumber = where(finite(res) eq 0) 561 562 if notanumber[0] NE -1 then res[notanumber] = nan … … 567 568 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat' 568 569 ;------------------------------------------------------------ 569 if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun 570 if keyword_set(key_performance) THEN print, 'temps moyenne', systime(1)-tempsun 570 571 return, res 571 572 ;------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.