Index: trunk/ToBeReviewed/PLOTS/DIVERS/checkfield.pro
===================================================================
--- trunk/PLOTS/DIVERS/checkfield.pro	(revision 2)
+++ trunk/ToBeReviewed/PLOTS/DIVERS/checkfield.pro	(revision 37)
@@ -20,4 +20,7 @@
 ;
 ; KEYWORD PARAMETERS:
+; 
+;         /WDEPTH: to specify that the field is at W depth instad of T 
+;         depth (automatically activated if vargrid eq 'W')
 ;
 ; OUTPUTS:
@@ -36,37 +39,85 @@
 ;------------------------------------------------------------
 ;------------------------------------------------------------
-;------------------------------------------------------------
-FUNCTION checkfield, field, procedure, TYPE = type, BOITE = boite, DIREC = direc, NOQUESTION = noquestion, VECTEUR = vecteur, _EXTRA = ex
-;--------------------------------------------------------------
-@common
+FUNCTION err_1d, type, n1, name, n2
+  return, report(['Error in "' + type + '" type plot with a 1D input array:' $
+                  , 'the number of elements of the input vector ('+strtrim(n1, 1)+') ' $
+                  , 'is not equal to ' + name + ' ('+strtrim(n2, 1)+')'], /simple)
+END
+;
+FUNCTION err_2d, type, sz, nx, ny, nz
+  @cm_4mesh
+  @cm_4cal
+  return, report(['Error in "' + type + '" type plot with a 2D input array:' $
+                  , 'the array dimensions ' + tostr(sz[1:2]) + ' are incompatible' $
+                  , 'with the the domain dimensions ' $
+                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
+                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
+                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
+                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
+                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
+END
+;
+FUNCTION err_3d, type, sz, nx, ny, nz
+  @cm_4mesh
+  @cm_4cal
+  return, report(['Error in "' + type + '" type plot with a 3D input array:' $
+                  , 'the array dimensions ' + tostr(sz[1:3]) + ' are incompatible' $
+                  , 'with the the domain dimensions ' $
+                  , '[jpi/nx, jpj/ny, jpk/nz, jpt] = [' $
+                  + strtrim(jpi, 1) + '/' + strtrim(nx, 1) $
+                  + ', ' + strtrim(jpj, 1) + '/' + strtrim(ny, 1) $
+                  + ', ' + strtrim(jpk, 1) + '/' + strtrim(nz, 1) $
+                  + ', ' + strtrim(jpt, 1) + ']'], /simple)
+END
+;--------------------------------------------------------------
+;
+FUNCTION checkfield, field, procedure, TYPE = type, BOXZOOM = boxzoom, DIREC = direc, NOQUESTION = noquestion, VECTEUR = vecteur, WDEPTH = wdepth, _EXTRA = ex
+;--------------------------------------------------------------
+; include commons
+@cm_4mesh
+@cm_4cal
+@cm_4data
+  IF NOT keyword_set(key_forgetold) THEN BEGIN
+@updatenew
+@updatekwd
+  ENDIF
 ;--------------------------------------------------------------
 ; I1) lecture du champ
 ;--------------------------------------------------------------
-   if n_elements(field) EQ 0 then return, report('field undefined')
-   z2d = litchamp(field)
-   nan = total(finite(z2d,/nan)) < 1
+  if n_elements(field) EQ 0 then return, report('field undefined')
+  arr = litchamp(field)
+; first check
+  IF n_elements(arr) EQ 1 THEN BEGIN
+    if arr EQ -1 then $
+      return, report('Error: input array = -1. Maybe the reading did ont perform well...', /simple) $
+    ELSE return, report('Error: input array is a scalar', /simple)     
+  ENDIF
+  nan = total(finite(arr, /nan)) < 1
 ;---------------------------------------------------------------
 ; redefinition du domaine 
 ;---------------------------------------------------------------
-   minprof = 0
-   profdefault = 200
-   if keyword_set(boite) then BEGIN 
-;
-;      if n_elements(integration3d) EQ 0 THEN integration3d = n_elements(boite) ne 4
-;
-      neleboitein = N_Elements(Boite)
-      Case neleboitein Of
-         1:boite=[lon1, lon2, lat1, lat2, minprof,boite[0]]
-         2:boite=[lon1, lon2, lat1, lat2, boite[0],boite[1]]
-         4:$ 
-          if strpos(type, 'z') NE -1 THEN boite=[Boite, minprof, profdefault] $
-         ELSE boite=[Boite, prof1, prof2]
-         5:boite=[Boite[0:3], minprof, Boite[4]]
-         6:boite=Boite
-         Else: return, report('Mauvaise Definition de Boite')
-      ENDCASE
-   ENDIF ELSE neleboitein = 0
+  minprof = 0.
+  profdefault = 200.
+;
+  Case n_elements(boxzoom) OF
+    0:
+    1:localbox = [minprof, boxzoom[0]]
+    2:localbox = boxzoom
+    4:if strpos(type, 'z') NE -1 THEN $
+      localbox = [boxzoom, minprof, profdefault] ELSE localbox = boxzoom
+    5:localbox = [Boxzoom[0:3], minprof, Boxzoom[4]]
+    6:localbox = boxzoom
+    Else: return, report('Bad definition of boxzoom')
+  ENDCASE
+;
+  if keyword_set(localbox) then BEGIN
+    if keyword_set(vecteur) then grillechoice = [vargrid, 'T', 'U', 'V'] $
+    ELSE grillechoice = [vargrid, 'T']
+    if keyword_set(wdepth) then grillechoice = [grillechoice, 'W']
+    domdef, localbox, GRIDTYPE = grillechoice, _extra = ex
+  ENDIF
+;
 ; la procedure domdef determine les elements qui sont a l''interieur
-; de la boite. 
+; de la boxzoom. 
 ; si on fait un plot contenant l''axe z:
 ; Suivant l''axe z si on veut par ex faire un dessin
@@ -76,278 +127,220 @@
 ; elevees). Pour ne pas que le dessin s''arrete a 900 mais bien a
 ; 1000, on va aller chercher le niveau au dessous de 1000, d''ou la
