;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ;+ ; NAME: grossemoyenne ; ; PURPOSE: averages a 3- or 4-d time serie field over a selected ; geographical area or along the time axis. For one ore more ; selected axes (x, y, z, t) ; ; CATEGORY: ; ; CALLING SEQUENCE: result = grossemoyenne(tab,'direc',BOXZOOM=boxzoom) ; ; INPUTS: tab = 3 or 4d field ; direc ='x' 'y' 'z' 't' 'xy' 'xz' 'yz' 'xyz' 'xt' 'yt' 'zt' ; 'xyt' 'xzt' 'yzt' or 'xyzt' ; ; KEYWORD PARAMETERS: ; ; boxzoom = [xmin,xmax,ymin,ymax (,(zmin,)zmax)] pour plus ; de detail cf domdef ; boxzoom peut prendre 5 formes: ; [vert2], [vert1, vert2],[lon1, lon2, lat1, lat2], ; [lon1, lon2, lat1, lat2, vert2],[lon1, lon2, lat1, lat2, vert1,vert2] ; ; NAN: not a number, a activer si l''on peut faire veut ; faire une moyenne sans tenir compte de certaines ; valeurs masques de tab. ; si les valeurs masques de tab sont la valeur consacree ; par IDL (!values.f_nan), il suffit de mettre /NAN. ; si les valeurs masques de tab on pour valeur a (a doit ; etre differente de 1 (correspond a nan = ; !values.f_nan) et de 0 (qui desactive nan). ; Il faut mettre NAN=a. ; Rq: en sorties les points de result qui sont NAN ; auront pour valeur a ou !values.f_nan. ; ; NODOMDEF: activer si l''on ne veut pas passer ds ; domdef bien que le mot cle boxzoom soit present (comme ; c''est le cas qd grossemoyenne est appelee via ; checkfield) ; ; INTEGRATION: pour faire une integrale plutot qu''une ; moyenne ; ; /SPATIALFIRST, when performing at the same time ; spatial and temporal mean, grossemoyenne is assuming ; that the mask is not changing with the time. In ; consequence, grossemoyenne performs temporal mean ; first and then call moyenne. Activate /SPATIALFIRST if ; you want to perform the spatial mean before the ; temporal mean. Note that if NAN is activated, then ; SPATIALFIRST is activated automatically. ; ; /TEMPORALFIRST: to force to perform first temporal ; mean even if nan is activated (see SPATIALFIRST ; explanations...) ; ; ; /WDEPTH: to specify that the field is at W depth instad of T ; depth (automatically activated if vargrid eq 'W') ; ; OUTPUTS: ; ; COMMON BLOCKS: result:un tableau ; common domdef ; ; SIDE EFFECTS: met les valeurs correspondants a la terre a 1e20 ; ; RESTRICTIONS: ; ; EXAMPLE: ; ; MODIFICATION HISTORY: Jerome Vialard (jv@lodyc.jussieu.fr) ; 2/7/98 ; Sebastien Masson (smasson@lodyc.jussieu.fr) ; adaptation pour les tableaux comportants une dimension temporelle ; 14/8/98 ; 15/1/98 ; 12/3/99 adaptation pour NAN et utilisation de TEMPORARY ;- ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ ; PLAN DU PROGRAMME: ;------------------------------------------------------------ ;------------------------------------------------------------ ;I) preliminaires ; I.1) determination des directions de moyennes d''apres direc ; I.2) verification de la taille du tableau d''entree ; I.3) obtention des facteurs d''echelles et du masque sur le sous ; domaine concerne par la moyenne ;II) moyennes pour les tableaux 3d (x,y,t) ; II.1) verification de la coherence de la taille du tableau a ; moyenner ; II.2) renvoie sur moyenne qd une moyenne sur t est demandee ; II.3) differents types de moyennes possibles ;III) moyennes pour les tableaux 4d (x,y,z,t) ; III.1) verification de la coherence de la taille du tableau a ; moyenner ; III.2) differents types de moyennes possibles ;IV ) finitions ; IV.1) on masque les terres par une valeur a 1e+20 ; IV.2) on remplace, quand nan ne 1, !values.f_nan par nan ; IV.3) on revient au sous domaine initial. ;------------------------------------------------------------ ;------------------------------------------------------------ ;------------------------------------------------------------ function grossemoyenne, tab, direc, BOXZOOM = boxzoom, INTEGRATION = integration $ , NAN = nan, NODOMDEF = nodomdef, WDEPTH = wdepth $ , SPATIALFIRST = spatialfirst, TEMPORALFIRST = temporalfirst $ , _extra = ex ;--------------------------------------------------------- ; compile_opt idl2, strictarrsubs ; @cm_4mesh @cm_4data @cm_4cal IF NOT keyword_set(key_forgetold) THEN BEGIN @updatenew @updatekwd ENDIF ;--------------------------------------------------------- tempsun = systime(1) ; pour key_performance ;------------------------------------------------------------ ;I) preliminaires ;------------------------------------------------------------ dirt = 0 dirx = 0 diry = 0 dirz = 0 dim = 'aa' ;------------------------------------------------------------ ; I.1) direction(s) suivants lesquelles on integre ;------------------------------------------------------------ if ( strpos(direc, 't') ge 0 ) then dirt = 1 if ( strpos(direc, 'x') ge 0 ) then dirx = 1 if ( strpos(direc, 'y') ge 0 ) then diry = 1 if ( strpos(direc, 'z') ge 0 ) then dirz = 1 IF keyword_set(NAN) AND (dirx EQ 1 OR diry EQ 1 OR dirz EQ 1) $ THEN spatialfirst = 1 IF keyword_set(temporalfirst) THEN spatialfirst = 0 ;------------------------------------------------------------ ; I.2) verification de la taille du tableau d'entree ;------------------------------------------------------------ taille = size(tab) case 1 of taille[0] eq 1 :return, report('Le tableau n''a qu''une dimension, cas non traite!') taille[0] eq 2 :return, report('Le tableau n''a qu''deux dimension, cas non traite!') taille[0] eq 3 :BEGIN dim = '3d' if dirx eq 0 and diry eq 0 and dirt eq 0 then return, tab END taille[0] eq 4 :BEGIN dim = '4d' if dirx eq 0 and diry eq 0 and dirz eq 0 and dirt eq 0 then return, tab END else : return, report('Le tableau d entree doit etre a 3 ou 4 dimensions s''il ne contient pas de dim temporelle utiliser moyenne') endcase ;------------------------------------------------------------ ; I.4) obtention des facteurs d''echelles et du masque sur le sous ; domaine concerne par la moyenne ; redefinition du domaine ajuste a boxzoom (a 6 elements) ; ceci va nous permetre de faire les calcules que sur le sous domaine ; comcerne par la moyenne. domdef, suivit de grille nous donne tous ; les tableaux de la grille sur le sous domaine ;------------------------------------------------------------ if keyword_set(boxzoom) then BEGIN Case 1 Of N_Elements(Boxzoom) Eq 1: bte = [lon1, lon2, lat1, lat2, 0., boxzoom[0]] N_Elements(Boxzoom) Eq 2: bte = [lon1, lon2, lat1, lat2, boxzoom[0], boxzoom[1]] N_Elements(Boxzoom) Eq 4: bte = [Boxzoom, vert1, vert2] N_Elements(Boxzoom) Eq 5: bte = [Boxzoom[0:3], 0, Boxzoom[4]] N_Elements(Boxzoom) Eq 6: bte = Boxzoom Else: return, report('Wrong Definition of Boxzoom') endcase if NOT keyword_set(nodomdef) then BEGIN savedbox = 1b saveboxparam, 'boxparam4grmoyenne.dat' domdef, bte, GRIDTYPE = vargrid, _extra = ex ENDIF ENDIF ;--------------------------------------------------------------- ; attribution du mask et des tableaux de longitude et latitude... ;--------------------------------------------------------------- grille, mask, glam, gphi, gdep, nx, ny, nz, firstx, firsty, firstz, lastx, lasty, lastz, e1, e2, e3, WDEPTH = wdepth ;------------------------------------------------------------ ; I.3) si dirt eq 1 on fait la moyenne temporelle et on envoie ds moyenne ;------------------------------------------------------------ if dirt EQ 1 AND NOT keyword_set(spatialfirst) then begin if dim EQ 3d then BEGIN case 1 of taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpt: $ res = tab[firstx:firstx+nx-1 $ , firsty:firsty+ny-1, *] taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpt:res = tab else:BEGIN if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, report('Probleme d''adequation entre les tailles du domaine nx*ny*jpt '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1)) END ENDCASE if keyword_set(integration) then begin res = total(res, 3, nan = nan) ENDIF ELSE BEGIN if keyword_set(nan) then BEGIN divi = finite(res) divi = total(temporary(divi), 3) notanum = where(divi EQ 0) res = total(res, 3, nan = keyword_set(nan))/ (1 > divi) if notanum[0] NE -1 then res[temporary(notanum)] = !values.f_nan ENDIF ELSE res = total(res, 3)/(1.*taille[3]) ENDELSE ENDIF ELSE BEGIN case 1 of taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpk and taille[4] eq jpt: $ res = tab[firstx:lastx, firsty:lasty, firstz:lastz, *] taille[1] eq jpi and taille[2] eq jpj and taille[3] eq nz and taille[4] eq jpt: $ res = tab[firstx:lastx, firsty:lasty, *, *] taille[1] EQ nx and taille[2] eq ny and taille[3] eq nz and taille[4] eq jpt:res = tab taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpk and taille[4] eq jpt: $ res = tab[*, *, firstz:lastz, *] else:BEGIN if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz*jpt ' $ +strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(nz, 1)+'*' $ +strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*' $ +strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1)+'*' $ +strtrim(taille[4], 1)) END endcase if keyword_set(integration) then begin res = total(res, 4, nan = nan) ENDIF ELSE BEGIN if keyword_set(nan) then begin divi = finite(res) divi = total(temporary(divi), 4) notanum = where(divi EQ 0) res = total(res, 4, /nan)/(1 > divi) if notanum[0] NE -1 then res[temporary(notanum)] = !values.f_nan ENDIF ELSE res = total(res, 4)/(1.*taille[4]) ENDELSE ENDELSE if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, moyenne(temporary(res), direc, BOXZOOM = boxzoom, NAN = nan, INTEGRATION = integration, NODOMDEF = nodomdef, WDEPTH = wdepth, _extra = ex) ENDIF ELSE res = tab IF jpt EQ 1 THEN BEGIN if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, moyenne(reform(res, /over), direc, BOXZOOM = boxzoom, NAN = nan, INTEGRATION = integration, NODOMDEF = nodomdef, WDEPTH = wdepth, _extra = ex) END ;------------------------------------------------------------ ;------------------------------------------------------------ ; II) Cas serie tableaux 2d (tab3d) ;------------------------------------------------------------ ;------------------------------------------------------------ if (dim eq '3d') then begin ;--------------------------------------------------------------- ; II.1) verification de la coherence de la taille du tableau a ; moyenner ; verification de la coherence entre la taille du tableau et le ; domaine definit par domdef ; le tableau en entree doit avoir soit la taille du domaine total ; (jpi,jpj,jpt) soit celle du domaine reduit (nx,ny,jpt) ;--------------------------------------------------------------- case 1 of taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpt: $ res = tab[firstx:firstx+nx-1 $ , firsty:firsty+ny-1, *] taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpt:res = tab else:BEGIN if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, report('Probleme d''adequation entre les tailles du domaine nx*ny*jpt '+strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1)) enD endcase if keyword_set(nan) NE 0 then BEGIN if nan NE 1 then BEGIN ; si nan n''est pas !values.f_nan ; on le met a !values.f_nan if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ ELSE notanumber = where(abs(res) GT abs(nan)/10.) if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan ENDIF ENDIF ;--------------------------------------------------------------- ; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET ; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI ; PEUVENT SEMBLER INUTILE AU DEPART ;--------------------------------------------------------------- if nx EQ 1 OR ny EQ 1 then BEGIN res = reform(res, nx, ny, jpt, /over) e1 = reform(e1, nx, ny, /over) e2 = reform(e2, nx, ny, /over) endif if nx EQ 1 OR ny EQ 1 OR nz EQ 1 THEN $ mask = reform(mask, nx, ny, nz, /over) ;--------------------------------------------------------------- ; II.3) differents types de moyennes ;--------------------------------------------------------------- if keyword_set(nan) NE 0 then msknan = finite(res) ELSE msknan = -1 mask = mask[*, *, 0] case 1 of (dirx eq 1) and (diry eq 0) : begin e = temporary(e1)*temporary(mask) echelle = (temporary(e))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, jpt, /over) if keyword_set(integration) then divi = 1 ELSE BEGIN IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 1) $ ELSE divi = total(echelle, 1) ENDELSE res = total(temporary(res)*echelle, 1, nan = nan)/(divi > 1.) if msknan[0] NE -1 then BEGIN echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(temporary(testnan), 1) $ +(total(temporary(echelle), 1) EQ 0) endif end (dirx eq 0) and (diry eq 1) : begin e = temporary(e2)*temporary(mask) if nx EQ 1 OR ny EQ 1 then e = reform(e, nx, ny, /over) echelle = (temporary(e))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, jpt, /over) if keyword_set(integration) then divi = 1 ELSE BEGIN IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 2) $ ELSE divi = total(echelle, 2) ENDELSE res = total(temporary(res)*echelle, 2, nan = nan)/(divi > 1.) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(temporary(testnan), 2) $ +(total(temporary(echelle), 2) EQ 0) endif end (dirx eq 1) and (diry eq 1) : begin echelle = (temporary(e1)*temporary(e2)*temporary(mask))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, jpt, /over) if keyword_set(integration) then divi = 1 ELSE BEGIN IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 1) $ ELSE divi = total(total(echelle, 1), 1) ENDELSE res = total(temporary(total(temporary(res)*echelle, 1, nan = nan)), 1, nan = nan)/(divi > 1.) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(total(temporary(testnan), 1), 1) $ +(total(total(temporary(echelle), 1), 1) EQ 0) endif end endcase endif ;------------------------------------------------------------ ;------------------------------------------------------------ ; III) Cas serie tableaux 3d (tab4d) ;------------------------------------------------------------ if (dim eq '4d') then begin ;--------------------------------------------------------------- ; III.1) verification de la coherence de la taille du tableau a ; moyenner ; verification de la coherence entre la taille du tableau et le ; domaine definit par domdef ; le tableau en entree doit avoir soit la taille du domaine total ; (jpi,jpj,jpk,jpt) soit celle du domaine reduit (nx,ny,ny,jpt) ;--------------------------------------------------------------- case 1 of taille[1] eq jpi and taille[2] eq jpj and taille[3] eq jpk and taille[4] eq jpt: $ res = tab[firstx:lastx, firsty:lasty, firstz:lastz, *] taille[1] eq jpi and taille[2] eq jpj and taille[3] eq nz and taille[4] eq jpt: $ res = tab[firstx:lastx, firsty:lasty, *, *] taille[1] EQ nx and taille[2] eq ny and taille[3] eq nz and taille[4] eq jpt:res = tab taille[1] EQ nx and taille[2] eq ny and taille[3] eq jpk and taille[4] eq jpt: $ res = tab[*, *, firstz:lastz, *] else:BEGIN if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, report('Probleme d''adequation entre les tailles du domaine nx*ny*nz*jpt ' $ +strtrim(nx, 1)+'*'+strtrim(ny, 1)+'*'+strtrim(nz, 1)+'*' $ +strtrim(jpt, 1)+' et du tableau '+strtrim(taille[1], 1)+'*' $ +strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1)+'*' $ +strtrim(taille[4], 1)) END endcase if nx EQ 1 OR ny EQ 1 OR nz EQ 1 OR jpt EQ 1 then res = reform(res, nx, ny, nz, jpt, /over) if keyword_set(nan) NE 0 then BEGIN if nan NE 1 then BEGIN ; si nan n''est pas !values.f_nan ; on le met a !values.f_nan if abs(nan) LT 1e6 then notanumber = where(res EQ nan) $ ELSE notanumber = where(abs(res) GT abs(nan)/10.) if notanumber[0] NE -1 then res[temporary(notanumber)] = !values.f_nan ENDIF ENDIF ;--------------------------------------------------------------- ; rq IL FAUT FAIRE ATTENTION AUX CAS OU LA DIM A MOYENNER = 1, ET ; S'ASSURER QU'ELLE EXISTE BIEN. D'OU LES reform(...,nx,ny,...) QUI ; PEUVENT SEMBLER INUTILE AU DEPART ;--------------------------------------------------------------- if nx EQ 1 OR ny EQ 1 OR nz EQ 1 then BEGIN res = reform(res, nx, ny, nz, jpt, /over) mask = reform(mask, nx, ny, nz, /over) ENDIF IF keyword_set(key_partialstep) THEN BEGIN ; the top of the ocean floor is IF vargrid EQ 'T' OR vargrid EQ 'W' THEN bottom = total(mask, 3) $ ELSE bottom = total(tmask[firstx:lastx, firsty:lasty, firstz:lastz], 3) ; we suppress columns with only ocean or land good = where(bottom NE 0 AND bottom NE nz) ; the bottom of the ocean in 3D index is: bottom = lindgen(nx*ny)+(temporary(bottom)-1L)*nx*ny IF good[0] NE -1 THEN bottom = bottom[good] $ ELSE bottom = -1 ENDIF ELSE bottom = -1 ;--------------------------------------------------------------- ; III.2) differents types de moyennes ;--------------------------------------------------------------- IF keyword_set(nan) NE 0 THEN msknan = finite(res) ELSE msknan = -1 case 1 of (dirx eq 1) and (diry eq 0) and (dirz eq 0) : BEGIN e13 = (temporary(e1))[*]#replicate(1., nz) e13 = reform(e13, nx, ny, nz, /over) echelle = (temporary(e13)*temporary(mask))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ AND nx NE 1 THEN BEGIN IF msknan[0] EQ -1 THEN BEGIN msknan = replicate(1b, nx, ny, nz, jpt) nan = 1 ENDIF bottom = bottom#replicate(1, jpt) $ ; 4D bottom! + replicate(1, n_elements(bottom))#(nx*ny*nz*lindgen(jpt)) msknan[bottom] = 0 res[temporary(bottom)] = !values.f_nan ENDIF if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 1) $ ELSE divi = total(echelle, 1) endelse res = temporary(res)*echelle res = total(temporary(res), 1, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(temporary(testnan), 1) $ +(total(temporary(echelle), 1) EQ 0) endif end (dirx eq 0) and (diry eq 1) and (dirz eq 0) : begin e23 = temporary(e2[*])#replicate(1., nz) e23 = reform(e23, nx, ny, nz, /over) echelle = (temporary(e23)*temporary(mask))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ AND ny NE 1 THEN BEGIN IF msknan[0] EQ -1 THEN BEGIN msknan = replicate(1b, nx, ny, nz) nan = 1 endif bottom = bottom#replicate(1, jpt) $ ; 4D bottom! + replicate(1, n_elements(bottom))#(nx*ny*nz*lindgen(jpt)) msknan[bottom] = 0 res[temporary(bottom)] = !values.f_nan ENDIF if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 2) $ ELSE divi = total(echelle, 2) endelse res = total(temporary(res)*echelle, 2, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(temporary(testnan), 2) $ +(total(temporary(echelle), 2) EQ 0) endif end (dirx eq 0) and (diry eq 0) and (dirz eq 1) : begin e33 = replicate(1, 1.*nx*ny)#e3 e33 = reform(e33, nx, ny, nz, /over) IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN IF keyword_set(wdepth) THEN $ e33[bottom] = (e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ ELSE e33[bottom] = (e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] ENDIF echelle = (temporary(e33)*temporary(mask))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(echelle*msknan, 3) $ ELSE divi = total(echelle, 3) endelse res = total(temporary(res)*echelle, 3, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(temporary(testnan), 3) $ +(total(temporary(echelle), 3) EQ 0) endif end (dirx eq 1) and (diry eq 1) and (dirz eq 0) : begin e13 = e1[*]#replicate(1., nz) e13 = reform(e13, nx, ny, nz, /over) e23 = e2[*]#replicate(1., nz) e23 = reform(e23, nx, ny, nz, /over) echelle = (temporary(e13)*temporary(e23)*temporary(mask))[*]#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) IF keyword_set(key_partialstep) AND bottom[0] NE -1 $ AND nx*ny NE 1 THEN BEGIN IF msknan[0] EQ -1 THEN BEGIN msknan = replicate(1b, nx, ny, nz) nan = 1 endif bottom = bottom#replicate(1, jpt) $ ; 4D bottom! + replicate(1, n_elements(bottom))#(nx*ny*nz*lindgen(jpt)) msknan[bottom] = 0 res[temporary(bottom)] = !values.f_nan ENDIF if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 1) $ ELSE divi = total(total(echelle, 1), 1) endelse res = total(total(temporary(res)*echelle, 1, nan = nan), 1, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(total(temporary(testnan), 1), 1) $ +(total(total(temporary(echelle), 1), 1) EQ 0) endif end (dirx eq 1) and (diry eq 0) and (dirz eq 1) : begin e133 = e1[*]#e3 IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN IF keyword_set(wdepth) THEN $ e133[bottom] = (e1*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ ELSE e133[bottom] = (e1*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] ENDIF echelle = (temporary(e133[*])*temporary(mask[*]))#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 1), 2) $ ELSE divi = total(total(echelle, 1), 2) endelse res = total(total(temporary(res)*echelle, 1, nan = nan), 2, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(total(temporary(testnan), 1), 2) $ +(total(total(temporary(echelle), 1), 2) EQ 0) endif end (dirx eq 0) and (diry eq 1) and (dirz eq 1) : begin e233 = e2[*]#e3 IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN IF keyword_set(wdepth) THEN $ e233[bottom] = (e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ ELSE e233[bottom] = (e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] ENDIF echelle = (temporary(e233[*])*temporary(mask[*]))#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(total(echelle*msknan, 2), 2) $ ELSE divi = total(total(echelle, 2), 2) endelse res = total(total(temporary(res)*echelle, 2, nan = nan), 2, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(total(temporary(testnan), 2), 2) $ +(total(total(temporary(echelle), 2), 2) EQ 0) endif end (dirx eq 1) and (diry eq 1) and (dirz eq 1) : begin e1233 = (e1[*]*e2[*])#e3 IF keyword_set(key_partialstep) AND bottom[0] NE -1 THEN BEGIN IF keyword_set(wdepth) THEN $ e1233[bottom] = (e1*e2*e3w_ps[firstx:lastx, firsty:lasty])[temporary(good)] $ ELSE e1233[bottom] = (e1*e2*e3t_ps[firstx:lastx, firsty:lasty])[temporary(good)] ENDIF echelle = (temporary(e1233[*])*temporary(mask[*]))#replicate(1, jpt) echelle = reform(echelle, nx, ny, nz, jpt, /over) if keyword_set(integration) then divi = 1 ELSE begin IF msknan[0] NE -1 THEN divi = total(total(total(echelle*msknan, 1), 1), 1) $ ELSE divi = total(total(total(echelle, 1), 1), 1) endelse res = total(total(total(temporary(res)*echelle, 1, nan = nan), 1, nan = nan), 1, nan = nan)/(divi > 1) if msknan[0] NE -1 then begin echelle = temporary(echelle) NE 0 testnan = temporary(msknan)*echelle testnan = total(total(total(temporary(testnan), 1), 1), 1) $ +(total(total(total(temporary(echelle), 1), 1), 1) EQ 0) endif end endcase endif ;------------------------------------------------------------ if dirt EQ 1 AND keyword_set(spatialfirst) then BEGIN IF (reverse(size(res, /dimension)))[0] NE jpt THEN BEGIN print, 'the last dimension of res is not equal to jpt: '+strtrim(jpt, 2) if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' return, -1 ENDIF tdim = size(res, /n_dimensions) if keyword_set(integration) then res = total(res, tdim, nan = nan) $ ELSE BEGIN if keyword_set(nan) then BEGIN testnan = testnan < 1 testnan = total(temporary(testnan), tdim) divi = testnan ENDIF ELSE divi = jpt res = total(res, tdim, nan = nan)/(1 > divi) ENDELSE ENDIF ;------------------------------------------------------------ ;------------------------------------------------------------ ;IV ) finitions ;------------------------------------------------------------ ;------------------------------------------------------------ ; IV.1) on masque les terres par une valeur a 1e+20 ;------------------------------------------------------------ valmask = 1e+20 terre = where(divi EQ 0) IF terre[0] NE -1 THEN BEGIN res[temporary(terre)] = 1e+20 ENDIF ;------------------------------------------------------------ ; IV.2) on remplace, quand nan ne 1, !values.f_nan par nan ;------------------------------------------------------------ if keyword_set(nan) NE 0 then BEGIN puttonan = where(temporary(testnan) EQ 0) if puttonan[0] NE -1 then res[temporary(puttonan)] = !values.f_nan if nan NE 1 then BEGIN notanumber = where(finite(res) eq 0) if notanumber[0] NE -1 then res[temporary(notanumber)] = nan ENDIF ENDIF ;------------------------------------------------------------ ; IV.3) on se remplace ds le sous domaine qui etait definit a l''entree de ; moyenne ;------------------------------------------------------------ if keyword_set(savedbox) THEN restoreboxparam, 'boxparam4grmoyenne.dat' ;------------------------------------------------------------ if keyword_set(key_performance) THEN print, 'temps grossemoyenne', systime(1)-tempsun return, res ;------------------------------------------------------------ ;------------------------------------------------------------ end