Index: /trunk/procs/com_eg.pro
===================================================================
--- /trunk/procs/com_eg.pro	(revision 40)
+++ /trunk/procs/com_eg.pro	(revision 41)
@@ -4,5 +4,5 @@
 ; attributs horizontal+vertical means
 ;
-COMMON zm_att, box_h, depth_z, zoom_z, diaznl_idx, box_plot, legbox, hpa_max, hpa_min, max_spec, spec_win, vert_type, vert_mean,  vert_switch, glamboundary_box, msf_mean
+COMMON zm_att, box_h, depth_z, zoom_z, diaznl_idx, box_plot, legbox, hpa_max, hpa_min, max_spec, spec_win, vert_type, vert_mean,  vert_switch, glamboundary_box, msf_mean, name_level
 ;
 ; attributs hoevmoeller
@@ -12,5 +12,7 @@
 ; attributs formats + div
 ;
-COMMON formats, look, free_1d_minmax, lat_axis, cont_fill, multi_win, atmos_msk, line_thick, line_style, line_color, title_type, fill_space, vector_sample, symbol_style, symbol_color, symbol_families, contour_options, mean_sc_only, nc_grids_list, cont_real, symbol_size, xchartxt, ychartxt,  linfit_sep
+COMMON formats, look, free_1d_minmax, lat_axis, cont_fill, multi_win, atmos_msk, line_thick, line_style, line_color, title_type, fill_space, vector_sample, symbol_style, symbol_color, symbol_families, contour_options, mean_sc_only, nc_grids_list, cont_real, symbol_size, xchartxt, ychartxt, linfit_sep
+COMMON switches, cmd1_back,  cmd2_back, file_name1, file_name2, ncdf_db1, ncdf_db2, grid1_full, grid2_full
+
 ;
 ; attributs couleur
Index: /trunk/procs/data_read.pro
===================================================================
--- /trunk/procs/data_read.pro	(revision 40)
+++ /trunk/procs/data_read.pro	(revision 41)
@@ -10,4 +10,5 @@
 ; same data as previous read ?
 
+   IF debug_w THEN print, '   '
    IF debug_w THEN print, '   ENTER data_read...'
    IF debug_w THEN print, '       cmd at top of data_read = ', cmd
@@ -79,11 +80,7 @@
    def_file_name, cmd, ncdf_db, file_name, delta_t1
 
-   IF debug_w THEN print, '       varexp step 1 in data_read = ', varexp
-
 ; get file if remote
 
    get_file, file_name, ncdf_db
-
-   IF debug_w THEN print, '       varexp step 2 in data_read = ', varexp
 
 ; read grid from file if require (@<grid> option) 
@@ -92,7 +89,7 @@
       mesh_from_file, cmd.grid, file_name, ncdf_db, cmd.var
       key_shift_map = key_shift
+      file_name2 = file_name
+      ncdf_db2 = ncdf_db
    ENDIF 
-
-   IF debug_w THEN print, '       varexp step 3 in data_read = ', varexp
 
 ; define data domain
@@ -101,5 +98,5 @@
       ; get hovmoeller box + stride
       box_plot = def_box(cmd.plt, dimplot, legbox, time_stride)
-      IF debug_w THEN print, 'box_plot for domdef in data_read = ', box_plot
+      IF debug_w THEN print, '    box_plot for domdef in data_read = ', box_plot
       CASE n_elements(box_plot) OF
          4: domdef, box_plot[0:3], /MEMEINDICES
@@ -181,4 +178,6 @@
                fldr1 = nc_read(file_name, var1, ncdf_db, $
                                TIME_1 = time1,  TIME_2 =  time2, ALL_DATA = all_data, _extra = ex)
+               file_name1 = file_name
+               ncdf_db1 = ncdf_db
                CASE cmd.grid OF 
                   'U': vargrid1 = 'U'
@@ -200,20 +199,30 @@
                   cmd2.spec = cmd.spec
                   datyp2 = def_dptyp(cmd2)
+                  cmd2_back = cmd2
                   ; other grid ?
+                  grid2_test = cmd2.grid
                   sw_diffg = 0
-                  IF cmd2.grid NE cmd.grid THEN BEGIN
+                  IF grid2_test NE cmd.grid THEN BEGIN 
                      sw_diffg = 1
                      jptb =  jpt
-                     def_grid, cmd2
-                     IF debug_w THEN print, 'def_grid, cmd2 dans data_read : '
+                     IF debug_w THEN print, '    (in data_read) cmd2.grid <> cmd.grid ', cmd2.grid, cmd.grid
+                     IF debug_w THEN print, '    exec def_grid, cmd2_back in data_read : '
+                     grid2_full = cmd2_back.grid
+                     def_grid, cmd2_back
                      jpt = jptb
                   ENDIF 
                   fldr2 = data_read(cmd2, datyp2.hotyp, datyp2.plttyp, '1', '0', ALL_DATA = all_data, _extra = ex)
                   var2 = cmd2.var