-; manip suivante sur la boite: l''approfondir de 1 niveau sur la
+; manip suivante sur la boxzoom: l''approfondir de 1 niveau sur la
 ; verticale (si possible) sans changer les y range. 
-   if strpos(type, 'z') NE -1 THEN BEGIN
-      if NOT keyword_set(boite) then boite = 1.*[lon1,lon2,lat1,lat2,minprof, profdefault]
-      !y.range = [boite[5], boite[4]] ;on garde les yranges (axe z) avant de changer la boite.
-      profmax = boite[5]
-      if vargrid EQ 'W' then gdep = gdepw ELSE gdep = gdept
-; check with vertical grid limits (nearest level)
-      gwork = gdep
-; check the increse or decrese of the z axis
-      IF gwork[1] LE gwork[0] THEN gwork = reverse(gdep, 1)
-      niveauprof = where(gwork ge boite[5]) & niveauprof = niveauprof[0]
-      if niveauprof NE -1 then boite[5] = gwork[niveauprof]+1
-   ENDIF
-   if keyword_set(boite) then BEGIN
-      if keyword_set(vecteur) then grillechoice = [vargrid, 'T', 'U', 'V'] ELSE grillechoice = [vargrid, 'T']
-      if neleboitein LE 2 then domdef, boite, GRILLE=grillechoice ELSE domdef, boite, GRILLE=grillechoice, _extra = ex
-   ENDIF
+  if strpos(type, 'z') NE -1 THEN BEGIN
+    if NOT keyword_set(localbox) then BEGIN 
+      localbox = [minprof, profdefault]
+      if keyword_set(wdepth) then grillechoice = 'W' $
+      ELSE grillechoice = vargrid
+      domdef, localbox, GRIDTYPE = grillechoice
+    END
+    nelbox = n_elements(localbox)
+;on garde les yranges (axe z) avant de changer la boxzoom.
+    !y.range = [localbox[nelbox-1], localbox[nelbox-2]] 
+    if vargrid EQ 'W' OR keyword_set(wdepth) then BEGIN
+      firstzw = 0 > (firstzw-1)
+      lastzw = (lastzw+1) < (jpk-1)
+      nzw = lastzw - firstzw + 1
+    ENDIF ELSE BEGIN
+      firstzt = 0 > (firstzt-1)
+      lastzt = (lastzt+1) < (jpk-1)
+      nzt = lastzt - firstzt + 1
+    ENDELSE
+    @updateold
+  ENDIF
+; make the automatic definition of type for pltz if type is not specified.
+  IF type EQ 'z' AND procedure EQ 'pltz' THEN $
+    if (lon2-lon1) gt (lat2-lat1) then type = 'xz' else type = 'yz'
+; make the automatic definition of type for pltt if type is not specified.
+  IF type EQ 'unkownpltt' AND procedure EQ 'pltt' THEN $
+    if (lon2-lon1) gt (lat2-lat1) then type = 'xt' else type = 'yt'
 ;--------------------------------------------------------------
 ; verification de la taille du tableau d''entree et de la valeur de type
 ;--------------------------------------------------------------
