Changeset 142 for trunk/SRC/ToBeReviewed/CALCULS/moyenne.pro
- Timestamp:
- 07/21/06 14:47:49 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SRC/ToBeReviewed/CALCULS/moyenne.pro
r134 r142 3 3 ;------------------------------------------------------------ 4 4 ;+ 5 ; NAME: moyenne6 ; 7 ; PURPOSE:averages a 2- or 3-d field over a selected5 ; 6 ; @file_comments 7 ; averages a 2- or 3-d field over a selected 8 8 ; geographical area and along one ore more 9 9 ; selected axes (x, y or z) 10 10 ; 11 ; CATEGORY: 12 ; 13 ; CALLING SEQUENCE: result = moyenne(tab,'direc',BOXZOOM=boxzoom) 14 ; 15 ; INPUTS: tab = 2 or 3d field 16 ; direc = 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz' 17 ; 18 ; KEYWORD PARAMETERS: 19 ; 20 ; BOXZOOM = [xmin,xmax,ymin,ymax (,(zmin,)zmax)] pour plus 21 ; de detail cf domdef. 22 ; boxzoom peut prendre 5 formes: 23 ; [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2], 24 ; [lon1, lon2, lat1, lat2, vert2],[lon1, lon2, lat1, 25 ; lat2, vert1,vert2] 26 ; 27 ; NAN: not a number, a activer si l''on peut faire veut 28 ; faire une moyenne sans tenir compte de certaines 29 ; valeurs masques de tab. 30 ; si les valeurs masques de tab sont la valeur consacree 31 ; par IDL (!values.f_nan), il suffit de mettre /NAN. 32 ; si les valeurs masques de tab on pour valeur a (a doit 33 ; etre differente de 1 (correspond a nan = 34 ; !values.f_nan) et de 0 (qui desactive nan) 35 ; il faut mettre NAN=a. 36 ; Rq: en sorties les points de result qui sont NAN 37 ; auront pour valeur a ou !values.f_nan. 38 ; 39 ; NODOMDEF: activer si l''on ne veut pas passer ds 40 ; domdef bien que le mot cle boxzoom soit present (comme 41 ; c''est le cas qd moyenne est appelee via checkfield) 11 ; @categories 12 ; 13 ; @param TAB {in}{required} 14 ; 2 or 3d field 15 ; 16 ; @param DIREC {in}{required} 17 ; 'x' 'y' 'z' 'xy' 'xz' 'yz' or 'xyz' 18 ; 19 ; @keyword BOXZOOM 20 ; [xmin,xmax,ymin,ymax (,(zmin,)zmax)] to more details, see domdef 21 ; boxzoom can have 5 forms: 22 ; [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2], 23 ; [lon1, lon2, lat1, lat2, vert2],[lon1, lon2, lat1, lat2, vert1,vert2] 24 ; 25 ; @keyword NAN 26 ; not a number, we activate it if we want to average without considerate some masked values of TAB. 27 ; If masked values of TAB are values consecrated by IDL(!values.f_nan), wr just have to put NAN. 28 ; If masked values of TAB are valued a (a must be different of 1, corresponding to nan = 29 ; !values.f_nan and of 0, which desactivate nan). We have to put NAN=a. 30 ; Comment: In output, rsult points which are NAN will be valued a or !values.f_nan. 42 31 ; 43 ; INTEGRATION: pour faire une integrale plutot qu''une moyenne 32 ; @keyword NODOMDEF 33 ; We activate it if we do not want to pass in domdef even if the keyword boxzoom 34 ; is present (like when grossemoyenne is called via checkfield) 35 ; 36 ; @keyword INTEGRATION 37 ; To make an integral rather than an average 44 38 ; 45 ; /WDEPTH: to specify that the field is at W depth instad of T 46 ; depth (automatically activated if vargrid eq 'W') 39 ; @keyword WDEPTH 40 ; to specify that the field is at W depth instad of T 41 ; depth (automatically activated if vargrid eq 'W') 47 42 ; 48 ; OUTPUTS: result:un tableau 49 ; 50 ; COMMON BLOCKS: 51 ; common domdef 52 ; 53 ; SIDE EFFECTS:met les valeurs correspondants a la terre a 1e20 54 ; 55 ; RESTRICTIONS: 56 ; 57 ; EXAMPLE: 58 ; 59 ; MODIFICATION HISTORY: Jerome Vialard (jv@lodyc.jussieu.fr) 43 ; @returns 44 ; An array 45 ; 46 ; @uses 47 ; common 48 ; domdef 49 ; 50 ; @restrictions Put values corresponding to land at 1.e20 51 ; 52 ; @history 53 ; Jerome Vialard (jv@lodyc.jussieu.fr) 60 54 ; 2/7/98 61 55 ; Sebastien Masson (smasson@lodyc.jussieu.fr) 62 ; mise au propre de certains truc (les terres...)63 56 ; 14/8/98 64 57 ; 15/1/98 65 ; 11/3/99 adaptation pour NAN 66 ; 28/7/99 moyennes tableaux 1d 58 ; 11/3/99 adaptation for NAN 59 ; 28/7/99 Averages 1d arrays 60 ; 61 ; @version 62 ; $Id$ 63 ; 67 64 ;- 68 ;------------------------------------------------------------ 69 ;------------------------------------------------------------ 70 ; PLAN DU PROGRAMME: 71 ;------------------------------------------------------------ 72 ;------------------------------------------------------------ 73 ;I) preliminaires 74 ; I.1) determination des directions de moyennes d''apres direc 75 ; I.2) verification de la taille du tableau d''entree 76 ; I.3) obtention des facteurs d''echelles et du masque sur le sous 77 ; domaine concerne par la moyenne 78 ; ) moyennes pour les tableaux 1d (x,y) 79 ;II) moyennes pour les tableaux 2d (x,y) 80 ; II.1) verification de la coherence de la taille du tableau a 81 ; moyenner 82 ; II.2) differents types de moyennes possibles 83 ;III) moyennes pour les tableaux 3d (x,y,z) 84 ; III.1) verification de la coherence de la taille du tableau a 85 ; moyenner 86 ; III.2) differents types de moyennes possibles 87 ;IV ) finitions 88 ; IV.1) on masque les terres par une valeur a 1e+20 89 ; IV.2) on remplace, quand nan ne 1, !values.f_nan par nan 90 ; IV.3) on revient au sous domaine initial. 91 ;------------------------------------------------------------ 92 ;------------------------------------------------------------ 65 93 66 function moyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $ 94 67 , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $ … … 106 79 ENDIF 107 80 ;--------------------------------------------------------- 108 tempsun = systime(1) ; pourkey_performance109 ;------------------------------------------------------------ 110 ;I) prelimina ires81 tempsun = systime(1) ; To key_performance 82 ;------------------------------------------------------------ 83 ;I) preliminaries 111 84 ;------------------------------------------------------------ 112 85 dirt = 0 … … 115 88 dirz = 0 116 89 ;------------------------------------------------------------ 117 ; I.1) direction(s) suivants lesquelles on integre90 ; I.1) Directions(s) we follow to integrate 118 91 ;------------------------------------------------------------ 119 92 if ( strpos(direc, 't') ge 0 ) then dirt = 1 … … 123 96 if (dirx eq 0 and diry eq 0 and dirz eq 0) then return, tab 124 97 ;------------------------------------------------------------ 125 ; I.2) verification de la taille du tableau d'entree98 ; I.2) verification of the input array's size 126 99 ;------------------------------------------------------------ 127 100 taille = size(tab) … … 139 112 endcase 140 113 ;------------------------------------------------------------ 141 ; I.3) obtention des facteurs d''echelles et du masque sur le sous 142 ; domaine concerne par la moyenne 143 ; redefinition du domaine ajuste a boxzoom (a 6 elements) 144 ; ceci va nous permetre de faire les calcules que sur le sous domaine 145 ; comcerne par la moyenne. domdef, suivit de grille nous donne tous 146 ; les tableaux de la grille sur le sous domaine 114 ; I.3) Obtainment of scale's factors and of the mask on the subdomain concernedby the average. 115 ; Redefinition of the domain ajusted at boxzoom (at 6 elements) 116 ; This will allowed us to calculate only in the domain concerned by the average. 117 ; Domdef, followed by grid give us all arrays of the grid on the subdomain 147 118 ;------------------------------------------------------------ 148 119 if keyword_set(boxzoom) then BEGIN … … 162 133 ENDIF 163 134 ;--------------------------------------------------------------- 164 ; attribution du mask et des tableaux de longitude et latitude...135 ; attribution of the mask and of longitude and latitude arrays... 165 136 ;--------------------------------------------------------------- 166 137 IF vargrid EQ 'W' THEN wdepth = 1 … … 168 139 ;------------------------------------------------------------ 169 140 ;------------------------------------------------------------ 170 ; II) Cas du tableau 1d141 ; II) Case of the 1d array 171 142 ;------------------------------------------------------------ 172 143 ;------------------------------------------------------------ … … 177 148 ENDIF 178 149 case 1 of 179 nx EQ 1 AND ny EQ 1:BEGIN ;vect eur suivantz150 nx EQ 1 AND ny EQ 1:BEGIN ;vector following z 180 151 case n_elements(tab) of 181 152 jpk:res = tab[firstz:lastz] … … 194 165 ENDELSE 195 166 END 196 ny EQ 1:BEGIN ;vect eur suivantx167 ny EQ 1:BEGIN ;vector following x 197 168 case n_elements(tab) of 198 169 jpi:res = tab[firstx:lastx] … … 211 182 ENDELSE 212 183 END 213 nx EQ 1:BEGIN ;vect eur suivanty184 nx EQ 1:BEGIN ;vector following y 214 185 case n_elements(tab) of 215 186 jpj:res = tab[firsty:lasty] … … 232 203 ;------------------------------------------------------------ 233 204 ;------------------------------------------------------------ 234 ; II) Cas du tableau 2d205 ; II) Case of the 2d array 235 206 ;------------------------------------------------------------ 236 207 ;------------------------------------------------------------ 237 208 if (dim eq '2d') then begin 238 209 ;--------------------------------------------------------------- 239 ; II.1) verification de la coherence de la taille du tableau a 240 ; moyenner 241 ; verification de la coherence entre la taille du tableau et le 242 ; domaine definit par domdef 243 ; le tableau en entree doit avoir soit la taille du domaine total 244 ; (jpi,jpj) soit celle du domaine reduit (nx,ny) 210 ; II.1) verification of the coherence of the array's size to average 211 ; Verification of the coherence between the array's size and the domain defined by domdef 212 ; The input array must have either the total domain's size (jpi,jpj) or this 213 ; one of the reduced domain (nx,ny) 245 214 ;--------------------------------------------------------------- 246 215 case 1 of … … 254 223 ENDCASE 255 224 if keyword_set(nan) NE 0 then BEGIN 256 if nan NE 1 then BEGIN ; si nan n''est pas!values.f_nan257 ; on le met a!values.f_nan225 if nan NE 1 then BEGIN ; If nan is not !values.f_nan 226 ; we put it at !values.f_nan 258 227 if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ 259 228 ELSE notanumber = where(abs(res) GT abs(nan)/10.) … … 262 231 ENDIF 263 232 ;--------------------------------------------------------------- 264 ; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET265 ; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI266 ; PEUVENT SEMBLER INUTILE AU DEPART233 ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 234 ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 235 ; LOOK USELESS AT THE BEGINNING 267 236 ;--------------------------------------------------------------- 268 237 if nx EQ 1 OR ny EQ 1 then BEGIN … … 274 243 mask = reform(mask, nx, ny, nz, /over) 275 244 ;--------------------------------------------------------------- 276 ; II.3) differents types de moyennes245 ; II.3) Different types of average 277 246 ;--------------------------------------------------------------- 278 247 mask = mask[*, *, 0] … … 330 299 ;------------------------------------------------------------ 331 300 ;------------------------------------------------------------ 332 ; III) Cas du tableau 3d301 ; III) Case 3d arrays series (tab4d) 333 302 ;------------------------------------------------------------ 334 303 ;------------------------------------------------------------ 335 304 if (dim eq '3d') then begin 336 305 ;--------------------------------------------------------------- 337 ; III.1) verification de la coherence de la taille du tableau a 338 ; moyenner 339 ; verification de la coherence entre la taille du tableau et le 340 ; domaine definit par domdef 341 ; le tableau en entree doit avoir soit la taille du domaine total 342 ; (jpi,jpj,jpk) soit celle du domaine reduit (nx,ny,ny) 306 ; III.1) Verification of the coherence of the array to average size 307 ; Verification of the coherence between the array's size and the domain 308 ; defind by domdef 309 ; The input array must have either the total domain size (jpi,jpj,jpk) 310 ; or this one of the reduced domain (nx,ny,ny) 343 311 ;--------------------------------------------------------------- 344 312 case 1 of … … 356 324 endcase 357 325 if keyword_set(nan) NE 0 then BEGIN 358 if nan NE 1 then BEGIN ; si nan n''est pas!values.f_nan359 ; on le met a!values.f_nan326 if nan NE 1 then BEGIN ; if nan is not !values.f_nan 327 ; we put it at !values.f_nan 360 328 if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ 361 329 ELSE notanumber = where(abs(res) GT abs(nan)/10.) … … 364 332 ENDIF 365 333 ;--------------------------------------------------------------- 366 ; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET367 ; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI368 ; PEUVENT SEMBLER INUTILE AU DEPART334 ; Comment : WE HAVE TO BE CAREFUL ABOUT CASES WHERE THE DIMENSION TO AVERAGE = 1, 335 ; AND MAKE SURE THAT IT EXIST. THAT IS WHY WE USE reform(...,nx,ny,...) WHICH CAN 336 ; LOOK USELESS AT THE BEGINNING 369 337 ;--------------------------------------------------------------- 370 338 if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN … … 387 355 ENDIF ELSE bottom = -1 388 356 ;--------------------------------------------------------------- 389 ; III.2) different s types de moyennes357 ; III.2) different average types 390 358 ;--------------------------------------------------------------- 391 359 if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1 … … 570 538 ;------------------------------------------------------------ 571 539 ;------------------------------------------------------------ 572 ;IV ) fini tions573 ;------------------------------------------------------------ 574 ;------------------------------------------------------------ 575 ; IV.1) on masque les terres par une valeur a 1e+20540 ;IV ) finishing 541 ;------------------------------------------------------------ 542 ;------------------------------------------------------------ 543 ; IV.1) We mask land by a value equal to 1.e+20 576 544 ;------------------------------------------------------------ 577 545 valmask = 1e+20 … … 581 549 ENDIF 582 550 ;------------------------------------------------------------ 583 ; IV.2) on remplace, quand nan ne 1, !values.f_nan parnan551 ; IV.2) We replace, when nan equal 1, !values.f_nan by nan 584 552 ;------------------------------------------------------------ 585 553 if keyword_set(nan) NE 0 then BEGIN … … 592 560 ENDIF 593 561 ;------------------------------------------------------------ 594 ; IV.3) on se remplace ds le sous domaine qui etait definit a l''entree de 595 ; moyenne 562 ; IV.3) We replace in the domain whch was defined at the entry of average 596 563 ;------------------------------------------------------------ 597 564 if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4moyenne.dat'
Note: See TracChangeset
for help on using the changeset viewer.