-                  print,  'Variable ',  var2,  ' lue sur grille ',  vargrid
+                  print,  '   Variable 2 ',  var2,  ' read on vargrid ',  vargrid
                   jptb =  jpt
+                  if debug_w THEN print, '   yfx grids different ? / sw_diffg = ', sw_diffg
                   IF sw_diffg EQ 1 THEN BEGIN
-                     def_grid, cmd
-                     IF debug_w THEN print, 'def_grid, cmd dans data_read : '
+                     IF debug_w THEN print, '   exec def_grid, cmd1_back in data_read : '
+                     grid1_full = cmd1_back.grid
+                     def_grid, cmd1_back
+                     IF read_grid_from_file EQ 1 THEN BEGIN 
+                        mesh_from_file, cmd1_back.grid, file_name1, ncdf_db1, cmd1_back.var
+                        key_shift_map = key_shift
+                     ENDIF 
                   ENDIF
                   jpt = jptb
Index: /trunk/procs/def_file_name.pro
===================================================================
--- /trunk/procs/def_file_name.pro	(revision 40)
+++ /trunk/procs/def_file_name.pro	(revision 41)
@@ -7,5 +7,5 @@
 @com_eg
    IF debug_w THEN print, ' '
-   IF debug_w THEN print, '  ENTER def_file_name...'
+   IF debug_w THEN print, '    ENTER def_file_name...'
 
 ; define date1 and date2
@@ -20,5 +20,5 @@
    f_suffix = suffix
 
-   IF debug_w THEN print, '   suffix before search_time_file = ', suffix
+   IF debug_w THEN print, '     suffix before search_time_file = ', suffix
 
    CASE strmid(cmd.plt, 0, 2) OF
@@ -39,11 +39,11 @@
       END  
    ENDCASE 
-   IF debug_w THEN print, ' suffix after search_time_file = ', suffix
+   IF debug_w THEN print, '     suffix after search_time_file = ', suffix
    
    file_name = cmd.exp+'_'+timavef+'_'+date1+'_'+date2+suffix+'.nc'
    base_file_name = cmd.exp+'_'+timavef+'_'+date1+'_'+date2
    
-   IF debug_w THEN print,  ' vargrid = ',  vargrid
-   IF debug_w THEN print,  ' file_name in def_file_name = ',file_name 
-   IF debug_w THEN print, '  ... EXIT def_file_name'
+   IF debug_w THEN print,  '     vargrid = ',  vargrid
+   IF debug_w THEN print,  '     file_name in def_file_name = ',file_name 
+   IF debug_w THEN print, '     ... EXIT def_file_name'
 END 
Index: /trunk/procs/def_grid.pro
===================================================================
--- /trunk/procs/def_grid.pro	(revision 40)
+++ /trunk/procs/def_grid.pro	(revision 41)
@@ -9,4 +9,6 @@
    IF debug_w THEN print, ' '
    IF debug_w THEN print, '  ENTER def_grid / cmd =', cmd
+
+   varexp = cmd.exp
 
    IF cmd.out EQ 'cdf' THEN BEGIN
@@ -36,5 +38,5 @@
    ENDIF 
 
-   IF debug_w THEN print, '  file_suff_var = ', file_suff_var
+   IF debug_w THEN print, '    file_suff_var = ', file_suff_var
 
 ; read_grid_from_file ?
@@ -45,5 +47,5 @@
       cmd.grid = strmid(cmd.grid, 1, strlen(cmd.grid)-1)
       read_grid_from_file = 1
-      print, ' Will read grid info '+cmd.grid+' from data file'
+      print, '   Will read grid info '+cmd.grid+' from data file'
       key_shift_map = 0
       IF strpos(cmd.var, '@@') NE -1 THEN BEGIN 
@@ -53,5 +55,5 @@
    ENDIF ELSE var_read_grd_file = cmd.var
 
-   IF debug_w THEN print,    '  cmd.grid after test read_grid_from_file: ', cmd.grid
+   IF debug_w THEN print,    '    cmd.grid after test read_grid_from_file: ', cmd.grid
 
 ; choose grid (if not already loaded)
@@ -72,13 +74,13 @@
  ; read attributes from Defaults/Grids/grid_config.def
       file_grid_config = hom_def+'grid_config.def'
-      IF debug_w THEN print, '    doing: grep -i "\ '+cmd.grid+' " '+file_grid_config
+      IF debug_w THEN print, '      doing: grep -i "\ '+cmd.grid+' " '+file_grid_config
       spawn, 'grep -i "\ '+cmd.grid+' " '+file_grid_config, line
       line = strcompress(strtrim(line[0], 2)) 
       length = strlen(line)
 
-      IF debug_w THEN print, '  line from grid_config.def  ',line 
+      IF debug_w THEN print, '      line from grid_config.def  ',line 
 
       IF length EQ 0 THEN BEGIN
-         print, '    *** def_grid : define grid ', cmd.grid, ' in file ', file_grid_config 
+         print, ' *** def_grid : define grid ', cmd.grid, ' in file ', file_grid_config 
          stop   
       ENDIF ELSE BEGIN 