-   grille, mask, glam, gphi, gdep, nx, ny,nz,premierx,premiery,premierz,dernierx,derniery,dernierz
-   taille=size(z2d)
-   case taille[0] of
-;--------------------------------------------------------------
-      0:BEGIN 
-         if z2d EQ -1 then $
-          return, report('Attention le tableau est egale a -1. Probleme lors de la lecture...') $
-         ELSE return, report('Attention le tableau est un scalaire') 
-      END 
-;--------------------------------------------------------------
-      1:BEGIN
-         nele = n_elements(z2d)
-         case type of
-            't':if jpt NE nele then $
-             return, report('jpt: '+strtrim(jpt, 1)+' n''est pas egale au nombres d''elements du vecteur: '+strtrim(nele, 1))
-            'x':BEGIN 
-               case nele of
-                  jpi:z2d = z2d[premierx:dernierx]
-                  nx:
-                  ELSE:return, report('nx: '+strtrim(nx, 1)+' n''est pas egale au nombres d''elements du vecteur: '+strtrim(nele, 1))
-               endcase
-            end
-            'y':BEGIN 
-               case nele of
-                  jpj:z2d = z2d[premiery:derniery]
-                  ny:
-                  ELSE:return, report('ny: '+strtrim(ny, 1)+' n''est pas egale au nombres d''elements du vecteur: '+strtrim(nele, 1))
-               endcase
-            END
-            'z':BEGIN 
-               case nele of
-                  jpk:z2d = z2d[premierz:dernierz]
-                  nz:
-                  ELSE:return, report('nz: '+strtrim(nz, 1)+' n''est pas egale au nombres d''elements du vecteur: '+strtrim(nele, 1))
-               endcase
-            END
-            ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 1d en entree: '+strtrim(nele, 1))
-         ENDCASE
-      END 
-;--------------------------------------------------------------
-      2:BEGIN
-         case type of
-            'x':BEGIN
-               case taille[2] of
-                  ny:direc = 'y'
-                  jpj:direc = 'y'
-                  jpt:direc = 't'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 2d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            end
-            'y':BEGIN
-               case 1 of
-                  taille[1] EQ jpi OR taille[1] EQ nx:direc = 'x'
-                  taille[2] EQ jpt:direc = 't'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 2d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-            'z':BEGIN
-               if taille[2] EQ jpt then direc = 't' $
-               ELSE return, report('imcompatibilite entre type: '+type+' et la taille du tableau 2d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-            END
-            't':BEGIN
-               case 1 of
-                  taille[1] EQ jpi OR taille[1] EQ nx:BEGIN
-                     direc = 'x'
-                     timearray = 1
-                  END
-                  jpt EQ 1:BEGIN
-                     ras = report('Field average: '+strtrim(moyenne(z2d, 'xy', boite = boite, NAN = nan, _extra = ex), 1)+' in box: '+tostr(boite))
-                     return,  -1
-                  END
-                  ELSE: return, report('imcompatibilite entre type: '+type+' et la taille du tableau 2d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               ENDCASE
-            END
-            'xy':BEGIN 
-               case 1 of
-                  taille[1] eq  nx and taille[2] eq  ny:
-                  taille[1] eq jpi and taille[2] eq jpj:z2d=z2d[premierx:dernierx, premiery:derniery]
-                  else: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))
-               endcase
-               if vargrid EQ 'W' then niveau = premierzw+1 ELSE niveau = premierzt+1
-            END
-            'xz':BEGIN 
-               case 1 of
-                  taille[1] eq jpi and taille[2] eq jpk:z2d = z2d[premierx:dernierx,premierz:dernierz]
-                  taille[1] eq nx and taille[2] eq jpk:z2d = z2d[*,premierz:dernierz]
-                  taille[1] eq nx and taille[2] eq nz:
-                  else:return, report('Probleme d''adequation entre les tailles du domaine nx*nz '+strtrim(nx, 1)+'*'+strtrim(nz, 1)+'et du tableau'+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-            'yz':BEGIN 
-               case 1 of
-                  taille[1] eq jpj and taille[2] eq jpk:z2d = z2d[premiery:derniery,premierz:dernierz]
-                  taille[1] eq ny and taille[2] eq jpk:z2d = z2d[*,premierz:dernierz]
-                  taille[1] eq ny and taille[2] eq nz:
-                  else:return, report('Probleme d''adequation entre les tailles du domaine ny*nz '+strtrim(ny, 1)+'*'+strtrim(nz, 1)+'et du tableau'+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-            'xt':BEGIN
-               case 1 of
-                  taille[1] eq jpi and taille[2] eq jpt:z2d = z2d[premierx:dernierx,*]
-                  taille[1] eq nx and taille[2] eq jpt:
-                  else:return, report('Probleme d''adequation entre les tailles du domaine nx*jpt '+strtrim(nx, 1)+'*'+strtrim(jpt, 1)+'et du tableau'+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-            'yt':BEGIN
-               case 1 of
-                  taille[1] eq jpj and taille[2] eq jpt:z2d = z2d[premiery:derniery,*]
-                  taille[1] eq ny and taille[2] eq jpt:
-                  else:return, report('Probleme d''adequation entre les tailles du domaine ny*jpt '+strtrim(ny, 1)+'*'+strtrim(jpt, 1)+'et du tableau'+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-            'zt':BEGIN
-               case 1 of
-                  taille[1] eq jpk and taille[2] eq jpt:z2d = z2d[premierz:dernierz,*]
-                  taille[1] eq nz and taille[2] eq jpt:
-                  else:return, report('Probleme d''adequation entre les tailles du domaine nz*jpt '+strtrim(nz, 1)+'*'+strtrim(jpt, 1)+'et du tableau'+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1))
-               endcase
-            END
-         endcase
-      END
-;--------------------------------------------------------------
-      3:BEGIN
-         case type of
-            'x':BEGIN
-               case taille[3] of
-                  nz:direc = 'yz'
-                  jpk:direc = 'yz'
-                  jpt:direc = 'yt'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-            'y':BEGIN
-               case taille [3] of
-                  nz:direc = 'xz'
-                  jpk:direc = 'xz'
-                  jpt:direc = 'xt'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-            'z':BEGIN
-               case taille [3] of
-                  nz:direc = 'xy'
-                  jpk:direc = 'xy'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-            't':BEGIN
-               IF jpt EQ 1 THEN BEGIN 
-                  ras = report('Field average: '+strtrim(moyenne(z2d, 'xyz', boite = boite, NAN = nan, _extra = ex), 1)+' in box: '+tostr(boite))
-                  return,  -1
-               ENDIF ELSE BEGIN
-                  direc = 'xy'
-                  timearray = 1
-               ENDELSE
-            END
-            'xy':BEGIN
-               case 1 of
-                  taille[3] EQ jpt:BEGIN
-                     direc = 't'
-                     if vargrid EQ 'W' then niveau = premierzw+1 ELSE niveau = premierzt+1
-                  END
-                  taille[3] EQ nz OR taille[3] EQ jpk:BEGIN 
-                     if keyword_set(boite) OR keyword_set(noquestion) then begin
-                        direc = 'z'
-                        if vargrid EQ 'W' then niveau = premierzw+1 ELSE niveau = premierzt+1
-                     ENDIF ELSE BEGIN
-                        if vargrid EQ 'W' then premierz = premierzw ELSE premierz = premierzt
-                        if NZ NE 1 then begin
-                           niveau = xquestion('Le tableau d''entree est un tableau 3d,' $
-                                              +'!C a quel niveau faut-il faire le graphique?', '1', /chkwidget)
-                           niveau = 1 > fix(niveau) < (jpk-premierz)
-                           case 1 of
-                              taille[1] EQ nx AND taille[2] EQ ny: $
-                               z2d=z2d[*, *,niveau-1]
-                              taille[1] EQ jpi AND taille[2] EQ jpj: $
-                               z2d=z2d[premierx:dernierx, premiery:derniery,niveau-1]
-                              ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-                           endcase
-                        ENDIF ELSE niveau = 1
-                        niveau = premierz+niveau
-                     endelse    
-                  END
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-            'xz':BEGIN
-               case 1 of
-                  (taille[2] EQ ny OR taille[2] EQ jpj) AND taille[3] EQ jpk:BEGIN
-                     z2d = z2d[*, *, premierz:dernierz]
-                     direc = 'y'
-                  END
-                  (taille[2] EQ ny OR taille[2] EQ jpj) AND taille[3] EQ nz:direc = 'y'
-                  taille[3] EQ jpt:direc = 't'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-            'yz':BEGIN
-               case 1 of
-                  (taille[1] EQ nx OR taille[1] EQ jpi) AND taille[3] EQ jpk:BEGIN
-                     z2d = z2d[*, *, premierz:dernierz]
-                     direc = 'x'
-                  END
-                  (taille[1] EQ nx OR taille[1] EQ jpi) AND taille[3] EQ nz:direc = 'x'
-                  ELSE:return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-               endcase
-            END
-         'xt':BEGIN & direc = 'y' & timearray = 1 & end
-         'yt':BEGIN & direc = 'x' & timearray = 1 & end
-            'zt':return, report('imcompatibilite entre type: '+type+' et la taille du tableau 3d en entree: '+strtrim(taille[1], 1)+'*'+strtrim(taille[2], 1)+'*'+strtrim(taille[3], 1))
-         ENDCASE
-      end
-;--------------------------------------------------------------
-      4:BEGIN 
-         case type of
-            'x':direc = 'yzt'
-            'y':direc = 'xzt'
-            'z':direc = 'xyt'
-            't':direc = 'xyz'
-            'xy':BEGIN 
-               if keyword_set(boite) OR keyword_set(noquestion) then begin
-                  if vargrid EQ 'W' then niveau = premierzw+1 ELSE niveau = premierzt+1
-                  direc = 'zt'
-               ENDIF ELSE BEGIN 
-                  if vargrid EQ 'W' then premierz = premierzw ELSE premierz = premierzt
-                  if NZ NE 1 then begin
-                     niveau = xquestion('Le tableau d''entree est un tableau 4d,' $
-                                        +'!C a quel niveau faut-il faire le graphique?', '1', /chkwidget)
-                     niveau = 1 > fix(niveau) < (jpk-premierz)
-                     z2d=reform(z2d[*,*,niveau-1, *], /over)
-                  ENDIF ELSE niveau = 1
-                  niveau = premierz+niveau
-                  direc = 't'
-               ENDELSE
-            END
-            'xz':direc = 'yt'
-            'yz':direc = 'xt'
-            'xt':direc = 'yz'
-            'yt':direc = 'xz'
-            'zt':direc = 'xy'
-         endcase
-      END
-   ENDCASE
-;--------------------------------------------------------------
-   if keyword_set(direc) then begin
-      if strpos(direc, 't') NE -1 OR keyword_set(timearray) OR taille[0] EQ 4 then $
-       z2d = grossemoyenne(z2d, direc, boite = boite, NAN = nan, /nodomdef, _extra = ex) $
-      ELSE z2d = moyenne(z2d, direc, boite = boite, NAN = nan, /nodomdef, _extra = ex)
-   ENDIF
-;--------------------------------------------------------------
-;--------------------------------------------------------------
-;--------------------------------------------------------------
-;--------------------------------------------------------------
-   return, z2d
-end
+  grille, -1, -1, -1, -1, nx, ny, nz, firstx, firsty $
+    , firstz, lastx, lasty, lastz, WDEPTH = wdepth
+;--------------------------------------------------------------
+; basic checks
+;--------------------------------------------------------------
+  CASE 1 OF
+    nx EQ 1: IF strpos(type, 'x') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nx = 1 ', /simple)
+    ny EQ 1: IF strpos(type, 'y') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with ny = 1 ', /simple)
+    nz EQ 1: IF strpos(type, 'z') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with nz = 1 ', /simple)
+    jpt EQ 1: IF strpos(type, 't') NE -1 THEN return, report('Error: impossible to make a "' + type + '" type plot with jpt = 1 ', /simple)
+    ELSE:
+  ENDCASE
+;--------------------------------------------------------------
+; is the size of the array compatible with teh domain?
+;--------------------------------------------------------------
+  arr = fitintobox(temporary(arr), nx, ny, nz, firstx, firsty $
+    , firstz, lastx, lasty, lastz)
+;--------------------------------------------------------------
+  sz = size(arr)
+  case sz[0] of
+;--------------------------------------------------------------
+    0:return, arr
+;--------------------------------------------------------------
+    1:BEGIN
+      nele = n_elements(arr)
+      case type of
+        't':if jpt NE nele THEN return, err_1d(type, nele, 'jpt', jpt)
+        'x':IF  nx NE nele THEN return, err_1d(type, nele,  'nx',  nx)
+        'y':IF  ny NE nele THEN return, err_1d(type, nele,  'ny',  ny)
+        'z':IF  nz NE nele THEN return, err_1d(type, nele,  'nz',  nx)
+        ELSE:return, report('Error: ' $
+                            , 'Impossible to make a "'+type+'" plot with a 1D array', /simple)
+      ENDCASE
+    END 
+;--------------------------------------------------------------
+    2:BEGIN
+      case type of
+        'x':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny:direc = 'y' ; xy array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'z' ; x(y)z array
+            sz[1] EQ nx AND sz[2] EQ jpt:direc = 't' ; xt array
+            ELSE:return, err_2d(type, sz, nx, ny, nz)
+          endcase
+        end
+        'y':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny:direc = 'x' ; xy array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'z' ; (x)yz array
+            sz[1] EQ ny AND sz[2] EQ jpt:direc = 't' ; yt array
+            ELSE:return, err_2d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'z':BEGIN
+          case 1 of
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz:direc = 'x' ; x(y)z array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz:direc = 'y' ; (x)yz array
+            sz[1] EQ nz AND sz[2] EQ jpt:direc = 't' ; zt array
+            ELSE:return, err_2d(type, sz, nx, ny, nz)
+          endcase
+        END
+        't':BEGIN
+          case 1 OF
+            sz[1] EQ nx AND sz[2] EQ jpt:direc = 'x' ; xt array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ jpt:direc = 'y' ; (x)yt array
+            nx EQ 1 AND ny EQ 1 AND sz[1] EQ nz AND sz[2] EQ jpt:direc = 'z' ; (x)(y)zt array
+            ELSE:return, err_2d(type, sz, nx, ny, nz)
+          ENDCASE
+        END
+        'xy':IF sz[1] NE nx OR sz[2] ne  ny THEN return, err_2d(type, sz, nx, ny, nz) ; xy array
+        'xz':IF sz[1] NE nx OR sz[2] ne  nz THEN return, err_2d(type, sz, nx, ny, nz) ; xz array
+        'yz':IF sz[1] NE ny OR sz[2] NE  nz THEN return, err_2d(type, sz, nx, ny, nz) ; yz array
+        'xt':IF sz[1] NE nx OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; xt array
+        'yt':IF sz[1] NE ny OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; yt array
+        'zt':IF sz[1] NE nz OR sz[2] NE jpt THEN return, err_2d(type, sz, nx, ny, nz) ; zt array
+      ENDCASE
+    END 
+;--------------------------------------------------------------
+    3:BEGIN
+      case type of
+        'x':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'yz' ; xyz array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; x(y)zt array
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'yt' ; xyt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'y':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xz' ; xyz array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'zt' ; (x)yzt array
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xt' ; xyt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'z':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ nz:direc = 'xy' ; xyz array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yt' ; (x)yzt array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xt' ; x(y)zt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        't':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'xy' ; xyt array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'yz' ; (x)yzt array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'xz' ; x(y)zt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'xy':BEGIN
+          case 1 OF
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'z' ; xyz array
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 't' ; xyt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'xz':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'y' ; xyz array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; x(y)zt
+            ELSE:return, err_3d(type, sz, nx, ny, nz)
+          endcase
+        END
+        'yz':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ  nz:direc = 'x' ; xyz array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 't' ; (x)yzt
+            ELSE:return, err_3d(type, sz, nx, ny, nz) 
+          endcase
+        END
+        'xt':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'y' ; xyt array
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; x(y)zt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz) 
+          endcase
+        END
+        'yt':BEGIN
+          case 1 of
+            sz[1] EQ nx AND sz[2] EQ ny AND sz[3] EQ jpt:direc = 'x' ; xyt array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'z' ; (x)yzt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz) 
+          endcase
+        END
+        'zt':BEGIN
+          case 1 of
+            sz[1] EQ nx AND ny EQ 1 AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'x' ; x(y)zt array
+            nx EQ 1 AND sz[1] EQ ny AND sz[2] EQ nz AND sz[3] EQ jpt:direc = 'y' ; (x)yzt array
+            ELSE:return, err_3d(type, sz, nx, ny, nz) 
+          ENDCASE
+        END 
+      ENDCASE 
+    END 
+;--------------------------------------------------------------
+    4:BEGIN 
+      CASE type OF
+        'x':direc = 'yzt'
+        'y':direc = 'xzt'
+        'z':direc = 'xyt'
+        't':direc = 'xyz'
+        'xy':direc = 'zt'
+        'xz':direc = 'yt'
+        'yz':direc = 'xt'
+        'xt':direc = 'yz'
+        'yt':direc = 'xz'
+        'zt':direc = 'xy'
+      ENDCASE 
+    END
+  ENDCASE
+;--------------------------------------------------------------
+  IF keyword_set(direc) THEN BEGIN
+    IF strpos(direc, 't') NE -1 OR strpos(type, 't') NE -1 THEN $
+      arr = grossemoyenne(temporary(arr), direc, boxzoom = localbox $
+                          , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex) $
+    ELSE arr = moyenne(temporary(arr), direc, boxzoom = localbox $
+                       , NAN = nan, /NODOMDEF, WDEPTH = wdepth, _extra = ex)
+  ENDIF
+;--------------------------------------------------------------
+;--------------------------------------------------------------
+;--------------------------------------------------------------
+;--------------------------------------------------------------
+  RETURN, arr
+END