@@ -88,7 +90,10 @@
          mesh_type2 = argvar[3]
          vargrid = argvar[4]
+         name_level = argvar[5]
       ENDELSE 
       meshlec_type = mesh_type
    ENDIF 
+
+   IF masked_data EQ 0 THEN atmos_msk = 0
 
 ; init zoom for data read
@@ -99,4 +104,5 @@
       izmindta = 0
    ENDIF 
+   IF debug_w THEN print,  '     varexp in def_grid before case cmd.grid:', varexp
 
    IF read_grid_from_file EQ 1 THEN GOTO, final
@@ -275,10 +281,11 @@
    box_h_prev = box_h
 
-   IF debug_w THEN print,  '   cmd.grid in def_grid:          ', cmd.grid 
-   IF debug_w THEN print,  '   file_suff_var in def_grid:     ', file_suff_var 
-   IF debug_w THEN print,  '   var_read_grd_file in def_grid: ', var_read_grd_file 
-   IF debug_w THEN print,  '   meshlec_type in def_grid:      ', meshlec_type
-   IF debug_w THEN print,  '   varexp in def_grid:            ', varexp
+   IF debug_w THEN print,  '     cmd.grid in def_grid:          ', cmd.grid 
+   IF debug_w THEN print,  '     file_suff_var in def_grid:     ', file_suff_var 
+   IF debug_w THEN print,  '     var_read_grd_file in def_grid: ', var_read_grd_file 
+   IF debug_w THEN print,  '     meshlec_type in def_grid:      ', meshlec_type
+   IF debug_w THEN print,  '     varexp in def_grid:            ', varexp
    IF debug_w THEN print,  '  ...EXIT def_grid'
+   IF debug_w THEN print,  '  '
   
 END 
Index: /trunk/procs/legend_overlay.pro
===================================================================
--- /trunk/procs/legend_overlay.pro	(revision 40)
+++ /trunk/procs/legend_overlay.pro	(revision 41)
@@ -27,5 +27,5 @@
 
 CASE plttyp OF 
-   'yfx': leg_txt = 'Linfit = '+coeff_txt+coefflu_txt
+   'yfx': leg_txt = 'Linfit = '+coeff_txt+coefflu_txt+coeffm_txt
    ELSE:
 END  
Index: /trunk/procs/meshes/mesh_from_file.pro
===================================================================
--- /trunk/procs/meshes/mesh_from_file.pro	(revision 40)
+++ /trunk/procs/meshes/mesh_from_file.pro	(revision 41)
@@ -40,4 +40,10 @@
          ELSE: var_local = var_read_grd_file
       ENDCASE 
+      IF strpos(var_local, '=f(next)') NE -1 THEN BEGIN
+         idx = strpos(var_local, '=f(')
+         var_local = strmid(var_local, 0, idx)
+      ENDIF 
+
+      IF debug_w THEN print, '   var_local = ', var_local
 
       ; find valmask
@@ -49,11 +55,20 @@
       FOR i = 0, varcontient.natts-1 DO BEGIN
          att_txt = ncdf_attname(cdfidl, varidl, i)
-         IF att_txt EQ 'missing_value' OR att_txt EQ 'mask value' OR att_txt EQ '_FillValue' THEN ncdf_attget, cdfidl, varidl, att_txt, valmask
-         IF debug_w THEN print, 'valmask found = ',valmask 
+         IF att_txt EQ 'missing_value' OR att_txt EQ 'mask value' OR att_txt EQ '_FillValue' THEN BEGIN 
+            ncdf_attget, cdfidl, varidl, att_txt, valmask
+            IF debug_w THEN print, '     valmask found = ',valmask, ' in attribute ', att_txt
+         ENDIF 
       ENDFOR 
       ncdf_close, cdfidl
-      ; read grid
-      initncdf, s_file, USEASMASK = var_local, missing_value = valmask, GLAMBOUNDARY = glamboundary_box, ZAXISNAME = 'depth'
-
+      ; build grid
+      CASE mesh_type of
+         'atm': initncdf, s_file, GLAMBOUNDARY = glamboundary_box, ZAXISNAME = name_level
+         ELSE: initncdf, s_file, USEASMASK = var_local, missing_value = valmask, GLAMBOUNDARY = glamboundary_box, ZAXISNAME = 'depth'
+      ENDCASE 
+      IF debug_w THEN print,  '     Grid info after initncdf :'
+      IF debug_w THEN print,  '     glamt :', size(glamt)
+      IF debug_w THEN print,  '     gphit :', size(gphit)
+      IF debug_w THEN print,  '     gdept :', size(gdept)
+      
    ENDELSE 
 
@@ -65,6 +80,7 @@
 ;
    diaznl_idx = 1
-   IF debug_w THEN print, '     model, vargrid, varexp at exit = ',model, vargrid,  varexp
+   IF debug_w THEN print, '     model, vargrid, varexp at exit = ',model, ' ', vargrid,' ',  varexp
    IF debug_w THEN print, '  ...EXIT mesh_from_file'
+   IF debug_w THEN print, '  '
 
   return
Index: unk/procs/meshes/mesh_lmdz.pro
===================================================================
--- /trunk/procs/meshes/mesh_lmdz.pro	(revision 40)
+++ 	(revision )
@@ -1,156 +1,0 @@
-PRO mesh_lmdz, res, NO_SHIFT = no_shift, WHOLE_ARRAYS = whole_arrays
-@common
-@com_eg
-;
-; init grid, sf, masks for LMDZ grid
-;
-   CASE res OF
-      'low': print, ' LMDZ low resolution inits '
-      'high':print, ' LMDZ high resolution inits '
-      ELSE: stop
-   ENDCASE 
-
-   CASE res OF
-      'low': BEGIN & jpi = 96L & jpj = 72L & jpk = 19L & key_shift = 0 & END 
-      'high': BEGIN & jpi = 144L & jpj = 97L & jpk = 19L & key_shift = 0 & END 
-   ENDCASE 
-   IF keyword_set(NO_SHIFT) THEN key_shift = 0
-
-   jpiglo = jpi
-   jpjglo = jpj
-   jpkglo = jpk
-
-   ixminmesh  =0
-   ixmaxmesh  =jpi-1
-;
-   iyminmesh  =0
-   iymaxmesh  =jpj-1
-;
-   izminmesh  =0
-   izmaxmesh  =jpk-1
-
-; 1.  Define longitudes 
-
-   glamt = 360.0*findgen(jpi)/float(jpi)-180
-   glamt = glamt#replicate(1, jpj)
-
-; 2 Define latitudes
-   CASE res OF
-      'low': BEGIN
-         gphit = 4*findgen(jpj/2)+2
-         gphit = [reverse(-gphit), gphit]
-         gphit = reverse(gphit)
-      END 
-      'high': BEGIN
-         gphit = 2.5*findgen(jpj/2)+2.5
-         gphit = [reverse(-gphit), 0, gphit]
-         gphit = reverse(gphit)
-      END 
-   ENDCASE 
-   gphit = replicate(1, jpi)#gphit
-
-; 3 Define scale factors
-
-   zrad=6371229.0
-
-   ; Exact method: integration on a sphere
-
-   e1t = abs(2*!pi*zrad*sin(gphit*!pi/180.0)/jpi)
-
-   ytop = (shift(gphit, 0, -1)+gphit)*0.5*!pi/180.0
-   ybot = (shift(gphit, 0, +1)+gphit)*0.5*!pi/180.0
-   
-   ytop(*, jpj-1) = !pi/2
-   ybot(*,     0) = -!pi/2
-
-   e2t = zrad*(ytop-ybot)
-
-; 4. Define mask
-
-; open mask file
-   CASE res OF
-      'low': BEGIN
-;          model = 'lmdzl'
-;          s_file = hom_idl+'grids/grids_'+model+'.nc'
-;          tmask = nc_get(s_file, 'sftlf') 
-;          tmask = shift(tmask,jpi/2, 0)
-;          tmask = reverse(tmask, 2) 
-;          tmask =  tmask < 1
-;          tmask =  1-tmask
-         nummsk = 12
-         s_file = hom_idl+'grids/mask_lmdz_'+res
-         openr, nummsk, s_file, /get_lun, /f77
-         tmask = lonarr(jpi, jpj)
-         readu, nummsk, tmask
-; convention : 1 on sea, 0 on land
-         tmask = 1-tmask
-         close, nummsk
-         free_lun, nummsk
-      END 
-      'high': BEGIN 
-;         nummsk = 12
-;         s_file = hom_idl+'grids/mask_lmdz_'+res
-;         openr, nummsk, s_file, /get_lun, /f77
-         tmask = lonarr(jpi, jpj)
-;         readu, nummsk, tmask
-; convention : 1 on sea, 0 on land
-         tmask(*, *)= 1
-;         close, nummsk
-;         free_lun, nummsk
-      END
-   ENDCASE 
-
-; 5. vertical grid (hPa)
-   gdept = [ 100426.5, 98327.56, 95346.5, 90966.84, 84776.86, 76536.46, $ 
-    66292.22, 54559.26, 42501.76, 31805.98, 23787.52, 18252.75, 13995.97, $ 
-    10320.8, 7191.053, 4661.738, 2732.851, 1345.618, 388.2433 ]
-
-   gdept = gdept/100.
-   gdepw = gdept
-
-   e3t = shift(gdept, 1)-gdept
-   e3t[0] = e3t[1]
-
-; Shift re-init U,V,F
-
-; key_shit to have first longitude at 20E
-
-   
-
-   glamt = shift(glamt,key_shift, 0)
-;   glamt(where(glamt LT 20) ) = glamt(where(glamt LT 20) )+360.
-   gphit = shift(gphit,key_shift, 0)
-   e1t = shift(e1t,key_shift, 0)
-   e2t = shift(e2t,key_shift, 0)
-   tmask = reform(shift(tmask,key_shift, 0), jpi*jpj)
-   tmask = reform(tmask#replicate(1, jpk), jpi, jpj, jpk)
-
-   glamu = glamt
-   gphiu = gphit
-   e1u = e1t
-   e2u = e2t
-   glamv = glamt
-   gphiv = gphit
-   e1v = e1t
-   e2v = e2t
-
-   glamf = 0.5*(shift(glamt, -1, 0)+glamt)
-   gphif = 0.5*(shift(gphit, 0, -1)+gphit)
-   glamf(jpi-1, *) =  glamf(jpi-2, *) + (glamf(jpi-2, *)-glamf(jpi-3, *))
-   gphif(*, jpj-1) =  gphif(*, jpj-2) + (gphif(*, jpj-2)-gphif(*, jpj-3))
-   e1f = e1t
-   e2f = e2t
-   
-   e3w = e3t
-   
-   key_periodique=1
-
-   key_offset = [0, 0, 0]
-;
-; indice i pour grille j moyenne zonale
-;
-   diaznl_idx = 1
-
-  return
-END 
-
Index: /trunk/procs/meshes/mesh_pcmdi.pro
===================================================================
--- /trunk/procs/meshes/mesh_pcmdi.pro	(revision 40)
+++ /trunk/procs/meshes/mesh_pcmdi.pro	(revision 41)
@@ -5,5 +5,9 @@
 ; init grid, sf, masks for grids with regular grid IPCC netCDF standard
 ;
-   print,' Model inits for ', model
+   IF debug_w THEN print, ' '
+   IF debug_w THEN print, '   ENTER mesh_pcmdi / model =', model
+  
+   print,'   Model inits for ', model
+   IF debug_w THEN print,  '     varexp at start of mesh_pcmdi:', varexp
 
    varexpp =  varexp
@@ -70,5 +74,8 @@
    varexp =  varexpp
    
-   print,' End of initialisation for pcmdi grid:', model
+   print,'    End of initialisation for pcmdi grid:', model
+   IF debug_w THEN print,  '     varexp at end of mesh_pcmdi:', varexp
+   IF debug_w THEN print, '   ...EXIT mesh_pcmdi'
+   IF debug_w THEN print,  '  '
    
    return
Index: /trunk/procs/nc_read.pro
===================================================================
--- /trunk/procs/nc_read.pro	(revision 40)
+++ /trunk/procs/nc_read.pro	(revision 41)
@@ -15,5 +15,7 @@
 
 ; inits
-   IF debug_w THEN print, 'DEBUG: Entering nc_read...'
+   IF debug_w THEN print, ' '
+   IF debug_w THEN print, '  ENTER nc_read'
+
    IF NOT keyword_set(TIME_1) THEN time_1 =  1
    IF NOT keyword_set(TIME_2) THEN time_2 =  time_1
@@ -22,5 +24,5 @@
 ;
 
-   IF debug_w THEN print, 'keyword_set(ALL_DATA) : ', keyword_set(ALL_DATA) 
+   IF debug_w THEN print, '     keyword_set(ALL_DATA) : ', keyword_set(ALL_DATA) 
 
    IF keyword_set(ALL_DATA) THEN BEGIN
@@ -47,9 +49,9 @@
    ENDELSE
 
-   IF debug_w THEN print, 'nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz'
-   IF debug_w THEN print, nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz
-
-   IF debug_w THEN print,  'key_offset =', key_offset
-   IF debug_w THEN print,  'jpi, jpj, jpk =',  jpi, jpj, jpk
+   IF debug_w THEN print, '     nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz'
+   IF debug_w THEN print, '     ', nx,ny,nz,firstx,firsty,firstz,lastx,lasty,lastz
+
+   IF debug_w THEN print,  '     key_offset =', key_offset
+   IF debug_w THEN print,  '     jpi, jpj, jpk =',  jpi, jpj, jpk
 
 
@@ -60,5 +62,5 @@
    z_count = nz
 
-   IF debug_w THEN print,  'nx,ny,nz =', nx,ny,nz 
+   IF debug_w THEN print,  '     nx,ny,nz =', nx,ny,nz 
 
 ; force izmaxmesh to lastz
@@ -69,10 +71,10 @@
       key_shift_read = 0
    ENDIF ELSE key_shift_read = key_shift
-   IF debug_w THEN print,  'key_shift_read=', key_shift_read
+   IF debug_w THEN print,  '     key_shift_read=', key_shift_read
 
    x_offset = key_offset[0]+ firstx+(key_shift_read-key_shift)
    y_offset = key_offset[1]+ firsty
    z_offset = key_offset[2]+ firstz
-   IF debug_w THEN print,  'offset =', x_offset, y_offset, z_offset
+   IF debug_w THEN print,  '     offset =', x_offset, y_offset, z_offset
 
 ; pour trouver un fichier, tu as
@@ -191,14 +193,16 @@
    name = varid
 
-   IF debug_w THEN print, 'key=', key 
-   IF debug_w THEN print, 'jpitotal=', jpitotal
-   IF debug_w THEN print, 'ixmindta,iymindta,izmindta  =', ixmindta,iymindta,izmindta
-   IF debug_w THEN print, 'ixminmesh,iyminmesh=', ixminmesh,iyminmesh
-   IF debug_w THEN print, 'ixmaxmesh,iymaxmesh=', ixmaxmesh,iymaxmesh 
-   IF debug_w THEN print, 'izminmesh,izmaxmesh=', izminmesh,izmaxmesh 
-   IF debug_w THEN print, 'ixmin,iymin=', ixmin,iymin 
-   IF debug_w THEN print, 'firsttps,lasttps=', firsttps, lasttps
-   IF debug_w THEN print, 'key_shift in nc_read=', key_shift
-   IF debug_w THEN print, 'key_yreverse, firsty, lasty',key_yreverse, firsty, lasty
+   IF debug_w THEN print, '     '
+   IF debug_w THEN print, '     key=', key 
+   IF debug_w THEN print, '     jpitotal=', jpitotal
+   IF debug_w THEN print, '     ixmindta,iymindta,izmindta  =', ixmindta,iymindta,izmindta
+   IF debug_w THEN print, '     ixminmesh,iyminmesh=', ixminmesh,iyminmesh
+   IF debug_w THEN print, '     ixmaxmesh,iymaxmesh=', ixmaxmesh,iymaxmesh 
+   IF debug_w THEN print, '     izminmesh,izmaxmesh=', izminmesh,izmaxmesh 
+   IF debug_w THEN print, '     ixmin,iymin=', ixmin,iymin 
+   IF debug_w THEN print, '     firsttps,lasttps=', firsttps, lasttps
+   IF debug_w THEN print, '     key_shift in nc_read=', key_shift
+   IF debug_w THEN print, '     key_yreverse, firsty, lasty',key_yreverse, firsty, lasty
+   IF debug_w THEN print, '     '
 
    CASE n_elements(varinq.dim) OF
@@ -227,5 +231,5 @@
             ENDIF ELSE BEGIN 
                print, '    Reading ', var_name, ' (2D data time serie)', strcompress(string(time_1)),'-', strtrim(string(time_2), 2), ' [every ',strtrim(string(time_stride), 2), ']   from ', file_name
-               IF debug_w THEN print,  'x_offset et y_offset et time_1 :',  x_offset,  y_offset,  time_1
+               IF debug_w THEN print,  '     x_offset et y_offset et time_1 :',  x_offset,  y_offset,  time_1
                @read_ncdf_varget
                lec_data = res
@@ -245,22 +249,9 @@
             print, '    Reading ', var_name, ' (3D data - index ', strcompress(string(time_1)),') from ', file_name
             ; read vertical levels
+            IF debug_w THEN print, '   mesh_type= ',mesh_type 
             IF mesh_type EQ 'atm' THEN BEGIN
                ncdf_diminq,cdfid,2, name_level, nb_level
-
-               ; get name of vertical level from metadata
-               file_grid_config = hom_def+'grid_config.def'
-               spawn, 'grep -i "\ '+meshlec_type+' " '+file_grid_config, line
-               line = strcompress(strtrim(line[0], 2)) 
-               length = strlen(line)
-   
-               IF length EQ 0 THEN BEGIN
-                  print, '    *** nc_read : define name_level from grid ', meshlec_type, $
-                   ' in file ', file_grid_config
-                  name_level = ''
-                  return, -1
-               ENDIF ELSE BEGIN 
-                  argvar = str_sep(line, ' ') 
-                  name_level = argvar[4]
-               ENDELSE
+               IF debug_w THEN print, 'name_level, nb_level = ', name_level, nb_level
+
                dimidl = ncdf_dimid(cdfid, name_level)
                ncdf_diminq,cdfid,dimidl, name_level, nb_level
@@ -313,7 +304,6 @@
                   CASE vert_type OF
                      'z': BEGIN ;  depth range
-                        IF time_1 EQ time_2 THEN BEGIN
-                           zmean = moyenne(lec_data, 'z', boite = vert_mean, NAN =1.e20)
-                        END ELSE zmean = grossemoyenne(lec_data, 'z', boite = vert_mean, NAN =1.e20)
+                        IF debug_w THEN print, ' performing average'
+                        zmean = grossemoyenne(lec_data, 'z', boite = vert_mean)
                         IF vert_mean[0] EQ vert_mean[1] THEN BEGIN
                            name_suff = ' at '+strtrim(string(long(gdept(vert_mean(0)))), 2)+' hPa'
@@ -576,7 +566,8 @@
 ;jpk = jpk_orig
 
-   IF keyword_set(key_yreverse) THEN print, ' key_yreverse active : ',  key_yreverse
-
-   IF debug_w THEN print, 'DEBUG: Exiting nc_read...'
+   IF keyword_set(key_yreverse) THEN print, '    key_yreverse active : ',  key_yreverse
+
+   IF debug_w THEN print,  '  ...EXIT nc_read'
+   IF debug_w THEN print,  '  '
 
    return, field
Index: /trunk/procs/plt_map.pro
===================================================================
--- /trunk/procs/plt_map.pro	(revision 40)
+++ /trunk/procs/plt_map.pro	(revision 41)
@@ -156,7 +156,8 @@
 ; read if new type + triangule
 ;
+   cmd1_back = cmd
    sw_diffg =  0
    def_grid, cmd
-   IF debug_w THEN  print,  '   after def_grid in plt_map: cmd.grid, varexp, vargrid ',cmd.grid, varexp, vargrid 
+   IF debug_w THEN  print,  '   after def_grid in plt_map: cmd.grid/varexp/vargrid ',cmd.grid,' ', varexp, ' ', vargrid 
 
 ; vertical average if 3D field
@@ -586,5 +587,5 @@
 ; vertical grid type
 ;
-   IF debug_w THEN print, 'splot=', splot
+   IF debug_w THEN print, '    splot=', splot
    CASE mesh_type OF
       'oce': BEGIN 
Index: /trunk/procs/yfx.pro
===================================================================
--- /trunk/procs/yfx.pro	(revision 40)
+++ /trunk/procs/yfx.pro	(revision 41)
@@ -21,8 +21,8 @@
                   boxx = ' ['+boxx+']'
                   vargrid = vargrid1
-                  IF debug_w THEN print, '   domdef and vargrid : ',  boite_plt1d[0:3], vargrid
+                  IF debug_w THEN print, '   yfx: domdef and vargrid : ',  boite_plt1d[0:3], vargrid
                   domdef, boite_plt1d[0:3]
                   print, '   Averaging (time serie plot) cmd.var '+cmd.var+' in'+boxx
-                  IF debug_w THEN print, 'fld size', size(fld)  
+                  IF debug_w THEN print, '    fld size', size(fld)  
                   fld = checkfield(fld, 'plt1d', type = datyp.hotyp, boite = boite_plt1d)
                   IF cmd.trend GT 0 THEN BEGIN
@@ -33,14 +33,23 @@
                ENDIF 
               ; space and time plots fld2
+               IF debug_w THEN print, '   cmd1_back = ', cmd1_back
+               IF debug_w THEN print, '   cmd2_back = ', cmd2_back
+               IF debug_w THEN print, '   grid1_full = ', grid1_full
+               IF debug_w THEN print, '   grid2_full = ', grid2_full
                IF sw_diffg EQ 1 THEN BEGIN
                   jptb = jpt
-                  IF debug_w THEN print,  '    calling def_grid, cmd2 dans plt_map '
-                  def_grid, cmd2
+                  IF debug_w THEN print,  '  calling def_grid, cmd2_back in plt_map/yfx '
+                  cmd2_back.grid = grid2_full
+                  def_grid, cmd2_back
+                  IF read_grid_from_file EQ 1 THEN BEGIN 
+                     mesh_from_file, cmd2_back.grid, file_name2, ncdf_db2, cmd2_back.var
+                     key_shift_map = key_shift
+                  ENDIF 
                   jpt = jptb
                ENDIF 
                IF strpos(cmd2.plt, 'xy_') NE -1 THEN BEGIN
-                  mask_z, fld2, cmd2, boite_plt2, dimplot, boxy
+                  mask_z, fld2, cmd2_back, boite_plt2, dimplot, boxy
                   boxy = ' ['+boxy+']'
-                  print, '   Averaging (space) '+cmd2.var+' in'+boxy
+                  print, '   Averaging (space) '+cmd2_back.var+' in'+boxy
                   fld2 = checkfield(fld2, 'plt', type = 'xy', boite = boite_plt2)
                ENDIF  
@@ -51,5 +60,5 @@
                      cmd2.plt = strmid(cmd2.plt, 0, strpos(cmd2.plt, '@r'))
                   ENDIF  
-                  mask_z, fld2, cmd2, boite_plt1d2, dimplot, boxy
+                  mask_z, fld2, cmd2_back, boite_plt1d2, dimplot, boxy
                   boxy = ' ['+boxy+']'
                   vargrid = vargrid2
@@ -68,25 +77,36 @@
                   sw_diffg = 0
                   jptb = jpt
-                  IF debug_w THEN print,  '   calling def_grid, cmd dans plt_map '
-                  def_grid, cmd
+                  IF debug_w THEN print,  ' calling def_grid, cmd1_back in plt_map/yfx '
+                  cmd1_back.grid = grid1_full
+                  def_grid, cmd1_back
+                  IF read_grid_from_file EQ 1 THEN BEGIN 
+                     mesh_from_file, cmd1_back.grid, file_name1, ncdf_db1, cmd1_back.var
+                     key_shift_map = key_shift
+                  ENDIF 
                   jpt = jptb
                ENDIF 
 
                ; Compute linear fit coeeficients
+               fmt_linfit = '(F9.4)'
                ;  whole serie
                coeff = linfit(fld2, fld, CHISQ = linerr, PROB = proberr, SIGMA = sigmaerr)
                print, '    Linfit coef (a+bx) = ', coeff(0), coeff(1), ' errbar = ',sigmaerr
                ; text for plot info in legend_overlay
-               coeff_txt = strtrim(coeff(1), 2)
+               coeff_txt = strtrim(string(coeff(1), format = fmt_linfit), 2)
                IF proberr NE 1.0 THEN print, '    WARNING: proba = ',proberr
-
                ; divide serie in two domains (on x axis) seperated by linfit_sep (plt_def)
-               IF linfit_sep NE -99999 THEN begin 
+               ; do only if 1m@t412 (if full serie, then separate by season)
+
+               IF linfit_sep NE -99999 AND cmd.trend EQ 412 THEN begin 
+
                   idx_low = where (fld2 LE linfit_sep)
                   idx_up = where (fld2 GE linfit_sep)
+                  coefflu_txt = ' ['
                   
                   IF idx_low(0) NE -1 THEN BEGIN 
                      coeffl = linfit(fld2(idx_low), fld(idx_low), CHISQ = linerrl, PROB = proberrl, SIGMA = sigmaerrl)
                      print, '    Linfit coef below ',strtrim(string(linfit_sep), 2),' = ', coeffl(0), coeffl(1), ' errbar = ',sigmaerrl
+                     IF proberrl NE 1.0 THEN print, '    *** WARNING: proba lower = ',proberrl
+                     coefflu_txt = coefflu_txt+strtrim(string(coeffl(1), format = fmt_linfit), 2)+'<'+strtrim(string(linfit_sep,  format = '(F4.2)'), 2)
                   ENDIF 
                   
@@ -94,9 +114,8 @@
                      coeffu = linfit(fld2(idx_up), fld(idx_up), CHISQ = linerru, PROB = proberru, SIGMA = sigmaerru)
                      print, '    Linfit coef above ',strtrim(string(linfit_sep), 2),' = ', coeffu(0), coeffu(1), ' errbar = ',sigmaerru
-                  ENDIF 
-                  IF proberrl NE 1.0 THEN print, '    *** WARNING: proba lower = ',proberrl
-                  IF proberru NE 1.0 THEN print, '    *** WARNING: proba upper = ',proberru
-                  coefflu_txt = ' ['+strtrim(coeffl(1), 2)+'<'+strtrim(linfit_sep, 2)+'>'+strtrim(coeffu(1), 2)+']'
-
+                     IF proberru NE 1.0 THEN print, '    *** WARNING: proba upper = ',proberru
+                  coefflu_txt = coefflu_txt+'>'+strtrim(string(coeffu(1), format = fmt_linfit), 2)
+                  ENDIF 
+                  coefflu_txt = coefflu_txt+']'
                ENDIF ELSE coefflu_txt = ''
 
@@ -127,5 +146,5 @@
                IF hotyp EQ 't' THEN BEGIN ; time scatter plot
                   IF mean_sc_only EQ 0 OR mean_sc_only EQ 4 THEN BEGIN 
-           ; number of time colors
+                    ; number of time colors
                      IF strpos(symbol_families, 'x') NE -1 THEN BEGIN 
                         coding = str_sep(symbol_families, 'x')
@@ -144,4 +163,5 @@
                         linprob = fltarr(ncolors)
                         linerr0 = fltarr(ncolors)
+                        coeffm_txt = ' ['
                         WHILE ic LE ncolors-1 DO BEGIN 
                            idx0 = (floor(findgen(jpto/(ncolors*ntimes)))*ncolors*ntimes)+ic*(ntimes)
@@ -160,5 +180,6 @@
                            lincoef(ic) = coeff(1)
                            linerr0(ic) = sigmaerr(0)
-                           IF debug_w THEN print, '     Period '+strtrim(string(ic), 2)+' Linear fit slope, chisq, prob =', coeff(0),coeff(1), sigmaerr, prblin
+                           print, '    Period '+strtrim(string(ic+1), 2)+' Linfit coef =', coeff(0),coeff(1), ' errbar = ',sigmaerr
+                           coeffm_txt =  coeffm_txt+strtrim(string(coeff(1), format = fmt_linfit), 2)+'/'
                            IF mean_sc_only EQ 0 THEN BEGIN 
                               pltcmd = 'pltsc,fldp,fldp2,minc,maxc,minc2,maxc2,varlegend2, boite=boxyfx'+com_strplt+',ov1d='+string(ic)+',COLOR='+string(symbol_color(ic))+', STY1D='+string(symbol_style(ic)-1)+', SYMSIZE='+string(symbol_size)
@@ -203,4 +224,5 @@
                            ic = ic + 1
                         ENDWHILE 
+                        coeffm_txt = coeffm_txt+']'
                      ENDIF ELSE BEGIN ; one color
                         IF debug_w THEN print, '   ',pltcmdstd
@@ -212,4 +234,5 @@
                   res = execute(pltcmdstd(0))
                ENDELSE
+               IF cmd.trend EQ 412 THEN coeffm_txt = ''
                ; Add slope value
                @legend_overlay
