Index: /tags/LIM1D_v3.20/GRAPHICS/ALL_contours.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/ALL_contours.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/ALL_contours.pro	(revision 6)
@@ -0,0 +1,1323 @@
+;
+;---------------------------------------------------
+; This script makes plots of biological simulations
+; (c) Martin Vancoppenolle, UCL-ASTR, june 2007
+; reviewed may 2008
+; works for BARROW-ISPOL
+;---------------------------------------------------
+;
+
+;
+;------------------------------------------------------------------------------
+; Read input data in exp_id.dat
+;------------------------------------------------------------------------------
+;
+
+exp_id = 'E001'
+indir  = ''
+outdir = ''
+dt     = 86400
+c_bio_model = 'BFMSI'
+site        = 'TOURNAI'
+
+OPENR, 11, 'exp_id.dat'
+READF, 11, exp_id & READF, 11, indir & READF, 11, outdir & READF, 11, dt & READF, 11, c_bio_model & READF, 11, site & CLOSE, 11
+
+file_name = exp_id+'_contours.ps'
+
+numplot_x = 6       ; number of horizontal plots
+numplot_y = 3       ; number of vertical plots
+
+device = 'PS'       ; 'PS' or 'X'
+
+;
+;------------------------------------------------------------------------------
+; DEFINE OUTPUT PLOT
+;------------------------------------------------------------------------------
+;
+figuresize_x = numplot_x * 4.0 ; figure size on x direction
+figuresize_y = numplot_y * 5.0 ; figure size on y direction
+set_plot, device
+IF ( device EQ 'PS' ) THEN BEGIN
+   device, /COLOR, /LANDSCAPE, filename=outdir+file_name, $
+           XSIZE=figuresize_x,YSIZE=figuresize_y,FONT_SIZE=9.0
+ENDIF
+
+IF ( device EQ 'X' ) THEN BEGIN
+   xsize = 1200
+   ysize = 800
+   colorkey = 'rd'
+   init_graphics_x, xsize, ysize, colorkey
+ENDIF
+
+!X.MARGIN=[6,3]
+!Y.MARGIN=[6,3]
+
+;
+;------------------------------------------------------------------------------
+; Read files
+;------------------------------------------------------------------------------
+;
+
+ open_fields_v7, indir, exp_id, c_bio_model, $
+                 numt, doy, ts_d, ts_m,                        $
+                 h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                 dhib, dhisu, dhisi,                           $
+                 AoCb, NO3b, PO4b, DSib, chla, eoCb,           $
+                 Argb, Argbub, $
+                 Oxyb, Oxybub, $
+                 DICb, Alkb, CO2b, CO2bub,                     $
+                 CO2aq, HCO3m, CO32m, pH, pCO2, Ikab,          $
+                 dFeb, aFeb, eFeb,                             $
+                 AoCt, NO3t, PO4t, DSit, eoCt, Argt,           $
+                 DICt, Alkt, CO2t, Ikat,                       $
+                 dFet, aFet, eFet,                             $
+                 FDAbd, FDAbpos, FDAsi,                        $
+                 FNO3, FNO3bpos, FNO3si,                       $
+                 FCO2_atm, FCO2_bub,                           $
+                 syn, rsp, lys, rem,                           $
+                 lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+;DEVICE, /CLOSE
+;SET_PLOT, "X"
+;!P.MULTI=[0,2,2]
+;STOP
+                
+; conversion for carbon units if KRILL is used
+IF ( c_bio_model EQ 'KRILL' ) THEN BEGIN
+
+zunit = 12.
+AoCb = AoCb * zunit
+eoCb = eoCb * zunit
+AoCt = AoCt * zunit
+eoCt = eoCt * zunit
+syn    = syn       * zunit * 86400.
+lys    = lys       * zunit * 86400.
+rem    = rem       * zunit * 86400.
+
+ENDIF
+
+;
+;------------------------------------------------------------------------------
+; Extract size of arrays & time axis in months
+;------------------------------------------------------------------------------
+;
+zdummy = SIZE(z_ip)
+nlay = zdummy(1)
+
+zdummy = SIZE(z_ib)
+nlay_bio = zdummy(1)
+
+zdummy = SIZE(numt)
+PRINT, size(numt)
+nts = zdummy(1)
+numy = LONG ( (nts+364) / 365 )     ; number of years
+
+PRINT, ' nlay     : ', nlay
+PRINT, ' nlay_bio : ', nlay_bio
+PRINT, ' nts      : ', nts
+
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   mon = numt * dt / 86400. / 30.4166 + 1 ; time axis (Barrow)
+ENDIF
+
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   mon = numt / 30.41666666 + 1
+ENDIF
+
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   mon = numt / 30.41666666 + 1
+ENDIF
+
+;
+;------------------------------------------------------------------------------
+; OBS
+;------------------------------------------------------------------------------
+;
+;  OPEN FILE
+
+IF ( site EQ 'BARROW' ) THEN BEGIN
+
+   data_dir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/DATA/'
+   file_name_2 = 'obs_barrow_seb.txt'
+   OPENR, 10, data_dir+file_name_2 ; 'ouverture de l'accès au fichier'
+   num_lines = 589 ; nombre de lignes
+   jd_obs    = FLTARR(num_lines)
+   annee_obs    = FLTARR(num_lines)
+   jour_entier = FLTARR(num_lines)
+   heure_obs    = FLTARR(num_lines)
+   hi_obs    = FLTARR(num_lines)
+   hs_obs    = FLTARR(num_lines)
+   
+   FOR i = 0, num_lines - 1 DO BEGIN
+      READF, 10, var1, var2, var3, var4, var5, var6
+      jd_obs   (i) = var1 & annee_obs   (i) = var2 & jour_entier(i) = var3
+      heure_obs   (i) = var4 & hs_obs   (i) = var5 & hi_obs   (i) = var6
+   ENDFOR
+   mon_obs    = jd_obs / 30.467 + 1
+   
+   CLOSE, 10
+
+ENDIF
+
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+
+   data_dir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/DATA/'
+   file_no = NCDF_OPEN(data_dir+'ISPOL.nc', /NOWRITE)
+   ;NCDF_VARGET, file_no, h_i_no, h_i
+   day_obs_no  = NCDF_VARID( file_no, 'nday'  )
+   hi_ulb_no   = NCDF_VARID( file_no, 'hi_ULB'  )
+   hs_ulb_no   = NCDF_VARID( file_no, 'hs_ULB'  )
+   hi_awi_no   = NCDF_VARID( file_no, 'hi_AWI'  )
+   hs_awi_no   = NCDF_VARID( file_no, 'hs_AWI'  )
+   dsi_obs_no  = NCDF_VARID( file_no, 'dsi' )
+   s_i_obs_no  = NCDF_VARID( file_no, 'sal_phy' )
+   
+   NCDF_VARGET, file_no, day_obs_no, day_obs
+   NCDF_VARGET, file_no, hi_ulb_no, hi_ulb
+   NCDF_VARGET, file_no, hs_ulb_no, hs_ulb
+   NCDF_VARGET, file_no, hi_awi_no, hi_awi
+   NCDF_VARGET, file_no, hs_awi_no, hs_awi
+   NCDF_VARGET, file_no, dsi_obs_no, dsi_obs
+   NCDF_VARGET, file_no, s_i_obs_no, s_i_obs
+   
+   NCDF_CLOSE, file_no
+   
+   hi_obs = ( hi_ulb + hi_awi ) / 2.0
+   hs_obs = ( hs_ulb + hs_awi ) / 2.0
+
+   mon_obs    = day_obs / 30.467 + 1
+
+ENDIF
+
+
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   hi_obs =     [ 1.472, 1.609, 1.670, 1.690, 1.708, 1.714, 1.711, 1.677, 1.693 ]
+   hi_obs_std = [ 0.023, 0.014, 0.009, 0.011, 0.011, 0.009, 0.016, 0.024, 0.014 ]
+   hs_obs = REPLICATE(0.01, 9)
+   day_obs =[ 263, 279, 292, 299, 306, 312, 318, 327, 355 ]
+   mon_obs    = day_obs / 30.467 + 1
+ENDIF
+
+;
+;------------------------------------------------------------------------------
+; PLOTS
+;------------------------------------------------------------------------------
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+
+; initialize plot positions
+i_plot = -1
+horpos = 0.02
+vertpos = 0.015
+dv = 1./FLOAT(numplot_y)
+dh = 1./FLOAT(numplot_x)
+leveling = 1
+cb_length = 0.8*dh
+
+
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   zmin = -1.30
+   zmax = 0.30
+ENDIF
+
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   zmin = -1.5
+   zmax = 0.5
+ENDIF
+
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   zmin = -2.0
+   zmax = 0.0
+ENDIF
+
+;-------------------
+; Salinity contours
+;-------------------
+i_plot   = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 13
+levels = [ 0,1,2,3,4,5,6,7,8,9,10,11,12]
+colors = [ 241,221,201,181,161,141,121,101,81,61,41,21,1]
+
+ct = 1 ; colortable
+tmin = MIN(mon)
+tmax = MAX(mon)
+
+title = ' Salinity '
+
+icecontour, s_i, h_i, h_s, nlevels, colors, levels, ct, z_ip, mon, nlay, nts, $
+            tmin, tmax, zmin, zmax, title
+
+LOADCT, 13
+oplot, mon_obs, -hi_obs, PSYM=1, SYMSIZE=1.0, THICK = 3, COLOR =255
+oplot, mon_obs, hs_obs, PSYM=1, SYMSIZE=1.0, THICK = 3, COLOR = 255
+LOADCT, ct
+
+; colorbar
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+format='(f5.0)'
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;--------------
+; Brine volume
+;--------------
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 11
+levels = [   0.,   2.,  4.,   5.,   8.,  10.,  15.,20., 25., 30., 50.]
+colors = [   20,  60,  100,  150,  160,  170, 180, 190, 200, 210, 250 ]
+;colors = [  150, 140,  130,  100,   90,   80,  70,  50,  40,  30,  20 ]
+
+ct = 33 ; colortable
+title = ' Brine volume '
+
+icecontour, e_i, h_i, h_s, nlevels, colors, levels, ct, z_ip, mon, nlay, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+format='(i3)'
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;-----------------
+; Rayleigh number
+;-----------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 11
+levels = [ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10. ]
+colors = [ 20,  40,   60,   80,  100,  160, 180, 200, 220, 240, 250 ]
+
+ct = 11 ; colortable
+title = ' Rayleigh number '
+
+; contours
+icecontour, Ra, h_i, h_s, nlevels, colors, levels, ct, z_ip, mon, nlay, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(i2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; PAR         
+;--------------
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+i_plot = 0
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+levels = [  0.0,0.015, 0.1,  1.0,  10.,  15.,  20.,  30., 50., 80.,120., 150. ]
+levels = [  0.0,0.015, 0.1,  1.0,  10.,  15.,  20.,  30., 40., 50., 60.,  70. ]
+levels = [  0.0,0.05, 0.1,  2.5,  5., 7.5,    10.,  12.5, 15., 17.5, 20. ]
+colors = [   20,  40,   60,   80,  140,  160, 180, 190, 200, 210,  220 ]
+
+ct = 3 ; colortable
+title = ' PAR (muE/m2/s)'
+
+icecontour, PAR , h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+LOADCT, 1
+oplot, mon_obs, -hi_obs, PSYM=1, SYMSIZE=1.0, THICK = 3, COLOR = 150
+oplot, mon_obs, hs_obs, PSYM=1, SYMSIZE=1.0, THICK = 3, COLOR = 150
+LOADCT, ct
+
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;----------------------
+; Temperature contours
+;----------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+levels = [ -25., -18, -16., -14., -12., -10., -8., -6., -4., -2., 0. ]
+;levels = [ -10., -9.,  -8.,  -7.,  -6.,  -5., -4., -3., -2., -1., 0. ]
+colors = [   20,  40,   60,   80,  100,  120, 140, 160, 180, 200, 220 ]
+
+ct = 3 ; colortable
+title = ' Temperature '
+
+icecontour, t_i, h_i, h_s, nlevels, colors, levels, ct, z_ip, mon, nlay, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f5.0)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;-------------------------
+; Brine Salinity contours
+;-------------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+sigma = s_i * 100. / e_i
+sigma = - t_i / 0.053
+
+nlevels = 10
+fmin = 0. & fmax = 300.
+cmin = 75 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+levels(nlevels) = 400. ; trick trick to avoid meaningless huge values on ze plot
+
+ct = 1 ; colortable
+title = ' Brine Salinity '
+
+icecontour, sigma, h_i, h_s, nlevels, colors, levels, ct, z_ip, mon, nlay, nts, $
+            tmin, tmax, zmin, zmax, title
+
+levels(nlevels) = 300. ; trick trick
+
+; colorbar
+format='(i3)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;---------------
+; Dissolved NO3 
+;---------------
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+colors = [   20,  40,   60,   80,  100,  120, 140, 160, 180, 200, 220 ]
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   levels = [   0.,   0.2,  0.4,   0.6,   0.8,  1.0,  1.2, 1.4, 1.6, 1.8, 2.0]
+ENDIF
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   levels = [   0.,     2.,   4.,    6.,    8.,  10.,   12.,14., 16., 18., 20.]
+   nlevels = 7.
+   levels = [ 0., 1.6, 4., 6., 8., 10., 12., 20.]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   nlevels = 7.
+   levels = [ 0., 1.6, 4., 6., 8., 10., 12., 20.]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+
+ct =  5 ; colortable
+title = ' NO3 (mmol/m3)'
+
+icecontour, no3b, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;---------------
+; Dissolved PO4 
+;---------------
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 11
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   levels = [   0.,   0.1,  0.2,   0.3,   0.4,  0.5,  0.6, 0.7, 0.8, 0.9, 1.0]
+   colors = [   20,  40,   60,   80,  100,  120, 140, 160, 180, 200, 220 ]
+ENDIF
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   levels = [   0.,   0.2,  0.4,   0.6,   0.8,  1.0,  1.2, 1.4, 1.6, 1.8, 2.0]
+   nlevels = 7
+   levels = [ 0., 0.24, 0.4, 0.6, 0.8, 1., 2. ]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   nlevels = 7
+   levels = [ 0., 0.24, 0.4, 0.6, 0.8, 1., 2. ]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+
+ct = 5 ; colortable
+title = ' PO4 (mmol/m3)'
+
+icecontour, PO4b, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f4.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;--------------
+; Dissolved Si
+;--------------
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 11
+;levels = [   0.,   2.,  4.,   6.,   8.,  10.,  12.,14., 16., 18., 20.]
+;levels = [   0.,     4.,   8.,   12.,   16.,  20.,   24.,28., 32., 36., 40.]
+levels = [   0.,   1.,  2.,   3.,   4.,  5.,  6., 7., 8., 9., 10.]
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   levels = [   0., 0.5,   1.,  1.5,  2.0, 2.5, 3.0,3.5, 4., 4.5, 5.]
+   colors = [   20,  40,   60,   80,  100,  120, 140, 160, 180, 200, 220 ]
+ENDIF
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   levels = [   0.,   2.,  4.,   6.,   8.,  10.,  12.,14., 16., 18., 20.]
+   nlevels = 7.
+   levels = [ 0., 3.9, 8., 12., 16., 20., 24., 40.]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+   nlevels = 7.
+   levels = [ 0., 3.9, 8., 12., 16., 20., 24., 40.]
+   colors = [ 20, 60, 100, 140, 180, 220, 240 ]
+ENDIF
+
+ct = 5 ; colortable
+title = ' DSi (mmol/m3)'
+
+icecontour, dsib, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f4.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; light limitation
+;------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3  ; colortable
+title = ' Light limitation '
+
+; contours
+icecontour, lim_lig, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; Temp limitation
+;------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3  ; colortable
+title = ' Temp limitation '
+
+; contours
+icecontour, lim_tem, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+;
+;------------------
+; Salt limitation
+;------------------
+;
+
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3  ; colortable
+title = ' Salt limitation '
+
+; contours
+icecontour, lim_sal, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; NO3 limitation
+;------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' NO3 limitation '
+
+; contours
+icecontour, lim_no3, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; PO4 limitation
+;------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' PO4 limitation '
+
+; contours
+icecontour, lim_po4, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; DSI limitation
+;------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' DSi limitation '
+
+; contours
+icecontour, lim_dsi, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------
+; 3-nut limitation
+;------------------
+;
+
+zlim_nut = FLTARR(nlay, nts)
+FOR i = 0, nts - 1 DO BEGIN
+   FOR layer = 0, nlay - 1 DO BEGIN
+      zlim_nut(layer,i) = MIN( [ lim_dsi(layer,i), lim_no3(layer,i), lim_po4(layer,i) ] ) 
+   ENDFOR
+ENDFOR
+
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 1.0001
+cmin = 0 & cmax = 250
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' Nutrient limitation '
+
+; contours
+icecontour, zlim_nut, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;----------------------
+; Algal organic carbon
+;----------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 8
+fmin = 0.0 & fmax = MAX(AoCb)
+fmin = 0.0 & fmax = 1000.
+cmin = 255. & cmax = 80.
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 8 ; colortable
+title = ' AoCb (mgC/m3)'
+
+; contours
+icecontour, AoCb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f5.0)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.0155 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;-------------------------
+; Detrital organic carbon
+;-------------------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 8
+fmin = 0.0 & fmax = MAX(eOCb)
+fmin = 0.0 & fmax = 1000.
+cmin = 255. & cmax = 80.
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 8 ; colortable
+title = ' eoCb (mgC/m3)'
+
+; contours
+icecontour, eOCb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f5.0)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.0155 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+
+;
+;-----------------
+; chla
+;-----------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = MAX(chla)
+fmin = 0.0 & fmax = 80.
+cmin = 255. & cmax = 80.
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+;   zmax = 0.
+;    levels = [   0.,   5., 10.,  15.,  20.,  25.,  30., 35., 40., 45., 50.] ; CHL_LONG_001
+;   levels = [   0.,  2.5,  5.,  7.5,  10., 12.5,  15.,17.5, 20.,22.5, 25.] ; CTL_LONG_01
+;   levels = [   0.,  35., 70., 105., 140., 175., 210., 245., 280., 315., 350.] ; PCS_LON_008
+;   levels = [ 0., 10., 20., 30., 40., 50., 60., 70., 80., 90., 100. ] ; PCS_LONG_009
+;   levels = [ 0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300. ]
+ENDIF
+
+ct = 8 ; colortable
+title = ' chla (mg/m3) '
+
+; contours
+icecontour, chla, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f5.0)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;-----------------
+; Synthesis
+;-----------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+; contour parameters
+nlevels = 8 
+fmin = 0.00 & fmax = MAX(syn) ; LONG(MAX(syn)) + 1
+cmin = 255 & cmax = 80
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 8 ; colortable
+title = ' syn (mgC/m3/d) '
+
+; contours
+icecontour, syn, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;-----------------
+; Lysis
+;-----------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+; contour parameters
+nlevels = 8
+fmin = 0.0 & fmax = MAX(lys) ; LONG(MAX(lys)) + 1
+cmin = 255 & cmax = 80
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+;IF ( zmax LE 0.0 ) THEN levels = [ 0, 1, 2, 3 ,4,5,6]
+
+ct = 8 ; colortable
+title = ' lys (mgC/m3/d) '
+
+; contours
+icecontour, lys, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; Argon bulk
+;--------------
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+i_plot = 0
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 10. ;MAX(Argb)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Arg (mmol/m3)'
+
+icecontour, Argb , h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; Argon bubbles
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 10. ; MAX(Argbub)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Arg bubbles (mmol/m3) '
+
+icecontour, Argbub, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; Oxygen bulk
+;--------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 200. ;MAX(Argb)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Oxy (mmol/m3)'
+
+icecontour, Oxyb , h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I3)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;----------------
+; Oxygen bubbles
+;----------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 200.; MAX(Argbub)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Oxy bubbles (mmol/m3) '
+
+icecontour, Oxybub, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+
+;
+;---------------
+; DIC
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 600. ; MAX(DICb)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' DIC (mmol/m3) '
+
+icecontour, DICb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; CO2aq
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 20. ; MAX(CO2aq)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' CO2aq (mmol/m3) '
+
+icecontour, CO2aq, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; HCO3m
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 600.
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' HCO3m (mmol/m3) '
+
+icecontour, HCO3m, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; CO32m
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax =  40.
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' CO32m (mmol/m3) '
+
+icecontour, CO32m, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; pCO2 
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 5
+fmin = 0.0 & fmax =12000.
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' pCO2 in brine (muatm) '
+
+icecontour, pCO2, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(E7.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;---------------
+; pH   
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 7.5 & fmax = 9.5
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' pH '
+
+icecontour, pH, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(F3.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+
+;
+;---------------
+; Alk
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax = 600. ; MAX(Alkb)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Alk (mmol/m3) '
+
+icecontour, Alkb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;---------------
+; Ika
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin =  0.0 & fmax = 120. ; MAX(Alkb)
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' Ika (mmol/m3) '
+
+icecontour, Ikab, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(I4)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+
+; DEVICE, /CLOSE
+; SET_PLOT, "X"
+; !P.MULTI=[0,2,2]
+; STOP
+
+;
+;---------------
+; CO2bub
+;---------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+fmin = 0.0 & fmax =  60. ;  MAX(CO2bub) ;1.0
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 1 ; colortable
+title = ' CO2bub (mmol/m3) '
+
+icecontour, CO2bub, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(F3.1)'
+format='(I2)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; dFe         
+;--------------
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+i_plot = 0
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+nlevels = 10
+fmin = 0.0 & fmax = MAX(dFeb) ;
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' dFe (mumol/m3)'
+
+icecontour, dFeb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; aFe         
+;--------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+nlevels = 10
+fmin = 0.0 & fmax = MAX(aFeb) ;
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' aFe (mumol/m3)'
+
+icecontour, aFeb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;--------------
+; eFe         
+;--------------
+;
+i_plot = i_plot + 1
+i_plot_h = i_plot MOD numplot_x
+i_plot_v = i_plot / numplot_x + 1
+
+; contour parameters
+nlevels = 10
+nlevels = 10
+fmin = 0.0 & fmax = MAX(eFeb) ;
+cmin = 000 & cmax = 255
+do_levels, fmin, fmax, cmin, cmax, nlevels, levels, colors
+
+ct = 3 ; colortable
+title = ' eFe (mumol/m3)'
+
+icecontour, eFeb, h_i, h_s, nlevels, colors, levels, ct, z_ib, mon, nlay_bio, nts, $
+            tmin, tmax, zmin, zmax, title
+
+; colorbar
+format='(f5.1)'
+horpos   = 0.02 + i_plot_h * dh
+vertpos  = 0.015 + ( numplot_y - i_plot_v ) * dv ; position of colorbar.
+colorbarn, horpos, vertpos, cb_length, 0.02, MIN(levels), MAX(levels), leveling, nlevels+1, levels, colors, format
+
+;
+;------------------------------------------------------------------------------
+; End of the script
+;------------------------------------------------------------------------------
+;
+IF ( device EQ 'PS' ) THEN BEGIN
+   DEVICE, /CLOSE
+   SET_PLOT, "X"
+   !P.MULTI=[0,2,2]
+ENDIF
+END
+
Index: /tags/LIM1D_v3.20/GRAPHICS/ALL_stocks.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/ALL_stocks.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/ALL_stocks.pro	(revision 6)
@@ -0,0 +1,526 @@
+;
+;------------------------------------------------------------------------------
+;
+; This script makes plots of biological simulations
+;
+; works at BARROW, ISPOL, YROSIAE
+;
+; STOCKS (./m2)
+;
+; organic carbon
+; stock
+; NO3 stock
+; PO4 stock
+; DSi
+;
+; (c) Martin Vancoppenolle, UCL-ASTR, june 2007
+; reviewed may 2008
+; reviewed feb 2010, for biological model
+; reviewed aug-oct 2014, Helsinki/Lille
+;
+;------------------------------------------------------------------------------
+;
+i_auto = 1             ; 1=use exp_id.dat; 0=use manual mode with sensitivity runs
+plot_type = 'DEFAULT'  ; 
+miss_val = -9999.
+;
+;==============================================================================
+; General Options
+;==============================================================================
+;
+
+IF ( i_auto EQ 1 ) THEN BEGIN ; automatic mode
+
+   i_ylog = 0 
+   nruns  = 1
+   control_run = 'E001' & indir = '' & outdir = '' & dt = 86400 & c_bio_model = 'BFMSI' & site = 'TOURNAI'
+   
+   OPENR, 11, 'exp_id.dat'
+   READF, 11, control_run & READF, 11, indir & READF, 11, outdir 
+   READF, 11, dt & READF, 11, c_bio_model & READF, 11, site 
+   CLOSE, 11
+   
+   PRINT, control_run
+   PRINT, indir
+   PRINT, outdir
+   PRINT, dt
+   PRINT, c_bio_model
+   PRINT, site
+
+ENDIF
+
+;-------------
+; Manual mode
+;-------------
+IF ( i_auto EQ 0 ) THEN BEGIN
+
+   c_bio_model = 'KRILL'
+   site        = 'ISPOL'
+   indir_base = '/Users/ioulianikolskaia/Boulot/CODES/BFMLIM_2013/BFM-LIM-2506_2014/LIM/RUN/'
+   outdir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/plots/'
+   dt   = 3600.        ; time step
+   control_run = 'ISPOL_CTL_LONG_01'
+
+   ; limitations processes
+   sensiti_run = [ 'ISPOL_PCS_LONG_001', 'ISPOL_PCS_LONG_002', 'ISPOL_PCS_LONG_003', 'ISPOL_PCS_LONG_004', 'ISPOL_PCS_LONG_005', 'ISPOL_PCS_LONG_006', 'ISPOL_PCS_LONG_007' ]
+   i_ylog      = 1 ; log axis for carbon
+
+   ; limitations processes - version 2
+   control_run = 'ISPOL_CHL_LONG_001'
+   sensiti_run = [ 'ISPOL_PCS_LONG_001', 'ISPOL_PCS_LONG_008', 'ISPOL_PCS_LONG_009', 'ISPOL_PCS_LONG_010' ]
+   i_ylog      = 1 ; log axis for carbon
+
+   ; #3 parameter values
+   control_run = 'ISPOL_CTL_LONG_05'
+   sensiti_run = [ 'ISPOL_PCS_LONG_012','ISPOL_PCS_LONG_013','ISPOL_PCS_LONG_014','ISPOL_PCS_LONG_015','ISPOL_PCS_LONG_016', $
+                   'ISPOL_PCS_LONG_017','ISPOL_PCS_LONG_018','ISPOL_PCS_LONG_019','ISPOL_PCS_LONG_020','ISPOL_PCS_LONG_021', $
+                   'ISPOL_PCS_LONG_022','ISPOL_PCS_LONG_023', $ 
+                   'ISPOL_PCS_LONG_024','ISPOL_PCS_LONG_025','ISPOL_PCS_LONG_026','ISPOL_PCS_LONG_027','ISPOL_PCS_LONG_028', $
+                   'ISPOL_PCS_LONG_029','ISPOL_PCS_LONG_030','ISPOL_PCS_LONG_031','ISPOL_PCS_LONG_032','ISPOL_PCS_LONG_033', $
+                   'ISPOL_PCS_LONG_034','ISPOL_PCS_LONG_035' ]
+   i_ylog      = 0 ; log axis for carbon
+
+;   ; long run vs short run
+;   sensiti_run = [ 'ISPOL_PCS_LONG_001', 'ISPOL_CTL_SUMMER_01', 'ISPOL_PCS_SUMMER_001' ]
+;   i_ylog      = 0 ; no log axis for carbon
+
+   dummy = SIZE(sensiti_run) 
+   nruns = dummy(1) + 1 ; sensitivity runs + 1 control run
+   print, 'nruns ', nruns
+
+   indir = STRARR(nruns)
+   indir(0) = indir_base+control_run+'/'
+   FOR i = 1, nruns-1 DO BEGIN
+      indir(i) = indir_base+sensiti_run(i-1)+'/'
+   ENDFOR
+
+ENDIF
+
+;
+;==============================================================================
+; Graphic Options
+;==============================================================================
+;
+
+;--------------------------------
+;--- plot_type dependent options
+;--------------------------------
+
+IF ( plot_type EQ 'DEFAULT' ) THEN BEGIN
+
+   IF ( i_auto EQ 1 ) THEN stamp_out   = control_run+'_stocks'
+
+   ; limitations processes
+   IF ( i_auto EQ 0 ) THEN stamp_out   = control_run+'_stocks_PCS'
+   ct          = 13
+   ; version 1
+   colors      = [  0,   0 ,    50   ,   255   ,   100   ,    50   ,   255 ,  155 ]     
+   linestyle   = [  0,   2 ,    1    ,    1    ,     1   ,     0   ,     0 ,    0 ]
+   thick       = [  5, 5.  ,    2    ,    2    ,     2   ,     2   ,     2 ,    2 ]
+
+   ; version 2
+   IF ( i_auto EQ 0 ) THEN stamp_out   = control_run+'_stocks_PCS2'
+   ct = 8
+   colors      = [ 150,   0 ,   0 ,    0    ,   150   ]
+   linestyle   = [   0,   0 ,   2 ,    0    ,    0    ]
+   thick       = [   5,   5 ,   5 ,    2    ,    2    ] 
+
+   ; long run vs short runs, with and without bio
+;  IF ( i_auto EQ 0 ) THEN stamp_out   = control_run+'_stocks_LNG'
+;  ct = 8
+;  colors      = [  100, 0 ,  100, 0 ]
+;  linestyle   = [  0,   0, 0, 0 ]
+;  thick       = [  5, 5, 2, 2 ]
+
+   ; #3 1050% parameters
+   IF ( i_auto EQ 0 ) THEN stamp_out   = control_run+'_stocks_param10pct'
+   ct = 11
+   colors      = [   0, 250 , 250 , 250 , 250 , 250 , 250 , 250 , 250 , 250 , 250 , 250 , 250,  $ 
+                        100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100 , 100  ] 
+   linestyle   = [   0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0, $
+                           0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0 ]
+   thick       = [  05,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1, $
+                           1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1,    1 ]
+
+   cs          = 2.0 ; charsize
+   !X.MARGIN   = [11,3]
+   !Y.MARGIN   = [3,3]
+   x_size      = 8.
+   y_size      = 8.
+   add_obs     = 'YES'
+
+ENDIF
+
+file_name = stamp_out+'.ps'
+
+numplot_x = 4       ; number of horizontal plots
+numplot_y = 2       ; number of vertical plots
+
+device = 'PS'       ; 'PS' or 'X'
+
+;--------------------------------
+;--- define output plots
+;--------------------------------
+figuresize_x = numplot_x * x_size ; figure size on x direction
+figuresize_y = numplot_y * y_size ; figure size on y direction
+set_plot, device
+IF ( device EQ 'PS' ) THEN BEGIN
+   device, /COLOR, /LANDSCAPE, filename=outdir+file_name, $
+           XSIZE=figuresize_x,YSIZE=figuresize_y,FONT_SIZE=9.0
+   loadct, ct
+ENDIF
+
+IF ( device EQ 'X' ) THEN BEGIN
+   xsize = 1200
+   ysize = 800
+   colorkey    = 'rd'
+   init_graphics_x, xsize, ysize, colorkey
+ENDIF
+
+;
+;==============================================================================
+; DATA COLLECTION / DIAGNOSTICS
+;==============================================================================
+;
+
+;
+;------------------------------------------------------------------------------
+; OBS ...
+;------------------------------------------------------------------------------
+;
+
+; taken from data_ISPOL.pro
+IF ( site EQ 'ISPOL' ) THEN BEGIN
+   doy_obs    = [     334 ,     339 ,     344 ,     349 ,     354 ,     360 ,     365 ]
+   Ichla_obs  = [ 2.29791 , 2.59326 , 2.59555 , 1.96935 , 3.52818 , 3.39265 , 2.25618 ]
+   ISi_obs    = [ 2.59932 , 1.41743 ,  1.93791,  1.61004,  1.48831, 2.32319 , 1.47295 ]
+   IN_obs     = [ 0.872224, 0.990353,  1.24385,  1.54099,  1.59959, 0.644944, miss_val]
+   IP_obs     = [ 0.663441, 0.329396, 0.265860, 0.525806, 0.609341, 0.280607, miss_val]
+ENDIF
+
+IF ( site EQ 'BARROW' ) THEN BEGIN
+   doy_obs = [ 29,     34 ,    86 ,    89  ,   94  ,   97  ,  100 ,   128 ,   132 ,   156 ]
+   Ichla_obs  = [ 0.409588  ,  0.369906  ,   2.61920  ,  0.914727  ,   2.98023   ,  4.03025   ,  9.07010  ,  0.812893,     4.69713  ,   9.04900 ]
+   ; replace first IN (./m2) value by 1.48*initial thickness, otherwise it is screwed
+   ; IN value from data = 0.9842 (h=0.65) hence we replace by 1.48*0.7505 = 0.36024
+   IN_obs     = [ 9999.99,    1.110740  ,   9999.99   ,  9999.99   ,  9999.99    , 9999.99  ,   1.53789   ,  1.02420 ,      9999.99  ,  0.539000 ]
+   ; same for IP, replace 0.119700 by 0.18*0.7505 = 0.13509
+   IP_obs     = [ 9999.99   , 0.135090  ,   9999.99   ,  9999.99    , 9999.99    , 9999.99  ,  0.236833 ,   0.253800 ,      9999.99   , 0.251000 ]
+   ISi_obs    = REPLICATE(1,10) * miss_val
+ENDIF
+
+IF ( site EQ 'YROSIAE' ) THEN BEGIN
+; YROSIAE
+; taken from yrosiae ASPECT log sheets (Fripiat et al, oct 2015)
+   doy_obs    = [ 263 , 299,  318 , 279 , 306 , 327,  292 , 312  ,335 ]
+   Ichla_obs  = [ 1.4683  , 4.6038  ,45.4413, 128.0884,  44.5830 ,219.1416 ,208.6254 ,108.0657 , 87.9038 ]
+   ISi_obs    = [ 22.6631 , 21.1690 , 19.2174,  18.8949 , 18.9943,  18.9517,  20.5963,  16.6855,  13.8374 ]
+   IN_obs     = [ 9.0613  , 5.6130  , 9.4723,  10.0763,  11.4708 , 14.6193 , 14.4107 ,  4.7585 ,  2.1876 ]
+   IP_obs     = [ 0.4976  , 0.4067  , 1.1311,   1.8459,   2.3452 ,  3.7857 ,  3.6948 ,  1.3270 ,  1.2602 ]
+ENDIF
+
+;
+;------------------------------------------------------------------------------
+; MODEL DIAGNOSTICS
+;------------------------------------------------------------------------------
+;
+
+; *** control run
+ open_fields_v7, indir(0), control_run, c_bio_model, $
+                 znumt, zdoy, ts_d, ts_m,                        $
+                 h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                 dhib, dhisu, dhisi,                           $
+                 DAFb, NO3b, PO4b, DSib, chla, eoCb,           $
+                 Argb, Argbub,                                 $
+                 Oxyb, Oxybub,                                 $
+                 DICb, Alkb, CO2b, CO2bub,                     $
+                 CO2aq, HCO3m, CO32m, pH, pCO2, Ikab,          $
+                 dFeb, aFeb, eFeb,                             $
+                 DAFt, NO3t, PO4t, DSit, eoCt, Argt,           $
+                 DICt, Alkt, CO2t, Ikat,                       $
+                 dFet, aFet, eFet,                             $
+                 FDAbd, FDAbpos, FDAsi,                        $
+                 FNO3, FNO3bpos, FNO3si,                       $
+                 FCO2_atm, FCO2_bub,                           $
+                 syn, rsp, lys, rem,                           $
+                 lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+;open_fields_v6, indir(0), control_run, c_bio_model, $
+;                znumt, zdoy, ts_d, ts_m,                        $
+;                h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+;                dhib, dhisu, dhisi,                           $
+;                DAFb, NO3b, PO4b, DSib, chla,                 $
+;                DAFt, NO3t, PO4t, DSit,                       $
+;                FDAbd, FDAbpos, FDAsi,                        $
+;                FNO3, FNO3bpos, FNO3si,                       $
+;                syn, lys, rem,                                $
+;                lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+
+zsize = SIZE(DAFb)
+nlay = zsize(1)   ; number of layers
+nts  = zsize(2)   ; number of time steps
+
+; define arrays
+Ichla = FLTARR(nruns, nts) & Ichla(*,*) = 0.0
+IN    = FLTARR(nruns, nts) & IN(*,*) = 0.0
+IP    = FLTARR(nruns, nts) & IP(*,*) = 0.0
+ISi   = FLTARR(nruns, nts) & ISi(*,*) = 0.0
+IC    = FLTARR(nruns, nts) & IC(*,*) = 0.0
+IeoC  = FLTARR(nruns, nts) & IeoC(*,*) = 0.0
+Iika  = FLTARR(nruns, nts) & Iika(*,*) = 0.0
+Csyn  = DBLARR(nruns, nts) & Csyn(*,*) = 0.0
+Crsp  = DBLARR(nruns, nts) & Crsp(*,*) = 0.0
+Crem  = DBLARR(nruns, nts) & Crem(*,*) = 0.0
+NPP   = FLTARR(nruns)      & NPP(*) = 0.0
+GPP   = FLTARR(nruns)      & GPP(*) = 0.0
+NCP   = FLTARR(nruns)      & NCP(*) = 0.0
+numt  = FLTARR(nruns, nts) & numt(*,*) = 0.0
+doy   = FLTARR(nruns, nts) & doy(*,*) = 0.0
+ntss  = LONARR(nruns)      & ntss(*) = 0
+
+; diagnostics
+cc2stock, z_ib, chla, zdummy & Ichla(0,*) = zdummy
+cc2stock, z_ib, NO3b, zdummy & IN(0,*) = zdummy
+cc2stock, z_ib, PO4b, zdummy & IP(0,*) = zdummy
+cc2stock, z_ib, DSib, zdummy & ISi(0,*) = zdummy
+cc2stock, z_ib, DAFb, zdummy & IC(0,*) = zdummy
+cc2stock, z_ib, eoCb, zdummy & IeoC(0,*) = zdummy
+cc2stock, z_ib, Ikab, zdummy & Iika(0,*) = zdummy
+cc2stock, z_ib, syn , zdummy & Csyn(0,*) = zdummy * 12.
+cc2stock, z_ib, rsp , zdummy & Crsp(0,*) = - zdummy * 12.
+cc2stock, z_ib, rem , zdummy & Crem(0,*) = - zdummy * 12.
+numt(0,*) = znumt ; time axis
+doy(0,*)  = zdoy  ; time axis
+ntss(0)   = nts   ; number of time steps
+
+; *** sensitivity runs
+FOR i_run = 1, nruns - 1 DO BEGIN
+   open_fields_v7, indir(i_run), sensiti_run(i_run-1), c_bio_model, $
+                znumt, zdoy, ts_d, ts_m,                        $
+                h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                dhib, dhisu, dhisi,                           $
+                DAFb, NO3b, PO4b, DSib, chla, eoCb,           $
+                DAFt, NO3t, PO4t, DSit, eoCt,                 $
+                FDAbd, FDAbpos, FDAsi,                        $
+                FNO3, FNO3bpos, FNO3si,                       $
+                syn, lys, rem,                                $
+                lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+   zsize = SIZE(znumt)
+   ntss(i_run) = zsize(1)
+   numt(i_run,0:ntss(i_run)-1) = znumt
+   doy (i_run,0:ntss(i_run)-1) = zdoy
+   cc2stock, z_ib, chla, zdummy & Ichla(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, NO3b, zdummy & IN(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, PO4b, zdummy & IP(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, DSib, zdummy & ISi(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, DAFb, zdummy & IC(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, eoCb, zdummy & IeoC(i_run,0:ntss(i_run)-1) = zdummy
+   cc2stock, z_ib, syn , zdummy & Csyn(i_run,0:ntss(i_run)-1) = zdummy * 12.
+   cc2stock, z_ib, rsp , zdummy & Crsp(i_run,0:ntss(i_run)-1) = zdummy * 12.
+   cc2stock, z_ib, rem , zdummy & Crem(i_run,0:ntss(i_run)-1) = zdummy * 12.
+
+ENDFOR
+
+; *** GPP, NPP, NCP
+FOR i_run = 0, nruns - 1 DO BEGIN
+   GPP(i_run) = TOTAL(Csyn(i_run,*)) * dt
+   NPP(i_run) = TOTAL(Csyn(i_run,*)+Crsp(i_run,*)) * dt
+   NCP(i_run) = TOTAL(Csyn(i_run,*)+Crsp(i_run,*)+Crem(i_run,*)) * dt
+ENDFOR
+
+; *** time axis
+mon = numt / 30.416666666 + 1
+;mon = doy / 30.416666666 + 1
+mon_obs    = doy_obs / 30.467 + 1
+
+;
+;------------------------------------------------------------------------------
+; PLOTS
+;------------------------------------------------------------------------------
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+
+IF ( ( plot_type EQ 'DEFAULT' ) ) THEN BEGIN
+
+   ;--- Integrated organic carbon
+   ymin = 0.0000   & ymax = MAX(IeoC)*12.
+   ymax = MAX(IC)*12.
+   xmin = LONG(MIN(mon)) & xmax = LONG( MAX(mon) ) + 0.5
+
+;  xmin = 11.
+
+   IF ( i_ylog EQ 0 ) THEN BEGIN
+      PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+            XTITLE = 'mon', YTITLE = 'IC (mgC/m2)', XSTYLE = 1
+   ENDIF
+   IF ( i_ylog EQ 1 ) THEN BEGIN
+      ymin = 1.0e-2
+      PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+            XTITLE = 'mon', YTITLE = 'IC (mgC/m2)', XSTYLE = 1, /YLOG
+   ENDIF
+
+   IF ( i_auto EQ 1 ) THEN BEGIN
+      ztitle = 'GPP: '+STRCOMPRESS(STRING(GPP/1000., FORMAT='(F5.2)'),/REMOVE_ALL)+' gC/m2'
+      XYOUTS, xmin+ (xmax-xmin)*0.25, ymax*0.85, ztitle
+      ztitle = 'NPP: '+STRCOMPRESS(STRING(NPP/1000., FORMAT='(F5.2)'),/REMOVE_ALL)+' gC/m2'
+      XYOUTS, xmin+ (xmax-xmin)*0.25, ymax*0.75, ztitle
+      ztitle = 'NCP: '+STRCOMPRESS(STRING(NCP/1000., FORMAT='(F5.2)'),/REMOVE_ALL)+' gC/m2'
+      XYOUTS, xmin+ (xmax-xmin)*0.25, ymax*0.65, ztitle
+   ENDIF
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), IC(i_run,0:ntss(i_run)-1)*12., color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+      OPLOT, mon(i_run,0:ntss(i_run)-1), IeoC(i_run,0:ntss(i_run)-1)*12., color = colors(i_run), linestyle = linestyle(i_run), thick = 0.5
+   ENDFOR
+   LOADCT, 0
+
+   ;--- Integrated chlorophyll
+   ymin = 0.0000   & ymax = 10.
+   IF ( i_auto EQ 0 ) THEN ymax = MAX(Ichla)
+
+   IF ( i_ylog EQ 0 ) THEN BEGIN
+      PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+            XTITLE = 'mon', YTITLE = 'Ichla (mg/m2)', XSTYLE = 1
+   ENDIF
+
+   IF ( i_ylog EQ 1 ) THEN BEGIN
+      ymin = 1.0e-4
+      PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+            XTITLE = 'mon', YTITLE = 'Ichla (mg/m2)', XSTYLE = 1, /YLOG
+   ENDIF
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), Ichla(i_run,0:ntss(i_run)-1), color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+   ENDFOR
+   LOADCT, 0
+
+   IF ( add_obs EQ 'YES' ) THEN BEGIN 
+      LOADCT, 8
+      OPLOT, mon_obs, Ichla_obs, PSYM = 1, THICK = 5, SYMSIZE = 1, COLOR = 150
+      LOADCT, 0
+   ENDIF
+
+   ; Integrated nitrogen
+   ymin = 0.0000   & ymax = MAX(IN)
+;   ymin = 0.05     & ymax = 30.
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'IN (mmol/m2)', XSTYLE = 1;, /YLOG, YSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), IN(i_run,0:ntss(i_run)-1), color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+   ENDFOR
+   LOADCT, 0
+
+   IF ( add_obs EQ 'YES' ) THEN BEGIN 
+      LOADCT, 1
+      OPLOT, mon_obs, IN_obs, PSYM = 1, THICK = 5, COLOR = 150
+   ENDIF
+
+   ; Integrated phosphorus
+   ymin = 0.0000   & ymax = MAX(IP)
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'IP (mmol/m2)', XSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), IP(i_run,0:ntss(i_run)-1), color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+   ENDFOR
+   LOADCT, 0
+
+   IF ( add_obs EQ 'YES' ) THEN BEGIN 
+      LOADCT, 1
+      OPLOT, mon_obs, IP_obs, PSYM = 1, THICK = 3, SYMSIZE = 1, COLOR = 150
+      LOADCT, 0
+   ENDIF
+
+   ; Integrated silicon
+   ymin = 0.0000   & ymax = MAX(ISi)
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'ISi (mmol/m2)', XSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), ISi(i_run,0:ntss(i_run)-1), color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+   ENDFOR
+   LOADCT, 0
+
+   IF ( add_obs EQ 'YES' ) THEN BEGIN 
+      LOADCT, 1
+      OPLOT, mon_obs, ISi_obs, PSYM = 1, THICK = 5, COLOR = 150
+      LOADCT, 0
+   ENDIF
+
+   ; Integrated ikaite 
+   ymin = 0.0000   & ymax = MAX(Ikat)*1.2
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'Iika (mmol/m2)', XSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), Iika(i_run,0:ntss(i_run)-1), color = colors(i_run), linestyle = linestyle(i_run), thick = thick(i_run)
+   ENDFOR
+   LOADCT, 0
+
+   ztitle = 'Max Ikaite Stock: '+STRCOMPRESS(STRING(MAX(Ikat), FORMAT='(F6.2)'),/REMOVE_ALL)+' mmol/m2'
+   XYOUTS, xmin+ (xmax-xmin)*0.10, ymax*0.90, ztitle
+
+   ; CO2 flux
+;  ymin = MIN(FCO2_atm+FCO2_bub) * 1.2 * 86400. & ymax = MAX(FCO2_atm + FCO2_bub)*1.2 * 86400.
+   ymin = -1.0 & ymax = 1.0
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'FCO2 (mmol/m2/d)', XSTYLE = 1, YSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon, (FCO2_atm+FCO2_bub)*86400., thick = 3
+      OPLOT, mon, FCO2_atm*86400., linestyle = 0, color = 150, thick = 2
+      OPLOT, mon, FCO2_bub*86400., linestyle = 0, color = 250, thick = 2
+   ENDFOR
+   LOADCT, 0
+
+   ztitle = 'Max FCO2 mag: '+STRCOMPRESS(STRING(MAX(ABS(FCO2_atm+FCO2_bub)*86400.), FORMAT='(F5.2)'),/REMOVE_ALL)+' mmol/m2/d'
+   XYOUTS, xmin+ (xmax-xmin)*0.10, ymax*0.80, ztitle
+
+   ; Iron stocks
+   ymin = 0.0000   & ymax = MAX(dFet)*1.2
+
+   PLOT, [xmin, xmax], [ ymin, ymax ], /NODATA, charsize = cs, $
+         XTITLE = 'mon', YTITLE = 'Iron (mumol/m2)', XSTYLE = 1, YSTYLE = 1
+
+   FOR i_run = nruns - 1, 0, -1 DO BEGIN
+      LOADCT, ct
+      OPLOT, mon(i_run,0:ntss(i_run)-1), dFet(0:ntss(i_run)-1), color = 150, thick = 2
+      OPLOT, mon(i_run,0:ntss(i_run)-1), aFet(0:ntss(i_run)-1), color = 0, thick = 2
+      OPLOT, mon(i_run,0:ntss(i_run)-1), eFet(0:ntss(i_run)-1), color = 0, thick = 1
+   ENDFOR
+   LOADCT, 0
+
+   ztitle = 'Max dFe stock: '+STRCOMPRESS(STRING(MAX(dFet), FORMAT='(F6.2)'),/REMOVE_ALL)+' mumol/m2'
+   XYOUTS, xmin+ (xmax-xmin)*0.10, ymax*0.90, ztitle
+
+
+ENDIF
+
+;
+;------------------------------------------------------------------------------
+; End of the script
+;------------------------------------------------------------------------------
+;
+IF ( device EQ 'PS' ) THEN BEGIN
+   DEVICE, /CLOSE
+   SET_PLOT, "X"
+   !P.MULTI=[0,2,2]
+ENDIF
+
+END
+
Index: /tags/LIM1D_v3.20/GRAPHICS/BARROW_profiles.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/BARROW_profiles.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/BARROW_profiles.pro	(revision 6)
@@ -0,0 +1,510 @@
+;
+;------------------------------------------------------------------------------
+;
+; This script makes plots of biological simulations
+;
+; chla stock
+; NO3 stock
+; PO4 stock
+;
+; (c) Martin Vancoppenolle, UCL-ASTR, june 2007
+; reviewed may 2008
+; reviewed feb 2010, for biological model
+; reviewed aug 2014, helsinki
+;
+;------------------------------------------------------------------------------
+;
+i_auto = 1             ; 1=use exp_id.dat; 2=use manual mode with sensitivity runs
+plot_type = 'DEFAULT'  ; 
+miss_val  = -9999.
+;
+;==============================================================================
+; General Options
+;==============================================================================
+;
+
+IF ( i_auto EQ 1 ) THEN BEGIN ; automatic mode
+
+   nruns = 1
+   control_run = 'E001' & indir = '' & outdir = '' & dt = 86400 & c_bio_model = 'BFMSI' & site = 'TOURNAI'
+   
+   OPENR, 11, 'exp_id.dat'
+   READF, 11, control_run & READF, 11, indir & READF, 11, outdir 
+   READF, 11, dt & READF, 11, c_bio_model & READF, 11, site 
+   CLOSE, 11
+   
+   PRINT, control_run
+   PRINT, indir
+   PRINT, outdir
+   PRINT, dt
+   PRINT, c_bio_model
+   PRINT, site
+
+ENDIF
+
+;-------------
+; Manual mode
+;-------------
+IF ( i_auto EQ 0 ) THEN BEGIN
+
+   indir_base = '/Users/ioulianikolskaia/Boulot/CODES/BFMLIM_2013/BFM-LIM-2506_2014/LIM/RUN/'
+   outdir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/plots/'
+   dt   = 3600.        ; time step
+
+   control_run = 'LIM_KR_ML'
+   sensiti_run = [ ]
+;  sensiti_run =  [ 'LIM_KR_SL', 'LIM_KR_BA' ]
+   dummy = SIZE(sensiti_run) 
+   nruns = dummy(1) + 1 ; sensitivity runs + 1 control run
+   print, 'nruns ', nruns
+
+   indir = STRARR(nruns)
+   indir(0) = indir_base+control_run+'/'
+   FOR i = 1, nruns-1 DO BEGIN
+      indir(i) = indir_base+sensiti_run(i-1)+'/'
+   ENDFOR
+
+ENDIF
+
+;
+;==============================================================================
+; Graphic Options
+;==============================================================================
+;
+
+;--------------------------------
+;--- plot_type dependent options
+;--------------------------------
+
+IF ( plot_type EQ 'DEFAULT' ) THEN BEGIN
+
+   colors      = [  0, 200 ,   100   ,   240   ,   240   ,   120   ,   120    ]     
+   linestyle   = [  0,0    ,    0    ,    1    ,     2   ,     2   ,     1    ]
+   thick       = [  5, 5.  ,    5.0  ,    2.0  ,   2.0   ,   2.0   ,    2.0   ]
+   stamp_out   = control_run+'_profiles'
+   cs          = 1.8 ; charsize
+   colorkey    = 'rd'
+   ct          = 0
+   !X.MARGIN   = [8,3]
+   !Y.MARGIN   = [3,3]
+   x_size      = 4.
+   y_size      = 6.
+   add_obs     = 'YES'
+
+ENDIF
+
+file_name = stamp_out+'.ps'
+
+numplot_x = 5       ; number of horizontal plots
+numplot_y = 2       ; number of vertical plots
+
+device = 'PS'       ; 'PS' or 'X'
+
+;--------------------------------
+;--- define output plots
+;--------------------------------
+figuresize_x = numplot_x * x_size ; figure size on x direction
+figuresize_y = numplot_y * y_size ; figure size on y direction
+set_plot, device
+IF ( device EQ 'PS' ) THEN BEGIN
+   device, /COLOR, /LANDSCAPE, filename=outdir+file_name, $
+           XSIZE=figuresize_x,YSIZE=figuresize_y,FONT_SIZE=9.0
+   loadct, ct
+ENDIF
+
+IF ( device EQ 'X' ) THEN BEGIN
+   xsize = 1200
+   ysize = 800
+   init_graphics_x, xsize, ysize, colorkey
+ENDIF
+
+;
+;==============================================================================
+; EXTRACT DATA
+;==============================================================================
+;
+;open_fields_v6, indir(0), control_run, c_bio_model, $
+;                numt, doy, ts_d, ts_m,                        $
+;                h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+;                dhib, dhisu, dhisi,                           $
+;;                DAFb, NO3b, PO4b, DSib, chla,                 $
+;                DAFt, NO3t, PO4t, DSit,                       $
+;                FDAbd, FDAbpos, FDAsi,                        $
+;                FNO3, FNO3bpos, FNO3si,                       $
+;                syn, lys, rem,                                $
+;                lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+ open_fields_v7, indir(0), control_run, c_bio_model, $
+                 numt, doy, ts_d, ts_m,                        $
+                 h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                 dhib, dhisu, dhisi,                           $
+                 DAFb, NO3b, PO4b, DSib, chla, eoCb,           $
+                 Argb, Argbub, $
+                 Oxyb, Oxybub, $
+                 DICb, Alkb, CO2b, CO2bub,                     $
+                 CO2aq, HCO3m, CO32m, pH, pCO2, Ikab,          $
+                 dFeb, aFeb, eFeb,                             $
+                 DAFt, NO3t, PO4t, DSit, eoCt, Argt,           $
+                 DICt, Alkt, CO2t, Ikat,                       $
+                 dFet, aFet, eFet,                             $
+                 FDAbd, FDAbpos, FDAsi,                        $
+                 FNO3, FNO3bpos, FNO3si,                       $
+                 FCO2_atm, FCO2_bub,                           $
+                 syn, lys, rem,                                $
+                 lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+zsize = SIZE(DAFb)
+nlay = zsize(1)   ; number of layers
+nts  = zsize(2)   ; number of time steps
+
+;
+;------------------------------------------------------------------------------
+; OBS ...
+;------------------------------------------------------------------------------
+;
+
+;
+; observed normalized profiles from Zhou et al.
+; interpolated in data_BARROW.pro
+;
+doy_obs = [ 29,     34 ,    86 ,    89  ,   94  ,   97  ,  100 ,   128 ,   132 ,   156 ]
+
+depth_obs = [ 5., 15., 25., 35., 45., 55., 65., 75., 85., 95. ] / 100.
+
+chla_obs = FLTARR(10,10)
+chla_obs[0,*] = [  0.108100 , 0.0643000 , 0.0400000 , 0.0422000 , 0.0714000 , 0.162400 , 0.254700 , 0.298500 , 0.737100 , 1.84438 ]
+chla_obs[1,*] = [ 0.0813250 , 0.0739750 , 0.0632500 , 0.0478250 , 0.0257750 , 0.188175 , 0.377175 , 0.509625 , 1.07558 , 1.75818 ]
+chla_obs[2,*] = [ 0.0242000 , 0.130550  , 0.0465000 , 0.0937001 , 0.315200  , 0.412000 , 0.386727 , 0.332500 , 0.950450, 10.9683 ]
+chla_obs[3,*] = [ 0.0788000 , 0.0500000 , 0.0940000 , 0.233600  , 0.147200  , 0.327200 , 0.675200 , 1.05043  , 2.62113 , 3.09060 ]
+chla_obs[4,*] = [ 0.00150000, 0.0285000 , 0.0400000 , 0.0790000 , 0.109000  , 0.271500 , 0.313500 , 0.385000 , 0.923001 , 12.6240 ]
+chla_obs[5,*] = [ 0.261100 ,  0.0646000 , 0.108500  , 0.142200  , 0.136200  , 0.545385 , 0.450000 , 0.525500 , 0.529700 , 16.3075 ]
+chla_obs[6,*] = [ 0.37075  ,  0.597000  , 0.145000  , 0.348750  , 0.312000  , 0.515750 , 0.618750 , 0.457500 , 1.05550 , 36.1653 ]
+chla_obs[7,*] = [ 0.169438 ,  0.127188  , 0.265938  , 0.230000  , 0.113714  , 0.0346250, 0.0195625, 0.0168750 , 0.0198125 , 2.40463 ]
+chla_obs[8,*] = [ 0.638500 , 0.557000 , 0.245000 , 0.391000 , 0.276000 , 0.349000 , 1.01000 , 0.725000 , 0.401000 , 15.2835 ]
+chla_obs[9,*] = [ 0.176500 ,  0.154750  , 0.167500  , 0.237500  , 0.257750 , 0.635250 , 0.938500 , 0.912500 , 0.629750 , 28.0268 ]
+
+nox_obs = FLTARR(10,10) & nox_obs(*,*) = miss_val
+nox_obs[1,*] = [ 2.71490 , 1.74470 , 1.17275 , 1.07783 , 1.05577 , 0.957775 , 0.907750 , 0.999250 , 2.13115 , 1.98073 ] 
+nox_obs[6,*] = [ 2.09375 , 1.05475 , 1.27000 , 0.901750 , 0.839500 , 1.15125 , 1.40625 , 1.21750 , 0.772500, 1.66975 ] 
+nox_obs[7,*] = [ 1.06462 , 0.470000 , 0.331875 , 0.444125 , 1.06200 , 0.735500 , 1.06737 , 0.500000 , 0.359250 , 0.897376] 
+nox_obs[9,*] = [ 0.551500, 0.317500 , 0.243750 , 0.200000 , 0.200000, 0.218500, 0.426250 , 0.390000 , 0.555750, 0.635500]
+
+po4_obs = FLTARR(10,10) & po4_obs(*,*) = miss_val
+po4_obs[1,*] = [ 0.390475 , 0.221425 , 0.130000 , 0.128550 , 0.113850 , 0.115425 , 0.120000 , 0.122000 , 0.239600 , 0.228912 ]
+po4_obs[6,*] = [ 0.218000 , 0.119500 , 0.140000 , 0.165500 , 0.142250 , 0.160000 , 0.220000 , 0.217500 , 0.189500 , 0.287250 ]
+po4_obs[7,*] = [ 0.200250 , 0.169500 , 0.133125 , 0.187250 , 0.184800 , 0.139250 , 0.101875 , 0.131875 , 0.0905000 , 0.335875 ]
+po4_obs[9,*] = [ 0.172500 , 0.0795000 , 0.0612500 , 0.0500000 , 0.0557500 , 0.0507500 , 0.0300000 , 0.0300000 , 0.0592500 , 0.597001 ]
+
+; physical observations
+nlay_p = [    16,     15,     23,     22,     23,    25 ,   24 ,    27 ,   27 ,   30  ]
+h_i_obs= [ 0.755,  0.665,  1.125,  1.075,  1.125, 1.225 , 1.225, 1.35  , 1.325, 1.40  ]
+
+t_i_obs = FLTARR(10,50)           & t_i_obs(*,*) = miss_val
+s_i_obs = FLTARR(10,50)           & s_i_obs(*,*) = miss_val
+e_i_obs = FLTARR(10,50)           & e_i_obs(*,*) = miss_val
+depth_phy_obs  = FLTARR(10,50)           & depth_phy_obs(*,*) = miss_val
+
+; station 1
+s_i_obs[0,0:nlay_p(0)-1] = [ 10.4, 8.3, 6.9, 4.6, 4.6, 4.1, 4.1, 4.9, 4.5, 6.0, 5.3, 5.0, 5.4, 4.9, 5.3, 9.1 ]
+t_i_obs[0,0:nlay_p(0)-1] = [-13.0,-12.2,-11.3,-10.65,-10.0,-9.3,-9.1,-8.3,-8.2,-7.8,-6.0,-5.8,-4.6,-3.3,-2.1,-1.8]
+; station 2
+s_i_obs[1,0:nlay_p(1)-1] = [  8.6, 7.7, 5.0, 4.4, 4.3, 4.4, 4.3, 4.2, 4.0, 4.5, 5.8, 5.3, 5.0, 6.25, 7.5 ]
+t_i_obs[1,0:nlay_p(1)-1] = [-11.9,-11.4,-10.2,-9.45,-8.7,-7.8,-7.5,-6.7,-6.0,-4.9,-5.0,-3.0,-2.2,-2.1,-1.8]
+; station 3
+s_i_obs[2,0:nlay_p(2)-1] = [  9.2, 10.9, 5.8, 5.0, 4.0, 3.8, 4.1, 4.1, 4.6, 5.2, 4.2, 3.9, 3.8, 3.6, 3.4, 3.1, 3.7, 4.0, 4.3, 4.7, 4.8, 5.5, 9.0 ]
+t_i_obs[2,0:nlay_p(2)-1] = [-15.3,-13.1,-12.7,-11.2,-11.5,-11.6,-10.8,-10.5,-10.5,-10.2,-10.0,-9.7,-9.4,-8.8,-8.4,-7.3,-6.4,-4.8,-4.3,-4.2,-2.8,-2.4,-2.4]
+; station 4
+s_i_obs[3,0:nlay_p(3)-1] = [ 7.2, 7.8,5.4,4.7,4.4,3.9,4.1,4.2,4.1,4.2,4.0,4.3,4.6,4.4,4.3,4.2,4.2,5.2,5.1,5.1,4.5,8.1]
+t_i_obs[3,0:nlay_p(3)-1] = [ -13.0, -11.5,-10.8,-9.8,-9.8,-9.2,-8.7,-8.3,-7.9,-7.5,-7.0,-6.5,-6.0,-5.5,-5.3,-4.3,-3.5,-3.0,-2.8,-2.3,-2.2,-2.1 ]
+; station 5
+s_i_obs[4,0:nlay_p(4)-1] = [ 6.8, 8.4,5.4,4.9,4.7,4.7,4.5,4.3,5.1,4.0,4.3,4.6,4.8,4.4,3.7,3.9,4.2,5.8,4.8,5.8,5.1,5.5,7.8]
+t_i_obs[4,0:nlay_p(4)-1] = [-14.4, -13.7,-14.4,-14.4,-13.0,-12.1,-11.8,-11.5,-11.4,-10.5,-9.9,-8.6,-7.4,-7.0,-6.3,-5.7,-5.2,-4.8,-4.2,-3.3,-2.9,-2.4,-2.1 ]
+; station 6
+s_i_obs[5,0:nlay_p(5)-1] = [ 6.7, 7.6,5.5,4.3,4.6,4.6,4.5,4.6,4.9,4.9,5.1,5.0,4.9,5.7,4.7,4.4,4.4,4.7,4.7,5.4,5.1,4.8,4.5,4.7,7.1 ]
+t_i_obs[5,0:nlay_p(5)-1] = [ -14.0, -13.5,-12.9,-12.6,-12.7,-12.7,-12.0,-11.7,-11.3,-11.1,-10.6,-10.4,-9.2,-8.1,-6.9,-6.0,-5.6,-5.1,-4.9,-4.3,-3.7,-3.1,-2.6,-2.3,-2.2 ]
+; station 7
+s_i_obs[6,0:nlay_p(6)-1] = [ 6.3, 7.4,5.4,4.4,4.4,4.9,4.4,5.0,4.5,4.4,4.1,4.0,3.9,4.4,4.4,3.8,3.8,3.6,4.2,4.9,4.5,4.1,4.5,7.8 ]
+t_i_obs[6,0:nlay_p(6)-1] = [ -10.0, -9.6,-9.3,-9.0,-8.5,-8.3,-8.8,-8.4,-7.9,-7.5,-7.4,-6.5,-6.1,-5.8,-5.0,-4.9,-3.9,-3.6,-3.2,-2.9,-2.5,-2.2,-2.2,-2.1 ]
+; station 8
+s_i_obs[7,0:nlay_p(7)-1] = [ 4.7, 6.7,5.9,4.3,4.8,4.9,4.7,4.7,4.9,4.5,4.7,4.6,4.8,6.4,4.6,3.7,3.7,4.9,4.4,4.4,4.6,4.5,4.5,4.5,4.9,5.3,10.4 ]
+t_i_obs[7,0:nlay_p(7)-1] = [-4.0,-3.9,-3.7,-3.5,-3.4,-3.2,-3.1,-2.9,-2.7,-2.2,-2.6,-2.6,-2.4,-2.3,-2.4,-2.2,-2.4,-2.2,-2.1,-1.9,-1.6,-1.6,-1.7,-1.5,-1.6,-1.4,-1.8 ]
+; station 9
+s_i_obs[8,0:nlay_p(8)-1] = [ 6.7,6.7,5.6,6.0,5.9,5.3,6.3,5.0,6.8,6.9,5.8,5.4,5.0,5.5,5.0,4.6,4.3,4.0,4.3,6.1,4.1,4.2,4.9,3.5,5.9,5.9,8.7 ]
+t_i_obs[8,0:nlay_p(8)-1] = [ -3.3, -3.5, -3.3,-2.7,-2.7,-2.9,-2.9,-2.6,-2.6,-2.5,-2.6,-2.3,-2.5,-2.5,-2.3,-2.0,-2.1,-2.1,-2.3,-2.0,-2.0,-1.7,-1.5,-1.4,-1.7,-1.9,-2.0 ]
+; station 10
+s_i_obs[9,0:nlay_p(9)-1] = [ 0.2, 0.2,0.5,0.3,1.5,2.8,3.6,3.5,3.4,3.9,4.3,4.6,3.9,3.9,3.9,3.7,3.9,3.7,4.0,4.2,4.0,4.7,4.3,3.7,3.8,4.2,4.6,4.4,6.2, 6.2]
+t_i_obs[9,0:nlay_p(9)-1] = [ -0.1, -0.1, -0.1, -0.2, -0.3, -0.7, -0.9, -1.1, -1.2, -1.2, -1.4, -1.5, -1.6, -1.5, -1.6, -1.7, -1.7, -1.7, -1.7, -1.65, -1.6, -1.7, -1.8, -1.8, -1.8, -1.8, -1.8, -1.8, -1.8, -1.8 ]
+
+FOR i = 0, 9 DO BEGIN
+   e_i_obs(i,0:nlay_p(i)-1) = -0.054 * s_i_obs(i,0:nlay_p(i)-1) / t_i_obs(i,0:nlay_p(i)-1)
+ENDFOR
+
+; station 1
+depth_phy_obs[0,0:nlay_p(0)-1] = [ 2.5, 7.5, 12.5,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,67.5,72.5,75.5 ] / 100. / h_i_obs(0)
+depth_phy_obs[1,0:nlay_p(1)-1] = [ 2.5, 7.5,12.5,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,65,66.5 ] / 100./ h_i_obs(1)
+depth_phy_obs[2,0:nlay_p(2)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,45,50,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5 ] / 100./ h_i_obs(2)
+depth_phy_obs[3,0:nlay_p(3)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,45,50,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5 ] / 100./ h_i_obs(3)
+depth_phy_obs[4,0:nlay_p(4)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,45,50,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5 ] / 100./ h_i_obs(4)
+depth_phy_obs[5,0:nlay_p(5)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5,117.5,122.5 ] / 100./ h_i_obs(5)
+depth_phy_obs[6,0:nlay_p(6)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,67.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5,117.5,122.5 ] / 100./ h_i_obs(6)
+depth_phy_obs[7,0:nlay_p(7)-1] = [ 2.5,7.5,12.5,17.5,22.5,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,105,110,115,120,125,130,135 ] / 100./ h_i_obs(7)
+depth_phy_obs[8,0:nlay_p(8)-1] = [ 2.5,7.5,12.5,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5,117.5,122.5,127.5,132.5 ] / 100./ h_i_obs(8)
+depth_phy_obs[9,0:nlay_p(9)-1] = [ 2.5,7.5,12.5,15,17.5,22.5,27.5,32.5,37.5,42.5,47.5,52.5,57.5,62.5,67.5,72.5,77.5,82.5,87.5,92.5,97.5,102.5,107.5,112.5,117.5,122.5,127.5,132.5,137.5,140 ] / 100./ h_i_obs(9)
+
+; interpolate brine volume on the physical grid
+e_i_obs_bio = FLTARR(10,10)
+FOR i_obs = 0, 9 DO BEGIN
+e_i_obs_bio(i_obs,*) = INTERPOL( e_i_obs(i_obs,0:nlay_p(i_obs)-1) , depth_phy_obs(i_obs,0:nlay_p(i_obs)-1), depth_obs(*) )
+ENDFOR
+
+iaddr = where ( po4_obs NE miss_val )
+po4_br_obs = FLTARR(10, 10)
+po4_br_obs(iaddr) = po4_obs(iaddr) / e_i_obs(iaddr)
+
+iaddr = where ( nox_obs NE miss_val )
+nox_br_obs = FLTARR(10, 10)
+nox_br_obs(iaddr) = nox_obs(iaddr) / e_i_obs(iaddr)
+;
+;==============================================================================
+; DIAGNOSTICS
+;==============================================================================
+;
+
+;
+;==============================================================================
+; PLOTS
+;==============================================================================
+;
+
+;--- T   
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, 9 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ -25., 0. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'deg C', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, -5, -0.1, ztitle
+
+   ; add obs
+   OPLOT, t_i_obs(i_obs,*), - depth_phy_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   PRINT, ' zz : ', -zz
+   LOADCT, 3 
+   OPLOT, t_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;--- S   
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, 9 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 15. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'g/kg', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 7., -0.1, ztitle
+
+   ; add obs
+   OPLOT, s_i_obs(i_obs,*), - depth_phy_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, s_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;--- e   
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, 9 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 50. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = '%', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 15., -0.1, ztitle
+
+   ; add obs
+   OPLOT, e_i_obs(i_obs,*)*100., - depth_phy_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, e_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;--- chla
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, 9 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.01, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mg chla / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 27., -0.1, ztitle
+
+   ; add obs
+   OPLOT, chla_obs(i_obs,*), - depth_obs, PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, chla(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;--- nox  
+!P.MULTI=[0,numplot_x, numplot_y]
+ii_obs = [ 1, 6, 7, 9 ]
+
+FOR j = 0, 3 DO BEGIN
+
+   i_obs = ii_obs(j)
+     
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 3. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 2.2, -0.3, ztitle
+
+   ; add obs
+   OPLOT, nox_obs(i_obs,*), - depth_obs, PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+
+ENDFOR
+
+;--- po4  
+!P.MULTI=[0,numplot_x, numplot_y]
+ii_obs = [ 1, 6, 7, 9 ]
+
+FOR j = 0, 3 DO BEGIN
+
+   i_obs = ii_obs(j)
+     
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 0.5 ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(F4.1)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 0.37, -0.3, ztitle
+
+   ; add obs
+   OPLOT, po4_obs(i_obs,*), - depth_obs, PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+
+ENDFOR
+
+;--- nox_br
+!P.MULTI=[0,numplot_x, numplot_y]
+ii_obs = [ 1, 6, 7, 9 ]
+
+FOR j = 0, 3 DO BEGIN
+
+   i_obs = ii_obs(j)
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0., 80. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 20.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, nox_br_obs(i_obs,*), - depth_obs(*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 1.6, 1.6 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;--- po4_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+ii_obs = [ 1, 6, 7, 9 ]
+
+FOR j = 0, 3 DO BEGIN
+
+   i_obs = ii_obs(j)
+     
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.0, 30. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, $
+         SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I3)', XMINOR = 2, XTICKS = 3 , YMINOR = 2
+   XYOUTS, 10., -0.15, ztitle
+
+   ; add obs
+   OPLOT, po4_br_obs(i_obs,*), - depth_obs(*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 0.24, 0.24 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;
+;==============================================================================
+; End of the script
+;==============================================================================
+;
+IF ( device EQ 'PS' ) THEN BEGIN
+   DEVICE, /CLOSE
+   SET_PLOT, "X"
+   !P.MULTI=[0,2,2]
+ENDIF
+
+END
+
Index: /tags/LIM1D_v3.20/GRAPHICS/ISPOL_profiles.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/ISPOL_profiles.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/ISPOL_profiles.pro	(revision 6)
@@ -0,0 +1,834 @@
+;
+;------------------------------------------------------------------------------
+;
+; This script makes plots of biological simulations
+;
+; chla stock
+; NO3 stock
+; PO4 stock
+;
+; (c) Martin Vancoppenolle, UCL-ASTR, june 2007
+; reviewed may 2008
+; reviewed feb 2010, for biological model
+; reviewed aug 2014, helsinki
+;
+;------------------------------------------------------------------------------
+;
+miss_val = -9999.
+i_auto = 1             ; 1=use exp_id.dat; 2=use manual mode with sensitivity runs
+plot_type = 'DEFAULT'  ; 
+;
+;==============================================================================
+; General Options
+;==============================================================================
+;
+
+IF ( i_auto EQ 1 ) THEN BEGIN ; automatic mode
+
+   nruns = 1
+   control_run = 'E001' & indir = '' & outdir = '' & dt = 86400 & c_bio_model = 'BFMSI' & site = 'TOURNAI'
+   
+   OPENR, 11, 'exp_id.dat'
+   READF, 11, control_run & READF, 11, indir & READF, 11, outdir 
+   READF, 11, dt & READF, 11, c_bio_model & READF, 11, site 
+   CLOSE, 11
+   
+   PRINT, control_run
+   PRINT, indir
+   PRINT, outdir
+   PRINT, dt
+   PRINT, c_bio_model
+   PRINT, site
+
+ENDIF
+
+;-------------
+; Manual mode
+;-------------
+IF ( i_auto EQ 0 ) THEN BEGIN
+
+   indir_base = '/Users/ioulianikolskaia/Boulot/CODES/BFMLIM_2013/BFM-LIM-2506_2014/LIM/RUN/'
+   outdir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/plots/'
+   dt   = 3600.        ; time step
+
+   control_run = 'LIM_KR_ML'
+   sensiti_run = [ ]
+;  sensiti_run =  [ 'LIM_KR_SL', 'LIM_KR_BA' ]
+   dummy = SIZE(sensiti_run) 
+   nruns = dummy(1) + 1 ; sensitivity runs + 1 control run
+   print, 'nruns ', nruns
+
+   indir = STRARR(nruns)
+   indir(0) = indir_base+control_run+'/'
+   FOR i = 1, nruns-1 DO BEGIN
+      indir(i) = indir_base+sensiti_run(i-1)+'/'
+   ENDFOR
+
+ENDIF
+
+;
+;==============================================================================
+; Graphic Options
+;==============================================================================
+;
+
+;--------------------------------
+;--- plot_type dependent options
+;--------------------------------
+
+IF ( plot_type EQ 'DEFAULT' ) THEN BEGIN
+
+   colors      = [  0, 200 ,   100   ,   240   ,   240   ,   120   ,   120    ]     
+   linestyle   = [  0,0    ,    0    ,    1    ,     2   ,     2   ,     1    ]
+   thick       = [  5, 5.  ,    5.0  ,    2.0  ,   2.0   ,   2.0   ,    2.0   ]
+   stamp_out   = control_run+'_profiles'
+   cs          = 1.8 ; charsize
+   colorkey    = 'rd'
+   ct          = 0
+   !X.MARGIN   = [8,3]
+   !Y.MARGIN   = [3,3]
+   x_size      = 4.
+   y_size      = 6.
+   add_obs     = 'YES'
+
+ENDIF
+
+file_name = stamp_out+'.ps'
+
+numplot_x = 5       ; number of horizontal plots
+numplot_y = 2       ; number of vertical plots
+
+device = 'PS'       ; 'PS' or 'X'
+
+;--------------------------------
+;--- define output plots
+;--------------------------------
+figuresize_x = numplot_x * x_size ; figure size on x direction
+figuresize_y = numplot_y * y_size ; figure size on y direction
+set_plot, device
+IF ( device EQ 'PS' ) THEN BEGIN
+   device, /COLOR, /LANDSCAPE, filename=outdir+file_name, $
+           XSIZE=figuresize_x,YSIZE=figuresize_y,FONT_SIZE=9.0
+   loadct, ct
+ENDIF
+
+IF ( device EQ 'X' ) THEN BEGIN
+   xsize = 1200
+   ysize = 800
+   init_graphics_x, xsize, ysize, colorkey
+ENDIF
+
+;
+;==============================================================================
+; EXTRACT DATA
+;==============================================================================
+;
+;open_fields_v6, indir(0), control_run, c_bio_model, $
+;                numt, doy, ts_d, ts_m,                        $
+;                h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+;                dhib, dhisu, dhisi,                           $
+;                DAFb, NO3b, PO4b, DSib, chla,                 $
+;                DAFt, NO3t, PO4t, DSit,                       $
+;                FDAbd, FDAbpos, FDAsi,                        $
+;                FNO3, FNO3bpos, FNO3si,                       $
+;                syn, lys, rem,                                $
+;                lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+                
+ open_fields_v7, indir(0), control_run, c_bio_model, $
+                 numt, doy, ts_d, ts_m,                        $
+                 h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                 dhib, dhisu, dhisi,                           $
+                 DAFb, NO3b, PO4b, DSib, chla, eoCb,           $
+                 Argb, Argbub, $
+                 Oxyb, Oxybub, $
+                 DICb, Alkb, CO2b, CO2bub,                     $
+                 CO2aq, HCO3m, CO32m, pH, pCO2, Ikab,          $
+                 dFeb, aFeb, eFeb,                             $
+                 DAFt, NO3t, PO4t, DSit, eoCt, Argt,           $
+                 DICt, Alkt, CO2t, Ikat,                       $
+                 dFet, aFet, eFet,                             $
+                 FDAbd, FDAbpos, FDAsi,                        $
+                 FNO3, FNO3bpos, FNO3si,                       $
+                 FCO2_atm, FCO2_bub,                           $
+                 syn, lys, rem,                                $
+                 lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+zsize = SIZE(DAFb)
+nlay = zsize(1)   ; number of layers
+nts  = zsize(2)   ; number of time steps
+
+;
+;------------------------------------------------------------------------------
+; OBS ...
+;------------------------------------------------------------------------------
+;
+
+; observed normalized profiles from Lannuzel et al. (2007)
+
+N_obs = 7 ; station numbers
+N_dpt = 6 ; number of depths
+
+; DOY
+doy_obs = [  334,    339,    344,    349,   354,   360,  365 ]
+
+; Ice thickness / snow depth (ULB SITE)
+hi_obs = [ 0.90 ,  0.92 ,  0.95 ,  0.87 , 0.94 , 0.94 , 0.83 ]
+hs_obs = [ 0.095,  0.130,  0.25 ,  0.15 , 0.110, 0.088, 0.06 ]
+
+; Depths
+depth_obs = FLTARR(N_obs, N_dpt)
+depth_obs[0,*] = [ 6, 12, 43, 63, 81, 87 ]  / 100. / hi_obs(0)
+depth_obs[1,*] = [ 6, 12, 43, 63, 81, 87 ]  / 100. / hi_obs(1)
+depth_obs[2,*] = [ 6, 12, 43, 63, 81, 87 ]  / 100. / hi_obs(2)
+depth_obs[3,*] = [4.5,12, 43, 63, 77, 83 ]  / 100. / hi_obs(3)
+depth_obs[4,*] = [ 7, 13, 43, 63, 80, 86 ]  / 100. / hi_obs(4)
+depth_obs[5,*] = [ 6, 12, 43, 63, 78, 87 ]  / 100. / hi_obs(5)
+depth_obs[6,*] = [ 6,12.5,43, 62, 77, 83 ]  / 100. / hi_obs(6)
+
+; Chlorophyll
+chla_obs = FLTARR(N_obs, N_dpt)
+chla_obs[0,*] = [ 0.35, 0.41, 0.18, 0.08, 3.98, 23.57] ; same
+chla_obs[1,*] = [ 0.44, 0.44, 0.45, 0.16, 3.44, 26.47] ; same
+chla_obs[2,*] = [ 0.97, 2.22, 0.40, 0.25, 2.56, 21.48] ; not the same
+chla_obs[3,*] = [ 0.69, 1.23, 0.27, 0.30, 2.19, 24.23] ; same
+chla_obs[4,*] = [ 0.78, 1.06, 0.20, 0.65, 4.20, 28.41] ; same as bug fix 1.0
+chla_obs[5,*] = [ 0.70, 0.66, 0.69, 0.29, 3.30, 16.33] ; same
+chla_obs[6,*] = [ 1.69, 0.97, 0.59, 0.95, 3.62, 24.77] ; same
+
+; Silicates
+dsi_obs = FLTARR(N_obs, N_dpt)
+dsi_obs[0,*] = [ 6.1, 1.9, 2.4, 1.5, 2.0,11.2 ]
+dsi_obs[1,*] = [ 0.3, 0.7, 0.7, 0.7, 2.8, 8.1 ]
+dsi_obs[2,*] = [ 2.2, 1.8, 1.5, 1.3, 0.8, 8.9 ]
+dsi_obs[3,*] = [ 0.9, 1.9, 1.2, 0.6, 1.8, 9.9 ]
+dsi_obs[4,*] = [ 0.5, 0.7, 1.6, 0.4, 0.7, 7.8 ]
+dsi_obs[5,*] = [ 0.6, 1.2, 1.7, 1.2, 1.5, 7.6 ]
+dsi_obs[6,*] = [ 0.9, 1.5, 1.4, 2.0, 2.6, miss_val ]
+
+; NOX
+nox_obs = FLTARR(N_obs, N_dpt)
+nox_obs[0,*] = [ 1.2, 0.5, 0.22, 0.3, 0.4, 7.9 ]
+nox_obs[1,*] = [ 0.4, 0.5,  0.5, 0.5, 0.8, 7.4 ]
+nox_obs[2,*] = [ 1.4, 1.3,  0.4, 0.9, 0.5, 7.3 ]
+nox_obs[3,*] = [ 1.4, 1.9,  0.7, 0.3, 1.9, 11.7]
+nox_obs[4,*] = [ 0.8, 1.4,  1.7, 0.7, 0.24, 6.9]
+nox_obs[5,*] = [ 0.3, 0.7,  0.0, 0.0, 0.0, 3.0 ]
+nox_obs[6,*] = [ 0.0, 0.6,  0.3, 0.4, 1.2, miss_val ]
+
+; PO4
+po4_obs = FLTARR(N_obs, N_dpt)
+po4_obs[0,*] = [ 1.0, 0.3, 0.2, 1.3, 0.3, 3.0 ]
+po4_obs[1,*] = [ 0.0, 0.1, 0.15,0.2, 0.2, 2.8 ]
+po4_obs[2,*] = [ 0.1, 0.0, 0.0,0.05, 0.1, 3.2 ]
+po4_obs[3,*] = [ 0.4, 0.5, 0.4, 0.3, 0.6, 3.22]
+po4_obs[4,*] = [ 0.4, 0.6, 0.5, 0.4, 0.4, 2.2 ]
+po4_obs[5,*] = [ 0.1, 0.1, 0.0, 0.0, 0.1, 1.5 ]
+po4_obs[6,*] = [ 0.0, 0.1, 0.1, 0.0, 0.1, miss_val ]
+
+; physical observations
+; T
+t_i_obs = FLTARR(N_obs, N_dpt)
+t_i_obs[0,*] = [ -3.1, -2.4, -2.3, -2.1, -2, -1.9 ]
+t_i_obs[1,*] = [ -1.7, -2.1, -1.9, -1.6, -1.8, -1.8 ]
+t_i_obs[2,*] = [ -1.2, -1.4, -1.9, -1.8, -1.8, -1.8 ]
+t_i_obs[3,*] = [ -1.5, -1.4, -1.7, -1.7, -1.8, -1.9 ]
+t_i_obs[4,*] = [ -0.4, -1.3, -1.4, -1.5, -1.6, -1.6 ]
+t_i_obs[5,*] = [ -0.2, -0.7, -1.2, -1.2, -1.2, -1.4 ]
+t_i_obs[6,*] = [ -1.1, -1.2, -1.4, -1.4, -1.6, -1.8 ]
+
+
+
+; S-physical core
+s_i_obs = FLTARR(N_obs, N_dpt)
+
+s_i_obs[0,*] = [ 8.74000   ,  7.78000    , 6.12000    , 4.60000   ,  5.80000  ,   9.43000 ]
+s_i_obs[1,*] = [ 5.91100   ,  5.58700    , 5.32000    , 3.39600   ,  5.22900  ,   8.50800 ]
+s_i_obs[2,*] = [ 3.62000   ,  4.34000    , 5.53000    , 5.01000   ,  3.99000  ,   5.16000 ]
+s_i_obs[3,*] = [ 8.36000   ,  5.21000    , 3.89000    , 3.39600   ,  4.69000  ,   8.30377 ] 
+s_i_obs[4,*] = [ 2.58000   ,  5.97000    , 4.47000    , 3.25000   ,  3.35000  ,   4.65000 ]
+s_i_obs[5,*] = [ 0.67000   ,  1.99000    , 4.99000    , 3.71000   ,  3.54000  ,   4.62000 ]
+s_i_obs[6,*] = [ 4.78000   ,  4.00000    , 3.93000    , 2.82000   ,  3.95000  ,   6.80384 ]
+
+e_i_obs = - 0.054*s_i_obs / t_i_obs
+
+; brine concentrations
+iaddr = where ( dsi_obs NE miss_val )
+dsi_br_obs = FLTARR(N_obs, N_dpt)
+dsi_br_obs(iaddr) = dsi_obs(iaddr) / e_i_obs(iaddr)
+
+iaddr = where ( po4_obs NE miss_val )
+po4_br_obs = FLTARR(N_obs, N_dpt)
+po4_br_obs(iaddr) = po4_obs(iaddr) / e_i_obs(iaddr)
+
+iaddr = where ( nox_obs NE miss_val )
+nox_br_obs = FLTARR(N_obs, N_dpt)
+nox_br_obs(iaddr) = nox_obs(iaddr) / e_i_obs(iaddr)
+
+;*** Mean observed Profiles
+t_i_obs_mean = MEAN( t_i_obs, dimension = 1 )
+t_i_obs_std = STDDEV( t_i_obs, dimension = 1 )
+
+s_i_obs_mean = MEAN( s_i_obs, dimension = 1 )
+s_i_obs_std = STDDEV( s_i_obs, dimension = 1 )
+
+e_i_obs_mean = MEAN( e_i_obs, dimension = 1 )
+e_i_obs_std = STDDEV( e_i_obs, dimension = 1 )
+
+depth_obs_mean = MEAN( depth_obs, DIMENSION = 1 )
+
+chla_obs_mean  = MEAN( chla_obs , DIMENSION = 1 )
+chla_obs_std = STDDEV( chla_obs, dimension = 1 )
+
+dsi_obs_mean = FLTARR(N_dpt) & dsi_obs_std = FLTARR(N_dpt)
+nox_obs_mean = FLTARR(N_dpt) & nox_obs_std = FLTARR(N_dpt)
+po4_obs_mean = FLTARR(N_dpt) & po4_obs_std = FLTARR(N_dpt)
+
+FOR i = 0, N_dpt - 1 DO BEGIN
+   i_addr = WHERE( dsi_obs(*,i) NE miss_val )
+   dsi_obs_mean(i) =  MEAN( dsi_obs(i_addr,i) )
+   dsi_obs_std(i)  = STDDEV( dsi_obs(i_addr,i) )
+   nox_obs_mean(i) =  MEAN( nox_obs(i_addr,i) )
+   nox_obs_std(i)  = STDDEV( nox_obs(i_addr,i) )
+   po4_obs_mean(i) =  MEAN( po4_obs(i_addr,i) )
+   po4_obs_std(i)  = STDDEV( po4_obs(i_addr,i) )
+ENDFOR
+
+;*** Corresponding model mean profiles
+t_i_mod_mean = FLTARR(nlay)  & t_i_mod_mean(*) = 0.
+t_i_mod_std  = FLTARR(nlay)  & t_i_mod_std (*) = 0.
+s_i_mod_mean = FLTARR(nlay)  & s_i_mod_mean(*) = 0.
+s_i_mod_std  = FLTARR(nlay)  & s_i_mod_std (*) = 0.
+e_i_mod_mean = FLTARR(nlay)  & e_i_mod_mean(*) = 0.
+e_i_mod_std  = FLTARR(nlay)  & e_i_mod_std (*) = 0.
+chla_mod_mean = FLTARR(nlay) & chla_mod_mean(*) = 0.
+chla_mod_std  = FLTARR(nlay) & chla_mod_std (*) = 0.
+nox_mod_mean = FLTARR(nlay)  & nox_mod_mean(*) = 0.
+nox_mod_std  = FLTARR(nlay)  & nox_mod_std (*) = 0.
+po4_mod_mean = FLTARR(nlay)  & po4_mod_mean(*) = 0.
+po4_mod_std  = FLTARR(nlay)  & po4_mod_std (*) = 0.
+dsi_mod_mean = FLTARR(nlay)  & dsi_mod_mean(*) = 0.
+dsi_mod_std  = FLTARR(nlay)  & dsi_mod_std (*) = 0.
+FOR i = 0, nlay - 1 DO BEGIN
+
+   FOR i_obs = 0, N_obs - 1 DO BEGIN
+      i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+      t_i_mod_mean(i)  = t_i_mod_mean(i) + t_i(i,i_mod) / FLOAT(N_obs)
+      s_i_mod_mean(i)  = s_i_mod_mean(i) + s_i(i,i_mod) / FLOAT(N_obs)
+      e_i_mod_mean(i)  = e_i_mod_mean(i) + e_i(i,i_mod) / FLOAT(N_obs)
+      chla_mod_mean(i) = chla_mod_mean(i) + chla(i,i_mod) / FLOAT(N_obs)
+      dsi_mod_mean(i)  = dsi_mod_mean(i) + dsib(i,i_mod) / FLOAT(N_obs)
+      nox_mod_mean(i)  = nox_mod_mean(i) + no3b(i,i_mod) / FLOAT(N_obs)
+      po4_mod_mean(i)  = po4_mod_mean(i) + po4b(i,i_mod) / FLOAT(N_obs)
+   ENDFOR
+
+   zsum   = 0
+   zsum_s = 0
+   zsum_e = 0
+   zsum_c = 0
+   zsum_d = 0
+   zsum_n = 0
+   zsum_p = 0
+   FOR i_obs = 0, N_obs - 1 DO BEGIN
+      i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+      zsum   = zsum + ( t_i(i,i_mod) - t_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_s = zsum_s + ( s_i(i,i_mod) - s_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_e = zsum_e + ( e_i(i,i_mod) - e_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_c = zsum_c + ( chla(i,i_mod) - chla_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_d = zsum_d + ( dsib(i,i_mod) - dsi_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_n = zsum_n + ( no3b(i,i_mod) - nox_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_p = zsum_p + ( po4b(i,i_mod) - po4_mod_mean(i) ) ^2 / FLOAT(N_obs)
+   ENDFOR
+   t_i_mod_std(i)  = SQRT( zsum   )
+   s_i_mod_std(i)  = SQRT( zsum_s )
+   e_i_mod_std(i)  = SQRT( zsum_e )
+   chla_mod_std(i) = SQRT( zsum_c )
+   nox_mod_std(i)  = SQRT( zsum_n )
+   po4_mod_std(i)  = SQRT( zsum_p )
+   dsi_mod_std(i)  = SQRT( zsum_d )
+
+ENDFOR
+
+;-------
+
+
+;
+;==============================================================================
+; DIAGNOSTICS
+;==============================================================================
+;
+phi=findgen(32)*(!PI*2/32.)
+phi = [ phi, phi(0) ]
+usersym, cos(phi), sin(phi), /fill
+
+;
+;==============================================================================
+; PLOTS
+;==============================================================================
+;
+;
+;==============================================================================
+; Time series of profiles 
+;==============================================================================
+;
+;---------
+;--- T ---
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ -3, 0. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'deg C', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, -1, -0.1, ztitle
+
+   ; add obs
+   OPLOT, t_i_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, t_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;---------
+;--- S   
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 15. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'g/kg', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 7., -0.1, ztitle
+
+   ; add obs
+   OPLOT, s_i_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, s_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;---------
+;--- e   
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 50. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = '%', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 15., -0.1, ztitle
+
+   ; add obs
+   OPLOT, e_i_obs(i_obs,*)*100., - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, e_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;--------------
+;--- chla
+;--------------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.01, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mg chla / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 27., -0.1, ztitle
+
+   ; add obs
+   OPLOT, chla_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, chla(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;------------
+;--- nox  
+;------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 12. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 2.2, -0.3, ztitle
+
+   ; add obs
+   OPLOT, nox_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy+1 EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+   PRINT, ' i_mod : ', i_mod
+   PRINT, ' NO3b  : ', no3b(*,i_mod)
+
+ENDFOR
+
+
+;-------------
+;--- po4  
+;-------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 4.0 ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 0.37, -0.3, ztitle
+
+   ; add obs
+   OPLOT, po4_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+
+;--------------
+;--- DSi  
+;--------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 12. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol Si / m3', XTICKFORMAT='(F4.1)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 0.37, -0.3, ztitle
+
+   ; add obs
+   OPLOT, dsi_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, dsib(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;
+;==============================================================================
+; Time series of profiles, brine concentrations
+;==============================================================================
+;
+
+;--- nox_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0., 30. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 20.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, nox_br_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 1.6, 1.6 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;--- po4_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.0, 15. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, $
+         SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I3)', XMINOR = 2, XTICKS = 3 , YMINOR = 2
+   XYOUTS, 10., -0.15, ztitle
+
+   ; add obs
+   OPLOT, po4_br_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 0.24, 0.24 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;--- dsi_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0., 30. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol Si / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 20.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, dsi_br_obs(i_obs,*), - depth_obs(i_obs,*), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, dsib(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 3.90, 3.90 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;
+;==============================================================================
+; Mean profiles
+;==============================================================================
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+
+;--- T ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean T"
+PLOT, [ -3, 0. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'deg C', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, t_i_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ t_i_obs_mean(i) - t_i_obs_std(i), t_i_obs_mean(i) + t_i_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+LOADCT, 3
+OPLOT, t_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, t_i_mod_mean+t_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, t_i_mod_mean-t_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- S ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean S"
+   PLOT, [0., 10. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'g/kg', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, s_i_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ s_i_obs_mean(i) - s_i_obs_std(i), s_i_obs_mean(i) + s_i_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+
+; add model
+LOADCT, 3
+OPLOT, s_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, s_i_mod_mean+s_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, s_i_mod_mean-s_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- e ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean e"
+   PLOT, [0., 50. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = '%', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, e_i_obs_mean*100., - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ e_i_obs_mean(i) - e_i_obs_std(i), e_i_obs_mean(i) + e_i_obs_std(i) ] * 100., $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+
+; add model
+LOADCT, 3
+OPLOT, e_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, e_i_mod_mean+e_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, e_i_mod_mean-e_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- chl-a ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean chla"
+PLOT, [ 0.01, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mg chla / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, chla_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ chla_obs_mean(i) - chla_obs_std(i), chla_obs_mean(i) + chla_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 0.155 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, chla_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, chla_mod_mean+chla_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, chla_mod_mean-chla_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- NOX ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean NOX"
+PLOT, [ 0.00, 30. ], [ -1.0, 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, nox_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ nox_obs_mean(i) - nox_obs_std(i), nox_obs_mean(i) + nox_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 26.90 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, nox_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, nox_mod_mean+nox_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, nox_mod_mean-nox_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- PO4 ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean PO4"
+PLOT, [ 0.00, 4.0 ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, po4_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ po4_obs_mean(i) - po4_obs_std(i), po4_obs_mean(i) + po4_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 2.35 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, po4_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, po4_mod_mean+po4_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, po4_mod_mean-po4_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- DSi ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean DSi"
+PLOT, [ 0.00, 60. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, dsi_obs_mean, - depth_obs_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_dpt - 1 DO BEGIN
+   OPLOT, [ dsi_obs_mean(i) - dsi_obs_std(i), dsi_obs_mean(i) + dsi_obs_std(i) ], $
+          [ -depth_obs_mean(i), -depth_obs_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 51.25 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, dsi_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, dsi_mod_mean+dsi_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, dsi_mod_mean-dsi_mod_std, -zz, THICK = 1, COLOR = 150
+
+;
+;==============================================================================
+; End of the script
+;==============================================================================
+;
+IF ( device EQ 'PS' ) THEN BEGIN
+   DEVICE, /CLOSE
+   SET_PLOT, "X"
+   !P.MULTI=[0,2,2]
+ENDIF
+
+END
+
Index: /tags/LIM1D_v3.20/GRAPHICS/YROSIAE_profiles.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/YROSIAE_profiles.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/YROSIAE_profiles.pro	(revision 6)
@@ -0,0 +1,993 @@
+;
+;------------------------------------------------------------------------------
+;
+; This script makes plots of biological simulations
+;
+; (c) Martin Vancoppenolle, UCL-ASTR, june 2007
+; reviewed may 2008
+; reviewed feb 2010, for biological model
+; reviewed aug 2014, helsinki
+; reviewed nov 2015, helsinki
+;
+;--------------------
+;--- YROSIAE site ---
+;--------------------
+;
+;------------------------------------------------------------------------------
+;
+miss_val = -9999.
+i_auto = 1             ; 1=use exp_id.dat; 2=use manual mode with sensitivity runs
+plot_type = 'DEFAULT'  ; 
+;
+;==============================================================================
+; General Options
+;==============================================================================
+;
+
+IF ( i_auto EQ 1 ) THEN BEGIN ; automatic mode
+
+   nruns = 1
+   control_run = 'E001' & indir = '' & outdir = '' & dt = 86400 & c_bio_model = 'BFMSI' & site = 'TOURNAI'
+   
+   OPENR, 11, 'exp_id.dat'
+   READF, 11, control_run & READF, 11, indir & READF, 11, outdir 
+   READF, 11, dt & READF, 11, c_bio_model & READF, 11, site 
+   CLOSE, 11
+   
+   PRINT, control_run
+   PRINT, indir
+   PRINT, outdir
+   PRINT, dt
+   PRINT, c_bio_model
+   PRINT, site
+
+ENDIF
+
+;-------------
+; Manual mode
+;-------------
+IF ( i_auto EQ 0 ) THEN BEGIN
+
+   indir_base = '/Users/ioulianikolskaia/Boulot/CODES/BFMLIM_2013/BFM-LIM-2506_2014/LIM/RUN/'
+   outdir = '/Users/ioulianikolskaia/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/plots/'
+   dt   = 3600.        ; time step
+
+   control_run = 'LIM_KR_ML'
+   sensiti_run = [ ]
+;  sensiti_run =  [ 'LIM_KR_SL', 'LIM_KR_BA' ]
+   dummy = SIZE(sensiti_run) 
+   nruns = dummy(1) + 1 ; sensitivity runs + 1 control run
+   print, 'nruns ', nruns
+
+   indir = STRARR(nruns)
+   indir(0) = indir_base+control_run+'/'
+   FOR i = 1, nruns-1 DO BEGIN
+      indir(i) = indir_base+sensiti_run(i-1)+'/'
+   ENDFOR
+
+ENDIF
+
+;
+;==============================================================================
+; Graphic Options
+;==============================================================================
+;
+
+;--------------------------------
+;--- plot_type dependent options
+;--------------------------------
+
+IF ( plot_type EQ 'DEFAULT' ) THEN BEGIN
+
+   colors      = [  0, 200 ,   100   ,   240   ,   240   ,   120   ,   120    ]     
+   linestyle   = [  0,0    ,    0    ,    1    ,     2   ,     2   ,     1    ]
+   thick       = [  5, 5.  ,    5.0  ,    2.0  ,   2.0   ,   2.0   ,    2.0   ]
+   stamp_out   = control_run+'_profiles'
+   cs          = 1.8 ; charsize
+   colorkey    = 'rd'
+   ct          = 0
+   !X.MARGIN   = [8,3]
+   !Y.MARGIN   = [3,3]
+   x_size      = 4.
+   y_size      = 6.
+   add_obs     = 'YES'
+
+ENDIF
+
+file_name = stamp_out+'.ps'
+
+numplot_x = 5       ; number of horizontal plots
+numplot_y = 2       ; number of vertical plots
+
+device = 'PS'       ; 'PS' or 'X'
+
+;--------------------------------
+;--- define output plots
+;--------------------------------
+figuresize_x = numplot_x * x_size ; figure size on x direction
+figuresize_y = numplot_y * y_size ; figure size on y direction
+set_plot, device
+IF ( device EQ 'PS' ) THEN BEGIN
+   device, /COLOR, /LANDSCAPE, filename=outdir+file_name, $
+           XSIZE=figuresize_x,YSIZE=figuresize_y,FONT_SIZE=9.0
+   loadct, ct
+ENDIF
+
+IF ( device EQ 'X' ) THEN BEGIN
+   xsize = 1200
+   ysize = 800
+   init_graphics_x, xsize, ysize, colorkey
+ENDIF
+
+;
+;==============================================================================
+; EXTRACT DATA
+;==============================================================================
+;
+;open_fields_v6, indir(0), control_run, c_bio_model, $
+;                numt, doy, ts_d, ts_m,                        $
+;                h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+;                dhib, dhisu, dhisi,                           $
+;                DAFb, NO3b, PO4b, DSib, chla,                 $
+;                DAFt, NO3t, PO4t, DSit,                       $
+;                FDAbd, FDAbpos, FDAsi,                        $
+;                FNO3, FNO3bpos, FNO3si,                       $
+;                syn, lys, rem,                                $
+;                lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+                
+ open_fields_v7, indir(0), control_run, c_bio_model, $
+                 numt, doy, ts_d, ts_m,                        $
+                 h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+                 dhib, dhisu, dhisi,                           $
+                 DAFb, NO3b, PO4b, DSib, chla, eoCb,           $
+                 Argb, Argbub, $
+                 Oxyb, Oxybub, $
+                 DICb, Alkb, CO2b, CO2bub,                     $
+                 CO2aq, HCO3m, CO32m, pH, pCO2, Ikab,          $
+                 dFeb, aFeb, eFeb,                             $
+                 DAFt, NO3t, PO4t, DSit, eoCt, Argt,           $
+                 DICt, Alkt, CO2t, Ikat,                       $
+                 dFet, aFet, eFet,                             $
+                 FDAbd, FDAbpos, FDAsi,                        $
+                 FNO3, FNO3bpos, FNO3si,                       $
+                 FCO2_atm, FCO2_bub,                           $
+                 syn, lys, rem,                                $
+                 lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+zsize = SIZE(DAFb)
+nlay = zsize(1)   ; number of layers
+nts  = zsize(2)   ; number of time steps
+
+;
+;------------------------------------------------------------------------------
+; OBS ...
+;------------------------------------------------------------------------------
+;
+
+; observed normalized profiles from Lannuzel et al. (2007)
+
+N_obs = 9 ; station numbers
+N_dpt = 50 ; number of depths
+
+; DOY
+doy_obs =[ 263, 279, 292, 299, 306, 312, 318, 327, 355 ]
+
+; Ice thickness / snow depth 
+hi_obs =     [ 1.472, 1.609, 1.670, 1.690, 1.708, 1.714, 1.711, 1.677, 1.693 ]
+hi_obs_std = [ 0.023, 0.014, 0.009, 0.011, 0.011, 0.009, 0.016, 0.024, 0.014 ]
+hs_obs = REPLICATE(0.01, 9)
+
+h_chl     = [ 1.52, 1.60, 1.69, 1.715, 1.75, 1.72, 1.73, 1.70, 1.70  ]
+h_nut     = [ 1.51, 1.60, 1.69, 1.70 , 1.72, 1.735,1.705, 1.70, 1.70 ]
+
+; Depths
+N_chl     = LONARR(N_obs)
+N_chl     =  [ 15, 16, 17, 18, 18, 18, 18, 17, 17 ]
+
+depth_chl = FLTARR(N_obs, N_dpt)
+
+depth_chl(*,*) = miss_val
+depth_chl[0,0:N_chl(0)-1] = [ 5, 15, 25, 35, 45, 55, 65, 76, 87, 97   , 107 , 117  , 127  , 137  , 147 ] / 100.
+depth_chl[1,0:N_chl(1)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 95   , 105 , 115  , 125  , 135  , 145  , 155 ] / 100.
+depth_chl[2,0:N_chl(2)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 94.5 , 104 , 114  , 124  , 134  , 144  , 154  , 164 ] / 100.
+depth_chl[3,0:N_chl(3)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 90.75, 96.5, 106.5, 116.5, 126.5, 136.5, 146.5, 156.5, 166.5 ] / 100.
+depth_chl[4,0:N_chl(4)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 92.5 , 100 , 110,   120  , 130  , 140  , 150  , 160  , 170 ] / 100.
+depth_chl[5,0:N_chl(5)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 91   , 97  , 107,   117  , 127  , 137  , 147  , 157  , 167 ] / 100.
+depth_chl[6,0:N_chl(6)-1] = [ 5, 15, 25, 35, 45, 55, 65, 65, 75, 85   , 95  , 106.5, 118  , 128  , 138  , 148  , 158  , 168 ] / 100.
+depth_chl[7,0:N_chl(7)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 95   , 105.2, 115.2,125.2, 135.2, 145.2, 155.2, 165.2 ] / 100.
+depth_chl[8,0:N_chl(8)-1] = [ 5, 15, 25, 35, 45, 55, 65, 75, 85, 95   , 105  , 115  , 125 , 135  , 145  , 155  , 165   ] / 100.
+
+; Chlorophyll
+rhoi = 917.
+rhow = 1020.
+chla_obs = FLTARR(N_obs, N_dpt)
+chla_obs(*,*) = miss_val
+chla_obs[0,0:N_chl(0)-1] = [ 0.14, 0.36, 0.12, 0.03, 0.14, 0.02, 0.01, 0.03, 0.03, 0.02, 0.19, 1.02, 1.03, 0.45, 13.28] 
+chla_obs[1,0:N_chl(1)-1] = [ 0.24, 0.04, 0.06, 0.03, 0.15, 0.06, 0.13, 0.16, 0.04, 0.07, 0.26, 0.62, 0.39, 0.49, 2.85, 45.33] 
+chla_obs[2,0:N_chl(2)-1] = [ 0.10, 0.08, 0.32, 0.03, 0.19, 0.06, 0.03, 0.03, 0.04, 0.06, 0.26, 0.26, 0.25, 0.27, 1.25, 2.30, 505.99 ]
+chla_obs[3,0:N_chl(3)-1] = [ 0.33, 0.22, 0.97, 0.00, 0.18, 0.08, 0.06, 0.05, 0.01, 0.42, 0.20, 0.32, 0.30, 0.25, 0.18, 0.26, 1.63, 1440.73 ]
+chla_obs[4,0:N_chl(4)-1] = [ 0.11, 0.12, 0.07, 0.06, 0.12, 0.06, 0.06, 0.04, 0.22, 0.13, 0.49, 0.28, 0.24, 0.36, 0.92, 1.11, 1.98, 501.79 ]
+chla_obs[5,0:N_chl(5)-1] = [ 0.75, 0.20, 0.13, 0.05, 0.03, 0.07, 0.03, 0.05, 0.03, 0.06, 0.08, 0.15, 0.10, 0.05, 0.07, 0.11, 0.81, 2443.38 ]
+chla_obs[6,0:N_chl(6)-1] = [ 0.18, 0.16, 0.06, 0.10, 0.08, 0.04, 0.06, 1.31, 0.03, 0.05, 0.25, 0.16, 0.06, 0.14, 0.05, 0.10, 1.39, 2342.79 ]
+chla_obs[7,0:N_chl(7)-1] = [ 0.35, 0.88, 0.86, 0.53, 0.84, 0.44, 0.96, 0.44, 0.30, 0.34, 1.07, 1.69, 6.05, 0.13, 1.68, 1.18, 1203.62       ]
+chla_obs[8,0:N_chl(8)-1] = [ 0.59, 0.29, 0.33, 0.28, 0.16, 0.17, 0.16, 0.11, 0.13, 0.27, 0.19, 0.22, 0.21, 0.63, 0.89, 2.35, 974.83        ]
+
+zaddr = WHERE(chla_obs NE miss_val) 
+chla_obs(zaddr) = chla_obs(zaddr)  * rhoi / rhow
+
+; depths for nuts
+N_nut = REPLICATE(6,9)
+depth_nut = FLTARR(N_obs, 6)
+depth_nut[0, 0:N_nut(0)-1] = [ 12.5, 37.5, 65.05, 103.5, 128.5, 146. ] / 100.
+depth_nut[1, 0:N_nut(1)-1] = [   15, 45  , 75   , 105  , 135  , 155  ] / 100.
+depth_nut[2, 0:N_nut(2)-1] = [   15, 47  , 79.5 , 111  , 143  , 164  ] / 100.
+depth_nut[3, 0:N_nut(3)-1] = [   16, 48  , 80   , 112  , 144  , 165  ] / 100.
+depth_nut[4, 0:N_nut(4)-1] = [   16, 48  , 80.5 , 113.3, 145.8, 167  ] / 100.
+depth_nut[5, 0:N_nut(5)-1] = [16.35, 49.05, 71.75, 114.45, 147.15, 168.5 ] / 100.
+depth_nut[6, 0:N_nut(6)-1] = [16.05, 48.15, 80.25, 112.35, 144.45, 165.5 ] / 100.
+depth_nut[7, 0:N_nut(7)-1] = [   16, 48, 80, 112, 144, 165 ] / 100.
+depth_nut[8, 0:N_nut(8)-1] = [ 17, 49.75, 85, 112.75, 144.25, 165 ] / 100.
+
+; Silicates
+dsi_obs = FLTARR(N_obs, 6)
+dsi_obs[0,0:N_nut(0)-1] = [ 20.10, 18.03, miss_val, 12.78, 12.45, 29.98 ]
+dsi_obs[1,0:N_nut(1)-1] = [ 19.81, 15.01,    14.31, 13.83,  9.68, 16.23 ]
+dsi_obs[2,0:N_nut(2)-1] = [ 17.11, 14.42,    12.32,  6.07,  9.14, 28.56 ]
+dsi_obs[3,0:N_nut(3)-1] = [ 17.23, 14.81,    11.90,  9.92,  4.37, 25.08 ]
+dsi_obs[4,0:N_nut(4)-1] = [ 17.07, 14.81,    12.17, 11.07,  3.49, 23.19 ]
+dsi_obs[5,0:N_nut(5)-1] = [ 17.89, 14.10,    12.72, 10.03,  3.10, 24.25 ]
+dsi_obs[6,0:N_nut(6)-1] = [ 19.54, 14.92,    12.94, 10.36,  2.83, 33.80 ]
+dsi_obs[7,0:N_nut(7)-1] = [ 20.80, 13.99,    10.85,  6.29,  1.29, 17.37 ]
+dsi_obs[8,0:N_nut(8)-1] = [ 16.30, 12.89,     9.86,  2.72,  1.18, 9.83  ]
+
+zaddr = WHERE(dsi_obs NE miss_val) 
+dsi_obs(zaddr) = dsi_obs(zaddr)  * rhoi / rhow
+
+; NOX
+nox_obs = FLTARR(N_obs, 6)
+nox_obs[0,0:N_nut(0)-1] = [ 10.00, 6.17, 5.80, 5.98, 3.25, 16.10 ]
+nox_obs[1,0:N_nut(1)-1] = [ 7.14, 3.96, 4.59, 2.28, 0.25, 7.45 ]
+nox_obs[2,0:N_nut(2)-1] = [ 8.64, 6.09, 5.04, 1.05, 1.50, 35.72 ] 
+nox_obs[3,0:N_nut(3)-1] = [ 8.13, 5.72, 4.67, 0.78, 0.42, 49.64 ]
+nox_obs[4,0:N_nut(4)-1] = [ 8.15, 7.07, 5.23, 0.83, 0.28, 58.91 ]
+nox_obs[5,0:N_nut(5)-1] = [ 5.80, 5.02, 8.02, 1.19, 0.61, 97.09 ]
+nox_obs[6,0:N_nut(6)-1] = [ 8.68, 5.90, 4.79, 0.84, 0.33, 93.78 ]
+nox_obs[7,0:N_nut(7)-1] = [ 7.39, 4.61, 1.40, 0.50, 0.35, 7.94  ]
+nox_obs[8,0:N_nut(8)-1] = [ 2.74, 1.29, 0.44, 0.21, 0.08, 8.54  ]
+
+zaddr = WHERE(nox_obs NE miss_val) 
+nox_obs(zaddr) = nox_obs(zaddr)  * rhoi / rhow
+
+; PO4
+po4_obs = FLTARR(N_obs, 6)
+po4_obs[0,0:N_nut(0)-1] = [ 0.49, 0.38, 0.31, 0.31, 0.29, 0.72 ]
+po4_obs[1,0:N_nut(1)-1] = [ 0.36, 0.24, 0.27, 0.20, 0.15, 1.80 ]
+po4_obs[2,0:N_nut(2)-1] = [ 0.42, 0.31, 0.28, 0.10, 0.23, 8.47 ]
+po4_obs[3,0:N_nut(3)-1] = [ 0.41, 0.28, 0.24, 0.22, 0.14, 16.54 ]
+po4_obs[4,0:N_nut(4)-1] = [ 0.44, 0.33, 0.25, 0.18, 0.11, 22.05 ]
+po4_obs[5,0:N_nut(5)-1] = [ 0.38, 0.33, 0.47, 0.27, 0.16, 37.34 ]
+po4_obs[6,0:N_nut(6)-1] = [ 0.50, 0.34, 0.32, 0.32, 0.19, 35.61 ]
+po4_obs[7,0:N_nut(7)-1] = [ 0.57, 0.38, 0.29, 0.22, 0.16, 9.79  ]
+po4_obs[8,0:N_nut(8)-1] = [ 0.37, 0.21, 0.15, 0.11, 0.11, 10.96 ]
+
+zaddr = WHERE(po4_obs NE miss_val) 
+po4_obs(zaddr) = po4_obs(zaddr)  * rhoi / rhow
+
+; physical observations
+
+N_TS = [ 31, 33, 33, 34, 34, 35, 35, 34, 35 ]
+; depth of TS cores
+depth_TS = FLTARR(N_obs, N_dpt)
+depth_TS(*,*) = miss_val
+
+depth_TS[0,0:N_TS(0)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5 ] / 100.
+depth_TS[1,0:N_TS(1)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 100  , 105  , 110  , 115  ,   120,   125,   130,   135,   140,   145,   150,   155, 160 ] / 100.
+depth_TS[2,0:N_TS(2)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 99.5, 104.5, 109.5, 114.5, 119.5, 124.5, 129.5, 134.5, 139.9, 144.5, 149.5, 154.5, 159.5, 164.5 ] / 100.
+depth_TS[3,0:N_TS(3)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5 ] / 100. 
+depth_TS[4,0:N_TS(4)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5 ] / 100.
+depth_TS[5,0:N_TS(5)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 94.5, 99.5, 104.5, 109.5, 114.5, 119.5, 124.5, 129.5, 134.5, 139.5, 144.5, 149.5, 154.5, 159.5, 164.5, 169.5 ] / 100.
+depth_TS[6,0:N_TS(6)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5, 172.5 ] / 100.
+depth_TS[7,0:N_TS(7)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5 ] / 100.
+depth_TS[8,0:N_TS(8)-1] = [ 2.5, 7.5, 12.5, 17.5, 22.5, 27.5, 32.5, 37.5, 42.5, 47.5, 52.5, 57.5, 62.5, 67.5, 72.5, 77.5, 82.5, 87.5, 92.5, 97.5, 102.5, 107.5, 112.5, 117.5, 122.5, 127.5, 132.5, 137.5, 142.5, 147.5, 152.5, 157.5, 162.5, 167.5, 172.5 ] / 100.
+
+h_TS = FLTARR(N_obs) ; We don't have thicknes of TS cores
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+  zdh         = ( depth_TS(i_obs,N_TS(i_obs)-1) - depth_TS(i_obs,N_TS(i_obs)-2) ) / 2. 
+  h_TS(i_obs) = depth_TS(i_obs,N_TS(i_obs)-1) + zdh
+ENDFOR
+
+; T-S
+t_i_obs = FLTARR(N_obs, N_dpt)
+t_i_obs(*,*) = miss_val
+
+t_i_obs[0,0:N_TS(0)-1] = [ -19.8, -18.7, -18.6, -18.2, -17.5, -16.8, -16.4, -16.2, -15.3, -14.7, -14.2, -13.5, -13.1, -12.6, -11.9, -11.5, -12.4, -11.5, -10.8, -10, -9.1, -8.6, -8.1, -7, -5.7, -4.7, -4.4, -3.7, -2.9, -2.4, -2.2 ]
+t_i_obs[1,0:N_TS(1)-1] = [ -12.7, -12.6, -12.8, -12.5, -12.6, -12.2, -12.3, -12.4, -11.9, -11.8, -11.6, -11.1, -10.7, -10.4, -10, -10, -9.9, -9.5, -9.4, -9.3, -8.5, -7.9, -7.3, -6.6, -6.1, -5.5, -5, -4.5, -4.2, -3.6, -2.8, -2.3, -1.9 ]
+t_i_obs[2,0:N_TS(2)-1] = [ -14.6, -14.6, -14.5, -14.1, -13.5, miss_val, -12.6, -11.6, -11.8, -11.5, -11.1, -10.5, -10.2, -9.9, -9.2, -8.9, -8.7, -8.8, -9.1, -6.1, -5.6, -5.2, -4.8, -4.3, -4.2, -4.1, -3.7, -3.6, -3.1, -2.8, -2.4, -1.9, -2 ]
+t_i_obs[3,0:N_TS(3)-1] = [ -12.6, -12.3, -12.2, -11.6, -11.4, -10.9, -10.1, -9.9, -9.6, -9, -8.8, -8.4, -8, -8, -7.9, -7.3, -6.9, -6.4, miss_val, miss_val, -6.2, -5.6, -5, -4.8, -4.5, -3.7, -3.7, -3.2, -2.7, -2.7, -2.6, -1.7, -2.1, -2 ]
+t_i_obs[4,0:N_TS(4)-1] = [ -12.4, -12.9, -12.5, -12.2, -11.8, -11.5, -11.1, -10.5, -10.3, -9.7, -9.2, miss_val, -8.8, -8.2, -8, -7.4, -7.3, -6.7, -6.3, miss_val, -5, -4.6, -4.6, -3.9, -3.6, -3.4, -3.1, -3, -3, -2.5, -2.7, -2.2, -2, -2 ]
+t_i_obs[5,0:N_TS(5)-1] = [ -10.2, -10.1, -10.2, -9.8, -9.4, -9.3, -8.9, miss_val, -8.7, -8.2, -7.8, -7.8, -7.6, -7.2, -6.6, -6.8, -6.4, -6.2, -6.2, miss_val, miss_val, -4.9, -4.6, -4.3, -4, -3.7, miss_val, -3.4, -3.2, -2.8, -2.6, -1.9, -2, -1.8, -2 ]
+t_i_obs[6,0:N_TS(6)-1] = [ -7.6, -8.3, -8.2, -7.7, -7.6, miss_val, -7.1, -6.4, -7, -6.8, -6.8, -6.8, -6.9, -6.8, -6.3, -5.9, miss_val, -5.2, -5, -5, -4.8, -4.5, -4.2, -4, miss_val, -3.7, -3.4, -2.7, -2.7, -2.5, -2, -2, -1.6, -1.6, -1.9 ]
+t_i_obs[7,0:N_TS(7)-1] = [ -4.5, -4.6, -4.7, -4.5, -4.6, miss_val, -4, -3.9, -3.4, -3.4, -3, -3.3, -3.2, -3, -2.7, -2.7, -2.9, -2.4, -2.4, -2.1, -2, -2.3, -1.8, -1.6, -1.7, -1.7, -1.4, -1.1, -1.4, -1.3, -1.4, -0.8, -2, -1.6 ]
+t_i_obs[8,0:N_TS(8)-1] = [ -2.1, -3.3, -3.6, -3.4, -3.1, -3, -3, -2.7, -2.6, miss_val, -2.9, -2.8, -2.2, -1.7, -1.6, -2.3, -1.6, -1.7, -1.7, -1.9, -1.8, -2, -1.8, -1.4, -1.9, -1.4, -1.7, -1.8, miss_val , -1.3, -1, -1, -1.6, miss_val, miss_val ]
+
+; S-physical core
+s_i_obs = FLTARR(N_obs, N_dpt)
+s_i_obs(*,*) = miss_val
+
+s_i_obs[0,0:N_TS(0)-1] = [ 13, 11.5, 11.3, 9.7, 10.1, 9.5, 8.5, 7.6, 7.1, 6.5, 6.8, 6.2, 6.9, 6.7, 7, 7.6, 6.6, 8.2, 5.6, 4.5, 4.8, 4.8, miss_val, 5.1, 5, 4.8, 4.8, 4.7, 4.7, 5.5, 9.2 ]
+s_i_obs[1,0:N_TS(1)-1] = [ 11.4, 10.1, 10.5, miss_val , 10.5, 8.8, 8, 7.1, 6.5, 6.8, 7.3, 7.2, 6.7, 6.1, 5.9, 5.9, 6, 6.2, 5.7, 5.1, 7.3, 5.9, 6, 6, 5, 4.8, 4.8, 5.7, 5.2, 3.7, 6.2, 7.1, 11 ]
+s_i_obs[2,0:N_TS(2)-1] = [ 11.2, 10.5, 10.1, 9.5, 9.6, 7.5, 7.6, 7.4, 6.7, 6.5, 6.5, 6.5, 6.3, 5.8, 5.7, 5.6, 5.9, 5.3, 5, 5.4, 5.3, 4.9, 4.7, 4.2, 4.1, 4.4, 4.8, 4.4, 4.8, 5.3, 5.5, miss_val, 12.5 ]
+s_i_obs[3,0:N_TS(3)-1] = [ 10.8, 10.9, 10.4, 9.4, 9.7, 8.2, 7.6, 7.1, 6.8, 6.7, 7, 7.2, 6.9, 6, 6.7, 5.9, 5.7, 5.3, 4.9, 5.4, 4.9, 5.2, 5, 4.9, 4.3, 4.6, 4.5, 4.7, 4.7, 5, 5.7, 5.4, 5.8, 13.7 ]
+s_i_obs[4,0:N_TS(4)-1] = [ 10.9, 10.8, 10.1, 9, 9.4, 8.2, 8.1, 7.2, 7.3, 6.5, 6.8, 6.7, 6.7, 6.3, miss_val, 6.5, 6.6, 6.9, 6.6, miss_val, 6.1, 5.5, 5.3, 5.2, 6, 5.7, 5.7, 5.5, 5.1, 5, 5.5, 4.8, 5.5, 12.2 ]
+s_i_obs[5,0:N_TS(5)-1] = [ 10.7, 10.6, 10.3, 9.6, 10.1, 8, 7.7, 7, 6.4, 6.7, 6.8, 7, 6.8, 5.4, 5.7, 5.9, 5.7, 5.4, 5, 4.8, 5.1, 5.1, 5, 4.7, 4.2, 4.1, 4.4, 4.3, 4.2, 4.9, 5.6, 5.7, 5, 5.6, 12 ]
+s_i_obs[6,0:N_TS(6)-1] = [ 11.1, 10.1, 10.4, 10.8, 10.3, 9.4, 8.2, 7, 7, 6.9, 7.3, 7.3, 6.7, 6.2, 6.2, 6.2, 6.5, 6.2, 5.5, 5.1, 5.3, 5.8, 5.7, 5.7, 5.8, 5, 4.7, 4.7, 4.7, 4.7, 5.2, 5.4, 4.8, 5.8, 12.2 ]
+s_i_obs[7,0:N_TS(7)-1] = [ 8.4, 9.5, 9.4, 10.1, 8.8, 7.8, 7.3, 7.3, 6.2, 6.7, 6.5, 6.2, 5.7, 5.7, 5.4, 6.1, 5.2, 4.6, 4.2, 4.3, 4.5, 4.3, 4.2, 3.6, 3.7, 3.5, 3.5, 3.3, 3.9, 4.4, 4.3, 4.7, 10.1, miss_val ]
+s_i_obs[8,0:N_TS(8)-1] = [ 5.4, 6.7, 7.2, 7.6, 8.4, 7.2, 6.9, 6.5, 6.1, 6.2, 5.9, 6.1, 5.8, 4.9, 4.8, 4.7, 4.7, 4.4, 3.9, 3.4, 4.1, 3.7, 4.1, 3.8, 3.3, 3.2, 3.6, 3.1, 3.2, 3.4, 4.1, 5.2, 3.9, 4.1, 9 ]
+
+e_i_obs = FLTARR(N_obs, N_dpt)
+e_i_obs(*,*) = miss_val
+zaddr = where( ( s_i_obs NE miss_val ) AND ( t_i_obs NE miss_val ) )
+e_i_obs(zaddr) = - 0.054*s_i_obs(zaddr) / t_i_obs(zaddr)
+
+; brine concentrations
+e_i_nut = FLTARR(N_obs, 6)
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+   zei   = e_i_obs(i_obs,*)
+   zd    = depth_TS(i_obs,*)
+   zaddr = WHERE(zei NE miss_val)
+   zei   = zei(zaddr)
+   zd    = zd(zaddr) / h_TS(i_obs)
+   zei_itp = INTERPOL(zei, zd, depth_nut(i_obs,*)/h_nut(i_obs)); interpolate bvf on nutrient depths
+   e_i_nut(i_obs,*) = zei_itp
+ENDFOR
+
+;DEVICE, /CLOSE
+;SET_PLOT, 'X'
+;!P.MULTI=[0,5,2]
+;FOR i_obs = 0, N_obs -1 DO BEGIN
+;   PLOT, [0., 100.], [-2., 0.], /NODATA, charsize = 2
+;   OPLOT, e_i_obs(i_obs,0:N_TS(i_obs)-1)*100., -depth_TS(i_obs,0:N_TS(i_obs)-1)/h_TS(i_obs), psym = 1
+;   OPLOT, e_i_nut(i_obs,*)*100., -depth_nut(i_obs,*)/h_nut(i_obs)
+;ENDFOR
+;STOP
+
+iaddr = where ( dsi_obs NE miss_val )
+dsi_br_obs = FLTARR(N_obs, 6)
+dsi_br_obs(iaddr) = dsi_obs(iaddr) / e_i_nut(iaddr)
+
+iaddr = where ( po4_obs NE miss_val )
+po4_br_obs = FLTARR(N_obs, 6)
+po4_br_obs(iaddr) = po4_obs(iaddr) / e_i_nut(iaddr)
+
+iaddr = where ( nox_obs NE miss_val )
+nox_br_obs = FLTARR(N_obs, 6)
+nox_br_obs(iaddr) = nox_obs(iaddr) / e_i_nut(iaddr)
+
+;*** Mean observed Profiles
+;--- interpolate T, S and e on standard depths ---
+N_std = 30
+depth_std = FINDGEN(30) / 30.+ 1./60.
+
+t_i_std = FLTARR(N_obs, N_std)
+s_i_std = FLTARR(N_obs, N_std)
+e_i_std = FLTARR(N_obs, N_std)
+chla_std = FLTARR(N_obs, N_std)
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+   zt = t_i_obs(i_obs,0:N_TS(i_obs)-1)
+   zd = depth_TS(i_obs,0:N_TS(i_obs)-1)
+   zaddr = WHERE( zt NE miss_val )
+   zt = zt(zaddr)
+   zd = zd(zaddr) / h_TS(i_obs)
+   ztstd = INTERPOL( zt, zd, depth_std )
+   t_i_std(i_obs,*) = ztstd(*)
+
+   zs = s_i_obs(i_obs,0:N_TS(i_obs)-1)
+   zd = depth_TS(i_obs,0:N_TS(i_obs)-1)
+   zaddr = WHERE( zs NE miss_val )
+   zs = zs(zaddr)
+   zd = zd(zaddr) / h_TS(i_obs)
+   zsstd = INTERPOL( zs, zd, depth_std )
+   s_i_std(i_obs,*) = zsstd(*)
+
+   ze = e_i_obs(i_obs,0:N_TS(i_obs)-1)
+   zd = depth_TS(i_obs,0:N_TS(i_obs)-1)
+   zaddr = WHERE( ze NE miss_val )
+   ze = ze(zaddr)
+   zd = zd(zaddr) / h_TS(i_obs)
+   zestd = INTERPOL( ze, zd, depth_std )
+   e_i_std(i_obs,*) = zestd(*)
+
+   zchl    = chla_obs(i_obs,0:N_chl(i_obs)-1)
+   zd      = depth_chl(i_obs,0:N_chl(i_obs)-1)
+   zaddr   = WHERE( zchl NE miss_val )
+   zchl    = zchl(zaddr)
+   zd      = zd(zaddr) / h_chl(i_obs)
+   zchlstd = INTERPOL( zchl, zd, depth_std )
+   chla_std(i_obs,*) = zchlstd(*)
+
+;  s_i_std = ...
+;  e_i_std = ...
+ENDFOR
+
+;***
+
+t_i_obs_mean = MEAN( t_i_std, dimension = 1 )
+t_i_obs_std = STDDEV( t_i_std, dimension = 1 )
+
+s_i_obs_mean = MEAN( s_i_std, dimension = 1 )
+s_i_obs_std = STDDEV( s_i_std, dimension = 1 )
+
+e_i_obs_mean = MEAN( e_i_std, dimension = 1 )
+e_i_obs_std = STDDEV( e_i_std, dimension = 1 )
+
+;depth_obs_mean = MEAN( depth_obs, DIMENSION = 1 )
+
+chla_obs_mean  = MEAN( chla_std , DIMENSION = 1 )
+chla_obs_std = STDDEV( chla_std, dimension = 1 )
+
+dsi_obs_mean = FLTARR(N_dpt) & dsi_obs_std = FLTARR(N_dpt)
+nox_obs_mean = FLTARR(N_dpt) & nox_obs_std = FLTARR(N_dpt)
+po4_obs_mean = FLTARR(N_dpt) & po4_obs_std = FLTARR(N_dpt)
+depth_nut_mean = FLTARR(N_dpt)
+depth_nut_std = FLTARR(N_obs,6)
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+   depth_nut_std(i_obs,*) = depth_nut(i_obs,*) / h_nut(i_obs)
+ENDFOR
+
+
+FOR i = 0, 5 DO BEGIN
+   i_addr = WHERE( dsi_obs(*,i) NE miss_val )
+   dsi_obs_mean(i) =  MEAN( dsi_obs(i_addr,i) )
+   dsi_obs_std(i)  = STDDEV( dsi_obs(i_addr,i) )
+   nox_obs_mean(i) =  MEAN( nox_obs(i_addr,i) )
+   nox_obs_std(i)  = STDDEV( nox_obs(i_addr,i) )
+   po4_obs_mean(i) =  MEAN( po4_obs(i_addr,i) )
+   po4_obs_std(i)  = STDDEV( po4_obs(i_addr,i) )
+   depth_nut_mean(i) = MEAN( depth_nut_std(i_addr,i) )
+ENDFOR
+
+;*** Corresponding model mean profiles
+t_i_mod_mean = FLTARR(nlay)  & t_i_mod_mean(*) = 0.
+t_i_mod_std  = FLTARR(nlay)  & t_i_mod_std (*) = 0.
+s_i_mod_mean = FLTARR(nlay)  & s_i_mod_mean(*) = 0.
+s_i_mod_std  = FLTARR(nlay)  & s_i_mod_std (*) = 0.
+e_i_mod_mean = FLTARR(nlay)  & e_i_mod_mean(*) = 0.
+e_i_mod_std  = FLTARR(nlay)  & e_i_mod_std (*) = 0.
+chla_mod_mean = FLTARR(nlay) & chla_mod_mean(*) = 0.
+chla_mod_std  = FLTARR(nlay) & chla_mod_std (*) = 0.
+nox_mod_mean = FLTARR(nlay)  & nox_mod_mean(*) = 0.
+nox_mod_std  = FLTARR(nlay)  & nox_mod_std (*) = 0.
+po4_mod_mean = FLTARR(nlay)  & po4_mod_mean(*) = 0.
+po4_mod_std  = FLTARR(nlay)  & po4_mod_std (*) = 0.
+dsi_mod_mean = FLTARR(nlay)  & dsi_mod_mean(*) = 0.
+dsi_mod_std  = FLTARR(nlay)  & dsi_mod_std (*) = 0.
+FOR i = 0, nlay - 1 DO BEGIN
+
+   FOR i_obs = 0, N_obs - 1 DO BEGIN
+      i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+      t_i_mod_mean(i)  = t_i_mod_mean(i) + t_i(i,i_mod) / FLOAT(N_obs)
+      s_i_mod_mean(i)  = s_i_mod_mean(i) + s_i(i,i_mod) / FLOAT(N_obs)
+      e_i_mod_mean(i)  = e_i_mod_mean(i) + e_i(i,i_mod) / FLOAT(N_obs)
+      chla_mod_mean(i) = chla_mod_mean(i) + chla(i,i_mod) / FLOAT(N_obs)
+      dsi_mod_mean(i)  = dsi_mod_mean(i) + dsib(i,i_mod) / FLOAT(N_obs)
+      nox_mod_mean(i)  = nox_mod_mean(i) + no3b(i,i_mod) / FLOAT(N_obs)
+      po4_mod_mean(i)  = po4_mod_mean(i) + po4b(i,i_mod) / FLOAT(N_obs)
+   ENDFOR
+
+   zsum   = 0
+   zsum_s = 0
+   zsum_e = 0
+   zsum_c = 0
+   zsum_d = 0
+   zsum_n = 0
+   zsum_p = 0
+   FOR i_obs = 0, N_obs - 1 DO BEGIN
+      i_mod = WHERE(doy EQ doy_obs(i_obs)-1)
+      zsum   = zsum + ( t_i(i,i_mod) - t_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_s = zsum_s + ( s_i(i,i_mod) - s_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_e = zsum_e + ( e_i(i,i_mod) - e_i_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_c = zsum_c + ( chla(i,i_mod) - chla_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_d = zsum_d + ( dsib(i,i_mod) - dsi_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_n = zsum_n + ( no3b(i,i_mod) - nox_mod_mean(i) ) ^2 / FLOAT(N_obs)
+      zsum_p = zsum_p + ( po4b(i,i_mod) - po4_mod_mean(i) ) ^2 / FLOAT(N_obs)
+   ENDFOR
+   t_i_mod_std(i)  = SQRT( zsum   )
+   s_i_mod_std(i)  = SQRT( zsum_s )
+   e_i_mod_std(i)  = SQRT( zsum_e )
+   chla_mod_std(i) = SQRT( zsum_c )
+   nox_mod_std(i)  = SQRT( zsum_n )
+   po4_mod_std(i)  = SQRT( zsum_p )
+   dsi_mod_std(i)  = SQRT( zsum_d )
+
+ENDFOR
+
+;-------
+
+
+;
+;==============================================================================
+; DIAGNOSTICS
+;==============================================================================
+;
+phi=findgen(32)*(!PI*2/32.)
+phi = [ phi, phi(0) ]
+usersym, cos(phi), sin(phi), /fill
+
+;
+;==============================================================================
+; PLOTS
+;==============================================================================
+;
+;
+;==============================================================================
+; Time series of profiles 
+;==============================================================================
+;
+;---------
+;--- T ---
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ -20, 0. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'deg C', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, -5, -0.1, ztitle
+
+   ; add obs
+   OPLOT, t_i_obs(i_obs,*), - depth_TS(i_obs,*)/h_TS(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, t_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;---------
+;--- S   
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 15. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'g/kg', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 7., -0.1, ztitle
+
+   ; add obs
+   OPLOT, s_i_obs(i_obs,*), - depth_TS(i_obs,*)/h_TS(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, s_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;---------
+;--- e   
+;---------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [0., 50. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = '%', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 15., -0.1, ztitle
+
+   ; add obs
+   OPLOT, e_i_obs(i_obs,*)*100., - depth_TS(i_obs,*)/h_TS(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ip(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 3 
+   OPLOT, e_i(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+;--------------
+;--- chla
+;--------------
+!P.MULTI=[0,numplot_x, numplot_y]
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.01, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mg chla / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 27., -0.1, ztitle
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, chla(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+   ; add obs
+   zchlaobs = chla_obs(i_obs,0:N_chl(i_obs)-1)
+   zz_obs   = depth_chl(i_obs,0:N_chl(i_obs)-1) / h_chl(i_obs)
+   zchla_obs2mod = INTERPOL( zchlaobs, zz_obs,zz )
+   OPLOT, zchla_obs2mod, -zz, PSYM = 1, THICK = 3, SYMSIZE = 0.8
+;   print, zchla_obs2mod
+
+ENDFOR
+
+
+;------------
+;--- nox  
+;------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 12. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 2.2, -0.3, ztitle
+
+   ; add obs
+   OPLOT, nox_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+   PRINT, ' i_mod : ', i_mod
+   PRINT, ' NO3b  : ', no3b(*,i_mod)
+
+ENDFOR
+
+
+;-------------
+;--- po4  
+;-------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 4.0 ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 0.37, -0.3, ztitle
+
+   ; add obs
+   OPLOT, po4_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs) , PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+
+
+;--------------
+;--- DSi  
+;--------------
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.00, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol Si / m3', XTICKFORMAT='(F4.1)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 3.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, dsi_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, dsib(*,i_mod), -zz, THICK = 3, COLOR = 150
+
+ENDFOR
+
+;
+;==============================================================================
+; Time series of profiles, brine concentrations
+;==============================================================================
+;
+
+;--- nox_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0., 300. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 20.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, nox_br_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, no3b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 1.6, 1.6 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;--- po4_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0.0, 15. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, $
+         SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I3)', XMINOR = 2, XTICKS = 3 , YMINOR = 2
+   XYOUTS, 10., -0.15, ztitle
+
+   ; add obs
+   OPLOT, po4_br_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, po4b(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 0.24, 0.24 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;--- dsi_br
+!P.MULTI=[0,numplot_x, numplot_y]
+
+FOR i_obs = 0, N_obs - 1 DO BEGIN
+
+   ; prepare plot
+   LOADCT, 0
+   ztitle = STRCOMPRESS(STRING(doy_obs(i_obs)), /REMOVE_ALL)
+   PLOT, [ 0., 750. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol Si / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2
+   XYOUTS, 20.0, -0.15, ztitle
+
+   ; add obs
+   OPLOT, dsi_br_obs(i_obs,*), - depth_nut(i_obs,*)/h_nut(i_obs), PSYM = 1, THICK = 3, SYMSIZE = 0.8
+
+   ; add model
+   i_mod = WHERE(doy EQ doy_obs(i_obs))
+   zz = FLTARR(nlay)
+   FOR i = 0, nlay - 1 DO BEGIN
+      zz(i) = z_ib(i,i_mod) / h_i(i_mod)
+   ENDFOR
+   LOADCT, 9 
+   OPLOT, dsib(*,i_mod)/e_i(*,i_mod)*100., -zz, THICK = 3, COLOR = 150
+   LOADCT, 1
+
+   OPLOT, [ 3.90, 3.90 ], [ -1., 0.], linestyle = 1, color = 150 , thick = 3
+
+ENDFOR
+
+;
+;==============================================================================
+; Mean profiles
+;==============================================================================
+;
+!P.MULTI=[0,numplot_x, numplot_y]
+
+;--- T ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean T"
+PLOT, [ -20., 0. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'deg C', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, t_i_obs_mean, - depth_std, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ t_i_obs_mean(i) - t_i_obs_std(i), t_i_obs_mean(i) + t_i_obs_std(i) ], $
+          [ -depth_std(i), -depth_std(i) ]
+ENDFOR
+LOADCT, 3
+OPLOT, t_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, t_i_mod_mean+t_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, t_i_mod_mean-t_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- S ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean S"
+PLOT, [0., 12. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'g/kg', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, s_i_obs_mean, - depth_std, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ s_i_obs_mean(i) - s_i_obs_std(i), s_i_obs_mean(i) + s_i_obs_std(i) ], $
+          [ -depth_std(i), -depth_std(i) ]
+ENDFOR
+
+; add model
+LOADCT, 3
+OPLOT, s_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, s_i_mod_mean+s_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, s_i_mod_mean-s_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- e ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean e"
+   PLOT, [0., 50. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = '%', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+
+; add obs
+OPLOT, e_i_obs_mean*100., - depth_std, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ e_i_obs_mean(i) - e_i_obs_std(i), e_i_obs_mean(i) + e_i_obs_std(i) ] * 100., $
+          [ -depth_std(i), -depth_std(i) ]
+ENDFOR
+
+; add model
+LOADCT, 3
+OPLOT, e_i_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, e_i_mod_mean+e_i_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, e_i_mod_mean-e_i_mod_std, -zz, THICK = 1, COLOR = 150
+
+
+
+;--- chl-a ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean chla"
+PLOT, [ 0.01, 40. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mg chla / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, chla_obs_mean, - depth_std, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ chla_obs_mean(i) - chla_obs_std(i), chla_obs_mean(i) + chla_obs_std(i) ], $
+          [ -depth_std(i), -depth_std(i) ]
+ENDFOR
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 0.08 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, chla_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, chla_mod_mean+chla_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, chla_mod_mean-chla_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- NOX ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean NOX"
+PLOT, [ 0.00, 35. ], [ -1.0, 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I3)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, nox_obs_mean, - depth_nut_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, 5 DO BEGIN
+   OPLOT, [ nox_obs_mean(i) - nox_obs_std(i), nox_obs_mean(i) + nox_obs_std(i) ], $
+          [ -depth_nut_mean(i), -depth_nut_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 31.16 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, nox_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, nox_mod_mean+nox_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, nox_mod_mean-nox_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- PO4 ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean PO4"
+PLOT, [ 0.00, 4.0 ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol P / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, po4_obs_mean, - depth_nut_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ po4_obs_mean(i) - po4_obs_std(i), po4_obs_mean(i) + po4_obs_std(i) ], $
+          [ -depth_nut_mean(i), -depth_nut_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 2.05 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, po4_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, po4_mod_mean+po4_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, po4_mod_mean-po4_mod_std, -zz, THICK = 1, COLOR = 150
+
+;--- DSi ---
+
+; prepare plot
+LOADCT, 0
+ztitle = "Mean DSi"
+PLOT, [ 0.00, 90. ], [ -1., 0. ], CHARSIZE = cs, /NODATA, SUBTITLE = 'mmmol N / m3', XTICKFORMAT='(I2)', XMINOR = 2, YMINOR = 2, TITLE = ztitle
+; add obs
+OPLOT, dsi_obs_mean, - depth_nut_mean, PSYM = 8, THICK = 3, SYMSIZE = 0.8
+FOR i = 0, N_std - 1 DO BEGIN
+   OPLOT, [ dsi_obs_mean(i) - dsi_obs_std(i), dsi_obs_mean(i) + dsi_obs_std(i) ], $
+          [ -depth_nut_mean(i), -depth_nut_mean(i) ]
+ENDFOR
+
+; plot seawater value
+LOADCT, 1
+OPLOT, [ 84.35 ], [ -1 ], PSYM = 8, THICK = 3, SYMSIZE = 1.6, COLOR = 150
+
+; add model
+LOADCT, 9
+OPLOT, dsi_mod_mean, -zz, THICK = 3, COLOR = 150
+LOADCT, 0
+OPLOT, dsi_mod_mean+dsi_mod_std, -zz, THICK = 1, COLOR = 150
+OPLOT, dsi_mod_mean-dsi_mod_std, -zz, THICK = 1, COLOR = 150
+
+;
+;==============================================================================
+; End of the script
+;==============================================================================
+;
+IF ( device EQ 'PS' ) THEN BEGIN
+   DEVICE, /CLOSE
+   SET_PLOT, "X"
+   !P.MULTI=[0,2,2]
+ENDIF
+
+END
+
Index: /tags/LIM1D_v3.20/GRAPHICS/cc2stock.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/cc2stock.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/cc2stock.pro	(revision 6)
@@ -0,0 +1,49 @@
+
+PRO cc2stock, z_ib, c_i, S_i
+
+;==================================================================================================
+;
+; this gorgeous script integrates a concentration c_i (./m3) into a stock S_i (./m2)
+; by integrating vertically on any grid
+; (c) Martouf, Helsinki, Aug 2014
+;
+;==================================================================================================
+;
+;--------------------------------------------------------------------------------------------------
+; extract number of layers and time steps
+;--------------------------------------------------------------------------------------------------
+
+zsize = SIZE(c_i)
+
+nlay = zsize(1)   ; number of layers
+nts  = zsize(2)   ; number of time steps
+
+S_i = FLTARR(nts)
+
+;--------------------------------------------------------------------------------------------------
+; Compute layer depths
+;--------------------------------------------------------------------------------------------------
+dz = FLTARR(nlay,nts)
+
+FOR i = 0, nts - 1 DO BEGIN
+   zz = 0. 
+   FOR jk = 0, nlay - 1 DO BEGIN
+      dz(jk,i) = 2.* ( z_ib(jk,i) - zz )
+      zz       = z_ib(jk,i) + dz(jk,i) / 2.
+   ENDFOR
+ENDFOR
+
+;--------------------------------------------------------------------------------------------------
+; Compute the weighted vertical average
+;--------------------------------------------------------------------------------------------------
+
+S_i[*] = 0.
+FOR i = 0, nts - 1 DO BEGIN
+    FOR k = 0, nlay - 1 DO BEGIN
+       S_i(i) = S_i(i) + dz(k,i) * c_i(k,i)
+    ENDFOR
+ENDFOR
+
+;--------------------------------------------------------------------------------------------------
+
+END
Index: /tags/LIM1D_v3.20/GRAPHICS/colorbarn.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/colorbarn.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/colorbarn.pro	(revision 6)
@@ -0,0 +1,32 @@
+PRO colorbarn,xpo, ypo, length, height, mindat, maxdat, leveling,nlevels,levels,colors, format, cs
+; does a colorbar
+; v1.0 by Ralph Timmermann, UCL-ASTR, 2002
+; tag v2.0, Martin Vancoppenolle, June 2nd, 2009
+;------------------------------------------------------------------------------
+
+; diese procedure zeichnet einen farbbalken
+; folgende parameter muessen gesetzt werden
+;
+; xpo,ypo  position der linken unteren ecke in Normalkoordinaten
+; length, height   laenge und Hoehe  des balkens
+; mindat,maxdat  wertegrenzen des balkens
+;
+;------------------------------------------------------------------------------
+
+; create the bar
+ncol=nlevels-1 ; ok
+bar=INTARR(ncol,2)
+bar(*,0)=REFORM(colors(0:ncol-1))
+bar(*,1)=bar(*,0)
+
+; plot the bar (congrid just expands an array
+TV, CONGRID(bar,ncol*20,10),xpo,ypo,xsize=length,ysize=height,/normal
+
+; add the black lines and the caption
+PLOT,[0,nlevels],[0,height],xsty=1,ysty=1,/nodata,/noerase,$
+yticks=1,yticklen=0,ytickv=[0,height],ytickname=[' ',' '],$
+xticks=nlevels-1,xtickn=string(levels,format=format),$
+position=[xpo,ypo,xpo+length,ypo+height],$
+/normal,xticklen=0.5,color=000, charsize=cs
+
+END
Index: /tags/LIM1D_v3.20/GRAPHICS/do_levels.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/do_levels.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/do_levels.pro	(revision 6)
@@ -0,0 +1,17 @@
+PRO do_levels, zmin, zmax, cmin, cmax, nlevels, levels, colors
+;this program does levels
+
+dz = ( zmax - zmin ) / FLOAT(nlevels)
+levels = FLTARR(nlevels+1)
+
+FOR i_lev = 0, nlevels  DO BEGIN
+   levels(i_lev) =  zmin + dz * FLOAT(i_lev)
+ENDFOR
+
+dc = ( cmax - cmin ) / FLOAT(nlevels-1)
+colors = LONARR(nlevels)
+FOR i_lev = 0, nlevels - 1 DO BEGIN
+   colors(i_lev) = LONG(cmin + dc * FLOAT(i_lev))
+ENDFOR
+
+END
Index: /tags/LIM1D_v3.20/GRAPHICS/icecontour.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/icecontour.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/icecontour.pro	(revision 6)
@@ -0,0 +1,59 @@
+PRO icecontour, field, hi, hs, nlevels, colors, levels, ct, z, time, nz, nt, $
+                tmin, tmax, zmin, zmax, title
+
+;
+;-----------------------------------------
+; Make the ice thickness, snow depth plot
+;-----------------------------------------
+;
+LOADCT, 0
+PLOT, [tmin, tmax], [zmin,zmax], /NODATA,       $
+title = title, ytitle = "z[m]", CHARSIZE=1, XSTYLE = 1, YSTYLE = 1;, $
+OPLOT, time , - hi
+OPLOT, time , hs
+;
+;------------
+; Dummy axes
+;------------
+; time
+time_matrix = FLTARR(nz+2, nt)
+FOR index = 0, nz+1 DO BEGIN
+   time_matrix[index,*] = time[*]
+ENDFOR
+
+; depth
+z_matrix = FLTARR(nz+2, nt)
+z_matrix[0,*]    =  0.0
+FOR index = 1, nz DO BEGIN
+   z_matrix[index,*] = z[index-1,*]
+ENDFOR
+z_matrix[nz+1,*] =  hi
+
+; field to plot
+field_matrix = FLTARR(nz+2,nt)
+field_matrix[0,*] = field[0,*]
+FOR index = 1, nz DO BEGIN
+   field_matrix[index,*] = field[index-1,*]
+ENDFOR
+field_matrix[nz+1,*] = field[nz-1,*]
+
+;print, ' time_matrix  : ', time_matrix[*,10]
+;print, ' z_matrix     : ', z_matrix[*,10]
+;print, ' field_matrix : ', field_matrix[*,10]
+
+;
+;----------
+; Contours
+;----------
+; colors
+LOADCT, ct
+color00 = MAX(colors)
+color99 = MIN(colors)
+
+CONTOUR, field_matrix, time_matrix, - z_matrix, /FILL, /OVERPLOT, C_COLORS = colors, levels = levels
+
+;CONTOUR, s_i, time_matrix, - z_ip, /OVERPLOT, levels = levels, $
+;C_LABELS=[  0,  1, 0, 0,  1,  1, 0, 0, 0,  1, 0, 0,   1], $
+;C_ANNOTATION=['0','1','','','4','5','','','','9','','','12']
+
+end
Index: /tags/LIM1D_v3.20/GRAPHICS/open_fields_v7.pro
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/open_fields_v7.pro	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/open_fields_v7.pro	(revision 6)
@@ -0,0 +1,299 @@
+
+PRO open_fields_v7, indir, exp_id, c_bio_model,            $
+             numt, doy, ts_d, ts_m,                        $ 
+             h_i, h_s, z_ip, z_ib, s_i, t_i, e_i, PAR, Ra, $
+             dhib, dhisu, dhisi,                           $
+             AoCb, dINb, dIPb, dSib, chla, eoCb,           $
+             Argb, Argbub,                                 $
+             Oxyb, Oxybub,                                 $
+             DICb, Alkb, CO2b, CO2bub,                     $
+             CO2aq, HCO3m, CO32m, pH, pCO2,                $
+             Ikab,                                         $
+             dFeb, aFeb, eFeb,                             $
+             AoCt, dINt, dIPt, dSit, eoCt, Argt,           $
+             DICt, Alkt, CO2t, Ikat,                       $
+             dFet, aFet, eFet,                             $
+             FAoC, FAoCb, FAoCsi,                          $
+             FdIN, FdINb, FdINsi,                          $
+             FCO2_atm, FCO2_bub,                           $
+             syn, rsp, lys, rem,                           $
+             lim_lig, lim_no3, lim_po4, lim_dsi, lim_tem, lim_sal
+
+; working for source_3.05
+; Helsinki, 2014
+; Bruxelles, nov 2014 avec Julie
+; this little nice script reads output from a bio simulation and extract stuff from it
+; 
+
+; IN 
+; indir, exp_id
+; OUT
+; remainder
+;==================================================================================================
+
+PRINT, ' indir = ', indir
+PRINT, ' exp_id= ', exp_id
+file_no = NCDF_OPEN(indir+"ice.out.nc."+exp_id, /NOWRITE)
+
+numt_no = NCDF_VARID( file_no, 'numt' )
+doy_no  = NCDF_VARID( file_no, 'doy' )
+ts_m_no = NCDF_VARID( file_no, 'ts_m' )
+ts_d_no = NCDF_VARID( file_no, 'ts_d' )
+
+h_i_no  = NCDF_VARID( file_no, 'h_i'  )
+h_s_no  = NCDF_VARID( file_no, 'h_s'  )
+z_ip_no = NCDF_VARID( file_no, 'z_ip' )
+z_ib_no = NCDF_VARID( file_no, 'z_ib' )
+s_i_no  = NCDF_VARID( file_no, 's_i' )
+t_i_no  = NCDF_VARID( file_no, 't_i' )
+e_i_no  = NCDF_VARID( file_no, 'e_i' )
+PAR_no  = NCDF_VARID( file_no, 'PAR' )
+Ra_no   = NCDF_VARID( file_no, 'ra' )
+
+dhib_no = NCDF_VARID( file_no, 'dhib' )
+dhisu_no = NCDF_VARID( file_no, 'dhisu' )
+dhisi_no = NCDF_VARID( file_no, 'dhisi' )
+
+IF ( c_bio_model EQ 'KRILL' ) THEN BEGIN
+
+AoCb_no = NCDF_VARID( file_no, 'AoCb' )
+dINb_no = NCDF_VARID( file_no, 'dINb' )
+dIPb_no = NCDF_VARID( file_no, 'dIPb' )
+dSib_no = NCDF_VARID( file_no, 'dSib' )
+chla_no = NCDF_VARID( file_no, 'Chla_bio' )
+eoCb_no = NCDF_VARID( file_no, 'eoCb' )
+Argb_no   = NCDF_VARID( file_no, 'Argb' )
+Argbub_no = NCDF_VARID( file_no, 'Argbub' )
+Oxyb_no   = NCDF_VARID( file_no, 'Oxyb' )
+Oxybub_no = NCDF_VARID( file_no, 'Oxybub' )
+DICb_no = NCDF_VARID( file_no, 'DICb' )
+Alkb_no = NCDF_VARID( file_no, 'Alkb' )
+CO2b_no = NCDF_VARID( file_no, 'CO2b' )
+CO2bub_no = NCDF_VARID( file_no, 'CO2bub' )
+
+CO2aq_no = NCDF_VARID( file_no, 'CO2aq' )
+HCO3m_no = NCDF_VARID( file_no, 'HCO3m' )
+CO32m_no = NCDF_VARID( file_no, 'CO32m' )
+pH_no    = NCDF_VARID( file_no, 'pH'   )
+pCO2_no  = NCDF_VARID( file_no, 'pCO2' )
+Ikab_no  = NCDF_VARID( file_no, 'Ikab' )
+dFeb_no  = NCDF_VARID( file_no, 'dFeb' )
+aFeb_no  = NCDF_VARID( file_no, 'aFeb' )
+eFeb_no  = NCDF_VARID( file_no, 'eFeb' )
+
+AoCt_no = NCDF_VARID( file_no, 'AoCt' )
+dINt_no = NCDF_VARID( file_no, 'dINt' )
+dIPt_no = NCDF_VARID( file_no, 'dIPt' )
+dSit_no = NCDF_VARID( file_no, 'dSit' )
+eoCt_no = NCDF_VARID( file_no, 'eoCt' )
+Argt_no = NCDF_VARID( file_no, 'Argt' )
+DICt_no = NCDF_VARID( file_no, 'DICt' )
+Alkt_no = NCDF_VARID( file_no, 'Alkt' )
+CO2t_no = NCDF_VARID( file_no, 'CO2t' )
+Ikat_no = NCDF_VARID( file_no, 'Ikat' )
+
+dFet_no = NCDF_VARID( file_no, 'dFet' )
+aFet_no = NCDF_VARID( file_no, 'aFet' )
+eFet_no = NCDF_VARID( file_no, 'eFet' )
+
+FAoC_no = NCDF_VARID( file_no, 'FAoC' )
+FAoCb_no = NCDF_VARID( file_no, 'FAoCb' )
+FAoCsi_no = NCDF_VARID( file_no, 'FAoCsi' )
+
+FdIN_no = NCDF_VARID( file_no, 'FdIN' )
+FdINb_no = NCDF_VARID( file_no, 'FdINb' )
+FdINsi_no = NCDF_VARID( file_no, 'FdINsi' )
+
+FCO2_atm_no = NCDF_VARID( file_no, 'FCO2_atm' )
+FCO2_bub_no = NCDF_VARID( file_no, 'FCO2_bub' )
+
+syn_no  = NCDF_VARID( file_no, 'syn' )
+rsp_no  = NCDF_VARID( file_no, 'rsp' )
+lys_no  = NCDF_VARID( file_no, 'lys' )
+rem_no  = NCDF_VARID( file_no, 'rem' )
+
+lim_lig_no = NCDF_VARID( file_no, 'lim_lig' )
+lim_no3_no = NCDF_VARID( file_no, 'lim_no3' )
+lim_po4_no = NCDF_VARID( file_no, 'lim_po4' )
+lim_dsi_no = NCDF_VARID( file_no, 'lim_dsi' )
+lim_tem_no = NCDF_VARID( file_no, 'lim_tem' )
+lim_sal_no = NCDF_VARID( file_no, 'lim_sal' )
+
+ENDIF
+
+IF ( c_bio_model EQ 'BFMSI' ) THEN BEGIN
+
+S1cb_no = NCDF_VARID( file_no, 'S1cb' )
+S2cb_no = NCDF_VARID( file_no, 'S2cb' )
+dIPb_no = NCDF_VARID( file_no, 'I1pb' )
+dINb_no = NCDF_VARID( file_no, 'I3nb' )
+dSib_no = NCDF_VARID( file_no, 'I5sb' )
+chla1_no = NCDF_VARID( file_no, 'S1lb' )
+chla2_no = NCDF_VARID( file_no, 'S1lb' )
+
+S1ct_no = NCDF_VARID( file_no, 'S1ct' )
+S2ct_no = NCDF_VARID( file_no, 'S2ct' )
+dIPt_no = NCDF_VARID( file_no, 'I1pb' )
+dINt_no = NCDF_VARID( file_no, 'I3nt' )
+dSit_no = NCDF_VARID( file_no, 'I5st' )
+
+FS1c_no = NCDF_VARID( file_no, 'FS1c' )
+FS1cb_no = NCDF_VARID( file_no, 'FS1cb' )
+FS1csi_no = NCDF_VARID( file_no, 'FS1csi' )
+FS1c_no = NCDF_VARID( file_no, 'FS2c' )
+FS1cb_no = NCDF_VARID( file_no, 'FS2cb' )
+FS1csi_no = NCDF_VARID( file_no, 'FS2csi' )
+
+FdIN_no = NCDF_VARID( file_no, 'FI3n' )
+FdINb_no = NCDF_VARID( file_no, 'FI3nb' )
+FdINsi_no = NCDF_VARID( file_no, 'FI3nsi' )
+
+syn_no  = NCDF_VARID( file_no, 'rugC' )
+lys_no  = NCDF_VARID( file_no, 'slc' )
+;rem_no  = NCDF_VARID( file_no, 'rem' )
+
+lim_lig_no = NCDF_VARID( file_no, 'eiSI' )
+lim_no3_no = NCDF_VARID( file_no, 'lim_no3' )
+lim_po4_no = NCDF_VARID( file_no, 'lim_po4' )
+lim_dsi_no = NCDF_VARID( file_no, 'ei5s' )
+lim_tem_no = NCDF_VARID( file_no, 'et' )
+
+ENDIF
+
+IF ( numt_no GT 0 ) THEN NCDF_VARGET, file_no, numt_no, numt
+IF ( doy_no  GT 0 ) THEN NCDF_VARGET, file_no, doy_no, doy
+IF ( ts_m_no GT 0 ) THEN NCDF_VARGET, file_no, ts_m_no, ts_m
+IF ( ts_d_no GT 0 ) THEN NCDF_VARGET, file_no, ts_d_no, ts_d
+
+IF ( h_i_no  GT 0 ) THEN NCDF_VARGET, file_no, h_i_no, h_i
+IF ( h_s_no  GT 0 ) THEN NCDF_VARGET, file_no, h_s_no, h_s
+IF ( z_ip_no GT 0 ) THEN NCDF_VARGET, file_no, z_ip_no, z_ip
+IF ( z_ib_no GT 0 ) THEN NCDF_VARGET, file_no, z_ib_no, z_ib
+IF ( s_i_no  GT 0 ) THEN NCDF_VARGET, file_no, s_i_no, s_i
+IF ( t_i_no  GT 0 ) THEN NCDF_VARGET, file_no, t_i_no, t_i
+IF ( e_i_no  GT 0 ) THEN NCDF_VARGET, file_no, e_i_no, e_i
+IF ( PAR_no  GT 0 ) THEN NCDF_VARGET, file_no, PAR_no, PAR
+IF ( Ra_no   GT 0 ) THEN NCDF_VARGET, file_no, Ra_no, Ra
+
+IF ( dhib_no GT 0 ) THEN NCDF_VARGET, file_no, dhib_no , dhib
+IF ( dhisu_no GT 0) THEN NCDF_VARGET, file_no, dhisu_no, dhisu
+IF ( dhisi_no GT 0) THEN NCDF_VARGET, file_no, dhisi_no, dhisi
+
+IF ( c_bio_model EQ 'KRILL' ) THEN BEGIN
+
+IF ( AoCb_no   GT 0 ) THEN NCDF_VARGET, file_no, AoCb_no, AoCb
+IF ( dINb_no   GT 0 ) THEN NCDF_VARGET, file_no, dINb_no, dINb
+IF ( dIPb_no   GT 0 ) THEN NCDF_VARGET, file_no, dIPb_no, dIPb
+IF ( dsib_no   GT 0 ) THEN NCDF_VARGET, file_no, dsib_no, dsib
+IF ( chla_no   GT 0 ) THEN NCDF_VARGET, file_no, chla_no, chla
+IF ( eoCb_no   GT 0 ) THEN NCDF_VARGET, file_no, eoCb_no, eoCb
+IF ( Argb_no   GT 0 ) THEN NCDF_VARGET, file_no, Argb_no, Argb
+IF ( Argbub_no   GT 0 ) THEN NCDF_VARGET, file_no, Argbub_no, Argbub
+IF ( Oxyb_no   GT 0 ) THEN NCDF_VARGET, file_no, Oxyb_no, Oxyb
+IF ( Oxybub_no   GT 0 ) THEN NCDF_VARGET, file_no, Oxybub_no, Oxybub
+IF ( DICb_no   GT 0 ) THEN NCDF_VARGET, file_no, DICb_no, DICb
+IF ( Alkb_no   GT 0 ) THEN NCDF_VARGET, file_no, Alkb_no, Alkb
+IF ( CO2b_no   GT 0 ) THEN NCDF_VARGET, file_no, CO2b_no, CO2b
+IF ( CO2bub_no   GT 0 ) THEN NCDF_VARGET, file_no, CO2bub_no, CO2bub
+IF ( CO2aq_no  GT 0 ) THEN NCDF_VARGET, file_no, CO2aq_no, CO2aq
+IF ( HCO3m_no  GT 0 ) THEN NCDF_VARGET, file_no, HCO3m_no, HCO3m
+IF ( CO32m_no  GT 0 ) THEN NCDF_VARGET, file_no, CO32m_no, CO32m
+IF ( pCO2_no   GT 0 ) THEN NCDF_VARGET, file_no, pCO2_no, pCO2
+IF ( Ikab_no   GT 0 ) THEN NCDF_VARGET, file_no, Ikab_no, Ikab
+IF ( dFeb_no   GT 0 ) THEN NCDF_VARGET, file_no, dFeb_no, dFeb
+IF ( aFeb_no   GT 0 ) THEN NCDF_VARGET, file_no, aFeb_no, aFeb
+IF ( eFeb_no   GT 0 ) THEN NCDF_VARGET, file_no, eFeb_no, eFeb
+IF ( pH_no     GT 0 ) THEN NCDF_VARGET, file_no, pH_no, pH
+
+IF ( AoCt_no   GT 0 ) THEN NCDF_VARGET, file_no, AoCt_no, AoCt
+IF ( dINt_no   GT 0 ) THEN NCDF_VARGET, file_no, dINt_no, dINt
+IF ( dIPt_no   GT 0 ) THEN NCDF_VARGET, file_no, dIPt_no, dIPt
+IF ( dsit_no   GT 0 ) THEN NCDF_VARGET, file_no, dsit_no, dsit
+IF ( eoCt_no   GT 0 ) THEN NCDF_VARGET, file_no, eoCt_no, eoCt
+IF ( Argt_no   GT 0 ) THEN NCDF_VARGET, file_no, Argt_no, Argt
+IF ( DICt_no   GT 0 ) THEN NCDF_VARGET, file_no, DICt_no, DICt
+IF ( Alkt_no   GT 0 ) THEN NCDF_VARGET, file_no, Alkt_no, Alkt
+IF ( CO2t_no   GT 0 ) THEN NCDF_VARGET, file_no, CO2t_no, CO2t
+IF ( Ikat_no   GT 0 ) THEN NCDF_VARGET, file_no, Ikat_no, Ikat
+IF ( dFet_no   GT 0 ) THEN NCDF_VARGET, file_no, dFet_no, dFet
+IF ( aFet_no   GT 0 ) THEN NCDF_VARGET, file_no, aFet_no, aFet
+IF ( eFet_no   GT 0 ) THEN NCDF_VARGET, file_no, eFet_no, eFet
+
+If ( FAoC_no   GT 0 ) THEN NCDF_VARGET, file_no, FAoC_no, FAoC
+IF ( FAoCb_no  GT 0 ) THEN NCDF_VARGET, file_no, FAoCb_no, FAoCb
+IF ( FAoCsi_no GT 0 ) THEN NCDF_VARGET, file_no, FAoCsi_no, FAoCsi
+
+IF ( FdIN_no   GT 0 ) THEN NCDF_VARGET, file_no, FdIN_no, FdIN
+IF ( FdINb_no  GT 0 ) THEN NCDF_VARGET, file_no, FdINb_no, FdINb
+IF ( FdINsi_no GT 0 ) THEN NCDF_VARGET, file_no, FdINsi_no, FdINsi
+IF ( FCO2_atm_no GT 0 ) THEN NCDF_VARGET, file_no, FCO2_atm_no, FCO2_atm
+IF ( FCO2_bub_no GT 0 ) THEN NCDF_VARGET, file_no, FCO2_bub_no, FCO2_bub
+
+IF ( syn_no    GT 0 ) THEN NCDF_VARGET, file_no, syn_no, syn
+IF ( rsp_no    GT 0 ) THEN NCDF_VARGET, file_no, rsp_no, rsp
+IF ( lys_no    GT 0 ) THEN NCDF_VARGET, file_no, lys_no, lys
+IF ( rem_no    GT 0 ) THEN NCDF_VARGET, file_no, rem_no, rem
+
+IF ( lim_lig_no GT 0 ) THEN NCDF_VARGET, file_no, lim_lig_no, lim_lig
+IF ( lim_no3_no GT 0 ) THEN NCDF_VARGET, file_no, lim_no3_no, lim_no3
+IF ( lim_po4_no GT 0 ) THEN NCDF_VARGET, file_no, lim_po4_no, lim_po4
+IF ( lim_dsi_no GT 0 ) THEN NCDF_VARGET, file_no, lim_dsi_no, lim_dsi
+IF ( lim_tem_no GT 0 ) THEN NCDF_VARGET, file_no, lim_tem_no, lim_tem
+IF ( lim_sal_no GT 0 ) THEN NCDF_VARGET, file_no, lim_sal_no, lim_sal
+
+ENDIF
+
+IF ( c_bio_model EQ 'BFMSI' ) THEN BEGIN
+
+NCDF_VARGET, file_no, S1cb_no, S1cb
+NCDF_VARGET, file_no, S2cb_no, S2cb
+AoCb = S1cb + S2cb
+NCDF_VARGET, file_no, dINb_no, dINb
+NCDF_VARGET, file_no, dIPb_no, dIPb
+NCDF_VARGET, file_no, dsib_no, dsib
+NCDF_VARGET, file_no, chla1_no, chla1
+NCDF_VARGET, file_no, chla2_no, chla2
+chla = chla1 + chla2
+
+NCDF_VARGET, file_no, S1ct_no, S1ct
+NCDF_VARGET, file_no, S2ct_no, S2ct
+AoCT = S1ct + S2ct
+NCDF_VARGET, file_no, dINt_no, dINt
+NCDF_VARGET, file_no, dIPt_no, dIPt
+NCDF_VARGET, file_no, dsit_no, dsit
+
+NCDF_VARGET, file_no, FS1c_no, FS1c
+NCDF_VARGET, file_no, FS1cb_no, FS1cb
+NCDF_VARGET, file_no, FS1csi_no, FS1csi
+NCDF_VARGET, file_no, FS1c_no, FS2c
+NCDF_VARGET, file_no, FS1cb_no, FS2cb
+NCDF_VARGET, file_no, FS1csi_no, FS2csi
+
+FAoC   = FS1c + FS2c
+FAoCb  = FS1cb + FS2cb
+FAoCsi = FS1csi + FS2csi
+
+NCDF_VARGET, file_no, FdIN_no, FdIN
+NCDF_VARGET, file_no, FdINb_no, FdINb
+NCDF_VARGET, file_no, FdINsi_no, FdINsi
+
+NCDF_VARGET, file_no, syn_no, syn
+NCDF_VARGET, file_no, rsp_no, rsp
+NCDF_VARGET, file_no, lys_no, lys
+NCDF_VARGET, file_no, rem_no, rem
+
+NCDF_VARGET, file_no, lim_lig_no, lim_lig
+NCDF_VARGET, file_no, lim_no3_no, lim_no3
+NCDF_VARGET, file_no, lim_po4_no, lim_po4
+NCDF_VARGET, file_no, lim_dsi_no, lim_dsi
+NCDF_VARGET, file_no, lim_tem_no, lim_tem
+;NCDF_VARGET, file_no, lim_sal_no, lim_sal
+lim_sal = lim_lig & lim_sal[*] = 1
+
+ENDIF
+
+NCDF_CLOSE, file_no
+
+;==================================================================================================
+
+END
Index: /tags/LIM1D_v3.20/GRAPHICS/plots_BARROW.exec
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/plots_BARROW.exec	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/plots_BARROW.exec	(revision 6)
@@ -0,0 +1,4 @@
+.r ../ALL_contours.pro
+.r ../ALL_stocks.pro
+.r BARROW_profiles.pro
+exit
Index: /tags/LIM1D_v3.20/GRAPHICS/plots_ISPOL.exec
===================================================================
--- /tags/LIM1D_v3.20/GRAPHICS/plots_ISPOL.exec	(revision 6)
+++ /tags/LIM1D_v3.20/GRAPHICS/plots_ISPOL.exec	(revision 6)
@@ -0,0 +1,4 @@
+.r ../ALL_contours.pro
+.r ../ALL_stocks.pro
+.r ISPOL_profiles.pro
+exit
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param	(revision 6)
@@ -0,0 +1,160 @@
+#
+# bio.param
+#
+# Parameter file for sea ice biogeochemistry BARROW, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Type of model and fluxes
+#---------------------------------------------------------------------------------
+#
+# c_grid      : type of grid: multilayer 'ML', deformed three layer 'DL', skeletal 'SL', or biologically-active 'BA'
+ML
+# h_skel      : prescribed biologically active layers thickness (SL & DL)
+0.10
+# e_thr_bal   : prescribed permeability threshold for BAL
+0.05
+#
+#---------------------------------------------------------------------------------
+# Process switches
+#---------------------------------------------------------------------------------
+#
+# ln_trbo     : bottom entrapment for tracers or not
+.TRUE.
+# ln_trsi     : snow-ice entrapment for tracers or not
+.TRUE.
+# ln_trdiff   : diffusion of tracers or not
+.TRUE.
+# ln_trremp   : remapping of tracers or not
+.TRUE.
+# ln_lim_dsi  : limitation of growth by DSi or not
+.TRUE.
+# ln_lim_no3  : limitation of growth by NO3
+.TRUE.
+# ln_lim_po4  : limitation of growth by PO3
+.TRUE.
+# ln_lim_lig  : light limitation or not
+.TRUE.
+# ln_lim_tem  : temperature inhibition or not
+.TRUE.
+# ln_lim_sal  : brine salinity inhibition or not
+.TRUE.
+# ln_lys      : lysis or not
+.TRUE. 
+# ln_rem      : remineralization or not
+.TRUE. 
+# ln_syn      : diatom synthesis or not
+.TRUE. 
+# ln_bubform  : gas buble formation
+.TRUE. 
+# ln_bubrise  : gas buble ascent
+.TRUE. 
+# ln_gasflux  : gas flux to ATM
+.TRUE. 
+# ln_carbon   : activate carbon cycle
+.TRUE.
+# ln_ikaite   : activate CaCO3 precipitation
+.TRUE.
+#
+#---------------------------------------------------------------------------------
+# Gas exchange / carbonate system / ikaite 
+#---------------------------------------------------------------------------------
+#
+# i_gas_flux      : Type of gas flux (1=Noflux, 2=ice-atm diffusive flux)
+2
+# brines_ar       : brines aspect ratio (vertical ellipsoid: <1; spheres: 1)
+1.00
+# bub_form_rate   : Gas Bubble formation rate (s-1) 2.5e-7
+2.5e-7 
+# bub_diss_rate   : Gas Bubble dissolution rate (s-1)  2.5e-3
+2.5e-3 
+# h_bl_gas        : Boundary layer thickness for diffusive gas flux (Moreau et al. 2005)
+0.5e-6
+# e_thr_gasflux   : Brine volume fraction threshold for gas fluxes
+0.05
+# e_thr_bubrise   : Brine volume fraction thershold for bubble rise
+0.10
+# sursat_gas      : Sursaturation tolerated in brines (1 = 100%)
+1.00
+ # nn_carbonate   : 1=Roy; 2=Mehrbach equilibration CO2 constants; Mehrbach (2) is default
+2
+ # caco3_time     : CaCO3 precipitation/dissolution time scale rate (360000s=100h by default)
+360000.
+#
+#---------------------------------------------------------------------------------
+# Physiological parameters
+#---------------------------------------------------------------------------------
+#
+# nn_bio_opt  : type of biological model (0=NP; 1=NPD Redfield; 2=NPD + Si; 3=NPD non-RedF; 4=NPD n.r + iron, 5=carbon cycle & gases)
+5
+#--- Bio-optical parameters
+#
+# astar_alg   : specific attenuation coefficient ( m-1 / ( mg chla m-3 ) ) - 0.01 Tedesco
+0.005
+# fdet_alg    : fraction of detrital radiation absorption versus algal absorption - 0.2 (Arrigo et al 1993)
+0.2
+#
+#--- Growth, loss, remineralization
+#
+# pp_presc    : prescribed GPP (ln_syn = false, mmol C m-3 s-1 ) DEFLT 1.0e-5
+0.0e-5       
+# mumax_bio   : maximum specific growth rate (s-1) ( Sarthou 5e-6 -> 3.8e-5 )
+1.80e-5
+# klys_bio    : loss rate (s-1) ( Sarthou  5.8e-8 -> 2.75e-6 )
+1.80e-6
+# krsp_bio    : respiration rate (s-1) 
+1.0e-6
+# krem_bio    : remineralization rate for carbon (2.0e-7 Moreau et al Elementa Oxy 2015)
+5.0e-6
+# frem_bio    : Fraction of nutrient loss that is remineralized in case of an N-P formulation
+1.00
+#
+#--- Photosynthesis / light limitation
+#
+# nn_phs      : type of photosynthesis parameterization (1-4)
+4
+# ek_bio      : Light adaptation parameter (nn_phs = 1, muE m-2 s-1) - DEFLT 2
+2
+# alpha_bio   : Photosynthetic efficiency (nn_phs > 1, gC/gchla/s/(muE/m2/s)) DEFLT 1.8e-4 - Fragiliariopsis 5.56e-5 (Mar FM)
+3.6e-4
+# chla_c      : Chl/C in ice algae (g/g) - DEFLT 0.05 - Loern 95 0.003 - 0.05
+0.05
+# Estar       : PAR value at which Chl/C=min (nn_phs = 4) 360.
+50. 
+# nn_lys      : type of lysis [ 1: klys_bio prescribed; 2: klys_bio*exp(rg_bio*T) ]
+2
+# nn_rem      : type of remineralization [1: krem_bio prescribed; 2: krem_bio*exp(rg_bac*T) ]
+2
+#
+#--- Redfield ratios
+#
+# si_c        : silicon to carbon molar ratio in diatoms (mol/mol) - 0.11 Sarthou 2005
+0.11
+# no3_c       : nitrogen to carbon molar ratio in diatoms (mol/mol) - 0.14 Sarthou 2005; Redf - 0.151
+0.14
+# po4_c       : phosphorus to carbon molar ratio in diatoms (mol/mol) - 0.014 Sarthou 2005; 0.0094
+0.014
+# oxy_c       : oxygen release to carbon uptake ratio during photosynthesis (mol/mol) - Redf = 138/106 = 1.30 / Sarmiento Gruber 2006 150/106 = 1.41, Anderson et al
+1.30 
+#
+#--- Nutrient limitation, temperature and salinity inhibition
+#
+# khs_si_bio  : halfsat cst for Si uptake (micrmol m-3) - 3.9 Sarthou et al
+3.9
+# khs_n_bio   : halfsat cst for N uptake (micrmol m-3)  - 1.6 Sarthou et al
+1.6
+# khs_p_bio   : halfsat cst for P uptake (micrmol m-3)  - 0.24 Sarthou et al.
+0.24
+# rg_bio      : Temperature coefficient for algal physiological processes (0.0633 degC-1; Eppley, 1972)
+0.0633
+# rg_bac      : Temperature coefficient for bacterial respiration (0.41 degC-1; Moreau et al, Elementa 2015)
+0.41
+# nn_lim_sal  : Salinity lim. 1=Power-log gaussian, Arrigo 93 data; 2=Gaussian
+1
+# lim_sal_wid : Width of the limitation function (nn_lim_sal=2)
+20.0
+# lim_sal_smax: Salinity where limitation function equals 1 (nn_lim_sal=2)
+34.0
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param.ispol
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param.ispol	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/bio.param.ispol	(revision 6)
@@ -0,0 +1,227 @@
+#
+# bio.param
+#
+# Parameter file for sea ice biogeochemistry ISPOL, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Type of model and fluxes
+#---------------------------------------------------------------------------------
+#
+# c_grid      : type of grid: multilayer 'ML', deformed three layer 'DL', skeletal 'SL', or biologically-active 'BA'
+ML
+# h_skel      : prescribed biologically active layers thickness (SL & DL)
+0.10
+# e_thr_bal   : prescribed permeability threshold for BAL
+0.05
+#
+#---------------------------------------------------------------------------------
+# Process switches
+#---------------------------------------------------------------------------------
+#
+# ln_trbo     : bottom entrapment for tracers or not
+.TRUE.
+# ln_trsi     : snow-ice entrapment for tracers or not
+.TRUE.
+# ln_trdiff   : diffusion of tracers or not
+.TRUE.
+# ln_trremp   : remapping of tracers or not
+.TRUE.
+# ln_lim_dsi  : limitation of growth by DSi or not
+.TRUE.
+# ln_lim_no3  : limitation of growth by NO3
+.TRUE.
+# ln_lim_po4  : limitation of growth by PO3
+.TRUE.
+# ln_lim_lig  : light limitation or not
+.TRUE.
+# ln_lim_tem  : temperature inhibition or not
+.TRUE.
+# ln_lim_sal  : brine salinity inhibition or not
+.TRUE.
+# ln_lys      : lysis or not
+.TRUE. 
+# ln_rem      : remineralization or not
+.TRUE. 
+# ln_syn      : diatom synthesis or not
+.TRUE. 
+# ln_bubform  : gas buble formation
+.TRUE. 
+# ln_bubrise  : gas buble ascent
+.TRUE. 
+# ln_gasflux  : gas flux to ATM
+.TRUE. 
+# ln_carbon   : activate carbon cycle
+.TRUE.
+# ln_ikaite   : activate CaCO3 precipitation
+.TRUE.
+#
+#---------------------------------------------------------------------------------
+# Initial and boundary values 
+#---------------------------------------------------------------------------------
+#
+#  nn_init    : switch for initialization (0=from code, 1=cc|nml everywhere, 2=cc retrieved from stock=cc|nml.h_i, 3=profiles) - 2 for annual run, 3 for summer
+1
+# cdsi_ini    : initial cc of DSi (mmol Si m-3) 
+19.90
+# cno3_ini    : initial cc of NO3 (mmol N m-3)
+10.44
+# cpo4_ini    : initial cc of PO4 (mmol P m-3) 
+0.91
+# cdaf_ini    : initial cc of DAF (mmol C m-3)
+0.01
+# ceoC_ini    : initial cc of eoC (mmol C m-3)
+0.00
+# cdic_ini    : initial cc of DIC (mmol C m-3)
+800.
+# calk_ini    : initial cc of Alk (mmol m-3)
+880.
+# cika_ini    : initial cc of Ika (mmol m-3)
+0.
+# coxy_ini    : initial cc of Oxy (mmol O2 m-3) - unchecked
+71.4
+# cnit_ini    : initial cc of Nit (mmol N2 m-3) - unchecked
+127.
+# carg_ini    : initial cc of Arg (mmol Ar m-3)
+7.2
+# cco2_ini    : initial cc of CO2 (mmol m-3) - no impact since carbonate chemistry is equilibrated in ice_bio_diff
+0. 
+# ccal_ini    : initial cc of Ca2+ (mmol m-3)
+4240.0
+# cdsi_w      : seawater cc of DSi (mmol Si m-3)
+51.25
+# cno3_w      : seawater cc of NO3 (mmol N m-3)
+26.90
+# cpo4_w      : seawater cc of PO4 (mmol P m-3)
+2.35
+# cdaf_w      : seawater cc of DAF (mmol C m-3) 
+0.05
+# ceoC_w      : seawater cc of eoC (mmol C m-3)
+0.50
+# cdic_w      : seawater cc of DIC (mmol C m-3)
+2000.
+# calk_w      : seawater cc of Alk (mmol m-3)
+2200.
+# cika_w      : seawater cc of Ika (mmol m-3)
+0.
+# coxy_w      : seawater cc of Oxy (mmol O2 m-3)
+357.
+# cnit_w      : seawater cc of Nit (mmol N2 m-3)
+635.
+# carg_w      : seawater cc of Arg (mmol Ar m-3)
+18.
+# cco2_w      : seawater cc of aq CO2 (mmol m-3)
+10.
+# ccal_w      : seawater cc of Ca2+ (mmol m-3)
+10600.
+# mr_oxy      : Oxy atmospheric mixing ratio
+0.2095
+# mr_nit      : Nit atmospheric mixing ratio
+0.7808
+# mr_arg      : Arg atmospheric mixing ratio
+0.00934
+# mr_co2      : CO2 atmospheric mixing ratio
+3.8e-4
+#
+#---------------------------------------------------------------------------------
+# Gas exchange / carbonate system / ikaite 
+#---------------------------------------------------------------------------------
+#
+# i_gas_flux      : Type of gas flux (1=Noflux, 2=ice-atm diffusive flux)
+2
+# brines_ar       : Brines aspect ratio (vertical ellipsoid: <1; spheres: 1)
+1.00
+# bub_form_rate   : Gas Bubble formation rate (s-1) 2.5e-7
+2.5e-7 
+# bub_diss_rate   : Gas Bubble dissolution rate (s-1)  2.5e-3
+2.5e-3 
+# h_bl_gas        : Boundary layer thickness for diffusive gas flux (Moreau et al. 2005)
+0.5e-6
+# e_thr_gasflux   : Brine volume fraction threshold for gas fluxes
+0.05
+# e_thr_bubrise   : Brine volume fraction thershold for bubble rise
+0.10
+# sursat_gas      : Sursaturation tolerated in brines (1 = 100%)
+1.00
+ # nn_carbonate   : 1=Roy; 2=Mehrbach equilibration CO2 constants; Mehrbach (2) is default
+2
+ # caco3_time     : CaCO3 precipitation/dissolution time scale rate (360000s=100h by default)
+360000.
+#
+#---------------------------------------------------------------------------------
+# Physiological parameters
+#---------------------------------------------------------------------------------
+#
+# nn_bio_opt  : type of biological model (0=NP; 1=NPD Redfield; 2=NPD + Si; 3=NPD non-RedF; 4=NPD n.r + iron, 5=carbon cycle & gases)
+5
+#--- Bio-optical parameters
+#
+# astar_alg   : specific attenuation coefficient ( m-1 / ( mg chla m-3 ) ) - 0.01 Tedesco
+0.005
+# fdet_alg    : fraction of detrital radiation absorption versus algal absorption - 0.2 (Arrigo et al 1993)
+0.2
+#
+#--- Growth, loss, remineralization
+#
+# pp_presc    : prescribed GPP (ln_syn = false, mmol C m-3 s-1 ) DEFLT 1.0e-5
+0.0e-5       
+# mumax_bio   : maximum specific growth rate (s-1) ( Sarthou 5e-6 -> 3.8e-5 )
+1.00e-5
+# klys_bio    : loss rate (s-1) ( Sarthou  5.8e-8 -> 2.75e-6 )
+1.00e-6
+# krsp_bio    : respiration rate (s-1) 
+1.0e-6
+# krem_bio    : remineralization rate for carbon (2.0e-7 Moreau et al Elementa Oxy 2015)
+5.0e-6
+# frem_bio    : Fraction of nutrient loss that is remineralized in case of an N-P formulation
+1.00
+#
+#--- Photosynthesis / light limitation
+#
+# nn_phs      : type of photosynthesis parameterization (1-4)
+4
+# ek_bio      : Light adaptation parameter (nn_phs = 1, muE m-2 s-1) - DEFLT 2
+2
+# alpha_bio   : Photosynthetic efficiency (nn_phs > 1, gC/gchla/s/(muE/m2/s)) DEFLT 1.8e-4 - Fragiliariopsis 5.56e-5 (Mar FM)
+2.50e-5
+# chla_c      : Chl/C in ice algae (g/g) - DEFLT 0.05 - Loern 95 0.003 - 0.05 (applies only for nn_phs = 1-3)
+0.05
+# Estar       : PAR value at which Chl/C=min (nn_phs = 4) 360.
+40. 
+# nn_lys      : type of lysis [ 1: klys_bio prescribed; 2: klys_bio*exp(rg_bio*T) ]
+2
+# nn_rem      : type of remineralization [1: krem_bio prescribed; 2: krem_bio*exp(rg_bac*T) ]
+2
+#
+#--- Redfield ratios
+#
+# si_c        : silicon to carbon molar ratio in diatoms (mol/mol) - 0.11 Sarthou 2005
+0.11
+# no3_c       : nitrogen to carbon molar ratio in diatoms (mol/mol) - 0.14 Sarthou 2005; Redf - 0.151
+0.14
+# po4_c       : phosphorus to carbon molar ratio in diatoms (mol/mol) - 0.014 Sarthou 2005; 0.0094
+0.014
+# oxy_c       : oxygen release to carbon uptake ratio during photosynthesis (mol/mol) - Redf = 138/106 = 1.30 / Sarmiento Gruber 2006 150/106 = 1.41, Anderson et al
+1.30 
+#
+#--- Nutrient limitation, temperature and salinity inhibition
+#
+# khs_si_bio  : halfsat cst for Si uptake (micrmol m-3) - 3.9 Sarthou et al
+3.9
+# khs_n_bio   : halfsat cst for N uptake (micrmol m-3)  - 1.6 Sarthou et al
+1.6
+# khs_p_bio   : halfsat cst for P uptake (micrmol m-3)  - 0.24 Sarthou et al.
+0.24
+# rg_bio      : Temperature coefficient for algal physiological processes (0.0633 degC-1; Eppley, 1972)
+0.0633
+# rg_bac      : Temperature coefficient for bacterial respiration (0.41 degC-1; Moreau et al, Elementa 2015)
+0.41
+# nn_lim_sal  : Salinity lim. 1=Power-log gaussian, Arrigo 93 data; 2=Gaussian
+1
+# lim_sal_wid : Width of the limitation function (nn_lim_sal=2)
+20.0
+# lim_sal_smax: Salinity where limitation function equals 1 (nn_lim_sal=2)
+34.0
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1d	(revision 6)
@@ -0,0 +1,43 @@
+#--------------------------------------------------------------------------------------------------
+# Parameter file for forcing
+# LIM1D, version source_3.01 - BARROW forcing for intercomparison project
+#--------------------------------------------------------------------------------------------------
+# ts_forc	time step of the forcing
+86400
+# n0_forc	number of the first time step in forcing file wrt 1/1/2009 - 29/01/2009 0:00 = ts 673
+29
+# n1_forc	number of the forcing.nc last time step relative to 1/1/2009 - 30/06/2009 28:00 = ts 4321
+181
+#--------------------------------------------------------------------------------------------------
+# forc_swi 	0=read in nc, 1-N=computed, 99=prescribed
+# forc_uni 	multiplication factor compared to SI units
+# forc_val      constant value in case of prescribed value (forc_swi = 99)
+#--------------------------------------------------------------------------------------------------
+# forc_swi	forc_uni 	forc_val
+# shortwave radiation (W/m2) ; 1=Shine; 2=Zillmann
+0	1.0	0.0
+# longwave radiation (W/m2); 1=Efimova; 2=Berliand
+0	1.0	0.0
+# incident PAR (muE/m2/s); 1=Computed from shortwave
+1	1.0	0.0
+# air temperature (K)
+0	1.0	260.0
+# atmospheric pressure (Pa)
+0	1.0	0.0
+# specific humidity (kg/kg) ! there is a bias at ISPOL
+0	1.0	0.00
+# wind speed (m/s)
+0	1.0	0.0
+# cloudiness (0-1)
+0	1.0	0.0
+# oceanic heat flux (W/m2) ; 5. is the ref
+99	1.0	1.8
+# snowfall (dimensions=length/timestep) 0.012 - 1h - SEB CHANGE BELOW forc_uni 3600.
+0	3600.00	0.0
+# albedo (0-1); 1=Shine & Henderson-Sellers, 2=parameterized using obs from ISPOL
+1	1.00	0.70
+#--------------------------------------------------------------------------------------------------
+# Some parameters
+#--------------------------------------------------------------------------------------------------
+# opt_dept : optical depth (m) in Efimova 1961 parameterization; SIMBA - 16.297; ISPOL - ; BARROW - WHY 30. ?
+12.0
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1h
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1h	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/forcing.param.1h	(revision 6)
@@ -0,0 +1,43 @@
+#--------------------------------------------------------------------------------------------------
+# Parameter file for forcing
+# LIM1D, version source_3.01 - BARROW forcing for intercomparison project
+#--------------------------------------------------------------------------------------------------
+# ts_forc	time step of the forcing
+3600. 
+# n0_forc	number of the first time step in forcing file wrt 1/1/2009 - 29/01/2009 0:00 = ts 673
+673
+# n1_forc	number of the forcing.nc last time step relative to 1/1/2009 - 30/06/2009 28:00 = ts 4321
+4321
+#--------------------------------------------------------------------------------------------------
+# forc_swi 	0=read in nc, 1-N=computed, 99=prescribed
+# forc_uni 	multiplication factor compared to SI units
+# forc_val      constant value in case of prescribed value (forc_swi = 99)
+#--------------------------------------------------------------------------------------------------
+# forc_swi	forc_uni 	forc_val
+# shortwave radiation (W/m2) ; 1=Shine; 2=Zillmann
+0	1.0	0.0
+# longwave radiation (W/m2); 1=Efimova; 2=Berliand
+0	1.0	0.0
+# incident PAR (muE/m2/s); 1=Computed from shortwave
+1	1.0	0.0
+# air temperature (K)
+0	1.0	260.0
+# atmospheric pressure (Pa)
+0	1.0	0.0
+# specific humidity (kg/kg) ! there is a bias at ISPOL
+0	1.0	0.00
+# wind speed (m/s)
+0	1.0	0.0
+# cloudiness (0-1)
+0	1.0	0.0
+# oceanic heat flux (W/m2) ; 5. is the ref
+99	1.0	1.8
+# snowfall (dimensions=length/timestep) 0.012 - 1h - SEB CHANGE BELOW forc_uni
+0	3600.00	0.0
+# albedo (0-1); 1=Shine & Henderson-Sellers, 2=parameterized using obs from ISPOL
+1	1.0	0.70
+#--------------------------------------------------------------------------------------------------
+# Some parameters
+#--------------------------------------------------------------------------------------------------
+# opt_dept : optical depth (m) in Efimova 1961 parameterization; SIMBA - 16.297; ISPOL - ; BARROW - WHY 30. ?
+30.0
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/icephys.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/icephys.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/icephys.param	(revision 6)
@@ -0,0 +1,96 @@
+#
+# icephys.param - ISPOL
+#
+# Parameter file for sea ice physics, source v2.42
+#
+# (c) Martin Vancoppenolle, Oct 2011, Louvain-la-Neuve, Belgium
+#
+#==================================================================================================
+#
+#--------------------------------------------------------------------------------------------------
+# General parameters
+#--------------------------------------------------------------------------------------------------
+#
+# nlay_i        ! number of layers in the ice
+10
+# nlay_s        ! number of layers in the snow
+1
+# parsub	! switch for snow sublimation or not ! should not be used anymore
+0.0
+# ln_evap       ! switch for snow summer evaporation or not
+.TRUE.
+# tbq_ano       ! prescribed air temperature anomaly (K)
+0.0
+#
+#--------------------------------------------------------------------------------------------------
+# Ice desalination
+#--------------------------------------------------------------------------------------------------
+#
+# ln_grd        ! gravity drainage or not
+.TRUE.
+# ln_flu        ! flushing or not
+.TRUE.
+# ln_flo        ! flooding or not
+.TRUE.
+# flu_beta      ! fraction of meltwater percolating in summer
+1.0
+# e_thr         ! permeability threshold for flushing
+0.05
+# frtr_si_phy   ! fraction of salt trapped in snow-ice
+1.0
+# d_br_mol      ! molecular diffusivity of brine (def:1.0e-9, obs: 6.8e-10)
+6.8e-10
+# d_br_tur      ! turbulent diffusivity of brine (def: 1.0e-6) 3.0e-7 1.0e-7
+5.0e-7
+# ra_c          ! critical rayleigh number for brine convection (def: 5, obs: 10)
+7
+# ra_smooth     ! hyperbolic tangent coefficient for turbulent diffusivity (def:1)
+0.6
+# gravdr        ! type of gravity drainage 'CW' for Cox Weeks 88 or 'RA' for Rayleigh-number based
+RA
+# delta_cw      ! CW88 grav. drainage eff.(1.68e-7 for CW88 or 0.588e-7 for V08 value)
+1.68e-7
+#
+#--------------------------------------------------------------------------------------------------
+# Radiative transfer (SSL = surface scattering layer)
+#--------------------------------------------------------------------------------------------------
+#
+# emig          ! Surface emissivity (past 0.995)
+0.995
+# fpar_fsw      ! Visible energetic ratio (Fpar/Fsw, J/J) = 0.475 (Frouin Pinker 95)
+0.475
+# qpar_fsw      ! Quantum energetic ratio (Qpar/Fsw, µE/J) = 2.33 (Vancoppenollet al 2011)
+2.33
+# c_rad_scheme  ! use surface transmission parameter ('INOT'), use SSL extinction coefficients ('EXTC')
+INOT
+# c_rad_discr   ! discretization of radiation based on absorption ('ABS') or on transmission ('TRA')
+TRA
+# rad_inot_s_dry ! surface transmission parameter, dry snow, visible range (INOT ONLY) ! 0.22
+0.22 
+# rad_inot_s_wet ! surface transmission parameter, wet snow, visible range (INOT ONLY) ! 0.22
+0.22
+# rad_inot_i_dry ! surface transmission parameter, dry ice, visible range (INOT only). 
+0.58
+# rad_inot_i_wet ! surface transmission parameter, wet ice, visible range (INOT only). 
+0.96
+# h_not_s       ! SSL thickness, snow (Perovich 07 0.03 m)
+0.03
+# h_not_i       ! SSL thicknes, sea ice (Grenfell Maykut 0.1 m)
+0.10
+# rad_kappa_s_su_d ! surface extinction coefficient, dry snow (Jarvinen 73 m-1, Pogson 63.2373)  (EXTC only)
+63.2373
+# rad_kappa_s_su_m ! surface extinction coefficient, melting snow (Jarvinen 51 m-1)              (EXTC only)
+63.2373
+# rad_kappa_i_su_d ! surface extinction coefficient, cold ice (io = 0.30 for 10 cm -> 12.03 m-1) (EXTC only)
+12.03
+# rad_kappa_i_su_m ! surface extinction coefficient, melting ice                                 (EXTC only)
+12.03
+# rad_kappa_s_de_d ! depth extinction coefficient in dry snow (Jarvinen 24 m-1, Pogson 14, Nicolaus-analysis 7.33)
+7.33
+# rad_kappa_s_de_m ! depth extinction coefficient in melting snow (Jarvinen 7.8 m-1, Pogson 7.5, Perovich 24.28)
+7.33
+# rad_kappa_i_de_d ! attenuation coefficient in cold ice (Light et al., 2008 0.8 for visible radiation, Pogson 1.2, Nicolaus analysis, 0.4)
+0.6
+# rad_kappa_i_de_m ! attenuation coefficient in melting ice (Light et al., 2008 0.8 for visible radiation Pogson 0.8)
+0.6
+#
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1d	(revision 6)
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#   run.param (Barrow version)
+#------------------------------------------------------------------------------
+# contains information on the run itself
+#
+# exp_id	! name of the experiment
+LIM_BIO 
+# ddtb		! time step of the model (86400., 3600.)
+86400
+# nstart    ! first time step (def 673, 16/01/2009, 0:00)
+29
+# nend      ! last time step  (def 4321, 30/06/2009)
+180
+# nyear     ! initial year
+2009
+# nfr_out	! output frequency
+1
+# latitude	! latitude
+71.37
+# biological model ! 'NOBIO', 'KRILL', 'BFMSI'
+KRILL
+#------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1h
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1h	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/run.param.1h	(revision 6)
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#   run.param (Barrow version)
+#------------------------------------------------------------------------------
+# contains information on the run itself
+#
+# exp_id	! name of the experiment
+LIM_BIO 
+# ddtb		! time step of the model (86400., 3600.)
+3600
+# nstart    ! first time step (def 673, 16/01/2009, 0:00)
+673
+# nend      ! last time step  (def 4321, 30/06/2009)
+4321
+# nyear     ! initial year
+2009
+# nfr_out	! output frequency
+1
+# latitude	! latitude
+71.37
+# biological model ! 'NOBIO', 'KRILL', 'BFMSI'
+KRILL
+#------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/tracer.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/tracer.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/BARROW/source_3.20/tracer.param	(revision 6)
@@ -0,0 +1,34 @@
+#
+# tracer.param
+#
+# Parameter file for sea ice biogeochemistry ISPOL, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Initial and boundary values (not checked at ISPOL for carbonate system and gases)
+#---------------------------------------------------------------------------------
+#
+#  trc_nam    : tracer name in the code
+#  c_nc_name  : tracer name in the netcdf initialization file (if any)
+#  nn_init    : switch for initialization (0=from code, 1=read cst, 2=cc retrieved from stock=read cc.h_i, 3=profile read in netcdf file)
+#  c_i_ini    : initial ice concentration
+#  c_w_ini    : seawater concentration
+#  mixr_gas   : atmospheric mixing ratio
+#  dmol_gas   : molecular diffusivity (gas tracers only, from Broecker and Peng 74)
+#trc_nam | c_nc_name | nn_init | c_i_ini | c_w_ini | mixr_gas | dmol_gas |
+   'dSi'   'dsi'   1    2.05  12.79    0.       0.
+   'dIN'   'nox'   1    1.48   6.88    0.       0.
+   'dIP'   'po4'   1    0.18   1.28    0.       0.
+   'AoC'   'AoC'   1    1.63   0.02    0.       0.
+   'eoC'   'eoC'   1      0.    0.5    0.       0.
+   'DIC'   'DIC'   1    300.   2000.   0.       0.
+   'Alk'   'Alk'   1    400.   2200.   0.       0.
+   'CO2'   'CO2'   1      0.     10.   3.8e-4   0.94e-9 # the initial ice cc has no impact since recalculated from DIC and TA in ice_bio_diff
+   'Ika'   'Ika'   1      0.      0.   0.       0.
+   'Cal'   'Cal'   1   2210.  10600.   0.       0.
+   'Arg'   'Arg'   1     3.6     18.   0.00934  0.88e-9
+   'Oxy'   'Oxy'   1    71.4    357.   0.2095   1.17e-9 # not checked 
+   'Nit'   'Nit'   1     127.   635.   0.7808   0.95e-9 # not checked
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/bio.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/bio.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/bio.param	(revision 6)
@@ -0,0 +1,160 @@
+#
+# bio.param
+#
+# Parameter file for sea ice biogeochemistry ISPOL, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Type of model and fluxes
+#---------------------------------------------------------------------------------
+#
+# c_grid      : type of grid: multilayer 'ML', deformed three layer 'DL', skeletal 'SL', or biologically-active 'BA'
+ML
+# h_skel      : prescribed biologically active layers thickness (SL & DL)
+0.10
+# e_thr_bal   : prescribed permeability threshold for BAL
+0.05
+#
+#---------------------------------------------------------------------------------
+# Process switches
+#---------------------------------------------------------------------------------
+#
+# ln_trbo     : bottom entrapment for tracers or not
+.TRUE.
+# ln_trsi     : snow-ice entrapment for tracers or not
+.TRUE.
+# ln_trdiff   : diffusion of tracers or not
+.TRUE.
+# ln_trremp   : remapping of tracers or not
+.TRUE.
+# ln_lim_dsi  : limitation of growth by DSi or not
+.TRUE.
+# ln_lim_no3  : limitation of growth by NO3
+.TRUE.
+# ln_lim_po4  : limitation of growth by PO3
+.TRUE.
+# ln_lim_lig  : light limitation or not
+.TRUE.
+# ln_lim_tem  : temperature inhibition or not
+.TRUE.
+# ln_lim_sal  : brine salinity inhibition or not
+.TRUE.
+# ln_lys      : lysis or not
+.TRUE. 
+# ln_rem      : remineralization or not
+.TRUE. 
+# ln_syn      : diatom synthesis or not
+.TRUE. 
+# ln_bubform  : gas buble formation
+.TRUE. 
+# ln_bubrise  : gas buble ascent
+.TRUE. 
+# ln_gasflux  : gas flux to ATM
+.TRUE. 
+# ln_carbon   : activate carbon cycle
+.TRUE.
+# ln_ikaite   : activate CaCO3 precipitation
+.TRUE.
+#
+#---------------------------------------------------------------------------------
+# Gas exchange / carbonate system / ikaite 
+#---------------------------------------------------------------------------------
+#
+# i_gas_flux      : Type of gas flux (1=Noflux, 2=ice-atm diffusive flux)
+2
+# brines_ar       : Brines aspect ratio (vertical ellipsoid: <1; spheres: 1)
+1.00
+# bub_form_rate   : Gas Bubble formation rate (s-1) 2.5e-7
+2.5e-7 
+# bub_diss_rate   : Gas Bubble dissolution rate (s-1)  2.5e-3
+2.5e-3 
+# h_bl_gas        : Boundary layer thickness for diffusive gas flux (Moreau et al. 2005)
+0.5e-6
+# e_thr_gasflux   : Brine volume fraction threshold for gas fluxes
+0.05
+# e_thr_bubrise   : Brine volume fraction thershold for bubble rise
+0.10
+# sursat_gas      : Sursaturation tolerated in brines (1 = 100%)
+1.00
+ # nn_carbonate   : 1=Roy; 2=Mehrbach equilibration CO2 constants; Mehrbach (2) is default
+2
+ # caco3_time     : CaCO3 precipitation/dissolution time scale rate (360000s=100h by default)
+360000.
+#
+#---------------------------------------------------------------------------------
+# Physiological parameters
+#---------------------------------------------------------------------------------
+#
+# nn_bio_opt  : type of microbial formulation (0=NP; 1=NPD Redfield)
+1
+#--- Bio-optical parameters
+#
+# astar_alg   : specific attenuation coefficient ( m-1 / ( mg chla m-3 ) ) - 0.01 Tedesco
+0.005
+# fdet_alg    : fraction of detrital radiation absorption versus algal absorption - 0.2 (Arrigo et al 1993)
+0.2
+#
+#--- Growth, loss, remineralization
+#
+# pp_presc    : prescribed GPP (ln_syn = false, mmol C m-3 s-1 ) DEFLT 1.0e-5
+0.0e-5       
+# mumax_bio   : maximum specific growth rate (s-1) ( Sarthou 5e-6 -> 3.8e-5 )
+1.00e-5
+# klys_bio    : loss rate (s-1) ( Sarthou  5.8e-8 -> 2.75e-6 )
+1.00e-6
+# krsp_bio    : respiration rate (s-1) 
+1.0e-6
+# krem_bio    : remineralization rate for carbon (2.0e-7 Moreau et al Elementa Oxy 2015)
+5.0e-6
+# frem_bio    : Fraction of nutrient loss that is remineralized in case of an N-P formulation
+1.00
+#
+#--- Photosynthesis / light limitation
+#
+# nn_phs      : type of photosynthesis parameterization (1-4)
+4
+# ek_bio      : Light adaptation parameter (nn_phs = 1, muE m-2 s-1) - DEFLT 2
+2
+# alpha_bio   : Photosynthetic efficiency (nn_phs > 1, gC/gchla/s/(muE/m2/s)) DEFLT 1.8e-4 - Fragiliariopsis 5.56e-5 (Mar FM)
+2.50e-5
+# chla_c      : Chl/C in ice algae (g/g) - DEFLT 0.05 - Loern 95 0.003 - 0.05 (applies only for nn_phs = 1-3)
+0.05
+# Estar       : PAR value at which Chl/C=min (nn_phs = 4) 360.
+40. 
+# nn_lys      : type of lysis [ 1: klys_bio prescribed; 2: klys_bio*exp(rg_bio*T) ]
+2
+# nn_rem      : type of remineralization [1: krem_bio prescribed; 2: krem_bio*exp(rg_bac*T) ]
+2
+#
+#--- Redfield ratios
+#
+# si_c        : silicon to carbon molar ratio in diatoms (mol/mol) - 0.11 Sarthou 2005
+0.11
+# no3_c       : nitrogen to carbon molar ratio in diatoms (mol/mol) - 0.14 Sarthou 2005; Redf - 0.151
+0.14
+# po4_c       : phosphorus to carbon molar ratio in diatoms (mol/mol) - 0.014 Sarthou 2005; 0.0094
+0.014
+# oxy_c       : oxygen release to carbon uptake ratio during photosynthesis (mol/mol) - Redf = 138/106 = 1.30 / Sarmiento Gruber 2006 150/106 = 1.41, Anderson et al
+1.30 
+#
+#--- Nutrient limitation, temperature and salinity inhibition
+#
+# khs_si_bio  : halfsat cst for Si uptake (micrmol m-3) - 3.9 Sarthou et al
+3.9
+# khs_n_bio   : halfsat cst for N uptake (micrmol m-3)  - 1.6 Sarthou et al
+1.6
+# khs_p_bio   : halfsat cst for P uptake (micrmol m-3)  - 0.24 Sarthou et al.
+0.24
+# rg_bio      : Temperature coefficient for algal physiological processes (0.0633 degC-1; Eppley, 1972)
+0.0633
+# rg_bac      : Temperature coefficient for bacterial respiration (0.41 degC-1; Moreau et al, Elementa 2015)
+0.41
+# nn_lim_sal  : Salinity lim. 1=Power-log gaussian, Arrigo 93 data; 2=Gaussian
+1
+# lim_sal_wid : Width of the limitation function (nn_lim_sal=2)
+20.0
+# lim_sal_smax: Salinity where limitation function equals 1 (nn_lim_sal=2)
+34.0
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/forcing.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/forcing.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/forcing.param.1d	(revision 6)
@@ -0,0 +1,43 @@
+#--------------------------------------------------------------------------------------------------
+# Parameter file for forcing
+# LIM1D, version source_3.04 - ISPOL forcing
+#--------------------------------------------------------------------------------------------------
+# ts_forc	time step of the forcing
+86400.0
+# n0_forc	number of the first time step in forcing file wrt XXXX ????
+1
+# n1_forc	number of the forcing.nc last time step relative to XXXX ????
+366
+#--------------------------------------------------------------------------------------------------
+# forc_swi 	0=read in nc, 1-N=computed, 99=prescribed
+# forc_uni 	multiplication factor compared to SI units
+# forc_val      constant value in case of prescribed value (forc_swi = 99)
+#--------------------------------------------------------------------------------------------------
+# forc_swi	forc_uni 	forc_val
+# shortwave radiation (W/m2) ; 1=Shine; 2=Zillmann
+1	1.0	0.0
+# longwave radiation (W/m2); 1=Efimova; 2=Berliand
+1	1.0	0.0
+# incident PAR (muE/m2/s); 1=Computed from shortwave
+1	1.0	0.0
+# air temperature (K)
+0	1.0	0.0
+# atmospheric pressure (Pa)
+0	1.0	0.0
+# specific humidity (kg/kg) ! there is a bias at ISPOL
+0	1.00  0.0
+# wind speed (m/s)
+0	1.0	0.0
+# cloudiness (0-1)
+0	1.0	0.0
+# oceanic heat flux (W/m2) ; 5. is the ref
+99	1.0	12.00
+# snowfall (dimensions=length/timestep) 0.012 - 1h
+0	0.25000	0.0
+# albedo (0-1); 1=Shine & Henderson-Sellers, 2=parameterized using obs from ISPOL
+2	1.0	0.00
+#--------------------------------------------------------------------------------------------------
+# Some parameters
+#--------------------------------------------------------------------------------------------------
+# opt_dept : optical depth (m) in Efimova 1961 parameterization; SIMBA - 16.297; ISPOL - ; BARROW - WHY 30. ?
+12.0
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/icephys.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/icephys.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/icephys.param	(revision 6)
@@ -0,0 +1,96 @@
+#
+# icephys.param - ISPOL
+#
+# Parameter file for sea ice physics, source v2.42
+#
+# (c) Martin Vancoppenolle, Oct 2011, Louvain-la-Neuve, Belgium
+#
+#==================================================================================================
+#
+#--------------------------------------------------------------------------------------------------
+# General parameters
+#--------------------------------------------------------------------------------------------------
+#
+# nlay_i        ! number of layers in the ice
+10
+# nlay_s        ! number of layers in the snow
+1
+# parsub	! switch for snow sublimation or not ! should not be used anymore
+0.0
+# ln_evap       ! switch for snow summer evaporation or not
+.TRUE.
+# tbq_ano       ! prescribed air temperature anomaly (K)
+0.0
+#
+#--------------------------------------------------------------------------------------------------
+# Ice desalination
+#--------------------------------------------------------------------------------------------------
+#
+# ln_grd        ! gravity drainage or not
+.TRUE.
+# ln_flu        ! flushing or not
+.TRUE.
+# ln_flo        ! flooding or not
+.TRUE.
+# flu_beta      ! fraction of meltwater percolating in summer
+0.3
+# e_thr_flu     ! permeability threshold for flushing
+0.05
+# frtr_si_phy   ! fraction of salt trapped in snow-ice
+1.0
+# d_br_mol      ! molecular diffusivity of brine (def:1.0e-9, obs: 6.8e-10)
+6.8e-10
+# d_br_tur      ! turbulent diffusivity of brine (def: 1.0e-6) 3.0e-7 1.0e-7
+5.0e-7
+# ra_c          ! critical rayleigh number for brine convection (def: 5, obs: 10)
+7
+# ra_smooth     ! hyperbolic tangent coefficient for turbulent diffusivity (def:1)
+0.6
+# gravdr        ! type of gravity drainage 'CW' for Cox Weeks 88 or 'RA' for Rayleigh-number based
+RA
+# delta_cw      ! CW88 grav. drainage eff.(1.68e-7 for CW88 or 0.588e-7 for V08 value)
+1.68e-7
+#
+#--------------------------------------------------------------------------------------------------
+# Radiative transfer (SSL = surface scattering layer)
+#--------------------------------------------------------------------------------------------------
+#
+# emig          ! Surface emissivity (past 0.995)
+0.995
+# fpar_fsw      ! Visible energetic ratio (Fpar/Fsw, J/J) = 0.475 (Frouin Pinker 95)
+0.475
+# qpar_fsw      ! Quantum energetic ratio (Qpar/Fsw, µE/J) = 2.33 (Vancoppenollet al 2011)
+2.33
+# c_rad_scheme  ! use surface transmission parameter ('INOT'), use SSL extinction coefficients ('EXTC')
+INOT
+# c_rad_discr   ! discretization of radiation based on absorption ('ABS') or on transmission ('TRA')
+TRA
+# rad_inot_s_dry ! surface transmission parameter, dry snow, visible range (INOT ONLY) ! 0.22
+0.22
+# rad_inot_s_wet ! surface transmission parameter, wet snow, visible range (INOT ONLY) ! 0.22
+0.22
+# rad_inot_i_dry ! surface transmission parameter, dry ice, visible range (INOT only). 
+0.58
+# rad_inot_i_wet ! surface transmission parameter, wet ice, visible range (INOT only). 
+0.96
+# h_not_s       ! SSL thickness, snow (Perovich 07 0.03 m)
+0.03
+# h_not_i       ! SSL thicknes, sea ice (Grenfell Maykut 0.1 m)
+0.10
+# rad_kappa_s_su_d ! surface extinction coefficient, dry snow (Jarvinen 73 m-1, Pogson 63.2373)  (EXTC only)
+63.2373
+# rad_kappa_s_su_m ! surface extinction coefficient, melting snow (Jarvinen 51 m-1)              (EXTC only)
+63.2373
+# rad_kappa_i_su_d ! surface extinction coefficient, cold ice (io = 0.30 for 10 cm -> 12.03 m-1) (EXTC only)
+12.03
+# rad_kappa_i_su_m ! surface extinction coefficient, melting ice                                 (EXTC only)
+12.03
+# rad_kappa_s_de_d ! depth extinction coefficient in dry snow (Jarvinen 24 m-1, Pogson 14, Nicolaus-analysis 7.33)
+7.33
+# rad_kappa_s_de_m ! depth extinction coefficient in melting snow (Jarvinen 7.8 m-1, Pogson 7.5, Perovich 24.28)
+7.33 
+# rad_kappa_i_de_d ! attenuation coefficient in cold ice (Light et al., 2008 0.8 for visible radiation, Pogson 1.2, Nicolaus analysis, 0.4)
+0.6
+# rad_kappa_i_de_m ! attenuation coefficient in melting ice (Light et al., 2008 0.8 for visible radiation Pogson 0.8)
+0.6
+#
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.1d	(revision 6)
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#   run.param (ISPOL version)
+#------------------------------------------------------------------------------
+# contains information on the run itself
+#
+# exp_id	! name of the experiment
+LIM_BIO 
+# ddtb		! time step of the model (86400., 3600.)
+86400.
+# nstart    ! first time step (44,1057)
+44
+# nend      ! last time step  (365,8760) ! 408 for standard
+408 
+# nyear     ! initial year
+2004
+# nfr_out	! output frequency
+1
+# latitude	! latitude
+-68.0
+# biological model ! 'NOBIO', 'KRILL', 'BFMSI'
+KRILL
+#------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.summer.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.summer.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/run.param.summer.1d	(revision 6)
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#   run.param (ISPOL version)
+#------------------------------------------------------------------------------
+# contains information on the run itself
+#
+# exp_id	! name of the experiment
+LIM_BIO 
+# ddtb		! time step of the model (86400., 3600.)
+86400.
+# nstart    ! first time step (44,1057)
+333
+# nend      ! last time step  (365,8760)
+408
+# nyear     ! initial year
+2004
+# nfr_out	! output frequency
+1
+# latitude	! latitude
+-68.0
+# biological model ! 'NOBIO', 'KRILL', 'BFMSI'
+KRILL
+#------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/tracer.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/tracer.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/ISPOL/source_3.20/tracer.param	(revision 6)
@@ -0,0 +1,34 @@
+#
+# tracer.param
+#
+# Parameter file for sea ice biogeochemistry ISPOL, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Initial and boundary values (not checked at ISPOL for carbonate system and gases)
+#---------------------------------------------------------------------------------
+#
+#  trc_nam    : tracer name in the code
+#  c_nc_name  : tracer name in the netcdf initialization file (if any)
+#  nn_init    : switch for initialization (0=from code, 1=read cst, 2=cc retrieved from stock=read cc.h_i, 3=profile read in netcdf file)
+#  c_i_ini    : initial ice concentration
+#  c_w_ini    : seawater concentration
+#  mixr_gas   : atmospheric mixing ratio
+#  dmol_gas   : molecular diffusivity (gas tracers only, from Broecker and Peng 74)
+#trc_nam | c_nc_name | nn_init | c_i_ini | c_w_ini | mixr_gas | dmol_gas |
+   'dSi'   'dsi'   1   19.90  51.25    0.       0.
+   'dIN'   'nox'   1   10.44  26.90    0.       0.
+   'dIP'   'po4'   1    0.91   2.35    0.       0.
+   'AoC'   'AoC'   1    0.01   0.05    0.       0.
+   'eoC'   'eoC'   1      0.    0.5    0.       0.
+   'DIC'   'DIC'   1    800.   2000.   0.       0.
+   'Alk'   'Alk'   1    880.   2200.   0.       0.
+   'CO2'   'CO2'   1      0.     10.   3.8e-4   0.94e-9 # the initial ice cc has no impact since recalculated from DIC and TA in ice_bio_diff
+   'Ika'   'Ika'   1      0.      0.   0.       0.
+   'Cal'   'Cal'   1   4240.  10600.   0.       0.
+   'Arg'   'Arg'   1     7.2     18.   0.00934  0.88e-9
+   'Oxy'   'Oxy'   1    71.4    357.   0.2095   1.17e-9 # not checked 
+   'Nit'   'Nit'   1     127.   635.   0.7808   0.95e-9 # not checked
Index: /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/bio.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/bio.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/bio.param	(revision 6)
@@ -0,0 +1,160 @@
+#
+# bio.param
+#
+# Parameter file for sea ice biogeochemistry ISPOL, source v3.20
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Type of model and fluxes
+#---------------------------------------------------------------------------------
+#
+# c_grid      : type of grid: multilayer 'ML', deformed three layer 'DL', skeletal 'SL', or biologically-active 'BA'
+ML
+# h_skel      : prescribed biologically active layers thickness (SL & DL)
+0.10
+# e_thr_bal   : prescribed permeability threshold for BAL
+0.05
+#
+#---------------------------------------------------------------------------------
+# Process switches
+#---------------------------------------------------------------------------------
+#
+# ln_trbo     : bottom entrapment for tracers or not
+.TRUE.
+# ln_trsi     : snow-ice entrapment for tracers or not
+.TRUE.
+# ln_trdiff   : diffusion of tracers or not
+.TRUE.
+# ln_trremp   : remapping of tracers or not
+.TRUE.
+# ln_lim_dsi  : limitation of growth by DSi or not
+.TRUE.
+# ln_lim_no3  : limitation of growth by NO3
+.TRUE.
+# ln_lim_po4  : limitation of growth by PO3
+.TRUE.
+# ln_lim_lig  : light limitation or not
+.TRUE.
+# ln_lim_tem  : temperature inhibition or not
+.TRUE.
+# ln_lim_sal  : brine salinity inhibition or not
+.TRUE.
+# ln_lys      : lysis or not
+.TRUE. 
+# ln_rem      : remineralization or not
+.TRUE. 
+# ln_syn      : diatom synthesis or not
+.TRUE. 
+# ln_bubform  : gas buble formation
+.TRUE. 
+# ln_bubrise  : gas buble ascent
+.TRUE. 
+# ln_gasflux  : gas flux to ATM
+.TRUE. 
+# ln_carbon   : activate carbon cycle
+.TRUE.
+# ln_ikaite   : activate CaCO3 precipitation
+.TRUE.
+#
+#---------------------------------------------------------------------------------
+# Gas exchange / carbonate system / ikaite 
+#---------------------------------------------------------------------------------
+#
+# i_gas_flux      : Type of gas flux (1=Noflux, 2=ice-atm diffusive flux)
+2
+# brines_ar       : Brines aspect ratio (vertical ellipsoid: <1; spheres: 1)
+1.00
+# bub_form_rate   : Gas Bubble formation rate (s-1) 2.5e-7
+2.5e-7 
+# bub_diss_rate   : Gas Bubble dissolution rate (s-1)  2.5e-3
+2.5e-3 
+# h_bl_gas        : Boundary layer thickness for diffusive gas flux (Moreau et al. 2005)
+0.5e-6
+# e_thr_gasflux   : Brine volume fraction threshold for gas fluxes
+0.05
+# e_thr_bubrise   : Brine volume fraction thershold for bubble rise
+0.10
+# sursat_gas      : Sursaturation tolerated in brines (1 = 100%)
+1.00
+ # nn_carbonate   : 1=Roy; 2=Mehrbach equilibration CO2 constants; Mehrbach (2) is default
+2
+ # caco3_time     : CaCO3 precipitation/dissolution time scale rate (360000s=100h by default)
+360000.
+#
+#---------------------------------------------------------------------------------
+# Physiological parameters
+#---------------------------------------------------------------------------------
+#
+# nn_bio_opt  : type of biological model (0=NP; 1=NPD Redfield; 2=NPD + Si; 3=NPD non-RedF; 4=NPD n.r + iron, 5=carbon cycle & gases)
+5
+#--- Bio-optical parameters
+#
+# astar_alg   : specific attenuation coefficient ( m-1 / ( mg chla m-3 ) ) - 0.01 Tedesco
+0.005
+# fdet_alg    : fraction of detrital radiation absorption versus algal absorption - 0.2 (Arrigo et al 1993)
+0.2
+#
+#--- Growth, loss, remineralization
+#
+# pp_presc    : prescribed GPP (ln_syn = false, mmol C m-3 s-1 ) DEFLT 1.0e-5
+0.0e-5       
+# mumax_bio   : maximum specific growth rate (s-1) ( Sarthou 5e-6 -> 3.8e-5 )
+1.00e-5
+# klys_bio    : loss rate (s-1) ( Sarthou  5.8e-8 -> 2.75e-6 )
+1.00e-6
+# krsp_bio    : respiration rate (s-1) 
+1.0e-6
+# krem_bio    : remineralization rate for carbon (2.0e-7 Moreau et al Elementa Oxy 2015)
+5.0e-6
+# frem_bio    : Fraction of nutrient loss that is remineralized in case of an N-P formulation
+1.00
+#
+#--- Photosynthesis / light limitation
+#
+# nn_phs      : type of photosynthesis parameterization (1-4)
+4
+# ek_bio      : Light adaptation parameter (nn_phs = 1, muE m-2 s-1) - DEFLT 2
+2
+# alpha_bio   : Photosynthetic efficiency (nn_phs > 1, gC/gchla/s/(muE/m2/s)) DEFLT 1.8e-4 - Fragiliariopsis 5.56e-5 (Mar FM)
+2.50e-5
+# chla_c      : Chl/C in ice algae (g/g) - DEFLT 0.05 - Loern 95 0.003 - 0.05 (applies only for nn_phs = 1-3)
+0.05
+# Estar       : PAR value at which Chl/C=min (nn_phs = 4) 360.
+40. 
+# nn_lys      : type of lysis [ 1: klys_bio prescribed; 2: klys_bio*exp(rg_bio*T) ]
+2
+# nn_rem      : type of remineralization [1: krem_bio prescribed; 2: krem_bio*exp(rg_bac*T) ]
+2
+#
+#--- Redfield ratios
+#
+# si_c        : silicon to carbon molar ratio in diatoms (mol/mol) - 0.11 Sarthou 2005
+0.11
+# no3_c       : nitrogen to carbon molar ratio in diatoms (mol/mol) - 0.14 Sarthou 2005; Redf - 0.151
+0.14
+# po4_c       : phosphorus to carbon molar ratio in diatoms (mol/mol) - 0.014 Sarthou 2005; 0.0094
+0.014
+# oxy_c       : oxygen release to carbon uptake ratio during photosynthesis (mol/mol) - Redf = 138/106 = 1.30 / Sarmiento Gruber 2006 150/106 = 1.41, Anderson et al
+1.30 
+#
+#--- Nutrient limitation, temperature and salinity inhibition
+#
+# khs_si_bio  : halfsat cst for Si uptake (micrmol m-3) - 3.9 Sarthou et al
+3.9
+# khs_n_bio   : halfsat cst for N uptake (micrmol m-3)  - 1.6 Sarthou et al
+1.6
+# khs_p_bio   : halfsat cst for P uptake (micrmol m-3)  - 0.24 Sarthou et al.
+0.24
+# rg_bio      : Temperature coefficient for algal physiological processes (0.0633 degC-1; Eppley, 1972)
+0.0633
+# rg_bac      : Temperature coefficient for bacterial respiration (0.41 degC-1; Moreau et al, Elementa 2015)
+0.41
+# nn_lim_sal  : Salinity lim. 1=Power-log gaussian, Arrigo 93 data; 2=Gaussian
+1
+# lim_sal_wid : Width of the limitation function (nn_lim_sal=2)
+20.0
+# lim_sal_smax: Salinity where limitation function equals 1 (nn_lim_sal=2)
+34.0
Index: /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/forcing.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/forcing.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/forcing.param.1d	(revision 6)
@@ -0,0 +1,43 @@
+#--------------------------------------------------------------------------------------------------
+# Parameter file for forcing
+# LIM1D, version source_3.04 - ISPOL forcing
+#--------------------------------------------------------------------------------------------------
+# ts_forc	time step of the forcing
+86400.0
+# n0_forc	number of the first time step in forcing file wrt XXXX ????
+263
+# n1_forc	number of the forcing.nc last time step relative to XXXX ????
+340
+#--------------------------------------------------------------------------------------------------
+# forc_swi 	0=read in nc, 1-N=computed, 99=prescribed
+# forc_uni 	multiplication factor compared to SI units
+# forc_val      constant value in case of prescribed value (forc_swi = 99)
+#--------------------------------------------------------------------------------------------------
+# forc_swi	forc_uni 	forc_val
+# shortwave radiation (W/m2) ; 1=Shine; 2=Zillmann
+0	1.0	0.0
+# longwave radiation (W/m2); 1=Efimova; 2=Berliand
+0	1.0	0.0
+# incident PAR (muE/m2/s); 1=Computed from shortwave
+1	1.0	0.0
+# air temperature (K)
+0	1.0	0.0
+# atmospheric pressure (Pa)
+0	1.0	0.0
+# specific humidity (kg/kg) ! there is a bias at ISPOL
+0	1.00  0.0
+# wind speed (m/s)
+0	1.0	0.0
+# cloudiness (0-1)
+99  1.0	1.0
+# oceanic heat flux (W/m2) ; 5. is the ref
+99	1.0	4.
+# snowfall (dimensions=length/timestep) 0.012 - 1h
+99  1.0 0.0
+# albedo (0-1); 1=Shine & Henderson-Sellers, 2=parameterized using obs from ISPOL
+1	1.0	0.00
+#--------------------------------------------------------------------------------------------------
+# Some parameters
+#--------------------------------------------------------------------------------------------------
+# opt_dept : optical depth (m) in Efimova 1961 parameterization; SIMBA - 16.297; ISPOL - ; BARROW - WHY 30. ?
+12.0
Index: /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/icephys.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/icephys.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/icephys.param	(revision 6)
@@ -0,0 +1,96 @@
+#
+# icephys.param - ISPOL
+#
+# Parameter file for sea ice physics, source v2.42
+#
+# (c) Martin Vancoppenolle, Oct 2011, Louvain-la-Neuve, Belgium
+#
+#==================================================================================================
+#
+#--------------------------------------------------------------------------------------------------
+# General parameters
+#--------------------------------------------------------------------------------------------------
+#
+# nlay_i        ! number of layers in the ice
+10
+# nlay_s        ! number of layers in the snow
+1
+# parsub	! switch for snow sublimation or not ! should not be used anymore
+0.0
+# ln_evap       ! switch for snow summer evaporation or not
+.TRUE.
+# tbq_ano       ! prescribed air temperature anomaly (K)
+0.0
+#
+#--------------------------------------------------------------------------------------------------
+# Ice desalination
+#--------------------------------------------------------------------------------------------------
+#
+# ln_grd        ! gravity drainage or not
+.TRUE.
+# ln_flu        ! flushing or not
+.TRUE.
+# ln_flo        ! flooding or not
+.TRUE.
+# flu_beta      ! fraction of meltwater percolating in summer
+0.3
+# e_thr_flu     ! permeability threshold for flushing
+0.05
+# frtr_si_phy   ! fraction of salt trapped in snow-ice
+1.0
+# d_br_mol      ! molecular diffusivity of brine (def:1.0e-9, obs: 6.8e-10)
+6.8e-10
+# d_br_tur      ! turbulent diffusivity of brine (def: 1.0e-6) 3.0e-7 1.0e-7
+5.0e-7
+# ra_c          ! critical rayleigh number for brine convection (def: 5, obs: 10)
+7
+# ra_smooth     ! hyperbolic tangent coefficient for turbulent diffusivity (def:1)
+0.6
+# gravdr        ! type of gravity drainage 'CW' for Cox Weeks 88 or 'RA' for Rayleigh-number based
+RA
+# delta_cw      ! CW88 grav. drainage eff.(1.68e-7 for CW88 or 0.588e-7 for V08 value)
+1.68e-7
+#
+#--------------------------------------------------------------------------------------------------
+# Radiative transfer (SSL = surface scattering layer)
+#--------------------------------------------------------------------------------------------------
+#
+# emig          ! Surface emissivity (past 0.995)
+0.995
+# fpar_fsw      ! Visible energetic ratio (Fpar/Fsw, J/J) = 0.475 (Frouin Pinker 95)
+0.475
+# qpar_fsw      ! Quantum energetic ratio (Qpar/Fsw, µE/J) = 2.33 (Vancoppenollet al 2011)
+2.33
+# c_rad_scheme  ! use surface transmission parameter ('INOT'), use SSL extinction coefficients ('EXTC')
+INOT
+# c_rad_discr   ! discretization of radiation based on absorption ('ABS') or on transmission ('TRA')
+TRA
+# rad_inot_s_dry ! surface transmission parameter, dry snow, visible range (INOT ONLY) ! 0.22
+0.22
+# rad_inot_s_wet ! surface transmission parameter, wet snow, visible range (INOT ONLY) ! 0.22
+0.22
+# rad_inot_i_dry ! surface transmission parameter, dry ice, visible range (INOT only). 
+0.58
+# rad_inot_i_wet ! surface transmission parameter, wet ice, visible range (INOT only). 
+0.96
+# h_not_s       ! SSL thickness, snow (Perovich 07 0.03 m)
+0.03
+# h_not_i       ! SSL thicknes, sea ice (Grenfell Maykut 0.1 m)
+0.10
+# rad_kappa_s_su_d ! surface extinction coefficient, dry snow (Jarvinen 73 m-1, Pogson 63.2373)  (EXTC only)
+63.2373
+# rad_kappa_s_su_m ! surface extinction coefficient, melting snow (Jarvinen 51 m-1)              (EXTC only)
+63.2373
+# rad_kappa_i_su_d ! surface extinction coefficient, cold ice (io = 0.30 for 10 cm -> 12.03 m-1) (EXTC only)
+12.03
+# rad_kappa_i_su_m ! surface extinction coefficient, melting ice                                 (EXTC only)
+12.03
+# rad_kappa_s_de_d ! depth extinction coefficient in dry snow (Jarvinen 24 m-1, Pogson 14, Nicolaus-analysis 7.33)
+7.33
+# rad_kappa_s_de_m ! depth extinction coefficient in melting snow (Jarvinen 7.8 m-1, Pogson 7.5, Perovich 24.28)
+7.33 
+# rad_kappa_i_de_d ! attenuation coefficient in cold ice (Light et al., 2008 0.8 for visible radiation, Pogson 1.2, Nicolaus analysis, 0.4)
+0.6
+# rad_kappa_i_de_m ! attenuation coefficient in melting ice (Light et al., 2008 0.8 for visible radiation Pogson 0.8)
+0.6
+#
Index: /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/run.param.1d
===================================================================
--- /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/run.param.1d	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/run.param.1d	(revision 6)
@@ -0,0 +1,22 @@
+#------------------------------------------------------------------------------
+#   run.param (ISPOL version)
+#------------------------------------------------------------------------------
+# contains information on the run itself
+#
+# exp_id	! name of the experiment
+YROSIAE 
+# ddtb		! time step of the model (86400., 3600.)
+86400.
+# nstart    ! first time step (44,1057)
+263
+# nend      ! last time step  (365,8760) ! 408 for standard
+339 
+# nyear     ! initial year
+2012
+# nfr_out	! output frequency
+1
+# latitude	! latitude
+-77.63624
+# biological model ! 'NOBIO', 'KRILL', 'BFMSI'
+KRILL
+#------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/tracer.param
===================================================================
--- /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/tracer.param	(revision 6)
+++ /tags/LIM1D_v3.20/INPUT/YROSIAE/source_3.20/tracer.param	(revision 6)
@@ -0,0 +1,34 @@
+#
+# tracer.param
+#
+# Parameter file for sea ice biogeochemistry YROSIAE, source v3.20 !!! prescribed concentrations are completely unchecked
+#
+# (c) Martin, Dec 2015, Paris
+#
+#=================================================================================
+#
+#---------------------------------------------------------------------------------
+# Initial and boundary values (not checked at ISPOL for carbonate system and gases)
+#---------------------------------------------------------------------------------
+#
+#  trc_nam    : tracer name in the code
+#  c_nc_name  : tracer name in the netcdf initialization file (if any)
+#  nn_init    : switch for initialization (0=from code, 1=read cst, 2=cc retrieved from stock=read cc.h_i, 3=profile read in netcdf file)
+#  c_i_ini    : initial ice concentration
+#  c_w_ini    : seawater concentration
+#  mixr_gas   : atmospheric mixing ratio
+#  dmol_gas   : molecular diffusivity (gas tracers only, from Broecker and Peng 74)
+#trc_nam | c_nc_name | nn_init | c_i_ini | c_w_ini | mixr_gas | dmol_gas |
+   'dSi'   'dsi'   3   19.90  51.25    0.       0.
+   'dIN'   'nox'   3   10.44  26.90    0.       0.
+   'dIP'   'po4'   3    0.91   2.35    0.       0.
+   'AoC'   'AoC'   3    0.01   0.05    0.       0.
+   'eoC'   'eoC'   3      0.    0.5    0.       0.
+   'DIC'   'DIC'   1    800.   2000.   0.       0.
+   'Alk'   'Alk'   1    880.   2200.   0.       0.
+   'CO2'   'CO2'   1      0.     10.   3.8e-4   0.94e-9 # the initial ice cc has no impact since recalculated from DIC and TA in ice_bio_diff
+   'Ika'   'Ika'   1      0.      0.   0.       0.
+   'Cal'   'Cal'   1  1845.6  10600.   0.       0.
+   'Arg'   'Arg'   1     7.2     18.   0.00934  0.88e-9
+   'Oxy'   'Oxy'   1    71.4    357.   0.2095   1.17e-9 # not checked 
+   'Nit'   'Nit'   1     127.   635.   0.7808   0.95e-9 # not checked
Index: /tags/LIM1D_v3.20/MAKE/Makefile
===================================================================
--- /tags/LIM1D_v3.20/MAKE/Makefile	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/Makefile	(revision 6)
@@ -0,0 +1,179 @@
+# Makefile created by mkmf $Id: mkmf,v 14.0 2007/03/20 22:13:27 fms Exp $ 
+
+include ./gfortran_mac.inc
+
+
+.DEFAULT:
+	-touch $@
+all: lim1d.x
+biolim.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f
+flx.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f
+forcing.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f
+ice_bio_column.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f
+ice_bio_conserv.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f
+ice_bio_diff.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f
+ice_bio_grid.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f
+ice_bio_ini.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f
+ice_bio_interp_bio2phy.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f
+ice_bio_interp_phy2bio.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f
+ice_bio_param.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f
+ice_bio_remap.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f
+ice_bio_sms.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f
+ice_brine.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f
+ice_carb_chem.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f
+ice_cons.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f
+ice_gas.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f
+ice_gas_column.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f
+ice_gas_solu.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f
+ice_ikaite.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f
+ice_output.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f
+ice_phy_grid.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f
+ice_phy_ini.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f
+ice_phy_param.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f
+ice_phy_relay.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f
+ice_phy_remap.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f
+ice_rad.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f
+ice_sal_column.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f
+ice_sal_conserv.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f
+ice_sal_diff.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f
+ice_sal_diff_CW.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f
+ice_th.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f
+ice_th_dh.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f
+ice_th_diff.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f lib_fortran.o
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f
+libUN.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.inc /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//netcdf.inc
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c -I/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20/	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f
+lib_fortran.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f
+pdecli.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f
+shine.o: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f
+	$(FC) $(FFLAGS) $(OTHERFLAGS) -c	/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f
+./ice_th.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f .
+./biolim.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f .
+./ice_ikaite.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f .
+./pdecli.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f .
+./ice_bio_sms.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f .
+./ice_sal_diff.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f .
+./ice_gas_column.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f .
+./libUN.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f .
+./libUN.inc: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.inc
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.inc .
+./ice_rad.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f .
+./ice_phy_ini.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f .
+./flx.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f .
+./ice_bio_interp_phy2bio.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f .
+./ice_output.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f .
+./ice_bio_column.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f .
+./ice_th_diff.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f .
+./ice_bio_diff.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f .
+./shine.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f .
+./ice_phy_param.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f .
+./ice_bio_grid.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f .
+./forcing.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f .
+./ice_bio_ini.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f .
+./ice_gas_solu.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f .
+./ice_sal_conserv.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f .
+./ice_bio_interp_bio2phy.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f .
+./ice_sal_column.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f .
+./ice_th_dh.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f .
+./ice_carb_chem.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f .
+./ice_phy_grid.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f .
+./ice_gas.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f .
+./ice_phy_relay.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f .
+./ice_phy_remap.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f .
+./ice_brine.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f .
+./ice_bio_conserv.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f .
+./lib_fortran.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f .
+./ice_bio_param.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f .
+./ice_sal_diff_CW.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f .
+./netcdf.inc: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//netcdf.inc
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//netcdf.inc .
+./ice_bio_remap.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f .
+./ice_cons.f: /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f
+	cp /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f .
+SRC = /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.inc /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//netcdf.inc
+OBJ = flx.o pdecli.o ice_bio_column.o ice_sal_conserv.o ice_phy_remap.o ice_carb_chem.o ice_brine.o ice_sal_diff_CW.o ice_bio_diff.o ice_th.o libUN.o ice_bio_interp_bio2phy.o ice_phy_param.o ice_bio_sms.o ice_gas_column.o ice_sal_column.o ice_th_dh.o ice_bio_conserv.o ice_ikaite.o ice_phy_relay.o ice_bio_remap.o ice_bio_ini.o ice_cons.o ice_th_diff.o ice_gas_solu.o lib_fortran.o ice_bio_interp_phy2bio.o ice_bio_grid.o ice_gas.o shine.o ice_phy_ini.o ice_phy_grid.o ice_sal_diff.o ice_bio_param.o biolim.o forcing.o ice_output.o ice_rad.o
+OFF = /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//biolim.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_ikaite.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//pdecli.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_sms.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//libUN.inc /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_rad.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_ini.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//flx.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_phy2bio.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_output.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_diff.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//shine.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_param.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_grid.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//forcing.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_ini.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas_solu.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_conserv.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_interp_bio2phy.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_column.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_th_dh.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_carb_chem.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_grid.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_gas.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_relay.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_phy_remap.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_brine.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_conserv.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_param.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_sal_diff_CW.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//netcdf.inc /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_bio_remap.f /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//ice_cons.f
+clean: neat
+	-rm -f .cppdefs *.com *.mod $(OBJ) lim1d.x
+neat:
+	-rm -f $(TMPFILES)
+localize: $(OFF)
+	cp $(OFF) .
+TAGS: $(SRC)
+	etags $(SRC)
+tags: $(SRC)
+	ctags $(SRC)
+lim1d.x: $(OBJ) 
+	$(LD) $(OBJ) -o lim1d.x  $(LDFLAGS)
Index: /tags/LIM1D_v3.20/MAKE/config_lim1d.sh
===================================================================
--- /tags/LIM1D_v3.20/MAKE/config_lim1d.sh	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/config_lim1d.sh	(revision 6)
@@ -0,0 +1,31 @@
+#!/bin/sh
+set -xv
+LIMDIR="/Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20/"
+archfile=./gfortran_mac.inc
+KEY_LIM=""
+cppdefs="${KEY_LIM}"
+
+#---------------------------------------------------------------------
+# other flags
+#---------------------------------------------------------------------
+oflags=""
+exe=lim1d.x
+
+#---------------------------------------------------------------------
+#create source file lists and exit
+#---------------------------------------------------------------------
+if [ $1 == "SRC" ]; then
+   find ${LIMDIR} -name "*.[fF]" -print > LIM_SRC.lst
+   find ${LIMDIR} -name "*.com" -print >> LIM_SRC.lst
+exit 0
+fi
+
+#---------------------------------------------------------------------
+# get common blocks
+#---------------------------------------------------------------------
+cp ${LIMDIR}/*.com .
+
+#---------------------------------------------------------------------
+# make makefile                                                                                                    
+#---------------------------------------------------------------------
+./mkmf -c "${cppdefs}" -o "${oflags}" -t ${archfile} -p ${exe} LIM_SRC.lst
Index: /tags/LIM1D_v3.20/MAKE/gfortran_mac.inc
===================================================================
--- /tags/LIM1D_v3.20/MAKE/gfortran_mac.inc	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/gfortran_mac.inc	(revision 6)
@@ -0,0 +1,9 @@
+FC=gfortran-mp-4.7
+LD=gfortran-mp-4.7
+AR=ar
+ARFLAGS=-r
+NCDF_LIB=-L/opt/local/lib -lnetcdf -lnetcdff -llapack
+NCDF_INC=-I/opt/local/include -I/opt/local/include -DNDEBUG
+CPPFLAGS=
+FFLAGS= -g -fbacktrace -C -fbounds-check -funroll-all-loops -fcray-pointer -ftree-vectorize -std=legacy -m64
+LDFLAGS= ${NCDF_INC} ${NCDF_LIB}
Index: /tags/LIM1D_v3.20/MAKE/ifort_esker.inc
===================================================================
--- /tags/LIM1D_v3.20/MAKE/ifort_esker.inc	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/ifort_esker.inc	(revision 6)
@@ -0,0 +1,8 @@
+FC=ifort
+LD=ifort
+AR=ar
+ARFLAGS=-r
+NCDF_LIB=-L/opt/netcdf/intel/lib -lnetcdff -llapack
+NCDF_INC=-I/opt/netcdf/intel/include
+FFLAGS=-O3
+LDFLAGS= ${NCDF_INC} ${NCDF_LIB}
Index: /tags/LIM1D_v3.20/MAKE/lib_fortran.mod
===================================================================
--- /tags/LIM1D_v3.20/MAKE/lib_fortran.mod	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/lib_fortran.mod	(revision 6)
@@ -0,0 +1,26 @@
+GFORTRAN module version '9' created from /Users/ioulianikolskaia/Boulot/CODES/LIM1D/2015_v3.20/SOURCES/source_3.20//lib_fortran.f
+MD5:3da1ff0b41ee6c844deeca18ea3cef5b -- If you edit this, you'll get what you deserve.
+
+(() () () () () () () () () () () () () () () () () () () () () () () ()
+() () ())
+
+()
+
+(('sign' 'lib_fortran' 2))
+
+()
+
+()
+
+()
+
+(2 'sign_1d' 'lib_fortran' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC
+DECL UNKNOWN 0 0 FUNCTION) (REAL 8 0 0 0 REAL ()) 3 0 (4 5) () 2 () () ()
+0 0)
+4 'pa' '' '' 3 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN UNKNOWN 0
+0 DUMMY) (REAL 8 0 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
+5 'pb' '' '' 3 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN UNKNOWN 0
+0 DUMMY) (REAL 8 0 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
+)
+
+()
Index: /tags/LIM1D_v3.20/MAKE/mkmf
===================================================================
--- /tags/LIM1D_v3.20/MAKE/mkmf	(revision 6)
+++ /tags/LIM1D_v3.20/MAKE/mkmf	(revision 6)
@@ -0,0 +1,465 @@
+#!/usr/bin/perl
+#-----------------------------------------------------------------------
+#              mkmf: Perl script for makefile construction
+#
+# AUTHOR: V. Balaji (v.balaji@noaa.gov)
+#         Princeton University/GFDL
+#
+# Full web documentation for mkmf:
+#     http://www.gfdl.noaa.gov/~vb/mkmf.html
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# For the full text of the GNU General Public License,
+# write to: Free Software Foundation, Inc.,
+#           675 Mass Ave, Cambridge, MA 02139, USA.
+#-----------------------------------------------------------------------
+
+$ENV{'LANG'} = 'C';
+require 5;
+use strict;
+use File::Basename;
+use Getopt::Std;
+use Config;			# use to put in platform-specific stuff
+use vars qw( $opt_a $opt_c $opt_d $opt_f $opt_l $opt_m $opt_o $opt_p $opt_t $opt_v $opt_x ); # declare these global to be shared with Getopt:Std
+
+#subroutines
+sub ensureTrailingSlash {
+#ensure trailing slash on directory names
+   local $/ = '/'; chomp @_[0]; @_[0] .= '/';
+}
+
+my $version = '$Id: mkmf,v 14.0 2007/03/20 22:13:27 fms Exp $ ';
+
+# initialize variables: use getopts for these
+getopts( 'a:c:dfm:o:p:t:vx' ) || die "\aSyntax: $0 [-a abspath] [-c cppdefs] [-d] [-f] [-m makefile] [-o otherflags] ][-p program] [-t template] [-v] [-x] [targets]\n";
+$opt_v = 1 if $opt_d;	# debug flag turns on verbose flag also
+print "$0 $version\n" if $opt_v;
+
+my $mkfile = $opt_m || 'Makefile';
+print "Making makefile $mkfile ...\n" if $opt_v;
+
+$opt_p = 'a.out' unless $opt_p;	# set default program name
+my @targets = '.';		# current working directory is always included in targets
+push @targets, @ARGV;		# then add remaining arguments on command line
+
+ensureTrailingSlash($opt_a) if $opt_a;
+
+#some generic declarations
+my( $file, $include, $line, $module, $name, $object, $path, $source, $suffix, $target, $word );
+my @list;
+#some constants
+my $endline = $/;
+my @src_suffixes = ( q/\.F/, q/\.F90/, q/\.c/, q/\.f/, q/\.f90/ );
+my @inc_suffixes = ( q/\.H/, q/\.fh/, q/\.h/, q/\.inc/, q/\.h90/ );
+# push @inc_suffixes, @src_suffixes; # sourcefiles can be includefiles too: DISALLOW, 6 May 2004
+# suffixes for the target (mkmf -p): if isn't on the list below it's a program
+my @tgt_suffixes = ( q/\.a/ );
+
+my %compile_cmd = (			# command to create .o file from a given source file suffix
+      q/.F/   => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) $(OTHERFLAGS) -c/,
+      q/.F90/ => q/$(FC) $(CPPDEFS) $(CPPFLAGS) $(FFLAGS) $(OTHERFLAGS) -c/,
+      q/.c/   => q/$(CC) $(CPPDEFS) $(CPPFLAGS) $(CFLAGS) $(OTHERFLAGS) -c/,
+      q/.f/   => q/$(FC) $(FFLAGS) $(OTHERFLAGS) -c/,
+      q/.f90/ => q/$(FC) $(FFLAGS) $(OTHERFLAGS) -c/              );
+my %delim_match = ( q/'/ => q/'/,	# hash to find includefile delimiter pair
+		    q/"/ => q/"/,
+		    q/</ => q/>/ );
+
+#formatting command for MAKEFILE, keeps very long lines to 256 characters
+format MAKEFILE =
+^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< \~
+$line
+.
+
+sub print_formatted_list{
+#this routine, in conjunction with the format line above, can be used to break up long lines
+# it is currently used to break up the potentially long defs of SRC, OBJ, CPPDEFS, etc.
+# not used for the dependency lists
+   $line = "@_";
+   local $: = " \t\n";		# the default formatting word boundary includes the hyphen, but not here
+   while ( $opt_f && length $line > 254 ) {
+      write MAKEFILE, $line;
+   }
+   print MAKEFILE $line unless $line eq '';
+   print MAKEFILE "\n";
+}
+
+#begin writing makefile
+open MAKEFILE, ">$mkfile" or die "\aERROR opening file $mkfile for writing: $!\n";
+printf MAKEFILE "# Makefile created by %s $version\n\n", basename($0);
+print  MAKEFILE "include $opt_t\n\n" if $opt_t; #include template if supplied
+print  MAKEFILE "SRCROOT = $opt_a\n\n" if $opt_a; # make abspath a variable
+if ( $opt_c ) {
+   if ( $Config{osname} eq 'aix' ) {
+      $opt_c .= ' -D__aix';
+#AIX fortran (xlf) requires -WF, in front, comma delimiter, no spaces
+      my $cppdefs_xlf = '-WF "' . $opt_c . '"';
+      $cppdefs_xlf =~ s/,/\\,/g; # escape any commas already there
+      $cppdefs_xlf =~ s/\s+/,/g; # replace whitespace with commas
+      &print_formatted_list("CPPDEFS_XLF = $cppdefs_xlf");
+      $compile_cmd{'.F'}   = q/$(FC) $(CPPDEFS_XLF) $(FFLAGS) $(OTHERFLAGS) -c/;
+      $compile_cmd{'.F90'} = q/$(FC) $(CPPDEFS_XLF) $(FFLAGS) $(OTHERFLAGS) -c/;
+   }
+   &print_formatted_list("CPPDEFS = $opt_c") if $opt_c;
+}
+print MAKEFILE "\nOTHERFLAGS = $opt_o" if $opt_o;
+print MAKEFILE "\n.DEFAULT:\n\t-touch \$@\n";
+print MAKEFILE "all: $opt_p\n"; # first target should be program, so you can type just 'make'
+
+#if cppdefs flag is present, look for changes in cppdefs
+my %chgdefs;
+if ( $opt_c ) {
+#split argument of -c into newdefs
+   my %newdefs;
+   foreach ( split /\s*-D/, $opt_c ) {
+      $newdefs{$_} = 1;
+   }
+#get olddefs from file .cppdefs
+   my %olddefs;
+   my $cppdefsfile = '.cppdefs';
+   if ( -f $cppdefsfile ) {
+      open CPPFILE, $cppdefsfile or die "\aERROR opening cppdefsfile $cppdefsfile: $!\n";
+      while ( <CPPFILE> ) {
+	 foreach $word ( split ) {
+	    $olddefs{$word} = 1;
+	 }
+      }
+      close CPPFILE;
+#get words that are not in both newdefs and olddefs
+#if you move this foreach{} outside the enclosing if{} then
+#   all cppdefs will be considered changed if there is no .cppdefs file.
+      foreach ( keys %newdefs, keys %olddefs ) {
+	 $chgdefs{$_} = 1 unless( $newdefs{$_} && $olddefs{$_} );
+      }
+   }
+#write current cppdefs list to file .cppdefs
+   open  CPPFILE, ">$cppdefsfile";
+   my @newdefs = keys %newdefs;
+   print CPPFILE " @newdefs\n";
+   close CPPFILE;
+   if( $opt_d ) {
+      @list = keys %newdefs; print "newdefs= @list\n";
+      @list = keys %olddefs; print "olddefs= @list\n";
+      @list = keys %chgdefs; print "chgdefs= @list\n";
+   }
+}
+delete $chgdefs{''};
+
+# get a list of sourcefiles to be treated from targets
+# (a sourcefile is any regular file with a suffix matching src_suffixes)
+# if target is a sourcefile, add to list
+# if target is a directory, get all sourcefiles there
+# if target is a regular file that is not a sourcefile, look for a
+#    sourcefile on last work of each line, rest of line (if present) is the
+#    compile command to apply to this file.
+#@sources will contain a unique list of sourcefiles in targets
+#@objects will contain corresponding objects
+
+#separate targets into directories and files
+my %scanned;			# list of directories/files already scanned
+my %actual_source_of;		# hash returning sourcefile from object
+my %source_of; # sourcefile from object, using SRCROOT variable if present
+my @includepaths;
+my $scanOrder = 0;              # used to remember order of directory scan
+foreach $target ( @targets ) {
+   print STDERR '.' unless $opt_v; # show progress on screen (STDERR is used because it is unbuffered)
+   if ( $opt_a and substr($target,0,1) ne '/' ) {
+      # if an abs_path exists, attach it to all relative paths
+      $target = $opt_a . $target;
+   }
+   ensureTrailingSlash($target) if( -d $target );
+   print "target=$target\n" if $opt_v;
+#directory
+   if ( -d $target && !$scanned{$target} ) {
+      print "Processing directory $target\n" if $opt_v;
+      opendir DIR, $target;
+      my @files = readdir DIR;
+#find all sourcefiles in directory DIR
+      foreach ( @files ) {
+	 ( $name, $path, $suffix ) = fileparse( "$target$_", @inc_suffixes );
+         push @includepaths, $target if $suffix; # is this line doing anything? looks like includepaths='' later...
+	 ( $name, $path, $suffix ) = fileparse( "$target$_", @src_suffixes );
+	 $object = "$name.o";
+	 if( $suffix && !$actual_source_of{$object} ) {
+	    if ( $opt_a and substr($path,0,1) ne '/' ) { # if an abs_path exists, attach it to all relative paths
+	       ensureTrailingSlash($path);
+               $path = '' if $path eq './';
+               $source_of{$object} = '$(SRCROOT)' . "$path$name$suffix";
+	       $path = $opt_a . $path;
+	    }
+            $actual_source_of{$object} = "$path$name$suffix";
+            $source_of{$object} = $actual_source_of{$object} unless $source_of{$object};
+         }
+      }
+      closedir DIR;
+      $scanned{$target} = $scanOrder++;
+   } elsif ( -f $target ) {
+#file: check if it is a sourcefile
+      ( $name, $path, $suffix ) = fileparse( $target, @src_suffixes );
+      $object = "$name.o";
+      if ( !$actual_source_of{$object} ) {
+	 if ( $suffix ) {
+	    $path = '' if $path eq './';
+	    if ( $opt_a and substr($path,0,1) ne '/' ) { # if an abs_path exists, attach it to all relative paths
+	       ensureTrailingSlash($path);
+               $source_of{$object} = '$(SRCROOT)' . "$path$name$suffix";
+	       $path = $opt_a . $path;
+	    }
+	    $actual_source_of{$object} = "$path$name$suffix";
+            $source_of{$object} = $actual_source_of{$object} unless $source_of{$object};
+	 } else {
+            ( $name, $path, $suffix ) = fileparse( $target, @inc_suffixes );
+            if ( ! $suffix ) {
+#not a sourcefile: assume it contains list of sourcefiles
+#specify files requiring special commands (e.g special compiler flags) thus:
+#   f90 -Oaggress a.f90
+#if last word on line is not a valid sourcefile, line is ignored
+               open CMDFILE, $target;
+               print "Reading commands from $target...\n" if $opt_v;
+               while ( <CMDFILE> ) {
+                  next if ( $_ eq "\n");
+                  $line = $_;
+                  my @wordlist = split;
+                  $file = @wordlist[$#wordlist]; # last word on line
+                  ( $name, $path, $suffix ) = fileparse( $file, @src_suffixes );
+                  print "file=$file suffix=$suffix in $target\n" if $opt_d;
+                  $object = "$name.o";
+                  if ( $suffix && !$actual_source_of{$object} ) {
+                     $path = '' if $path eq './';
+                     if ( $opt_a and ( substr($path,0,1) ne '/' ) ) { # if an abs_path exists, attach it to all relative paths
+                        ensureTrailingSlash($path);
+                        $source_of{$object} = '$(SRCROOT)' . "$path$name$suffix";
+                        $path = $opt_a . $path;
+                     }
+                     $actual_source_of{$object} = "$path$name$suffix";
+                     $source_of{$object} = $actual_source_of{$object} unless $source_of{$object};
+                     $scanned{$path} = $scanOrder++ unless $scanned{$path};
+#command for this file is all of line except the filename
+                     $line =~ /\s+$file/; $line=$`;
+                     if ( $line ) {
+                        $compile_cmd{"$name$suffix"} = $line;
+                        print "Special command for file $name$suffix: ($line)\n" if $opt_v;
+                     }
+                  }
+                  if ( ! $suffix ) { # look for include files
+                     ( $name, $path, $suffix ) = fileparse( $file, @inc_suffixes );
+                     if ( $opt_a and ( substr($path,0,1) ne '/' ) ) { # if an abs_path exists, attach it to all relative paths
+                        ensureTrailingSlash($path);
+                        $path = $opt_a . $path;
+                     }
+                     print "file=$file path=$path suffix=$suffix order=$scanOrder in $target\n" if $opt_d;
+# anything that's found here is an includefile but not a sourcefile...
+# just include directory in scan
+                     $scanned{$path} = $scanOrder++
+                       if ( $suffix && !$scanned{$path} );
+                  }
+               }
+               close CMDFILE;
+            }
+	 }
+      }
+   }
+}
+delete $actual_source_of{''};
+# sort scanned directories by scan order
+sub ascendingScanOrder { $scanned{$a} <=> $scanned{$b}; }
+my @dirs = sort ascendingScanOrder keys %scanned;
+my @sources = values %source_of;
+my @objects = keys   %source_of;
+if( $opt_d ) {
+   print "DEBUG: dirs= @dirs\n";
+   print "DEBUG: sources= @sources\n";
+   print "DEBUG: objects= @objects\n";
+}
+
+my %obj_of_module;		# hash returning name of object file containing module
+my %modules_used_by;		# hash of modules used by a given source file (hashed against the corresponding object)
+my %includes_in;		# hash of includes in a given source file (hashed against the corresponding object)
+my %has_chgdefs;		# hash of files contains cppdefs that have been changed
+#subroutine to scan file for use and module statements, and include files
+# first argument is $object, second is $file
+sub scanfile_for_keywords {
+   my $object = shift;
+   my $file = shift;
+   local $/ = $endline;
+#if file has already been scanned, return: but first check if any .o needs to be removed
+   if( $scanned{$file} ) {
+       if( $has_chgdefs{$file} and -f $object ) {
+	   unlink $object or die "\aERROR unlinking $object: $!\n";
+	   print "   Object $object is out-of-date because of change to cppdefs, removed.\n" if $opt_v;
+       }
+       return;
+   }
+   print "Scanning file $file of object $object ...\n" if $opt_v;
+   open FILE, $file or die "\aERROR opening file $file of object $object: $!\n";
+   foreach $line ( <FILE> ) {
+      if ( $line =~ /^\s*module\s+(\w*)/ix ) {
+	 if ( $1 ) {
+	    my $module = lc $1;
+	    if ( $obj_of_module{$module} && $module ne "procedure" ) {
+	       die "\a\nAMBIGUOUS: Module $module is associated with $file as well as $actual_source_of{$obj_of_module{$module}}.\n";
+	    }
+	    $obj_of_module{$module} = $object;
+	 }
+      }
+      if ( $line =~ /^\s*use\s*(\w*)/ix ) {
+	 $modules_used_by{$object} .= ' ' . lc $1 if $1;
+      }
+      if ( $line =~ /^[\#\s]*include\s*(['""'<])([\w\.\/]*)$delim_match{\1}/ix ) {
+	 $includes_in{$file} .= ' ' . $2 if $2;
+      }
+      foreach ( keys %chgdefs ) {
+	 $_ .= '='; /\s*=/; $word=$`; #cut string at =sign, else whole string
+	 if ( $line =~ /\b$word\b/ ) {
+	    $has_chgdefs{$file} = 1;
+	    if ( -f $object ) {
+	       unlink $object or die "\aERROR unlinking $object: $!\n";
+	       print "   Object $object is out-of-date because of change to cppdef $word, removed.\n" if $opt_v;
+	    }
+	 }
+      }
+   }
+   close FILE;
+   $scanned{$file} = 1;
+   print "   uses modules=$modules_used_by{$object}, and includes=$includes_in{$file}.\n" if $opt_d;
+}
+
+foreach $object ( @objects ) {
+   &scanfile_for_keywords( $object, $actual_source_of{$object} );
+}
+
+my %off_sources;		# list of source files not in current directory
+my %includes;			# global list of includes
+my %used;			# list of object files that are used by others
+my @cmdline;
+# for each file in sources, write down dependencies on includes and modules
+foreach $object ( sort @objects ) {
+   print STDERR '.' unless $opt_v; # show progress on screen (STDERR is used because it is unbuffered)
+   my %is_used;			# hash of objects containing modules used by current object
+   my %obj_of_include;		# hash of includes for current object
+   $is_used{$object} = 1;	# initialize with current object so as to avoid recursion
+   print "Collecting dependencies for $object ...\n" if $opt_v;
+   @cmdline = "$object: $source_of{$object}";
+   ( $name, $path, $suffix ) = fileparse( $actual_source_of{$object}, @src_suffixes );
+   $off_sources{$source_of{$object}} = 1 unless( $path eq './' or $path eq '' );
+#includes: done in subroutine since it must be recursively called to look for embedded includes
+   @includepaths = '';
+   &get_include_list( $object, $actual_source_of{$object} );
+#modules
+   foreach $module ( split /\s+/, $modules_used_by{$object} ) {
+      $target = $obj_of_module{$module};
+#we need to check target ne '' also below, since it is not mkmf's privilege
+#to complain about modules not found. That should be left to the compiler.
+      if( $target and !$is_used{$target} ) {
+	 $is_used{$target} = 1;
+	 push @cmdline, $target;
+	 $used{$target} = 1;
+	 print "   found module $module in object $target ...\n" if $opt_v;
+      }
+   }
+#write the command line: if no file-specific command, use generic command for this suffix
+   &print_formatted_list(@cmdline);
+   $file = $actual_source_of{$object};
+   if ( $compile_cmd{$name.$suffix} ) {
+      print MAKEFILE "\t$compile_cmd{$name.$suffix}";
+   } else {
+      print MAKEFILE "\t$compile_cmd{$suffix}";
+   }
+   foreach ( @includepaths ) { # include files may be anywhere in directory array
+      print MAKEFILE " -I$_" if $_;
+   }
+   print MAKEFILE "\t$source_of{$object}\n";
+
+# subroutine to seek out includes recursively
+   sub get_include_list {
+      my( $incfile, $incname, $incpath, $incsuffix );
+      my @paths;
+      my $object = shift;
+      my $file = shift;
+      foreach ( split /\s+/, $includes_in{$file} ) {
+	 print "object=$object, file=$file, include=$_.\n" if $opt_d;
+	 ( $incname, $incpath, $incsuffix ) = fileparse( $_, @inc_suffixes );
+	 if( $incsuffix ) {	# only check for files with proper suffix
+	    undef $incpath if $incpath eq './';
+	    if( $incpath =~ /^\// ) {
+	       @paths = $incpath; # exact incpath specified, use it
+	    } else {
+	       @paths = @dirs;
+	    }
+	    foreach ( @paths ) {
+	       local $/ = '/'; chomp; # remove trailing / if present
+	       my $newincpath = "$_/$incpath" if $_;
+	       undef $newincpath if $newincpath eq './';
+	       $incfile = "$newincpath$incname$incsuffix";
+               if ( $opt_a and ( substr($newincpath,0,1) ne '/' ) ) {
+                  $newincpath = '$(SRCROOT)' . $newincpath;
+               }
+	       print "DEBUG: checking for $incfile in $_ ...\n" if $opt_d;
+	       if ( -f $incfile and $obj_of_include{$incfile} ne $object ) {
+		  print "   found $incfile ...\n" if $opt_v;
+		  push @cmdline, "$newincpath$incname$incsuffix";
+		  $includes{$incfile} = 1;
+		  chomp( $newincpath, $path );
+		  $off_sources{$incfile} = 1 if $newincpath;
+		  $newincpath = '.' if $newincpath eq '';
+		  push @includepaths, $newincpath unless( grep $_ eq $newincpath, @includepaths );
+		  &scanfile_for_keywords($object,$incfile);
+		  $obj_of_include{$incfile} = $object;
+		  &get_include_list($object,$incfile); # recursively look for includes
+		  last;
+	       }
+	    }
+	 }
+      }
+   }
+}
+
+#lines to facilitate creation of local copies of source from other directories
+#commented out because it makes make default rules kick in
+foreach ( keys %off_sources ) {
+   my $file = basename($_);
+   $file =~ s/\$\(SRCROOT\)//;
+   print MAKEFILE "./$file: $_\n\tcp $_ .\n";
+}
+
+#objects not used by other objects
+#if every object is a module, then only the unused objects
+#need to be passed to the linker (see commented OBJ = line below).
+#if any f77 or C routines are present, we need complete list
+my @unused_objects;
+foreach $object ( @objects ) {
+   push @unused_objects, $object unless $used{$object};
+}
+
+&print_formatted_list( "SRC =", @sources, keys %includes );
+&print_formatted_list( "OBJ =", @objects );
+# &print_formatted_list( "OBJ =", @unused_objects );
+my $noff = scalar keys %off_sources;
+&print_formatted_list( "OFF =", keys %off_sources ) if $noff > 0;
+
+#write targets
+print MAKEFILE "clean: neat\n\t-rm -f .cppdefs *.com *.mod \$(OBJ) $opt_p\n";
+print MAKEFILE "neat:\n\t-rm -f \$(TMPFILES)\n";
+print MAKEFILE "localize: \$(OFF)\n\tcp \$(OFF) .\n" if $noff > 0;
+print MAKEFILE "TAGS: \$(SRC)\n\tetags \$(SRC)\n";
+print MAKEFILE "tags: \$(SRC)\n\tctags \$(SRC)\n";
+( $name, $path, $suffix ) = fileparse( $opt_p, @tgt_suffixes );
+if( $suffix eq '.a' ) {
+   print MAKEFILE "$opt_p: \$(OBJ)\n\t\$(AR) \$(ARFLAGS) $opt_p \$(OBJ)\n";
+} else {
+# opt_l is a new flag added to take care of libraries
+   print MAKEFILE "$opt_p: \$(OBJ) $opt_l\n\t\$(LD) \$(OBJ) -o $opt_p $opt_l \$(LDFLAGS)\n";
+}
+close MAKEFILE;
+print " $mkfile is ready.\n";
+
+exec 'make', '-f', $mkfile if $opt_x;
Index: /tags/LIM1D_v3.20/README
===================================================================
--- /tags/LIM1D_v3.20/README	(revision 6)
+++ /tags/LIM1D_v3.20/README	(revision 6)
@@ -0,0 +1,17 @@
+#
+# LIM1D readme file
+# v3.20
+# prepared in Paris, Dec 11, 2015
+#
+#--------------------------------------------------------------------------------------------------
+# Compilation
+#--------------------------------------------------------------------------------------------------
+#
+from LIM/MAKE modify directories in config_lim1d.sh 
+   -> choose your LIM directory
+   -> choose your compilation option file xxx.inc [gfortran_mac.inc, ifort_esker.inc]
+from LIM/MAKE  edit compilation & ncdf options in your compilation option file (xxx.inc) 
+from LIM/MAKE  execute "./config_lim1d.sh SRC"
+from LIM/MAKE  execute "./config_lim1d.sh"
+from LIM/MAKE  execute "make"
+from LIM/SCRIPTS update your home directory into "./lim1d_$config.nqs" and execute it
Index: /tags/LIM1D_v3.20/SCRIPTS/lim1d_barrow.nqs
===================================================================
--- /tags/LIM1D_v3.20/SCRIPTS/lim1d_barrow.nqs	(revision 6)
+++ /tags/LIM1D_v3.20/SCRIPTS/lim1d_barrow.nqs	(revision 6)
@@ -0,0 +1,127 @@
+#/bin/bash
+#######################################################################################
+# Launching scripts for LIM1D
+#######################################################################################
+# v2.1, Sep 2009, Martin Vancoppenolle
+
+echo " ------------------------------------------------------------------------------------------------"
+# Adjust this section
+USERNICK="Martouf"       # user nickname
+
+EXP_ID="test_3.20_BARROW"  # name of the experiment ### CHANGE
+SOURCE="source_3.20"       # version of the sources
+TS="1d"                    # time step (1h or 1d)
+CONF="BARROW"              # site at which we run the model 
+MESSAGE="Test run"         # Little message to know what is the run about
+
+SUBDIR=`pwd`
+
+MAINDIR="$HOME/Boulot/CODES/LIM1D/2015_v3.20" ### CHANGE
+
+SCRATCHDIR="$MAINDIR/SCRATCH/$EXP_ID"        # SCRATCH - temporary directory on which code is run
+OUTDIR="$MAINDIR/RUN/$EXP_ID"                # STORE - repository where we put the output files in the end
+SOURCEDIR="$MAINDIR/MAKE"                    # EXECUTABLE - exectuable & sources
+INFILEDIR="$MAINDIR/INPUT/$CONF/$SOURCE"     # INPUT - initialization, forcing & param files
+
+GRAPHDIR="$HOME/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/$CONF" # IDL plots
+
+#######################################################################################
+
+#prints commands on output
+#set -x
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 1- Dear $USERNICK, the run is being prepared, please do something else"
+echo " ------------------------------------------------------------------------------------------------"
+#creates the experiment directory in run and scratch
+rm -rf $OUTDIR
+rm -rf $SCRATCHDIR
+
+mkdir $OUTDIR
+mkdir $SCRATCHDIR
+
+#goes to the scratch
+cd $SCRATCHDIR
+echo $MESSAGE > README
+mv README $OUTDIR
+
+#copies the executable
+cp $SOURCEDIR/lim1d.x $SCRATCHDIR/lim1d_$EXP_ID
+
+#copies the forcing and initialization files
+cp $INFILEDIR/* $SCRATCHDIR
+
+ls forcing_$CONF.nc.$TS
+ls forcing.param.$TS
+ls run.param.$TS
+
+mv forcing_$CONF.nc.$TS forcing.nc
+mv forcing.param.$TS    forcing.param
+mv run.param.$TS        run.param
+mv init_$CONF.nc init.nc
+
+# get time step and biological model
+DT=`sed -n 9,9p run.param`         # time step in seconds
+CMOD=`sed -n '21,21p' run.param`   # biological model
+
+#list the directory content
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 2- Dear $USERNICK, everything is copied on the scratch, I am gonna start "
+echo " the run, bordel, and it may take a while depending on the number of iterations you bastard chose"
+echo " ------------------------------------------------------------------------------------------------"
+
+#runs the code
+nice ./lim1d_$EXP_ID > output.run.$EXP_ID
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 3- I'm done and bored, $USERNICK, have to put everything in $OUTDIR "
+echo " ------------------------------------------------------------------------------------------------"
+
+#copies the relevant files in the run directory
+cp $SCRATCHDIR/lim1d_$EXP_ID $OUTDIR
+cp $SCRATCHDIR/*.param $OUTDIR
+cp $SCRATCHDIR/ice.out.nc  $OUTDIR/ice.out.nc.$EXP_ID
+cp $SCRATCHDIR/run.out.txt $OUTDIR/run.out.txt.$EXP_ID
+cp $SCRATCHDIR/cons_bio.out.txt $OUTDIR/cons_bio.out.txt.$EXP_ID
+cp $SCRATCHDIR/forcing.out.txt $OUTDIR/forcing.out.txt.$EXP_ID
+
+cp $SCRATCHDIR/output.run.$EXP_ID $OUTDIR
+cp $SCRATCHDIR/output.run.$EXP_ID $SUBDIR
+cp $SCRATCHDIR/time.step $OUTDIR/time.step.$EXP_ID
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 4- Everything copied, $USERNICK, is this fine ? "
+ls -lt $OUTDIR
+echo " If problem go to $OUTDIR and check "
+echo " thanks a lot for using LIM1D, (c) martouf 2008 "
+
+#rm -rf $SCRATCHDIR
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 5- Graphics "
+
+# read the time step and biological model in the namelists
+
+cd $GRAPHDIR
+echo $EXP_ID > exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $DT >> exp_id.dat
+echo $CMOD >> exp_id.dat
+echo $CONF  >> exp_id.dat
+echo
+echo AAAAAAAAAAAAAAAAHHHHHHHHHHHHH
+echo
+cat exp_id.dat
+cp exp_id.dat ..
+echo
+echo 
+idl < plots_$CONF.exec
+
+cd $OUTDIR
+gv -swap $EXP_ID'_contours.ps' &
+gv -swap $EXP_ID'_stocks.ps' &
+gv -swap $EXP_ID'_profiles.ps' &
Index: /tags/LIM1D_v3.20/SCRIPTS/lim1d_ispol.nqs
===================================================================
--- /tags/LIM1D_v3.20/SCRIPTS/lim1d_ispol.nqs	(revision 6)
+++ /tags/LIM1D_v3.20/SCRIPTS/lim1d_ispol.nqs	(revision 6)
@@ -0,0 +1,129 @@
+#/bin/bash
+#######################################################################################
+# Launching scripts for LIM1D
+#######################################################################################
+# v2.1, Sep 2009, Martin Vancoppenolle
+
+echo " ------------------------------------------------------------------------------------------------"
+# Adjust this section
+USERNICK="Martouf"            # user nickname
+
+EXP_ID="test_3.20_ISPOL_a"      # name of the experiment ### CHANGE
+SOURCE="source_3.20"          # version of the sources
+TS="1d"                       # time step (1h or 1d)
+CONF="ISPOL"                  # site at which we run the model 
+MESSAGE="Test run"            # Little message to know what is the run about
+
+SUBDIR=`pwd`
+
+MAINDIR="$HOME/Boulot/CODES/LIM1D/2015_v3.20" ### CHANGE
+
+SCRATCHDIR="$MAINDIR/SCRATCH/$EXP_ID"        # SCRATCH - temporary directory on which code is run
+OUTDIR="$MAINDIR/RUN/$EXP_ID"                # STORE - repository where we put the output files in the end
+SOURCEDIR="$MAINDIR/MAKE"                    # EXECUTABLE - exectuable & sources
+INFILEDIR="$MAINDIR/INPUT/$CONF/$SOURCE"     # INPUT - initialization, forcing & param files
+
+GRAPHDIR="$HOME/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/$CONF" # IDL plots
+
+#######################################################################################
+
+#prints commands on output
+#set -x
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 1- Dear $USERNICK, the run is being prepared, please do something else"
+echo " ------------------------------------------------------------------------------------------------"
+#creates the experiment directory in run and scratch
+rm -rf $OUTDIR
+rm -rf $SCRATCHDIR
+
+mkdir $OUTDIR
+mkdir $SCRATCHDIR
+
+#goes to the scratch
+cd $SCRATCHDIR
+echo $MESSAGE > README
+mv README $OUTDIR
+
+#copies the executable
+cp $SOURCEDIR/lim1d.x $SCRATCHDIR/lim1d_$EXP_ID
+
+#copies the forcing and initialization files
+cp $INFILEDIR/* $SCRATCHDIR
+
+ls "forcing_"$CONF"_hybrid.nc."$TS
+ls forcing.param.$TS
+ls run.param.$TS
+
+mv "forcing_"$CONF"_hybrid.nc."$TS forcing.nc
+mv forcing.param.$TS               forcing.param
+mv run.param.$TS                   run.param
+mv init_$CONF.nc                   init.nc
+#mv run.param.summer.$TS            run.param
+#mv "init_"$CONF"_summer".nc        init.nc
+
+# get time step and biological model
+DT=`sed -n 9,9p run.param`         # time step in seconds
+CMOD=`sed -n '21,21p' run.param`   # biological model
+
+#list the directory content
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 2- Dear $USERNICK, everything is copied on the scratch, I am gonna start "
+echo " the run, bordel, and it may take a while depending on the number of iterations you bastard chose"
+echo " ------------------------------------------------------------------------------------------------"
+
+#runs the code
+nice ./lim1d_$EXP_ID > output.run.$EXP_ID
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 3- I'm done and bored, $USERNICK, have to put everything in $OUTDIR "
+echo " ------------------------------------------------------------------------------------------------"
+
+#copies the relevant files in the run directory
+cp $SCRATCHDIR/lim1d_$EXP_ID $OUTDIR
+cp $SCRATCHDIR/*.param $OUTDIR
+cp $SCRATCHDIR/ice.out.nc  $OUTDIR/ice.out.nc.$EXP_ID
+cp $SCRATCHDIR/run.out.txt $OUTDIR/run.out.txt.$EXP_ID
+cp $SCRATCHDIR/cons_bio.out.txt $OUTDIR/cons_bio.out.txt.$EXP_ID
+cp $SCRATCHDIR/forcing.out.txt $OUTDIR/forcing.out.txt.$EXP_ID
+
+cp $SCRATCHDIR/output.run.$EXP_ID $OUTDIR
+cp $SCRATCHDIR/output.run.$EXP_ID $SUBDIR
+cp $SCRATCHDIR/time.step $OUTDIR/time.step.$EXP_ID
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 4- Everything copied, $USERNICK, is this fine ? "
+ls -lt $OUTDIR
+echo " If problem go to $OUTDIR and check "
+echo " thanks a lot for using LIM1D, (c) martouf 2008 "
+
+#rm -rf $SCRATCHDIR
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 5- Graphics "
+
+# read the time step and biological model in the namelists
+
+cd $GRAPHDIR
+echo $EXP_ID > exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $DT >> exp_id.dat
+echo $CMOD >> exp_id.dat
+echo $CONF  >> exp_id.dat
+echo
+echo AAAAAAAAAAAAAAAAHHHHHHHHHHHHH
+echo
+cat exp_id.dat
+cp exp_id.dat ..
+echo
+echo 
+idl < plots_$CONF.exec
+
+cd $OUTDIR
+gv -swap $EXP_ID'_contours.ps' &
+gv -swap $EXP_ID'_stocks.ps' &
+gv -swap $EXP_ID'_profiles.ps' &
Index: /tags/LIM1D_v3.20/SCRIPTS/lim1d_yrosiae.nqs
===================================================================
--- /tags/LIM1D_v3.20/SCRIPTS/lim1d_yrosiae.nqs	(revision 6)
+++ /tags/LIM1D_v3.20/SCRIPTS/lim1d_yrosiae.nqs	(revision 6)
@@ -0,0 +1,124 @@
+#/bin/bash
+#######################################################################################
+# Launching scripts for LIM1D
+#######################################################################################
+# v2.1, Sep 2009, Martin Vancoppenolle
+
+echo " ------------------------------------------------------------------------------------------------"
+# Adjust this section
+USERNICK="Martouf"            # user nickname
+
+EXP_ID="test_3.20_YROSIAE"    # name of the experiment ### CHANGE
+SOURCE="source_3.20"          # version of the sources
+TS="1d"                       # time step (1h or 1d)
+CONF="YROSIAE"                # site at which we run the model 
+MESSAGE="first test run"      # Little message to know what is the run about
+
+SUBDIR=`pwd`
+
+MAINDIR="$HOME/Boulot/CODES/LIM1D/2015_v3.20" ### CHANGE
+
+SCRATCHDIR="$MAINDIR/SCRATCH/$EXP_ID"        # SCRATCH - temporary directory on which code is run
+OUTDIR="$MAINDIR/RUN/$EXP_ID"                # STORE - repository where we put the output files in the end
+SOURCEDIR="$MAINDIR/MAKE"                    # EXECUTABLE - exectuable & sources
+INFILEDIR="$MAINDIR/INPUT/$CONF/$SOURCE"     # INPUT - initialization, forcing & param files
+
+GRAPHDIR="$HOME/Boulot/SCIENCE/PLOT_SCRIPTS/LIM1D_BIO/IDL/$CONF" # IDL plots
+
+#######################################################################################
+
+#prints commands on output
+#set -x
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 1- Dear $USERNICK, the run is being prepared, please do something else"
+echo " ------------------------------------------------------------------------------------------------"
+#creates the experiment directory in run and scratch
+rm -rf $OUTDIR
+rm -rf $SCRATCHDIR
+
+mkdir $OUTDIR
+mkdir $SCRATCHDIR
+
+#goes to the scratch
+cd $SCRATCHDIR
+echo $MESSAGE > README
+mv README $OUTDIR
+
+#copies the executable
+cp $SOURCEDIR/lim1d.x $SCRATCHDIR/lim1d_$EXP_ID
+
+#copies the forcing and initialization files
+cp $INFILEDIR/* $SCRATCHDIR
+
+# rename files
+mv "forcing_"$CONF"_"$TS".nc"      forcing.nc
+mv forcing.param.$TS               forcing.param
+mv run.param.$TS                   run.param
+mv init_$CONF.nc                   init.nc
+
+# get time step and biological model
+DT=`sed -n 9,9p run.param`         # time step in seconds
+CMOD=`sed -n '21,21p' run.param`   # biological model
+
+#list the directory content
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 2- Dear $USERNICK, everything is copied on the scratch, I am gonna start "
+echo " the run, bordel, and it may take a while depending on the number of iterations you bastard chose"
+echo " ------------------------------------------------------------------------------------------------"
+
+#runs the code
+nice ./lim1d_$EXP_ID > output.run.$EXP_ID
+ls -lt
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 3- I'm done and bored, $USERNICK, have to put everything in $OUTDIR "
+echo " ------------------------------------------------------------------------------------------------"
+
+#copies the relevant files in the run directory
+cp $SCRATCHDIR/lim1d_$EXP_ID $OUTDIR
+cp $SCRATCHDIR/*.param $OUTDIR
+cp $SCRATCHDIR/ice.out.nc  $OUTDIR/ice.out.nc.$EXP_ID
+cp $SCRATCHDIR/run.out.txt $OUTDIR/run.out.txt.$EXP_ID
+cp $SCRATCHDIR/cons_bio.out.txt $OUTDIR/cons_bio.out.txt.$EXP_ID
+cp $SCRATCHDIR/forcing.out.txt $OUTDIR/forcing.out.txt.$EXP_ID
+
+cp $SCRATCHDIR/output.run.$EXP_ID $OUTDIR
+cp $SCRATCHDIR/output.run.$EXP_ID $SUBDIR
+cp $SCRATCHDIR/time.step $OUTDIR/time.step.$EXP_ID
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 4- Everything copied, $USERNICK, is this fine ? "
+ls -lt $OUTDIR
+echo " If problem go to $OUTDIR and check "
+echo " thanks a lot for using LIM1D, (c) martouf 2008 "
+
+#rm -rf $SCRATCHDIR
+
+echo " ------------------------------------------------------------------------------------------------"
+echo " 5- Graphics "
+
+# read the time step and biological model in the namelists
+
+cd $GRAPHDIR
+echo $EXP_ID > exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $OUTDIR/ >> exp_id.dat
+echo $DT >> exp_id.dat
+echo $CMOD >> exp_id.dat
+echo $CONF  >> exp_id.dat
+echo
+echo AAAAAAAAAAAAAAAAHHHHHHHHHHHHH
+echo
+cat exp_id.dat
+cp exp_id.dat ..
+echo
+echo 
+idl < plots_$CONF.exec
+
+cd $OUTDIR
+gv -swap $EXP_ID'_contours.ps' &
+gv -swap $EXP_ID'_stocks.ps' &
+gv -swap $EXP_ID'_profiles.ps' &
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/TODO.txt
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/TODO.txt	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/TODO.txt	(revision 6)
@@ -0,0 +1,8 @@
+
+
+
+1) Implement iron in the code
+2) do .param files
+3) do the specific case study
+
+-------------------------------
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/bio.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/bio.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/bio.com	(revision 6)
@@ -0,0 +1,384 @@
+!
+!		COMMONS FOR SEA ICE BIOGEOCHEMISTRY
+!		===================================
+!
+!
+! z_i_bio       : vertical coordinate of the middle of bio-layers
+! deltaz_i_bio  : thickness of the bio-layers
+! c_i_bio       : concentration of tracers in the brines
+! cbu_i_bio     : bulk concentration of tracers in the ice
+! cbub_i_bio    : concentration of tracers in bubbles for bulk ice
+! f_bub         : Gas flux to the atmosphere due to gas bubbles
+! t_i_bio       : temperature in the ice, interpolated on the bio grid
+! s_i_bio       : salinity in the ice, interpolated on the bio grid
+! e_i_bio       : relative brine volume, interpolated on the bio grid
+! c_w_bio       : concentration of tracer in seawater
+
+      REAL(8), DIMENSION(nlay_bio) ::
+     &   z_i_bio,
+     &   deltaz_i_bio,
+     &   t_i_bio,
+     &   s_i_bio,
+     &   e_i_bio,
+     &   diff_br_bio
+
+      REAL(8), DIMENSION(0:nlay_bio) ::
+     &   zb_i_bio
+
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   cbu_i_nml,
+     &   c_w_bio,
+     &   ct_i_bio,
+     &   ch_bo_bio,
+     &   ch_si_bio,
+     &   c_s_bio,
+     &   f_su_tra,
+     &   f_bo_tra,
+     &   f_bogr,
+     &   f_sigr,
+     &   fcb,
+     &   fcbp,
+     &   fcsi,
+     &   fcbm,
+     &   fcsu,
+     &   fcb_max,
+     &   fgas, 
+     &   gas_trvel,
+     &   f_bub,
+     &   dmol_gas,
+     &   mixr_gas
+
+      INTEGER, DIMENSION(ntra_bio_max) ::
+     &   nn_init      !: switch for init ( 0=from code, 1=conc. conserved, 2=stock conserved, 3=read profile )
+
+      INTEGER ::
+     &   jn_dsi,      !: tracer number for dsi
+     &   jn_din,      !:  ...
+     &   jn_dip,      !:  ...
+     &   jn_aoc,      !:  ...
+     &   jn_eoc,      !:  ...
+     &   jn_dic,      !:  ...
+     &   jn_alk,      !:  ...
+     &   jn_ika,      !:  ...
+     &   jn_oxy,      !:  ...
+     &   jn_arg,      !:  ...
+     &   jn_pco,      !:  ...
+     &   jn_car,      !:  ...
+     &   jn_co2,      !:  ...
+     &   jn_cal
+
+      REAL(8), DIMENSION(ntra_bio_max,nlay_bio) ::
+     &   c_i_bio,
+     &   cbu_i_bio,
+     &   cbub_i_bio,
+     &   c_gtot_i,
+     &   pc_sat,
+     &   diag_divf_bio,
+     &   csat_gas,
+     &   sol_gas
+
+      REAL(8), DIMENSION(ntra_bio_max,0:nlay_bio) ::
+     &   fdiff
+
+      COMMON /bioarrays/
+     &   z_i_bio,
+     &   zb_i_bio,
+     &   deltaz_i_bio,
+     &   t_i_bio,
+     &   s_i_bio,
+     &   e_i_bio,
+     &   diff_br_bio,
+     &   ct_i_bio,
+     &   cbu_i_nml,
+     &   c_w_bio,
+     &   ch_bo_bio,
+     &   ch_si_bio,
+     &   c_s_bio,
+     &   f_su_tra,
+     &   f_bo_tra,
+     &   f_bogr,
+     &   f_sigr,
+     &   fcb,
+     &   fcbp,
+     &   fcsi,
+     &   fcbm,
+     &   fcsu,
+     &   fcb_max,
+     &   fgas,
+     &   f_bub, 
+     &   dmol_gas,
+     &   mixr_gas,
+     &   gas_trvel,
+     &   c_i_bio,
+     &   cbu_i_bio,
+     &   cbub_i_bio,
+     &   c_gtot_i,
+     &   pc_sat,
+     &   diag_divf_bio,
+     &   fdiff,
+     &   csat_gas,
+     &   sol_gas
+
+      COMMON /bioini/
+     &   nn_init                  !: type of initialization for bgc tracers
+
+      COMMON/biotrindex/
+     &   jn_dsi,      !: tracer number for dsi
+     &   jn_din,      !:  ...
+     &   jn_dip,      !:  ...
+     &   jn_aoc,      !:  ...
+     &   jn_eoc,      !:  ...
+     &   jn_dic,      !:  ...
+     &   jn_alk,      !:  ...
+     &   jn_ika,      !:  ...
+     &   jn_oxy,      !:  ...
+     &   jn_arg,      !:  ...
+     &   jn_pco,      !:  ...
+     &   jn_car,      !:  ...
+     &   jn_co2,      !:  ...
+     &   jn_cal
+
+      COMMON /biophyparams/
+     &   nn_bio_opt       ,       !: type of biological formulation
+     &   astar_alg        ,       !: specific absorption coeff (m-1 / (mg chla m-3))
+     &   fdet_alg         ,       !: fraction of detrital absorption compared to algal absorption
+     &   nn_phs           ,       !: type of photosynthesis
+     &   nn_lys           ,       !: type of lysis
+     &   nn_rem           ,       !: type of remineralization
+     &   pp_presc         ,       !: prescribed primary production
+     &   h_skel           ,       !: thickness of the biological layer ('SL' & 'BAL' only)
+     &   e_thr_bal        ,       !: thickness of the biological layer ('SL' & 'BAL' only)
+     &   h_bio            ,       !: thickness of the biological layer ('SL' & 'BAL' only)
+     &   brines_ar                !: brines aspect ratio (for gas exchange)
+
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   mt_i_bio_init, mt_i_bio_final,
+     &   mt_w_bio_init, mt_w_bio_final,
+     &   mt_i_bio
+     
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   mt_i_gas_init, mt_i_gas_final,
+     &   mt_i_gas
+
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   mt_i_carb_init, mt_i_carb_final,
+     &   mt_i_carb 
+
+      REAL(8), DIMENSION(ntra_bio_max,nlay_bio) ::
+     &   m_i_bio_init, m_i_bio_final
+
+
+      COMMON/bioconserv/
+     &   mt_i_bio_init, mt_i_bio_final,
+     &   mt_w_bio_init, mt_w_bio_final,     
+     &   mt_i_bio,
+     &   mt_i_gas_init, mt_i_gas_final,
+     &   mt_i_gas,
+     &   mt_i_carb_init, mt_i_carb_final,
+     &   mt_i_carb,
+     &   m_i_bio_init, m_i_bio_final
+
+      LOGICAL ::
+     &   flag_diff(ntra_bio_max)     , !: flag which describes diffusability of a tracer
+     &   flag_active(ntra_bio_max)   , !: describe whether a tracer is assumed active or not
+     &   flag_adsorb(ntra_bio_max)   , !: adsorbed or not ?
+     &   ln_trbo                 , !: activate tracer basal entrapment
+     &   ln_trsi                 , !: activate tracer surface entrapment
+     &   ln_trdiff               , !: activate tracer diffusion
+     &   ln_trremp               , !: activate tracer remapping
+     &   ln_lim_dsi              , !: activate DSi limitation
+     &   ln_lim_no3              , !: activate NO3 limitation
+     &   ln_lim_po4              , !: activate PO4 limitation
+     &   ln_lim_lig              , !: activate light limitation
+     &   ln_lim_tem              , !: activate temperature inhibition
+     &   ln_lim_sal              , !: activate brine salinity inhibition
+     &   ln_lys                  , !: activate lysis
+     &   ln_rem                  , !: activate remineralization
+     &   ln_syn                  , !: activate diatom synthesis
+     &   ln_bubform              , !: activate gas buble formation
+     &   ln_bubrise              , !: activate gas buble ascent
+     &   ln_gasflux              , !: activate gas flux to atm
+     &   ln_carbon               , !: activate carbon cycle
+     &   ln_ikaite                 !: activate CaCO3 
+     
+      INTEGER(4) ::
+     &   nn_bio_opt              , !: type of biological model (0=NP, 1=NPD Redfield)
+     &   nn_diff(ntra_bio_max)   , !: switch for diffusion (0=no diffus, 1=diffus, 2=reset brine cc to zero)
+     &   nn_remp(ntra_bio_max)   , !: switch for remapping (0=no remap , 1=diffus. remap, 2=squeeze remap.)
+     &   nn_phs                  , !: switch for photosynthesis (1=Ek, 2=chl-C, 3=chl-C+T/S, 4=variable chl-C)
+     &   nn_lys                  , !: type of loss term (1=prescribed, 2=T-dependent)
+     &   nn_rem                  , !: type of remineralization (1=prescribed, 2=T-dependent)
+     &   nn_lim_sal              , !: switch for the type of brine salinity inhibition
+     &   ntra_bio                , !: maximum number of tracers
+     &   layer_00                , !: index of the first layer
+     &   nn_carbonate              !: type of carbonate constants (1=Roy, 2=mehrbach)
+
+      REAL(8) ::
+     &   bub_form_rate           ,
+     &   bub_diss_rate           ,
+     &   h_bl_gas                ,
+     &   e_thr_bubrise           ,
+     &   e_thr_gasflux           ,
+     &   sursat_gas              ,
+     &   caco3_time               
+
+      COMMON /bioswi/
+     &   flag_diff               ,
+     &   flag_active             ,
+     &   flag_adsorb             ,
+     &   ln_trbo                 ,
+     &   ln_trsi                 ,
+     &   ln_trdiff               ,
+     &   ln_trremp               ,
+     &   ln_lim_dsi              ,
+     &   ln_lim_no3              ,
+     &   ln_lim_po4              ,
+     &   ln_lim_lig              ,
+     &   ln_lim_tem              ,
+     &   ln_lim_sal              ,
+     &   ln_lys                  ,
+     &   ln_rem                  ,
+     &   ln_syn                  ,
+     &   nn_diff                 ,
+     &   nn_remp                 ,
+     &   nn_lim_sal              ,
+     &   ntra_bio                ,
+     &   layer_00                , 
+     &   nn_carbonate            ,
+     &   i_gasflux               ,
+     &   ln_bubform              ,
+     &   ln_bubrise              ,
+     &   ln_gasflux              ,
+     &   ln_carbon               ,
+     &   ln_ikaite               ,
+     &   bub_form_rate           ,
+     &   bub_diss_rate           ,
+     &   h_bl_gas                ,
+     &   e_thr_bubrise           ,
+     &   e_thr_gasflux           ,
+     &   sursat_gas              ,
+     &   caco3_time               
+
+      !-----------------------
+      ! Brine characteristics
+      !-----------------------
+      REAL(8), DIMENSION(nlay_bio) ::  ! Brine characteristics
+     &   tc_bio                  ,  ! Celsius temperature on the bio-grid
+     &   sbr_bio                 ,  ! brine salinity on the bio-grid
+     &   rhobr_bio                  ! brine density on the bio-grid
+
+      COMMON/biobrine/
+     &   tc_bio                  ,
+     &   sbr_bio                 , 
+     &   rhobr_bio                 
+
+      !---------------------
+      ! Carbonate chemistry
+      !---------------------
+      REAL(8), DIMENSION(nlay_bio) ::  ! Carbonate chemistry diagnostics
+     &   CO2aq                   , ! aqueous CO2, bulk concentration
+     &   CO32m                   , ! carbonate (CO32-), bulk concentration
+     &   hCO3m                   , ! bicarbonate (HCO3-), bulk concentration
+     &   pH                      , ! pH, brine
+     &   pCO2                      ! pCO2, brine
+
+      COMMON/biocarbchem/       
+     &   CO2aq                   , ! aqueous CO2, bulk concentration
+     &   CO32m                   , ! carbonate (CO32-), bulk concentration
+     &   hCO3m                   , ! bicarbonate (HCO3-), bulk concentration
+     &   pH                      , ! pH, brine
+     &   pCO2                      ! pCO2, brine
+
+      CHARACTER(len=64) ::
+     &   biotr_i_nam(ntra_bio_max)  , !:
+     &   biotr_i_typ(ntra_bio_max)    !:
+
+      CHARACTER(len=64) ::         
+     &   biotr_i_uni(ntra_bio_max)
+
+      CHARACTER(len=2) ::         
+     &   c_grid
+
+      CHARACTER(len=3) ::
+     &   c_read_name(ntra_bio_max),
+     &   c_nc_name(ntra_bio_max)
+         
+      COMMON /biochar/
+     &   biotr_i_nam, 
+     &   biotr_i_typ,
+     &   biotr_i_uni,
+     &   c_grid,
+     &   c_read_name,
+     &   c_nc_name   
+
+      COMMON /biomass/
+     &   chla_i_bio(nlay_bio)     !: chlorophyll a concentration
+
+      REAL(8) ::
+     &   ika_rate(nlay_bio)      , !: CaCO3 precipitation / dissolution rate (mmol/m3/s)
+     &   ika_omega(nlay_bio)     , !: CACO3 saturation state (-)
+     &   syn_bio(nlay_bio)       , !: synthesis
+     &   lys_bio(nlay_bio)       , !: lysis
+     &   exu_bio(nlay_bio)       , !: exudation
+     &   rsp_bio(nlay_bio)       , !: respiration
+     &   rem_bio(nlay_bio)       , !: remineralization
+     &   lim_lig(nlay_bio)       , !: light limitation
+     &   lim_dsi(nlay_bio)       , !: DSi limitation
+     &   lim_no3(nlay_bio)       , !: NO3 limitation
+     &   lim_po4(nlay_bio)       , !: PO4 limitation
+     &   lim_tem(nlay_bio)       , !: temperature limitation
+     &   lim_sal(nlay_bio)       , !: salt limitation
+     &   chlC_bio(nlay_bio)        !: interactive chl-a / C ratio
+
+      COMMON /biosources/
+     &   ika_rate                , !: 
+     &   ika_omega               , !: 
+     &   syn_bio                 , !: 
+     &   lys_bio                 , !: 
+     &   exu_bio                 , !:
+     &   rsp_bio                 , !: 
+     &   rem_bio                 , !: 
+     &   lim_lig                 , !:
+     &   lim_dsi                 , !:
+     &   lim_no3                 , !:
+     &   lim_po4                 , !:
+     &   lim_tem                 , !:
+     &   lim_sal                 , !:
+     &   chlC_bio                  !: 
+
+      COMMON /biorad/             
+     &   par_bio(nlay_bio)         !: Photosynthetically available radiation
+                                   !: (flux micromol quanta m-2 s-1)
+      !---------------------------------------
+      ! Constants and parameters of the model
+      !---------------------------------------
+      REAL(8) ::
+     &   mumax_bio               , !: maximum specific growth (s-1)
+     &   klys_bio                , !: autolysis rate (s-1)
+     &   ek_bio                  , !: light adaptation micrmol quanta m-2 s-1
+     &   alpha_bio               , !: photosynthetic efficiency (gC/gchla/s-1/(muE/m2/s))
+     &   khs_si_bio              , !: half sat for Si uptake (mmol m-3)
+     &   khs_n_bio               , !: half sat for N uptake (mmol m-3)
+     &   khs_p_bio               , !: half sat for P uptake (mmol m-3)
+     &   frem_bio                , !: fraction of Si loss that is remineralized (-)
+     &   krem_bio                , !: carbon remineralization time constant (s-1)
+     &   krsp_bio                , !: carbon respiration time constant
+     &   rg_bio                  , !: temperature coefficient for diatom synthesis (deg C-1)
+     &   rg_bac                  , !: temperature coefficient for bacterial processes (deg C-1)
+     &   lim_sal_wid             , !: width of the limitation function (case 4)
+     &   lim_sal_smax            , !: salinity at which limitation function is 1 (case 4)
+     &   chla_c                  , !: Chlorophyll-to-carbon ratio
+     &   Estar                   , !: PAR level of minimum Chl/C
+     &   si_c                    , !: Si cell quota in diatoms
+     &   no3_c                   , !: N cell quota in diatoms
+     &   po4_c                   , !: N cell quota in diatoms
+     &   oxy_c                   , !: Oxygen cell quota in diatoms
+     &   c_molar                   !: carbon molar mass
+
+      COMMON /bioparams/
+     &   mumax_bio, klys_bio, ek_bio, alpha_bio,
+     &   khs_si_bio, khs_n_bio, khs_p_bio, frem_bio, 
+     &   krem_bio, krsp_bio, 
+     &   rg_bio, rg_bac, chla_c, Estar, si_c, no3_c, po4_c, oxy_c,
+     &   lim_sal_wid, lim_sal_smax, c_molar
+
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/biolim.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/biolim.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/biolim.f	(revision 6)
@@ -0,0 +1,88 @@
+      PROGRAM biolim
+
+      ! This is the BIOLIM code
+      ! composed of the halo-thermodynamic model of Vancoppenolle et al. (JGR 2007)
+      ! and of a newly developed biogeochemical component
+
+      ! (c) Martin Vancoppenolle (UCL-ASTR, 2002-2008)
+
+      INCLUDE 'type.com'
+      INCLUDE 'const.com'
+      INCLUDE 'para.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'forcing.com'
+      INCLUDE 'bio.com'
+ 
+!------------------------------------------------------------------------------
+!     1) CREATES THE OUTPUT FILES
+!------------------------------------------------------------------------------
+
+
+      OPEN(numout,file='run.out.txt',status='replace')        ! output text file
+      OPEN(503   ,file='cons_bio.out.txt',status='replace')   ! output conservation file
+      OPEN(85    ,file='forcing.out.txt',status='replace')
+      OPEN(86    ,file='time.step', status='replace')
+
+      WRITE(numout,*) ' ---------------------------------------------- '
+      WRITE(numout,*) '         *** BIO-LIM sea ice model ***          '
+      WRITE(numout,*) '  (c) UCL-ASTR, Louvain-La-Neuve Belgium        '
+      WRITE(numout,*) '  Martin Vancoppenolle, 2008.                   '
+      WRITE(numout,*) ' ---------------------------------------------- '
+      WRITE(numout,*) 
+      WRITE(numout,*) ' biolim :  '
+      WRITE(numout,*) ' ~~~~~~~~~ '
+      WRITE(numout,*) 
+!
+!------------------------------------------------------------------------------
+!     2) PARAMETERS
+!------------------------------------------------------------------------------
+!
+      CALL ice_phy_param       ! physical parameters
+
+      CALL ice_bio_param       ! biological parameters
+!
+!-----------------------------------------------------------------------
+!     3) MAIN LOOP                                                     |
+!-----------------------------------------------------------------------
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' Loop begins, iteration : ', nstart
+      WRITE(numout,*)
+      WRITE(numout,*) '  nstart = ', nstart
+      WRITE(numout,*) '  nend   = ', nend
+      WRITE(numout,*)
+
+      DO 300 numit = nstart, nend  
+
+         !---------------------
+         ! Time step variables
+         !---------------------
+         WRITE(86,*) numit
+
+         WRITE(numout,*) 
+     &   '============================================================='
+         WRITE(numout,*)
+         WRITE(numout,*) '   *** Beginning the time step *** ', numit
+         WRITE(numout,*)
+         WRITE(numout,*) 
+     &   '============================================================='
+         WRITE(numout,*)
+
+         CALL ice_th(n_i,n_s) ! main model routine
+ 
+ 300  CONTINUE ! End of the loop
+
+!-----------------------------------------------------------------------
+!     4) END OF THE RUN                                                |
+!-----------------------------------------------------------------------
+      ! close output files
+      CLOSE(numout) 
+      CLOSE(85)
+      CLOSE(86)
+      CLOSE(999) 
+      CLOSE(24)
+ 
+!-----------------------------------------------------------------------------!
+! End of the main routine
+!
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/const.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/const.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/const.com	(revision 6)
@@ -0,0 +1,25 @@
+
+!
+!		COMMONS FOR XXXX
+!		===================================
+!
+!       further cleaning required
+!
+
+      REAL(8) :: rlat  !keep
+ 
+      COMMON / iteration / 
+     &   numit,
+     &   rlat,
+     &   year, ! (useful?)
+     &   day, ! (useful ?)
+     &   nstart,
+     &   nend,
+     &   nitrun,
+     &   num_d,
+     &   nyear
+ 
+      COMMON / cstfix /
+     &  c_zero, one, pi, radian,
+     &  yeaday, gpes, rho0,
+     &  iyea_num
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/flx.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/flx.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/flx.f	(revision 6)
@@ -0,0 +1,195 @@
+	subroutine flx(hi2,thsfc,tair,qair,fsens,flat,qsfc,
+     &			zchu1,zchu2,uair2,zref)
+! inputs :hi2(m),thsfc(K),qsfc(kg/kg),tair(K),qair(kg/kg),uair(m/s),zref(m)
+! outputs:fsens (W/m^2), flat (W/m^2)
+!--- Computes turbulent fluxes of sensible and latent heat (z=10m).
+!--- Based on Andreas, E.L., 1987: A Theory for the Scalar Roughness 
+!--- and the Scalar Transfer Coefficients over Snow and Sea Ice,
+!--- Boundary Layer Meteorology, v.38, 159-184.
+! 
+        implicit double precision (a-h,o-z)
+!       implicit real (a-h,o-z)        
+        integer ii
+!--- Constants:
+!real aw,cp,cw2,epsi,epss,epsw,gd,grav,hilead,pci,one
+!       real pcs,pi,qb2,qi,rd,rv,qs,qs0,rho2,rhoice,rhosf,rhosm,rhow
+!       real sigma,t0, ai2, bi, ts2, ta2
+!
+!real alphae,alphah2,alrs,CEN,CHN2,cte,ctf
+!       real kn,L2,lnztz0,lnzqz0,nu,psih2,psim2,psiq,uair
+!       real qair,qsfc,Ri2,Rstar,sqrtCD,tair,thsfc,uair,usave,ustar
+!       real Ri2,Rstar,sqrtCD,usave,ustar
+!       double precision tair,thsfc,uair2,hi2,qair,fsens,flat,qsfc
+!       double precision zchu1,zchu2,CH2,CE2,CD,CDN
+!       real u_data,x2,z0,zeta,zq2,zref,zt
+        dimension b0t(3),b1t(3),b2t(3), b0q(3),b1q(3),b2q(3)
+        real lv,kn,L2,lnztz0,lnzqz0,nu
+        
+!!!	include 'const.cmn'
+!
+!--- Values of coefficients for polynomials, Table I, p.177
+	data b0t/1.250, 0.149, 0.317/
+	data b1t/0.000,-0.550,-0.565/
+	data b2t/0.000, 0.000,-0.183/
+	data b0q/1.610, 0.351, 0.396/
+	data b1q/0.000,-0.628,-0.512/
+	data b2q/0.000, 0.000,-0.180/
+!--03/08/2001      
+        uair=uair2
+!--- Constants
+	kn=0.4
+	nu=1.461e-5
+	alphah2=1.0
+	alphae=1.0
+	ai2   = 21.8746   
+	bi    =-265.5
+        grav  = 9.81            !  gravitational acceleration (m/s2)
+        lv    = 2.501e+6        !  latent heat of vaporization (J/kg)
+        rho2  = 1.275           !  density of dry air (kg/m3)
+        cp    = 1005.           !  heat capacity of dry air (J/kg.K)
+        zref  = 10.             !  (m)
+!--- cst rajoutees le 02/08/2001---
+        one   = 1.d0
+        pi    = 4.0 * dtan(one)
+!--- get surface sphum
+        ts2=thsfc-273.16
+        qsfc   =  0.622*6.11/1013.*exp(min(ai2*ts2/(ts2-bi),10.))
+!
+         
+	if(uair.le.0.) then
+	  fsens=0.
+	  flat=0.
+          ctf=0.
+          cte=0.
+	  return
+
+        else if (uair.lt.0.5) then
+!TEA save value (will linearly interpolate down from 0.5 m/s)
+          usave = uair
+          uair = 0.5
+        else
+          usave = -1.
+	endif
+!
+	Ri2=grav*zref*(tair-thsfc)/(tair*uair*uair)
+!
+!--- Thickness dependent roughness length (Guest & Davidson 1991 JGR)
+	if(hi2.lt.0.01) then
+	   z0=8.0e-4
+	elseif(hi2.ge.0.01.and.hi2.le.0.10) then
+	   z0=4.5e-4
+	elseif(hi2.gt.0.10.and.hi2.le.0.30) then 
+	   z0=2.4e-3
+	elseif(hi2.gt.0.30.and.hi2.le.2.00) then
+	   z0=1.3e-3
+	elseif(hi2.gt.2.00) then
+	   z0=2.0e-3
+	endif
+!
+!--- Using reference height of 10 m, get u* from uair and z0 using (1)
+!
+	ustar = uair * kn / dlog(zref/z0)
+!
+!--- Get roughness Reynolds number R* = u* z0 / v  (p.163)
+!
+	Rstar = ustar * z0 / nu
+!
+!--- Get ln(zT/z0) and ln(zQ/z0) from (53) and Table I  Andreas (p.177)
+!
+	if(Rstar.le.0.135) then
+	   ii=1
+	elseif(Rstar.gt.0.135.and.Rstar.lt.2.5) then
+	   ii=2
+	elseif(Rstar.ge.2.5) then
+	   ii=3
+	endif
+
+	alrs=dlog(Rstar)
+	lnztz0 = b0t(ii) + b1t(ii)*alrs + b2t(ii)*alrs*alrs
+	lnzqz0 = b0q(ii) + b1q(ii)*alrs + b2q(ii)*alrs*alrs
+	zt = z0*exp(lnztz0)     ! Roughness length for temperature
+	zq2 = z0*exp(lnzqz0)     ! Roughness length for q
+
+!
+!--- Get neutral drag coefficient CD from (10)  Andreas p. 162
+!
+	CDN = kn**2 / (dlog(zref/z0))**2
+!
+!--- Get neutral CH2 and CE2 from (11), (12) using alphah2=alphae=1.0
+!(p.162)
+!
+	sqrtCD = CDN**0.5
+	CHN2 = alphah2*kn*sqrtCD / (kn/sqrtCD - lnztz0)
+	CEN = alphae*kn*sqrtCD / (kn/sqrtCD - lnzqz0)
+!
+!--- Correct for stability dependence
+	if(tair.eq.thsfc) then
+!	 Neutral case
+	   CD=CDN
+	   CH2=CHN2
+	   CE2=CEN
+	   go to 9
+	endif
+!
+!--- Obukhov length (Stull 1988, eq.9.7.5k, p.386)
+        L2 = ustar*tair*uair / (kn*grav*(tair-thsfc))
+        zeta = zref/L2
+!
+!--- Stability functions (Liu et al 1979, p.1723) become negative for
+!--- low wind speeds, now using stability parameters f(RiB) from
+!--- Louis (1979) and Louis et al. (1981)
+!--- (Note A&M and Stull use different sign conventions for psim2)
+!--- Monin-Obukhov similarity theory applied to the surface layer
+!--- works only when the winds are NOT calm and u* is not zero
+!
+	if(Ri2.gt.0.) then        ! Stable surface layer case
+           psim2 = -7.*zeta
+           psih2 = psim2
+           psiq = psih2
+	else if(Ri2.lt.0.) then ! Unstable surface layer case
+           x2=(1.-16.*zeta)**0.25
+           psim2 = 2.*dlog((1.+x2)/2.) + dlog((1.+x2*x2)/2.) - 
+     &             2.*dtan(x2)+ pi/2.
+           psih2 = 2.*dlog((1.+x2*x2)/2.)
+           psiq = psih2
+	endif
+
+!
+!--- Get transfer coefficients from Andreas & Murphy (2.14-2.15)
+!
+        CD = kn**2 / (dlog(zref/z0)-psim2)**2
+        sqrtCD = CD**0.5
+        CH2 = alphah2*kn*sqrtCD / (kn/sqrtCD - lnztz0-(psih2-psim2))
+        CE2 = alphae*kn*sqrtCD / (kn/sqrtCD - lnzqz0-(psiq-psim2))
+!---test 10 /08/2001
+         CH2 =0.00175
+         CE2 =0.00175   
+!
+!---  For ECMWF or NCEP analyses, convert 10 m winds to 2 m winds
+!
+    9   u_data = uair    ! Save wind speed at 10 m
+!
+     	fsens=rho2*cp*CH2*uair*(thsfc-tair)   !  This line used to be numbered
+	flat= rho2*lv*CE2*uair*(qsfc-qair)    !  for goto 9
+ 100  format(8f15.9)
+!
+!---03/08/2001  calcul de zrchu----
+! 
+        zchu1=rho2*cp*CH2*uair
+        zchu2=rho2*lv*CE2*uair
+        uair = u_data    !  Return wind speed to 10 m value
+	ctf=CH2
+	cte=CE2
+!
+!TEA linearly interpolate
+        if (usave.gt.0.) then
+           fsens = fsens*(usave/uair)
+           flat  = flat*(usave/uair)
+           ctf = ctf*(usave/uair)
+           cte = cte*(usave/uair)
+        endif
+!--- restrict flat to non-negative values
+! test du 10/08/2001                  
+!          flat  = max(flat,0.)
+  	return
+	end
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.com	(revision 6)
@@ -0,0 +1,58 @@
+!
+!		COMMONS FOR FORCING
+!		====================
+!
+!
+! forc_nam      : name of the forcing fields
+! ts_forc       : time step of the forcing
+! forc_swi      : switch for computation of the forcing
+! forc_uni      : unit conversion factor for a given forcing field
+! forc_val      : prescribed value of a given forcing field if any
+
+      CHARACTER(len=8), DIMENSION(n_forc) ::         
+     &   forc_nam
+
+      INTEGER ::
+     &   n_fofr,
+     &   i_forc_ts,
+     &   i_forc_count,
+     &   i_forc,
+     &   n_forc_min,
+     &   n_forc_max,
+     &   n0_forc,
+     &   n1_forc
+
+      INTEGER, DIMENSION(n_forc) ::
+     &   forc_swi
+
+      REAL(8)                    ::
+     &   ts_forc,
+     &   doy
+
+      REAL(8), DIMENSION(n_forc) ::
+     &   forc_uni,
+     &   forc_val,
+     &   forc_arr_old,
+     &   forc_arr_new,
+     &   forc_coeff,
+     &   forc_arr
+
+      COMMON /forcingf/
+     &   forc_nam,
+     &   n_fofr,
+     &   n0_forc,
+     &   n1_forc,
+     &   i_forc_ts,
+     &   i_forc_count,
+     &   i_forc,
+     &   n_forc_min,
+     &   n_forc_max,
+     &   forc_swi,
+     &   ts_forc,
+     &   doy,
+     &   forc_uni,
+     &   forc_val,
+     &   forc_arr_old,
+     &   forc_arr_new,
+     &   forc_coeff,
+     &   forc_arr
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/forcing.f	(revision 6)
@@ -0,0 +1,576 @@
+      SUBROUTINE forcing
+
+        !!------------------------------------------------------------------
+        !!                ***       ROUTINE forcing      ***
+        !! ** Purpose :
+        !!      This routine computes the model forcing
+        !!       forc_swi = 0 -> read
+        !!                  1 -> computed
+        !!                 99 -> prescribed
+        !!
+        !! ** Method  :
+        !!
+        !! ** Arguments :
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !! 
+        !! ** External : 
+        !!
+        !! ** References : 
+        !!
+        !! ** History :
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'forcing.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jf          , ! : index for forcing field
+     &  numforc= 600  ! : reference number for bio.param
+
+      CHARACTER(len=10) :: 
+     &   filenc='forcing.nc'
+
+      REAL(4)        zforc(1), zforc2(2) ! forcing field dummy array
+      DIMENSION ws(96),zmue(96),zalcnp(96) ! for solar flux formula
+
+      REAL(8) ::
+     &   zhour
+
+      DIMENSION budyko(19)
+      DATA budyko /1.00,0.98,0.95,0.92,0.89,0.86,0.83,0.80,0.78,0.75,
+     &             0.72,0.69,0.67,0.64,0.61,0.58,0.56,0.53,0.50/
+
+      LOGICAL ::
+     &   ln_write_forc
+
+      ln_write_forc = .TRUE.
+
+      WRITE(numout,*) ' * forcing_nc : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+
+      ! Control parameters number of steps in the integration of shortwave rad
+      nintsr =  24   ! 24 ideally 
+      zsolar = 1368. ! solar constant
+      ji = 1
+
+!
+!-----------------------------------------------------------------------------!
+! 1) Names of the forcing variables
+!-----------------------------------------------------------------------------!
+!
+      forc_nam(1) = 'fsw'
+      forc_nam(2) = 'flw'
+      forc_nam(3) = 'par'
+      forc_nam(4) = 'tair'
+      forc_nam(5) = 'pres'
+      forc_nam(6) = 'qair'
+      forc_nam(7) = 'wspd'
+      forc_nam(8) = 'cld'
+      forc_nam(9) = 'foce'
+      forc_nam(10)= 'sfal'
+      forc_nam(11)= 'albe'
+!
+!-----------------------------------------------------------------------------!
+! 2) Reads namelist
+!-----------------------------------------------------------------------------!
+!
+      IF ( numit .EQ. nstart ) THEN
+
+      IF ( ln_write_forc ) THEN
+         WRITE(numout,*) ' Forcing parameters ... '
+         WRITE(numout,*)
+         WRITE(numout,*) ' forc_nam    : ',( forc_nam(i), i = 1, n_forc)
+      ENDIF
+
+      OPEN( unit = numforc, file='forcing.param', status='old' )
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*) ts_forc    ! Forcing time step
+      READ(numforc,*)
+      READ(numforc,*) n0_forc    ! Number of the first time step in the forcing file
+      READ(numforc,*)
+      READ(numforc,*) n1_forc    ! Number of the last time step in the forcing file
+      IF ( ln_write_forc ) WRITE(numout,*) '  ts_forc : ', ts_forc
+
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+
+      IF ( ln_write_forc ) WRITE(numout,*) '  forc_swi, forc_uni, 
+     & forc_val : '
+      DO i = 1, n_forc
+         READ(numforc,*) idum, dummy1, dummy2
+         READ(numforc,*)
+         forc_swi(i) = idum
+         forc_uni(i) = dummy1
+         forc_val(i) = dummy2
+         IF ( ln_write_forc ) WRITE(numout,*) forc_nam(i), forc_swi(i), 
+     &                                        forc_uni(i), forc_val(i)
+      END DO
+
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*)
+      READ(numforc,*) opt_dept
+      WRITE(numout,*) 'opt_dept : ', opt_dept
+
+      CALL CF_OPEN  (filenc,id) ! open forcing file
+      
+      IF ( ln_write_forc ) WRITE(numout,*)
+
+      ! number of days in a year
+      yeaday = 365.0
+
+      ENDIF ! numit=nstart
+!
+!-----------------------------------------------------------------------------!
+! 3) Calendar parameters
+!-----------------------------------------------------------------------------!
+!
+      IF ( ln_write_forc ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Calendar '
+         WRITE(numout,*)
+      ENDIF
+
+      ! Number of days in the year
+      ! and number of the year
+      IF ( num_d  .EQ. INT( yeaday+1 ) ) THEN
+         nyear    = nyear    + 1
+         yeaday   = 365.0
+         IF ( MOD(nyear  , 4) .EQ. 0 ) THEN
+            yeaday = 366.0
+         ENDIF
+      ENDIF
+
+      ! day of year
+      doy    = REAL(numit) * ddtb / 86400.    ! this does not reset xjour for the new year
+      zz_years = INT ( doy / 365.) + 1        ! number of years in the forcing
+      
+      doy    = doy - ( zz_years - 1 ) * 365. ! this is not yet perfect for leap years but error is very small
+      num_d  = INT(doy)
+
+      WRITE(numout,*) ' zz_years: ', zz_years
+      WRITE(numout,*) ' ddtb    : ', ddtb
+      WRITE(numout,*) ' nyear   : ', nyear 
+      WRITE(numout,*) ' doy     : ', doy
+      WRITE(numout,*) ' num_d   : ', num_d
+!
+!-----------------------------------------------------------------------------!
+! 3) Read the variables
+!-----------------------------------------------------------------------------!
+!
+
+      IF ( numit .EQ. nstart ) THEN
+         n_fofr = INT( ts_forc / ddtb ) ! forcing frequency
+         n_forc_min = n_fofr / 2 + nstart 
+         n_forc_max = ( nitrun - INT( FLOAT(n_fofr) / 2. ) ) + nstart
+         WRITE(numout,*) ' n_fofr : ', n_fofr
+         WRITE(numout,*) ' nstart     : ', nstart
+         WRITE(numout,*) ' n_forc_min : ', n_forc_min
+         WRITE(numout,*) ' n_forc_max : ', n_forc_max
+         WRITE(numout,*) ' nend       : ', nend
+         WRITE(numout,*) ' n0_forc    : ', n0_forc
+         i_forc_ts = nstart / n_fofr - n0_forc + 1
+         WRITE(numout,*) ' i_forc_ts  : ', i_forc_ts
+      ENDIF
+
+      i_forc = MOD( ( numit - nstart ) - n_fofr / 2 , n_fofr) ! indicates if forcing is to be read
+      WRITE(numout,*) ' numit - nstart : ', numit - nstart
+      WRITE(numout,*) ' n_fofr         : ', n_fofr
+      WRITE(numout,*) ' i_forc         : ', i_forc
+
+      !-------------------------------------
+      ! Time steps at which values are READ
+      !-------------------------------------
+      IF ( ( numit .EQ. nstart ) .OR. ( i_forc .EQ. 0.0 ) ) THEN
+         i_forc_count = 0
+         i_forc_ts    = i_forc_ts + 1
+
+         IF ( i_forc_ts .GT. n1_forc ) i_forc_ts = 1
+
+         WRITE(numout,*) ' Forcing read at this time step, numit : ', 
+     &                   numit
+         WRITE(numout,*) ' Forcing step, i_forc_ts  : ', i_forc_ts
+         WRITE(numout,*) ' n_forc : ', n_forc
+
+         DO i = 1, n_forc
+
+            IF ( forc_swi(i) .EQ. 0 ) THEN 
+               IF ( numit .GT. nstart ) forc_arr_old(i) =forc_arr_new(i)
+               IF ( numit .LT. n_forc_max ) THEN
+                  CALL CF_READ1D ( filenc, forc_nam(i), 
+     &                 i_forc_ts , 1, zforc )
+
+                  forc_arr_new(i) = REAL(zforc(1)) * forc_uni(i)
+               ENDIF
+               IF ( numit .EQ. nstart ) forc_arr_old(i) =forc_arr_new(i)
+               forc_coeff(i) = ( forc_arr_new(i) - forc_arr_old(i) ) /
+     &                           FLOAT(n_fofr)
+            ENDIF
+
+         END DO
+       
+      ENDIF
+
+      !-----------------------------------------
+      ! Time steps at which values are COMPUTED
+      !-----------------------------------------
+      i_forc_count = i_forc_count + 1
+      DO i = 1, n_forc
+         IF ( forc_swi(i) .EQ. 0 ) forc_arr(i) = forc_arr_old(i) 
+     &                     + forc_coeff(i) * FLOAT(i_forc_count)
+      END DO
+
+      ! Recover arrays (dirty patch to remove in the end)
+      IF ( forc_swi(1) .EQ. 0 ) zfsw = forc_arr(1)
+      IF ( forc_swi(2) .EQ. 0 ) zflw = forc_arr(2)
+      IF ( forc_swi(3) .EQ. 0 ) zpar = forc_arr(3)
+      IF ( forc_swi(4) .EQ. 0 ) ztair= forc_arr(4)
+      IF ( forc_swi(5) .EQ. 0 ) zpres= forc_arr(5)
+      IF ( forc_swi(6) .EQ. 0 ) zqair= forc_arr(6)
+      IF ( forc_swi(7) .EQ. 0 ) zwspd= forc_arr(7)
+      IF ( forc_swi(8) .EQ. 0 ) zcld = forc_arr(8)
+      IF ( forc_swi(9) .EQ. 0 ) zfoce= forc_arr(9)
+      IF ( forc_swi(10).EQ. 0 ) zsfal= forc_arr(10)
+
+      IF ( forc_swi(1) .EQ. 99 ) zfsw  = forc_val(1) * forc_uni(1)
+      IF ( forc_swi(2) .EQ. 99 ) zflw  = forc_val(2) * forc_uni(2)
+      IF ( forc_swi(3) .EQ. 99 ) zpar  = forc_val(3) * forc_uni(3)
+      IF ( forc_swi(4) .EQ. 99 ) ztair = forc_val(4) * forc_uni(4)
+      IF ( forc_swi(5) .EQ. 99 ) zpres = forc_val(5) * forc_uni(5)
+      IF ( forc_swi(6) .EQ. 99 ) zqair = forc_val(6) * forc_uni(6)
+      IF ( forc_swi(7) .EQ. 99 ) zwspd = forc_val(7) * forc_uni(7)
+      IF ( forc_swi(8) .EQ. 99 ) zcld  = forc_val(8) * forc_uni(8)
+      IF ( forc_swi(9) .EQ. 99 ) zfoce = forc_val(9) * forc_uni(9)
+      IF ( forc_swi(10).EQ. 99 ) zsfal = forc_val(10) * forc_uni(10)
+      IF ( forc_swi(11).EQ. 99 ) zalbe = forc_val(11) * forc_uni(11)
+
+      IF ( forc_swi(11).EQ. 0 ) THEN 
+         zalbe = forc_arr(11)
+         zfswn = ( 1. - zalbe ) * zfsw
+      ENDIF
+      ! snowfall has to be adjusted
+      zsfal = zsfal * ddtb / ts_forc
+!     ! sensitivity test 
+!     ztair = ztair + 2.
+!     zsfal = zsfal + zsfal
+!     zcld  = zcld - zcld / 10.
+!
+!-----------------------------------------------------------------------------!
+! 4) Compute some of the forcing fields if required
+!-----------------------------------------------------------------------------!
+!
+      !----------------------
+      ! 4.1) FLW computation
+      !----------------------
+      i = 1 ; j = 1
+      IF ( ( forc_swi(2) .GT. 0 ) .AND. ( forc_swi(2) .LT. 99 ) ) THEN
+         ze = zqair / ( 1. - zqair ) * zpres / 100.     ! wvp in hPa
+     &      / ( 0.622 - zqair / ( 1. - zqair ) )
+         zta4 = ztair * ztair * ztair * ztair
+         WRITE(numout,*) ' Efimova a'
+         WRITE(numout,*) ' zta4 : ', zta4
+         WRITE(numout,*) ' ze   : ', ze   
+         WRITE(numout,*) ' zcld : ', zcld 
+      ENDIF
+
+      ! Efimova (61) and Key et al (96)
+      !---------------------------------
+      IF ( forc_swi(2) == 1 ) THEN
+!        zflw = emig * stefan * zta4 * 
+!    &          ( 0.746 + 0.0066 * ze ) + ( 1 + 0.26 * zcld )
+         WRITE(numout,*) ' Efimova b'
+         WRITE(numout,*) ' zta4 : ', zta4
+         WRITE(numout,*) ' ze   : ', ze   
+         WRITE(numout,*) ' zcld : ', zcld 
+         ze = zqair / ( 1. - zqair ) * zpres / 100.     ! wvp in hPa
+     &      / ( 0.622 - zqair / ( 1. - zqair ) )
+         zflw = 0.97 * stefan * zta4 * 
+     &          ( 0.746 + 0.0066 * ze ) * ( 1. + 0.26 * zcld )
+      ENDIF
+
+      ! Berliand 
+      !----------
+      IF ( forc_swi(2) == 2 ) THEN
+!        covrai(i,j)=sin(rlat*radian)
+!        alat    = asin(covrai(i,j))/radian
+!        alat    = ASIN ( SIN ( rlat * radian ) ) / radian ! Is it absolute or not
+         clat    = (90.0-rlat)/10.0
+         indx    = 1+int(clat)
+         zflw = stefan*zta4*
+     &            (1.0-(0.39-0.05*sqrt(ze))*(1.0-budyko(indx)*
+     &              zcld*zcld))
+         zcorr_fac_lw = 0.1
+         zflw = zflw + zflw * zcorr_fac_lw
+      ENDIF ! forc_swi(2)
+
+      ! Lab
+      !----------
+      IF ( forc_swi(2) == 3 ) THEN
+         zflw = emig * stefan * zta4
+      ENDIF
+
+      !-------------------------
+      ! 4.2) Albedo computation
+      !-------------------------
+      ! Shine 
+      !-------
+      IF ( forc_swi(11) == 1 ) THEN
+         CALL shine(tfsn, tfsg, t_su_b(ji), t_s_b(ji,1), 
+     &              ht_i_b(ji), ht_s_b(ji), 
+     &              alb_c, alb_o)
+         zalbe =  ( ( 1. - zcld ) * alb_c + zcld * alb_o )
+      ENDIF ! 
+
+      ! Albedo from observed values , ISPOL 
+      !-------------------------------------
+      IF ( forc_swi(11) == 2 ) THEN
+         IF ( ht_s_b(ji) .LE. 0.0 ) THEN
+            zalbe = 0.50 !bare ice albedo
+         ELSE
+            IF ((t_su_b(ji) .GE. 273.15 ).OR.(t_s_b(ji,1) .GE. 273.15 ))
+     &      THEN
+               zalbe = 0.65 ! melting snow albedo
+               zalbe = 0.72 ! melting snow albedo (corrected from reprocessed data)
+            ELSE
+               zalbe = 0.80 ! dry snow albedo
+            ENDIF
+         ENDIF
+         alb_c = zalbe
+         alb_o = zalbe + 0.06
+         zalbe =  ( ( 1. - zcld ) * alb_c + zcld * alb_o )
+      ENDIF ! 
+
+      ! net SW flux in case SW is read in a file
+      !------------------------------------------
+      IF ( ( forc_swi(11) .GT. 0 ) .AND. ( forc_swi(11) .LT. 99 ) .AND. 
+     &     ( forc_swi(1) .EQ. 0 ) ) zfswn = zfsw * ( 1.0 - zalbe )
+
+      !----------------------
+      ! 4.3) FSW computation
+      !----------------------
+      IF ( ( forc_swi(1) .GT. 0 ) .AND. ( forc_swi(1) .LT. 99 ) ) THEN
+         zeps0 = 1.d-13
+         dpi   = 2*pi
+         indaet = 1
+
+         dec    = pdecli(indaet,num_d) * radian
+         sdec   = sin(dec)
+         cdec   = cos(dec)
+         DO j = 1, 1
+            DO i = 1, 1
+            ! geometric factors
+            !-------------------
+            slat   = SIN ( rlat * radian ) 
+            zps    = slat*sdec
+            zpc    = COS(ASIN(slat))*cdec
+
+            zljour = ACOS(-SIGN(one,zps)
+     &             * MIN(one,SIGN(one,zps)*(zps/zpc)))
+
+            dws    = (2.0*zljour)/REAL(nintsr)
+            zlmidi = ASIN(( zps +zpc ))/radian
+            zalcnq = 0.0
+            DO k = 1, nintsr
+              ws(k)     = zljour-(REAL(k)-0.5)*dws
+              zmue(k)   = MAX(c_zero,zps+zpc*COS(ws(k)))
+              zalcnp(k) = 0.05/(1.1*zmue(k)**1.4+0.15)
+              zalcnq    = zalcnp(k)
+            END DO
+            zalcnq = zalcnq/MAX(2.0*zljour,zeps0)
+            zmudum = 0.4
+
+            ! Irradiance 
+            !------------
+            ze = zqair / ( 1. - zqair ) * zpres      ! wvp in Pa
+     &         / ( 0.622 - zqair / ( 1. - zqair ) )
+            ztc = ztair - 273.15
+            zesw = 611.*EXP(17.269*ztc/(ztc+237.3)) ! Pa
+            ztdew = ze / zesw ! no units
+
+            !-------
+            ! Shine 
+            !-------
+            IF ( forc_swi(1) == 1 ) THEN
+               !-----------------
+               ! DAILY time step
+               !-----------------
+               IF ( ddtb .EQ. 86400.0 ) THEN
+                  frsdrg = 0.0
+                  frsdfg = 0.0
+                  frsdro = 0.0
+                  frsdfo = 0.0
+!                 opt_dept = 16.297 ! to put in the namelist
+!                 opt_dept = 5.6000 ! to put in the namelist
+                  DO k = 1 , nintsr ! integrate over the whole day
+                     frsdrg = frsdrg+dws*      ! clear 
+     &                       (zsolar*zmue(k)*zmue(k)*(1.0-alb_c))/
+     &                     (1.2*zmue(k)+(1.0+zmue(k))*ze*1.0e-05+0.0455)
+                     frsdfg  = frsdfg+dws*     ! overcast
+     &                     ( ( 53.5 + 1274.5*zmue(k) ) * SQRT(zmue(k) )
+     &                     * ( 1.0 - 0.996*alb_o ) )  
+     &                     / (1.0+0.139*(1.0-0.9435*alb_o)*opt_dept)
+                  END DO
+                  ! net solar heat flux (1-a)FSW
+                  zfswn = ( ( 1.0 - zcld ) * frsdrg + zcld * frsdfg ) / 
+     &                    dpi
+               ENDIF ! ddtb
+
+               !--------------------
+               ! SUBDAILY time step
+               !--------------------
+               IF ( ddtb .LT. 86400.00 ) THEN
+!                  WRITE(numout,*) ' Shine formula, subdaily time step '
+!                  WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+
+                   ! Solar angle
+                   zdecl  = pdecli(indaet,num_d) * radian
+                   zsdec  = SIN(zdecl)
+                   zcdec  = COS(zdecl)
+                   zslat  = SIN ( rlat * radian )
+                   zps    = zslat*zsdec
+                   zpc    = COS(ASIN(slat))*cdec
+                   zhour = ( doy - FLOAT(num_d) ) * 24.
+
+                   ! Hour angle
+                   zljour = ACOS(-SIGN(one,zps)
+     &                    * MIN(one,SIGN(one,zps)*(zps/zpc)))
+                   zhourang = - pi + 2.*pi / 24. * zhour
+                   ! Cosine of solar angle
+                   zcosz = 0.0
+                   IF ( ( zhourang .GT. -zljour ) .AND. 
+     &                  ( zhourang .LT. zljour ) ) 
+     &                zcosz = MAX(0.0,zps+zpc*COS(zhourang))
+                   zcosz2 = zcosz * zcosz
+
+                   ! Irradiance
+                   zqsr_clear = zsolar * zcosz2 
+     &                        / ( 1.2 * zcosz 
+     &                          + ( 1.0 + zcosz ) * ze * 1.0e-5 
+     &                          + 0.0455 )
+                   zqsr_cloud = ( 53.5 + 1274.5 * zcosz ) * 
+     &                          SQRT( zcosz ) / ( 1.0 + 0.139 * 
+     &                          ( 1.0 - 0.9435 * zalbe ) * opt_dept )
+                   zfsw = ( 1. - zcld ) * zqsr_clear 
+     &                  + zcld          * zqsr_cloud
+                   zfswn = ( 1. - zcld ) * ( 1. - alb_c ) * zqsr_clear
+     &                   + zcld * ( 1. - alb_o ) * zqsr_cloud
+
+                   WRITE(numout,*) ' zqsr_clear : ', zqsr_clear
+                   WRITE(numout,*) ' zqsr_cloud : ', zqsr_cloud
+
+               ENDIF ! ddtb
+
+            ENDIF ! Shine
+
+            !----------
+            ! Zillmann
+            !----------
+            IF ( forc_swi(1) == 2 ) THEN
+               IF ( ddtb .EQ. 86400.0 ) THEN
+               frsdtg = 0.0
+               frsdto = 0.0
+               DO k = 1 , nintsr
+                  albo   = (1.0-zcld)*zalcnp(k)+zcld*zalbe
+                  frsdtg = frsdtg+dws*(1.0-zalbe)*
+     &                     (zsolar*zmue(k)*zmue(k))/
+     &                     ((zmue(k)+2.7)*ze*1.0e-05+1.085*zmue(k)+0.10)
+               END DO
+               ! rewrite this next line correctly
+               zfswn      = 0.9*min(one,(1-.62*zcld+.0019*zcld))*
+     &                      frsdtg/dpi
+               ENDIF
+            ENDIF ! 
+            END DO
+         END DO
+      ENDIF ! forc_swi(1)
+
+      IF ( forc_swi(3) == 1 ) THEN
+         !-----------------
+         ! 4.2 PAR formula
+         !-----------------
+         zpar = 0.43
+      ENDIF
+!
+!-----------------------------------------------------------------------------!
+! 5) Case of prescribed values
+!-----------------------------------------------------------------------------!
+!
+      IF ( forc_swi(1) .EQ. 99 ) zfsw  = forc_val(1) * forc_uni(1)
+      IF ( forc_swi(2) .EQ. 99 ) zflw  = forc_val(2) * forc_uni(2)
+      IF ( forc_swi(3) .EQ. 99 ) zpar  = forc_val(3) * forc_uni(3)
+      IF ( forc_swi(4) .EQ. 99 ) ztair = forc_val(4) * forc_uni(4)
+      IF ( forc_swi(5) .EQ. 99 ) zpres = forc_val(5) * forc_uni(5)
+      IF ( forc_swi(6) .EQ. 99 ) zqair = forc_val(6) * forc_uni(6)
+      IF ( forc_swi(7) .EQ. 99 ) zwspd = forc_val(7) * forc_uni(7)
+      IF ( forc_swi(8) .EQ. 99 ) zcld  = forc_val(8) * forc_uni(8)
+      IF ( forc_swi(9) .EQ. 99 ) zfoce = forc_val(9) * forc_uni(9)
+      IF ( forc_swi(10).EQ. 99 ) zsfal = forc_val(10) * forc_uni(10)
+      IF ( forc_swi(11).EQ. 99 ) THEN
+         zalbe = forc_val(11) * forc_uni(11)
+         zfswn = ( 1. - zalbe ) * zfsw
+      ENDIF
+!
+!-----------------------------------------------------------------------------!
+! 6) Temporary dirty plug
+!-----------------------------------------------------------------------------!
+!
+
+      fsolgb(ji) = zfswn 
+      ratbqb(ji) = zflw
+      ! par is not yet included, should be
+      tabqb(ji)   = ztair
+      psbqb(ji)   = zpres
+      qabqb(ji)   = zqair
+      vabqb(ji)   = zwspd
+      cldqb(ji)   = zcld
+      oce_flx     = zfoce
+      hnpbqb(ji)  = zsfal
+      albgb(ji)   = zalbe
+      ze = zqair / ( 1. - zqair ) * zpres      ! wvp in Pa
+     &   / ( 0.622 - zqair / ( 1. - zqair ) )
+      ztc = ztair - 273.15
+      zesw = 611.*EXP(17.269*ztc/(ztc+237.3)) ! Pa
+      ztdew = ze / zesw ! no units
+      tdewb(ji)   = ztdew
+
+      IF ( ln_write_forc ) THEN
+         WRITE(numout,*) ' Forcing fields ... '
+         WRITE(numout,*)
+         WRITE(numout,*) ' fsolgb      : ', fsolgb(ji)
+         WRITE(numout,*) ' ratbqg      : ', ratbqb(ji)
+         WRITE(numout,*) ' tabqb       : ', tabqb(ji)
+         WRITE(numout,*) ' psbqb       : ', psbqb(ji)
+         WRITE(numout,*) ' qabqb       : ', qabqb(ji)
+         WRITE(numout,*) ' vabqb       : ', vabqb(ji)
+         WRITE(numout,*) ' cldqb       : ', cldqb(ji)
+         WRITE(numout,*) ' oce_flx     : ', oce_flx
+         WRITE(numout,*) ' hnpbqb      : ', hnpbqb(ji)
+         WRITE(numout,*) ' albgb       : ', albgb(ji)
+         WRITE(numout,*)
+      ENDIF
+
+
+!------------------------------------------------------------------------------
+! end of forcing 
+      RETURN
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice.com	(revision 6)
@@ -0,0 +1,233 @@
+!
+!  ice.F CLEANING REQUIRED
+!
+
+! tfsn      Melting point temperature of the snow
+! tfsg      Melting point temperature of the ice
+! xkn       Conductivity of the snow
+! xkg       Conductivity of the ice
+! rcpn      Density times specific heat for the snow
+! rcpg      Density times specific heat for the ice
+! rhog      Density of the ice
+! rhon      Density of the snow
+! emig      Emissivity of the ice
+! sglace    Salinity of the ice
+! hmelt     Maximum melting at the bottom
+! acrit(2)  Minimum fraction for leads
+! hgcrit(2) Ice thickness for lateral accretion
+! hgmin     Ice thickness corr. to max. energy stored in brine pocket
+! hndif     Computation of temp. in snow or not 
+! hgdif     Computation of temp. in ice or not 
+! hglim     Minimum ice thickness
+! amax      Maximum lead fraction
+! uscomi    =1.0/(1.0-amax)
+! beta      Numerical caracteritic of the scheme for diffusion in ice
+! ddtb      Time step for ice thermodynamics (s)
+! swiqst    Energy stored in brine pocket or not 
+! parlat    Percentage of energy used for lateral ablation
+! hakspl    Slope of distr. for Hakkinen-Mellor's lateral melting
+! hibspl    Slope of distribution for Hibler's lateral melting
+! exld      Exponent for leads-closure rate
+! hakdif    Coefficient for diffusions of ice and snow
+! hth       Threshold thickness for comp. of eq. thermal conductivity
+! hnzst     Thickness of the surf. layer in temp. computation
+! parsub    Switch for snow sublimation or not
+! cnscg     ratio  rcpn/rcpg
+! nbits     Number of time steps in Newton -Raphson procedure
+! stefan    Stefan-Boltzman constant
+! vkarmn    von Karman constant
+! cevap     Latent heat of evaporation of water
+! zemise    Emissivity of water
+! rhoesn    1/rhon
+! firg      IR flux over the ice (only used for outputs)
+! fcsg      Sensible heat flux over the ice (only used for outputs)
+! fleg      Latent heat flux over the ice (only used for outputs)
+! ts        Surface temperature of the ice
+! tfu       Melting point temperature of sea water
+! hnbq      Snow thickness
+! hgbq      Ice thickness
+! albq      Leads fraction
+! qstobq    Energy stored in the brine pockets
+! fbbq      Heat flux at the ice base
+! tbq       Temperature inside the ice/snow layer
+! dmnbq     Variation of snow mass
+! dmgbq     Variation of ice mass
+! qlbq      heat balance of the lead (or of the open ocean)
+! qcmbq     Energy needed to bring the ocean surface layer until its freezing 
+!	    point (at a factor 2)
+! thcm      part of the solar energy used in the lead heat budget
+! fstrbq    Solar flux transmitted trough the ice
+! ffltbq    Array linked with the max heat contained in brine pockets (?)
+! fscmbq    Linked with the solar flux below the ice (?)
+! fsbbq     Also linked with the solar flux below the ice (?)
+! qfvbq     Array used to store energy in case of toral lateral ablation (?)
+! xzo       rugosity of the ice (no more used)
+! dmgwi     Variation of the mass of snow ice
+! psbq      Surface air pressure
+! tabq      Surface air temperature
+! qabq      Surface air humidity
+! vabq      Surface wind velocity
+! hnplbq    Snow precipitation
+! fevabq    Evaporation flux
+! fsolcn    Solar flux at the ocean surface
+! fsolg     Solar flux at the ice surface
+! flecn     Latent heat flux at the ocean surface
+! fcscn     Sensible heat flux at the ocean surface
+! tenagx    Wind stress at the ice surface (x)
+! tenagy    Wind stress at the ice surface (y)
+! albg      03/08/2001 albedo obtenu du forcage simip2
+! albege    Albedo of the snow or ice (only for outputs)
+! tairox    Wind stress at the ocean surface (x)
+! tairoy    Wind stress at the ocean surface (y)
+! ratbqg    Longwave downward radiation flux over the ice
+! ratbqo    Longwave downward radiation flux over the ocean
+! cloud     Cloud fraction
+! tdew      Air relative humidity
+! albecn    Albedo of the ocean (only for outputs)
+! tauc      Cloud optical depth
+! runoff    river runoff
+! sdvt      u*^2/(Stress/density)
+! fcm1      Solar flux at the ocean surface
+! fcm2      Non-solar flux at the ocean surface
+! fwat      Freshwater flux (change of definition between the routines) 
+! reslum    Relative absorption of solar radiation in each ocean level
+!
+!--COMMON blocs :
+!------------------------------------------------------------------------------
+      COMMON /ice_grid/
+     &  deltaz_i_phy(maxnlay) ,       !: thicknesses of the physical ice layers
+     &  z_i_phy(maxnlay)      ,       !: cotes of the physical ice layers
+     &  zb_i_phy(0:maxnlay)      ,    !: cotes of the interfaces of the physical ice layers
+     &  deltaz_s_phy(maxnlay) ,       !: thicknesses of the physical snow layers
+     &  z_s_phy(maxnlay)              !: cotes of the physical snow layers
+
+      COMMON / ice_constants /
+     &  tfsn,tfsg,xkn,xkg,rcpn,rcpg,rhog,rhon,
+     &  emig,sglace,hmelt,acrit(2),hgcrit(2),hgmin,hndif,
+     &  hgdif,hglim,amax,uscomi,beta,ddtb,swiqst,parlat,
+     &  hakspl,hibspl,exld,hakdif,hth,hnzst,parsub,cnscg,nbits
+
+      COMMON / fluxsf /
+     &  stefan,lvap,lsub,vkarmn,cevap,zemise,rhoesn
+     
+      COMMON / comdia /
+     &  firg(imax,jmax),fcsg(imax,jmax),fleg(imax,jmax)
+
+      COMMON / comban /
+     &  ts(imax,jmax),tfu(imax,jmax),hnbq(imax,jmax),
+     &  hgbq(imax,jmax),albq(imax,jmax),
+     &  qstobq(imax,jmax),fbbq(imax,jmax),
+     &  dmnbq(imax,jmax),dmgbq(imax,jmax),
+     &  qlbq(imax,jmax),qcmbq(imax,jmax),thcm(imax,jmax),
+     &  fstrbq(imax,jmax),ffltbq(imax,jmax),fscmbq(imax,jmax),
+     &  fsbbq(imax,jmax),qfvbq(imax,jmax),xzo(imax,jmax),
+     &  dmgwi(imax,jmax),total(imax,jmax)
+c
+      COMMON / comfor /
+     &  psbq(imax,jmax),tabq(imax,jmax),
+     &  qabq(imax,jmax),vabq(imax,jmax),
+     &  hnplbq(imax,jmax),fevabq(imax,jmax),fsolcn(imax,jmax),
+     &  hnpbq(imax,jmax), 
+     &  fsolg(imax,jmax),flecn(imax,jmax),fcscn(imax,jmax),
+     &  tenagx(imax,jmax),tenagy(imax,jmax),albg(imax,jmax),
+     &  albege(imax,jmax),tairox(imax,jmax),tairoy(imax,jmax),
+     &  ratbqg(imax,jmax),ratbqo(imax,jmax),cloud(imax,jmax),
+     &  opt_dept,
+     &  tdew(imax,jmax),
+     &  albecn(imax,jmax),tauc(imax,jmax),runoff(imax,jmax),
+     &  sdvt(imax,jmax),fsolg2(imax,jmax)
+
+      COMMON / comca /
+     &  fcm1(imax,jmax),fcm2(imax,jmax),
+     &  fwat(imax,jmax),
+     &  reslum(imax,jmax,0:kmax+1)
+
+c global characteristics of the ice pack
+      COMMON / ice_global /
+     &  t_i(imax,jmax,maxnlay),t_s(imax,jmax,maxnlay),t_su(imax,jmax),
+     &  t_bo(imax,jmax),ht_s(imax,jmax),ht_i(imax,jmax),ht_w(imax,jmax),
+     &  s_i(imax,jmax,maxnlay)
+
+      COMMON / heat_fluxes /
+     &  fc_int
+
+      LOGICAL:: ln_evap
+
+      LOGICAL:: ln_flo, ln_grd, ln_flu
+      
+      COMMON/snow_phy/ln_evap
+
+      integer :: layer,layer_a,nconv,numofday
+      integer :: modul0, modul1a, modul2, modul3, modul4
+      integer :: modul1b,modul5,nbot0,nbot1,ntop0,ntop1
+
+c     Number of layers in the ice and snow
+      integer :: nlayi0, nlayi1, nlays0, nlays1
+      integer :: nlay_i, nlay_s
+
+      COMMON/layers/ n_i, n_s
+
+      COMMON/simip/zsim(0:maxnlay),tempsim(maxnlay),salsim(maxnlay),
+     &             tempint(maxnlay),salint(maxnlay),
+     &             thick0(maxnlay),
+     &             thick1(maxnlay),
+     &             hsold,hgold,hsnew,hgnew
+ 
+      COMMON/vertres/zm0(0:maxnlay),zm1(0:maxnlay),qm0(maxnlay),
+     &		     qm1(0:maxnlay+2), sal_new_layer
+
+      COMMON/heateqcoe/lfus,cpg,cpw,gammac,betak,tmut,tpw,
+     &	            cpoc,deltah, betak1, betak2, visc_br, beta_ocs
+
+      COMMON/barrowconf/sal_read(11), hi_read(11), hgins, hnins,
+     &              tsuins, oce_sal, oce_flx, num_sal, nday1,
+     &              i_sal
+     
+      COMMON/snowprecip/numd_sn1, numd_sn2, numd_sn3, 
+     &                  sn_prec_1, sn_prec_2
+
+      COMMON/tuneforcing/sf_mult, tabq_ano
+
+      COMMON/fluidtpt/flu_beta, rad_io,
+     &                frtr_si_phy, qsummer, d_br_mol, d_br_tur,
+     &                ra_c, ra_smooth, e_thr_flu, delta_cw, ini_swi, 
+     &                s_ini, ln_flo, ln_flu, ln_grd
+
+      CHARACTER*2 gravdr
+      CHARACTER*4 alb_char, pre_char, sal_char
+      CHARACTER*12 name_file_bar_par
+      CHARACTER*17 name_file_bar_for
+      CHARACTER*4  c_rad_scheme
+      CHARACTER*3  c_rad_discr
+       
+      COMMON/chars/gravdr, alb_char, pre_char, sal_char, 
+     &             name_file_bar_par, namefile_bar_for, 
+     &             c_rad_scheme, c_rad_discr
+
+      ! radiation transfer in sea ice
+      REAL(8) ::
+     &   rad_inot_s_dry, rad_inot_s_wet, 
+     &   rad_inot_i_dry, rad_inot_i_wet,
+     &   h_not_s, h_not_i, 
+     &   fpar_fsw, qpar_fsw,
+     &   rad_kappa_s_su_d, rad_kappa_s_su_m,
+     &   rad_kappa_s_de_d, rad_kappa_s_de_m,
+     &   rad_kappa_i_su_d, rad_kappa_i_su_m,
+     &   rad_kappa_i_de_d, rad_kappa_i_de_m
+ 
+      COMMON/icerad/
+     &   rad_inot_s_dry, rad_inot_s_wet, 
+     &   rad_inot_i_dry, rad_inot_i_wet,
+     &   h_not_s, h_not_i, 
+     &   fpar_fsw, qpar_fsw,
+     &   rad_kappa_s_su_d, rad_kappa_s_su_m,
+     &   rad_kappa_s_de_d, rad_kappa_s_de_m,
+     &   rad_kappa_i_su_d, rad_kappa_i_su_m,
+     &   rad_kappa_i_de_d, rad_kappa_i_de_m
+
+      CHARACTER*5 c_bio_model
+      COMMON/limbio/
+     &   c_bio_model
+!
+!--fin du fichier "ice.com"
+!-------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_column.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_column.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_column.f	(revision 6)
@@ -0,0 +1,47 @@
+      SUBROUTINE ice_bio_column(kideb,kiut,ntra,zmt_i,zc_i,
+     &                          zdeltaz,ln_write)
+
+! This routine sums the mass of tracers over the whole column
+! (c) Martin Vancoppenolle, June 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jn            ! : index for tracers
+
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   zmt_i
+      REAL(8), DIMENSION(ntra_bio_max,nlay_bio) ::
+     &   zc_i
+      REAL(8), DIMENSION(nlay_bio) ::
+     &   zdeltaz
+      LOGICAL ::
+     &   ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' *** ice_bio_column : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      DO jn = 1, ntra
+         zmt_i(jn) = 0.0
+      END DO
+
+      DO jn = 1, ntra
+         DO jk = 1, nlay_bio
+            zmt_i(jn) = zmt_i(jn) + zc_i(jn,jk) *
+     &      zdeltaz(jk)
+         END DO
+      END DO
+
+      RETURN
+
+!=============================================================================!
+!-- End of ice_bio_column --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_conserv.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_conserv.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_conserv.f	(revision 6)
@@ -0,0 +1,104 @@
+      SUBROUTINE ice_bio_conserv(kideb,kiut,ntra,message,trc_nam,err,
+     &                           zmb0,zmb1,zfb,zfsu,zdt)
+
+! This routine tests conservation of the mass of tracers
+! (c) Martin Vancoppenolle, June 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'bio.com'
+
+      CHARACTER(len=15) :: 
+     &   message       ! : message indicating the name of the routine calling
+
+      CHARACTER(len=64), DIMENSION(ntra_bio_max) :: 
+     &   trc_nam       ! : name of the tracer tested
+
+      CHARACTER(len=19) ::
+     &   zstr1
+      CHARACTER(len=3) ::
+     &   zstr2
+      CHARACTER(len=8) ::
+     &   zstr3
+
+      REAL(8) ::
+     &   err
+
+      REAL(8), DIMENSION(ntra_bio_max) ::
+     &   zmb0 ,
+     &   zmb1 ,
+     &   zfb  ,
+     &   zfsu
+
+      REAL(8) ::
+     &   zdt 
+         
+      INTEGER :: 
+     &   ji          , ! : index for space
+     &   jk          , ! : index for ice layers
+     &   jn            ! : index for tracers
+
+      REAL(8) ::
+     &   zdm           ! : actual mass variation
+     &   zdmf
+
+!=============================================================================!
+
+      WRITE(numout,*) ' ice_bio_conserv : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~ '
+      WRITE(numout,*) ' message     : ', message
+      WRITE(numout,*) ' error max   : ', err
+      WRITE(numout,*) ' kideb, kiut : ', kideb, kiut
+      WRITE(numout,*) ' ddtb        : ', zdt
+
+      DO jn = 1, ntra
+
+         IF ( flag_active(jn) ) THEN
+         
+          WRITE(numout,*) ' --- Tracer     : ', trc_nam(jn)
+          WRITE(numout,*) ' jn : ', jn
+          WRITE(numout,*) ' mt_i_bio_init  : ', zmb0(jn)
+          WRITE(numout,*) ' mt_i_bio_final : ', zmb1(jn)
+   
+          zdm = ( zmb1(jn) - zmb0(jn) ) / zdt
+          zdmf = zfb(jn) + zfsu(jn)
+   
+          WRITE(numout,*) ' Actual mass variation zdm       : ', zdm
+          WRITE(numout,*) ' Mass variation from fluxes zdmf : ', zdmf
+          zstr1 = ' Bio conserv error '
+          zstr2 = TRIM(trc_nam(jn))
+          WRITE(zstr3,'(E8.2)') ABS(zdm-zdmf)
+!         WRITE(numout,*) ' Bio conserv error : ', ABS(zdm-zdmf)
+          WRITE(numout,*) zstr1//'in '//TRIM(message)//' ('//zstr2//
+     &                    ') : '//zstr3
+          WRITE(503,*) zmb1(jn), ABS(zdm-zdmf)*zdt
+            
+          IF ( ABS ( zdm - zdmf ) .GT. err ) THEN
+           WRITE(numout,*) ' Conservation error after ', message
+           WRITE(numout,*) ' Error                           : ', 
+     &                      ABS( zdm - zdmf )
+!           WRITE(numout,*) ' Actual mass variation zdm       : ', zdm
+!           WRITE(numout,*) ' Mass variation from fluxes zdmf : ', zdmf
+           WRITE(numout,*)
+           WRITE(numout,*) ' mt_i_bio_init   : ', zmb0(jn)
+           WRITE(numout,*) ' mt_i_bio_final  : ', zmb1(jn)
+           WRITE(numout,*) ' Upper flux zfsu : ', zfsu(jn)
+           WRITE(numout,*) ' Lower flux zfb  : ', zfb(jn)
+           WRITE(numout,*)
+!           WRITE(numout,*) ' c_i_bio   : ', ( c_i_bio(jn,layer), 
+!    &                      layer = 1, nlay_bio )
+!           WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn,layer), 
+!    &                      layer = 1, nlay_bio )
+
+          ENDIF ! residual
+
+         ENDIF ! flag_active
+
+      END DO ! jn
+
+      RETURN
+
+!=============================================================================!
+!-- End of ice_bio_conserv --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_diff.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_diff.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_diff.f	(revision 6)
@@ -0,0 +1,713 @@
+      SUBROUTINE ice_bio_diff(kideb,kiut,nlay_i)
+
+!------------------------------------------------------------------------------!
+!
+!                              --- ice_bio_diff ---
+!
+!    Transport and diffusion of tracers
+!    (c) Martin Vancoppenolle, May 2007
+!        1.1 Rayleigh number based diffusivity, Oct 2008
+!        1.2 Includes open upper boundary condition for gas exchange Jul 2010 - Mar 2011
+!        1.3 Simplification and implementation of flooding velocity, Feb 2012
+!
+!     Rewriting of surface gas boundary condition (M. Vancoppenolle & S. Moreau, 2015)
+!        - routine for gas transfer velocity (ice_gas_trvel)
+!        - add solubility and partial pressure for each gas
+!
+!       ! Use the real surface pCO2 and not the 1st layer value
+!       ! remove ji
+!
+!------------------------------------------------------------------------------!
+
+      USE lib_fortran
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &   ji                 ,    ! : horizontal space index
+     &   jn                      ! : horizontal space index jn
+
+      REAL(8), DIMENSION( maxnlay ) ::  !: dummy factors for tracer equation
+     &   za                 ,    !: winter
+     &   zb                 ,   
+     &   zc                 ,   
+     &   ze                 ,    !: summer
+     &   zind               ,    !: independent term in the tridiag system
+     &   zindtbis           ,    !:
+     &   zdiagbis
+
+      REAL(8), DIMENSION(maxnlay,3) ::!: dummy factors for tracer equation
+     &   ztrid                   !: tridiagonal matrix
+
+      REAL(8), DIMENSION(nlay_bio) ::  
+     &   z_sbr_i                 !: brine salinity
+     
+      REAL(8), DIMENSION(ntra_bio_max) ::  
+     &   zpp_gas                 !: partial pressure
+
+      REAL(8) ::  
+     &   zdummy1            ,    !: dummy factors
+     &   zdummy2            ,    !: 
+     &   zdummy3            ,    !: 
+     &   zswitchs           ,    !: switch for summer drainage
+     &   f_sn_rat           ,
+     &   wspd_trs           ,           
+     &   zsat_arg           ,
+     &   zsat_oxy           ,
+     &   zsat_CO2           ,
+     &   zsat_nit           ,
+     &   mol_diff
+
+      INTEGER ::  
+     &   indtr              ,    !: index of tridiagonal system
+     &   iter                    !: time step  index
+     
+      LOGICAL ::
+     &   ln_write_bio       ,
+     &   ln_con_bio         ,
+     &   ln_flood           
+
+      ln_write_bio = .TRUE.
+      ln_con_bio   = .TRUE.
+      ln_flood     = .TRUE.
+
+      zsol      = 0.
+      zb0       = 0.
+      zpatm_gas = 0. 
+      zpp_gas(:) = 0.0
+
+!=======================================================================
+
+      WRITE(numout,*) 
+      WRITE(numout,*) ' ** ice_bio_diff : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~ '
+      WRITE(numout,*)
+
+      DO ji = kideb, kiut
+
+!
+!-----------------------------------------------------------------------
+! 1) Initialization
+!-----------------------------------------------------------------------
+!
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) ' Initialization '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+      ENDIF
+      
+      !---------------
+      ! Interpolation 
+      !---------------
+      CALL ice_bio_interp_phy2bio(kideb,kiut,nlay_i,.FALSE.) 
+                             ! interpolation of physical variables
+                             ! on the biological grid
+                             ! mass of salt, heat content, brine volume, Rb, PAR
+
+      CALL ice_bio_interp_diffus(kideb,kiut,nlay_i,.TRUE.) 
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) ' diff_br_bio : ', ( diff_br_bio(layer), 
+     &                   layer = 1, nlay_bio )
+      ENDIF
+
+      !--------------------------------
+      ! Brine concentration of tracers
+      !--------------------------------
+      DO jn = 1, ntra_bio
+         IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+            DO jk = 1, nlay_bio
+               c_i_bio(jn,jk) = cbu_i_bio(jn,jk) / e_i_bio(jk)
+            END DO
+         ENDIF
+         IF ( flag_adsorb(jn) .AND. flag_active(jn) ) THEN
+            DO jk = 1, nlay_bio
+               c_i_bio(jn,jk) = 0.
+            END DO
+         ENDIF
+         WRITE(numout,*) ' 01 *** jn = ', jn
+         WRITE(numout,*) ' c_i_bio : ', c_i_bio(jn,:)
+      END DO
+
+      
+      !---------------------------------------------------------------
+      ! Equilibrate carbonate system to get aqueous CO2 concentration
+      !---------------------------------------------------------------
+      IF ( ln_carbon ) CALL ice_carb_chem
+
+      DO jn = 1, ntra_bio
+         WRITE(numout,*) ' 02 *** jn = ', jn
+         WRITE(numout,*) ' c_i_bio : ', c_i_bio(jn,:)
+      END DO
+
+      !--------------------
+      ! Conservation check
+      !--------------------
+
+      CALL ice_bio_column(kideb,kiut,ntra_bio,mt_i_bio_init,cbu_i_bio,
+     &                    deltaz_i_bio, .FALSE.)
+
+      IF ( ln_write_bio ) THEN
+         DO jn = 1, ntra_bio
+            WRITE(numout,*) ' mt_i_bio_init : ', mt_i_bio_init(jn)
+         END DO
+      ENDIF
+
+      ! layer by layer
+      DO jn = 1, ntra_bio
+         DO jk = 1, nlay_bio
+            m_i_bio_init(jn,jk) = cbu_i_bio(jn,jk)*deltaz_i_bio(jk)
+         END DO
+      END DO
+      
+!
+!-----------------------------------------------------------------------
+! 3) Surface boundary condition for gases
+!-----------------------------------------------------------------------
+!
+      
+      zaeff        = e_i_bio(1) * brines_ar    ! proportionality factor for surface flux
+      
+      zpp_gas(:)   = mixr_gas(:) * psbqb(ji) / ! atmospheric partial pressure
+     &               101325.
+                                               !----------------------------
+      CALL ice_gas_solu                        ! Solubilities (sol_gas(jn))
+                                               !----------------------------
+
+                                               !-------------------------
+      gas_trvel(:) = 0.                        ! Gas transfer velocities
+                                               !-------------------------
+
+      DO jn = 1, ntra_bio
+
+      IF ( flag_active(jn) .AND. ( biotr_i_typ(jn) .EQ. 'gas' ) .AND. ! select gases only
+     &   ( flag_diff(jn) .OR. flag_adsorb(jn) ) .AND. ln_gasflux ) THEN
+                           
+         SELECT CASE ( i_gasflux )
+    
+            CASE (1) ! No flux
+   
+            CASE (2) ! Gas diffusion between ice and atm
+               
+               IF ( e_i_bio(1) .GT. e_thr_gasflux ) 
+     &            gas_trvel(jn) = dmol_gas(jn) / h_bl_gas
+               
+         END SELECT
+
+         IF ( ln_write_bio ) THEN
+            
+            WRITE(numout,*) '  *** Gas transfer velocity --- '
+            WRITE(numout,*) '  --- Tracer    --- :   ', biotr_i_nam(jn)
+            WRITE(numout,*) '  gas_trvel : ', gas_trvel(jn)
+               
+         ENDIF ! ln_write_bio
+   
+      ENDIF ! flags
+   
+!
+!-----------------------------------------------------------------------
+! 3) Switches, flushing and flooding velocities
+!-----------------------------------------------------------------------
+!
+      !----------
+      ! Switches
+      !----------
+      ! summer switch
+      zbvmin   = 1.0
+      DO layer = 1, nlay_bio
+         zbvmin = MIN( e_i_bio(layer) , zbvmin ) ! minimum brine volume
+      END DO
+      zswitchs = MAX( 0.0, SIGN ( 1.0d0, t_su_b(ji) - tpw ) ) ! 0 si hiver 1 si ete
+      IF ( zbvmin .LT. e_thr_flu ) zswitchs = 0.0
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) ' zswitchs : ', zswitchs
+         WRITE(numout,*) 
+      ENDIF
+     
+      ! flood switch
+      IF ( w_flood .GT. 0 ) THEN
+         z_flood = 0.0
+      ELSE
+         z_flood = 1.0
+      ENDIF
+
+      ! recompute flushing velocity
+      w_flush = qsummer / ddtb / e_i_bio(1)
+
+!
+!-----------------------------------------------------------------------
+! 4) Compute dummy factors for tracer diffusion equation
+!-----------------------------------------------------------------------
+!
+      IF ( ( flag_diff(jn) .OR. flag_adsorb(jn) ) 
+     &   .AND. flag_active(jn) ) THEN
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) ' --------------------------------- '
+         WRITE(numout,*) '  Diffusion for ', biotr_i_nam(jn)
+         WRITE(numout,*) ' --------------------------------- '
+
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Dummy factors '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+      ENDIF
+
+      !--------------------
+      ! za factors
+      !--------------------
+      DO layer = 1, nlay_bio
+         za(layer) = ddtb / ( deltaz_i_bio(layer) * e_i_bio(layer) )
+      END DO
+
+      !--------------------
+      ! zb, zc, ze factors
+      !--------------------
+      DO layer = 1, nlay_bio - 1
+         ! interpolate brine volume at the interface between layers
+         zdummy1 = ( e_i_bio(layer + 1) - e_i_bio(layer) ) /  
+     &             ( z_i_bio(layer + 1) - z_i_bio(layer) )
+         zdummy2 = deltaz_i_bio(layer) / 2.0
+         zdummy3 = e_i_bio(layer) + zdummy1 * zdummy2
+         zb(layer) = zdummy3 * diff_br_bio(layer) /
+     &               ( z_i_bio(layer+1) - z_i_bio(layer) )
+         zc(layer) = w_flood * zdummy3 * z_flood
+         ze(layer) = ( w_flood * ( 1. - z_flood ) + w_flush ) * zdummy3
+      END DO
+
+      ! Basal values
+      zb(nlay_bio) = 2. * e_i_bio(nlay_bio) /
+     &               deltaz_i_bio(nlay_bio) * diff_br_bio(nlay_bio)
+      zc(nlay_bio) = w_flood * e_i_bio(nlay_bio) * z_flood
+      ze(nlay_bio) = ( w_flood * ( 1. - z_flood ) + w_flush ) *
+     &               e_i_bio(nlay_bio)
+
+      ! Open upper boundary condition for gas
+      zb0 = 0.
+      IF ( biotr_i_typ(jn) .EQ. 'gas' ) zb0 = gas_trvel(jn) * zaeff
+
+      ! Block fluxes above the biologically active layer (SL & BAL cases)
+      IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) THEN
+         zb(1:nlay_bio-1) = 0.
+         zc(1:nlay_bio-1) = 0.
+         ze(1:nlay_bio-1) = 0.
+      ENDIF
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) ' Winter factors '
+         WRITE(numout,*) ' za       : ', ( za (layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*) ' zb       : ', ( zb (layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*) ' zc       : ', ( zc (layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*) ' ze       : ', ( ze (layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*)
+      ENDIF
+
+!
+!-----------------------------------------------------------------------
+! 5) Tridiagonal system terms for tracer diffusion equation, winter
+!-----------------------------------------------------------------------
+!
+      !----------------
+      ! first equation
+      !----------------
+      ztrid(1,1) = 0.0
+      ztrid(1,2) = 1.0 + za(1) * ( zb(1) + ze(1) + zb0 )
+      ztrid(1,3) = za(1) * ( -zb(1) + zc(1) )
+      zind(1)    = c_i_bio(jn,1) + za(1)*zb0*sol_gas(jn,1)*zpp_gas(jn)
+      
+      ! IF ( jn .NE. jn_dic ) THEN
+      !    zind(1)    = c_i_bio(jn,1) + za(1)*zb0*sol_gas(jn,1)*zpp_gas(jn)
+      ! ELSE
+      !    CALL ice_carb_chem
+      !    zind(1)    = c_i_bio(jn,1) + za(1)*zb0*( sol_gas(jn,1)*zpp_gas(jn) - co2aq(1) )
+      ! ENDIF
+
+                      ! for dic would read c_i_bio(jn,1) + za(1)*zb0*(sol_gas(jn,1)*zpp_gas(jn) - zco2 )
+                      ! where zco2 = co2aq(1)
+
+      !-----------------
+      ! inner equations
+      !-----------------
+      DO layer = 2, nlay_bio - 1
+         ztrid(layer,1) = - za(layer) * ( zb(layer-1) + ze(layer-1) )
+         ztrid(layer,2) = 1.0 + za(layer) * ( zb(layer) + 
+     &                    ze(layer) + zb(layer-1) - zc(layer-1) )
+         ztrid(layer,3) = za(layer) * ( -zb(layer) + zc(layer) )
+         zind(layer)    = c_i_bio(jn,layer)
+      END DO 
+
+      !----------------
+      ! last equation
+      !----------------
+      ztrid(nlay_bio,1) = -za(nlay_bio) * ( zb(nlay_bio-1) + 
+     &                    ze(nlay_bio-1) )
+      ztrid(nlay_bio,2) = 1.0 + za(nlay_bio) * ( zb(nlay_bio) + 
+     &                    ze(nlay_bio) + zb(nlay_bio-1) - 
+     &                    zc(nlay_bio-1) )
+      ztrid(nlay_bio,3) = 0.
+      zind(nlay_bio)    = c_i_bio(jn,nlay_bio) + za(nlay_bio) *
+     &                   ( zb(nlay_bio) - zc(nlay_bio) )*c_w_bio(jn)
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Tridiag terms : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+         DO layer = 1, nlay_bio
+            WRITE(numout,*) ' layer : ', layer
+            WRITE(numout,*) ' ztrid   : ', ztrid(layer,1), 
+     &                      ztrid(layer,2),
+     &                      ztrid(layer,3)
+            WRITE(numout,*) ' zind     : ',zind(layer)
+         END DO
+      ENDIF
+!
+!-----------------------------------------------------------------------
+! 6) Solving the tridiagonal system
+!-----------------------------------------------------------------------
+!
+      ! The tridiagonal system is solved with Gauss elimination
+      ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+      ! McGraw-Hill 1984.	
+      zindtbis(1) =  zind(1)
+      zdiagbis(1) =  ztrid(1,2)
+      DO layer = 2, nlay_bio
+         zdiagbis(layer)  =  ztrid(layer,2) - ztrid(layer,1) *
+     &                       ztrid(layer-1,3) / zdiagbis(layer-1)
+         zindtbis(layer)  =  zind(layer) - ztrid(layer,1) *
+     &                       zindtbis(layer-1) / zdiagbis(layer-1)
+      END DO
+
+      !-----------------------------
+      ! Tracer brine concentrations
+      !-----------------------------
+      c_i_bio(jn,nlay_bio) =  zindtbis(nlay_bio) / zdiagbis(nlay_bio) 
+      DO layer = nlay_bio - 1 , 1 , -1
+         c_i_bio(jn,layer)  =  (zindtbis(layer) - ztrid(layer,3)*
+     &                       c_i_bio(jn,layer+1)) / zdiagbis(layer)
+      END DO
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Resolution  '
+         WRITE(numout,*) ' ~~~~~~~~~~~ '
+         WRITE(numout,*)
+         DO layer = 1, nlay_bio
+            WRITE(numout,*) ' layer    : ', layer
+            WRITE(numout,*) ' zdiagbis : ', zdiagbis(layer)
+            WRITE(numout,*) ' zindtbis : ', zindtbis(layer)
+            WRITE(numout,*) ' c_i_bio  : ', c_i_bio(jn,layer)
+         END DO
+      ENDIF
+
+      ENDIF ! flag
+
+         ! Update gas flux
+         fgas(jn) = 0.
+
+         IF ( ( biotr_i_typ(jn) .EQ. 'gas' ) .AND. 
+     &        flag_active(jn) ) THEN
+
+            fgas(jn) = - zb0 * ( c_i_bio(jn,1) - 
+     &                 sol_gas(jn,1)*zpp_gas(jn) ) ! mmol/m2/s, positive to the ice
+
+         ENDIF
+
+         WRITE(numout,*) 
+         WRITE(numout,*) ' tracer : ', biotr_i_nam(jn)
+         WRITE(numout,*) ' fgas : ', fgas(jn)
+         WRITE(numout,*) 
+
+         
+      END DO ! jn
+
+!
+!-----------------------------------------------------------------------
+! 7) Recover bulk tracer concentrations
+!-----------------------------------------------------------------------
+!
+      !--------------------------------
+      ! Tracer bulk ice concentrations
+      !--------------------------------
+
+         IF ( ln_write_bio ) THEN
+            WRITE(numout,*) 
+            WRITE(numout,*) ' fgas Argon      : ', fgas(jn_arg)
+            WRITE(numout,*) ' fgas Oxygen     : ', fgas(jn_oxy)
+            WRITE(numout,*) ' fgas CO2        : ', fgas(jn_co2)
+            WRITE(numout,*)
+         ENDIF
+
+      DO jn = 1, ntra_bio
+
+         IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+
+            DO layer = 1, nlay_bio
+               cbu_i_bio(jn,layer) = c_i_bio(jn,layer) * e_i_bio(layer)
+            END DO
+
+            WRITE(numout,*) ' 03 *** jn = ', jn
+            WRITE(numout,*) ' cbu_i_bio : ', cbu_i_bio(jn,:)
+            WRITE(numout,*) ' c_i_bio : ', c_i_bio(jn,:)
+
+            IF ( jn .EQ. jn_dic ) THEN
+               
+               WRITE(numout,*)
+               WRITE(numout,*) ' Change in DIC :'
+               WRITE(numout,*) ' c_i_bio(11,1) before   :',c_i_bio(jn,1)
+               WRITE(numout,*) ' cbu_i_bio(11,1) befe :',cbu_i_bio(jn,1)
+
+               cbu_i_bio(jn,1)  = cbu_i_bio(jn,1) + fgas(jn_co2) * ! change in bulk DIC due to fgas
+     &                            ddtb / deltaz_i_bio(1)
+               c_i_bio(jn,1)    = cbu_i_bio(jn,1)  / e_i_bio(1)    ! update surface brine DIC after CO2 flux
+
+               WRITE(numout,*) ' c_i_bio(11,1) after  :',c_i_bio(jn,1) 
+               WRITE(numout,*) ' cbu_i_bio(11,1) after:',cbu_i_bio(jn,1)
+               WRITE(numout,*) ' fgas(20)             :', fgas(jn_co2)
+               WRITE(numout,*)
+
+            ENDIF
+
+         ENDIF ! flag_diff
+
+         IF ( flag_adsorb(jn) .AND. flag_active(jn) ) THEN
+            DO layer = 1, nlay_bio
+               cbu_i_bio(jn,layer) = cbu_i_bio(jn,layer) 
+     &                            + c_i_bio(jn,layer) * e_i_bio(layer)
+            END DO
+         ENDIF ! flag_adsorb
+
+      END DO ! jn
+
+      IF ( ln_write_bio ) THEN
+         DO jn = 1, ntra_bio
+         IF (      ( flag_diff(jn) .OR. flag_adsorb(jn) ) 
+     &        .AND.         flag_active(jn)               ) THEN
+  
+            WRITE(numout,*) 
+            WRITE(numout,*) ' Tracer concentrations '
+            WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~ '
+            WRITE(numout,*)
+            WRITE(numout,*) ' Tracer : ', biotr_i_nam(jn)
+            WRITE(numout,*) ' c_i_bio   : ', ( c_i_bio(jn,layer), 
+     &                      layer = 1, nlay_bio )
+            WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn,layer), 
+     &                      layer = 1, nlay_bio )
+            WRITE(numout,*)
+            WRITE(numout,*) ' The ', biotr_i_nam(jn), 'fluxdwn is :',
+     &                      fgas(jn), ' mol / m2 / s '
+         ENDIF ! flag_diff
+         END DO ! jn
+      ENDIF ! ln_write_bio
+!
+!-----------------------------------------------------------------------
+! 8) Conservation check
+!-----------------------------------------------------------------------
+!
+      IF ( ln_con_bio ) THEN
+
+      IF ( ln_write_bio ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Conservation check : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+      ENDIF ! ln_write_bio
+
+      CALL ice_bio_column(kideb,kiut,ntra_bio,mt_i_bio_final,cbu_i_bio,
+     &                    deltaz_i_bio, .FALSE.)
+
+      zerror = 1.0d-15
+
+      DO jn = 1, ntra_bio
+
+         IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+
+         IF ( ln_write_bio ) THEN
+            WRITE(numout,*) ' mt_i_bio_final : ', mt_i_bio_final(jn)
+         ENDIF
+
+         zfb = - e_i_bio(nlay_bio) * ( diff_br_bio(nlay_bio) * 2.0 / 
+     &         deltaz_i_bio(nlay_bio) * ( c_i_bio(jn,nlay_bio) - 
+     &         c_w_bio(jn) ) + w_flood * ( z_flood * c_w_bio(jn) +
+     &         ( 1. - z_flood ) * c_i_bio(jn,nlay_bio) ) + w_flush * 
+     &         c_i_bio(jn,nlay_bio) )
+         f_bo_tra(jn) = zfb
+         fcb(jn) = - zfb ! ice-ocean tracer flux
+
+         f_su_tra(jn) = fgas(jn)
+     &                + zswitchs * ( qsummer * c_s_bio(jn) ) / ddtb
+
+      ! fcb_max = idealized flux if c_i_bio(nlay_bio) .EQ. 0.0 all the time
+      fcb_max(jn)=   e_i_bio(nlay_bio) * ( diff_br_bio(nlay_bio) * 2.0 /
+     &         deltaz_i_bio(nlay_bio) * ( 0.0 - 
+     &         c_w_bio(jn) ) + w_flood * ( z_flood * c_w_bio(jn) +
+     &         ( 1. - z_flood ) * 0. ) + w_flush * 0. )
+
+
+         IF ( ln_write_bio ) THEN
+            WRITE(numout,*) ' f_bo_tra : ', f_bo_tra(jn)
+            WRITE(numout,*) ' f_su_tra : ', f_su_tra(jn)
+            WRITE(numout,*) ' zswitchs : ', zswitchs
+            WRITE(numout,*) ' qsummer  : ', qsummer 
+            WRITE(numout,*) ' c_i_bio(nlay_bio) : ',c_i_bio(jn,nlay_bio)
+            WRITE(numout,*) ' mt_i_bio_init  : ', mt_i_bio_init(jn)
+            WRITE(numout,*) ' mt_i_bio_final : ', mt_i_bio_final(jn)
+            WRITE(numout,*)
+         ENDIF ! ln_write_bio
+
+         ENDIF ! flag_diff
+
+      END DO ! jn
+
+      CALL ice_bio_conserv(kideb,kiut,ntra_bio,'ice_bio_diff   ',
+     &                     biotr_i_nam, zerror,
+     &                     mt_i_bio_init,mt_i_bio_final,
+     &                     f_bo_tra, f_su_tra, ddtb)
+
+      ENDIF ! ln_con_bio
+
+!
+!-----------------------------------------------------------------------
+! X) Control Print
+!-----------------------------------------------------------------------
+!
+      WRITE(numout,*) 
+      WRITE(numout,*) ' ** After CO2 fluxes with atmosphere : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      WRITE(numout,*)
+
+      DO jn = 1, ntra_bio
+
+         IF ( biotr_i_nam(jn) .EQ. 'CO2' ) THEN
+         WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn) 
+         WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                   layer = 1, nlay_bio )
+         ENDIF
+
+         IF ( biotr_i_nam(jn) .EQ. 'DIC' ) THEN
+         WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+         WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                   layer = 1, nlay_bio )
+         ENDIF
+
+         IF ( biotr_i_nam(jn) .EQ. 'Alk' ) THEN
+         WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+         WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                   layer = 1, nlay_bio )
+         ENDIF
+
+         IF ( biotr_i_nam(jn) .EQ. 'Ika' ) THEN
+         WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+         WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                   layer = 1, nlay_bio )
+         ENDIF
+
+      END DO
+
+!
+!-----------------------------------------------------------------------
+! 8) Flux divergence diagnostics
+!-----------------------------------------------------------------------
+!
+! not sure if those are good anymore
+      WRITE(numout,*) 
+      WRITE(numout,*) ' Diagnostics '
+      WRITE(numout,*) 
+      WRITE(numout,*) 
+
+      ! Right now, does not include summer
+      DO jn = 1, ntra_bio
+
+      IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+
+      fdiff(jn,0) = 0.0  ! top flux
+
+      DO layer = 1, nlay_bio - 1 ! inner fluxes
+         ! interpolate brine volume at the interface between layers
+         zdummy1 = ( e_i_bio(layer + 1 ) - e_i_bio(layer) ) /  
+     &             ( z_i_bio(layer + 1) - z_i_bio(layer) )
+         zdummy2 = deltaz_i_bio(layer) / 2.0
+         zdummy3 = e_i_bio(layer) + zdummy1 * zdummy2
+         fdiff(jn,layer) = - zdummy3 * 
+     &                   diff_br_bio(layer) *
+     &             ( c_i_bio(jn,layer+1) - c_i_bio(jn,layer) ) / 
+     &             ( z_i_bio(layer + 1) - z_i_bio(layer) )
+      END DO
+
+      ! lower flux
+      fdiff(jn,nlay_bio) = - 2.0 * e_i_bio(nlay_bio) *
+     &               diff_br_bio(layer) *
+     &               ( c_w_bio(jn) - c_i_bio(jn,nlay_bio) ) /
+     &               deltaz_i_bio(nlay_bio) 
+      WRITE(numout,*) ' c_w_bio : ', c_w_bio(jn)
+      WRITE(numout,*) ' c_i_bio(N) : ', c_i_bio(jn,nlay_bio)
+      WRITE(numout,*) ' deltaz_i_bio : ', deltaz_i_bio(nlay_bio)
+
+      ! divergence of the fluxes
+      DO layer = 1, nlay_bio
+         diag_divf_bio(jn,layer) = 
+     &   - ( fdiff(jn,layer) - fdiff(jn,layer-1) ) /
+     &       deltaz_i_bio(layer)
+      END DO
+
+      DO layer = 1, nlay_bio - 1
+         WRITE(numout,*) ' fdiff(layer)    : ', fdiff(jn,layer)
+      END DO
+      DO layer = 1, nlay_bio - 1
+         WRITE(numout,*) ' div_F(layer)    : ', diag_divf_bio(jn,layer)
+      END DO
+
+      ENDIF  ! flag_diff
+
+      END DO ! jn
+!
+!-----------------------------------------------------------------------
+! 9) End of the routine
+!-----------------------------------------------------------------------
+!
+      END DO ! ji
+
+      IF ( ln_write_bio ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** After diffusion of tracers *** '
+         WRITE(numout,*) '     model output '
+
+         DO jn = 1, ntra_bio
+            IF ( flag_active(jn) ) THEN
+               WRITE(numout,*) ' biotr_i_nam : ', biotr_i_nam(jn)
+               WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn, jk), 
+     &                         jk = 1, nlay_bio )
+            ENDIF ! flag_active
+         END DO ! jn
+         WRITE(numout,*)
+
+      ENDIF ! ln_write_bio
+
+      IF ( ln_carbon ) CALL ice_carb_chem
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_bio_diff '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+!
+!=============================================================================!
+!-- End of ice_bio_diff --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_grid.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_grid.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_grid.f	(revision 6)
@@ -0,0 +1,154 @@
+      SUBROUTINE ice_bio_grid(kideb,kiut,nlay_i,ln_write)
+
+! This routine creates biogeochemical vertical grid
+! (c) Martin Vancoppenolle, May 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jn            ! : index for tracers
+
+      LOGICAL ::
+     &   ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** ice_bio_grid : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+         WRITE(numout,*) ' c_grid : ', c_grid
+      ENDIF
+
+      DO ji = kideb, kiut
+
+      !-----------------------------------------------------------------------!
+      ! Thickness of the biologically-active layer: h_bio (SL & BA)
+      !-----------------------------------------------------------------------!
+
+      ! Skeletal layer case
+      IF ( c_grid .EQ. 'SL' ) THEN
+         h_bio = MIN( h_skel , ht_i_b(ji) )    !!! skeletal layer thickness is prescribed
+      ENDIF
+
+      ! Biologically-active layer case
+      IF ( c_grid .EQ. 'BA' ) THEN
+
+         ! Brine volume fraction
+         DO layer = 1, nlay_i
+            e_i_b(layer) = - tmut * s_i_b(ji,layer) / ( t_i_b(ji,layer) 
+     &                      - tpw )
+         END DO
+
+         ! Find the layer above which BAL is located
+         i_bal = 1
+         DO layer = 2, nlay_i
+            IF ( ( e_i_b(layer-1) .LT. e_thr_bal ) .AND. 
+     &           ( e_i_b(layer)   .GT. e_thr_bal ) ) i_bal = layer
+         END DO ! layer
+
+         ! Upper-boundary of the BAL (linear interpolation)
+         IF ( i_bal .GT. 1 ) THEN
+            zdh = ht_i_b(ji) / REAL( nlay_i )
+            zde = ( e_i_b( i_bal ) - e_i_b( i_bal-1 ) )
+            zm  = zde / zdh
+            zdz = ( e_thr_bal - e_i_b( i_bal - 1 ) ) / zm
+            zbal = z_i_phy(i_bal-1) + zdz
+         ELSE 
+            zbal = 0.
+         ENDIF
+
+         ! BAL thickness
+         h_bio = MIN( MAX( ht_i_b(ji) - zbal , h_skel ), 
+     &                ht_i_b(ji) - h_skel ) !!! BAL layer is computed
+         ! it cannot be higher than ht_i_b - h_skel
+         ! it cannot be smaller than h_skel
+
+      ENDIF ! c_grid .EQ. 'BA'
+
+      !-----------------------------------------------------------------------!
+      ! Layer thicknesses
+      !-----------------------------------------------------------------------!
+
+      ! Uniform multi-layer case
+      IF ( c_grid .EQ. 'ML' ) THEN
+
+         h_bio = ht_i_b(ji)                    !!! biologically-active layer = ice thickness
+
+         zh = ht_i_b(ji) / REAL( nlay_bio )
+         DO layer = 1, nlay_bio
+            deltaz_i_bio(layer) = zh
+         END DO
+
+      ENDIF
+
+      ! Deformed case (uppermost and lowermost have fixed thickness to h_skel)
+      IF ( c_grid .EQ. 'DL' ) THEN
+         h_bio = ht_i_b(ji)                    !!! biologically-active layer = ice thickness
+
+         deltaz_i_bio(1)        = MIN( ht_i_b(ji) / REAL( nlay_bio ) , 
+     &                            h_skel  )
+         deltaz_i_bio(nlay_bio) = MIN( ht_i_b(ji) / REAL( nlay_bio ) ,
+     &                            h_skel  )
+         zh = ( ht_i_b(ji) - deltaz_i_bio(1) - deltaz_i_bio(nlay_bio) )
+     &        / REAL( nlay_bio - 2 )
+         DO layer = 2, nlay_bio - 1
+            deltaz_i_bio(layer) = zh
+         END DO
+      ENDIF
+
+      IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) THEN
+         deltaz_i_bio(nlay_bio) = h_bio
+         DO layer = 1, nlay_bio - 1
+            deltaz_i_bio(layer) = ( ht_i_b(ji) - h_bio ) / 
+     &                            ( nlay_bio - 1 )
+         END DO
+         WRITE(numout,*) " h_bio : ", h_bio
+         WRITE(numout,*) " ht_i_b(ji) : ", ht_i_b(ji)
+         WRITE(numout,*) " deltaz_i_bio : ", ( deltaz_i_bio(layer), 
+     &                   layer = 1, nlay_bio )
+      ENDIF
+
+      !-----------------------------------------------------------------------!
+      ! Mid-point cotes
+      !-----------------------------------------------------------------------!
+      z_i_bio(1)  = deltaz_i_bio(1) / 2.0
+      DO layer = 2, nlay_bio
+         z_i_bio(layer)  = z_i_bio(layer-1) + ( deltaz_i_bio(layer-1) +
+     &                     deltaz_i_bio(layer) ) / 2.0
+      END DO
+
+      !-----------------------------------------------------------------------!
+      ! Layer boundaries
+      !-----------------------------------------------------------------------!
+      zb_i_bio(0) = 0.0
+      DO layer = 1, nlay_bio
+         zb_i_bio(layer) = zb_i_bio(layer-1) + deltaz_i_bio(layer)
+      END DO ! layer
+
+      !-----------------------------------------------------------------------!
+      END DO ! ji
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' deltaz_i_bio : ', ( deltaz_i_bio(layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*) ' z_i_bio  : ', ( z_i_bio(layer),  
+     &                   layer = 1, nlay_bio)
+         WRITE(numout,*) ' zb_i_bio : ', ( zb_i_bio(layer),  
+     &                   layer = 1, nlay_bio)
+
+         WRITE(numout,*)
+      ENDIF
+
+!=============================================================================!
+!-- End of ice_bio_ini --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_ini.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_ini.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_ini.f	(revision 6)
@@ -0,0 +1,492 @@
+      SUBROUTINE ice_bio_ini(kideb,kiut,nlay_i)
+!
+!------------------------------------------------------------------------------!
+!
+! This routine initializes biogeochemical tracers
+! (c) Martin Vancoppenolle, Oct 2014
+!
+! version: 3.04
+! 
+!------------------------------------------------------------------------------!
+!
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jn          , ! : index for tracers
+     &  numtra = 700, ! : reference number for bio.param
+     &  n_raw         ! : number of values in the raw initial profile
+
+      REAL(4)        zini(1)  ! forcing field dummy array
+
+      REAL(8), DIMENSION(maxnlay) ::
+     &   z_raw,
+     &   zq_raw,
+     &   zc_raw,
+     &   zq1,
+     &   zdh_bio
+
+      REAL(8), DIMENSION(maxnlay+2) ::
+     &   zdh_raw 
+
+      REAL(8), DIMENSION(0:maxnlay) ::
+     &   zb_raw
+
+      CHARACTER(len=61) :: 
+     &   zblank
+
+      CHARACTER(len=10) :: 
+     &   filenc='init.nc'
+
+      CHARACTER(len=3) :: 
+     &   zchar
+
+      LOGICAL ::
+     &   ln_initfile = .FALSE.
+
+      zblank = 
+     & '                                                             '
+      ji = 1
+
+!------------------------------------------------------------------------------!
+
+      WRITE(numout,*) ' ** ice_bio_ini : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~ '
+      WRITE(numout,*) 
+
+      IF ( c_bio_model .EQ. 'KRILL' ) THEN
+         ntra_bio = 21
+      ENDIF
+!
+!-----------------------------------------------------------------------------!
+! 1) Create grid and interpolate physical variables
+!-----------------------------------------------------------------------------!
+!
+
+      CALL ice_bio_grid(kideb,kiut,nlay_i,.TRUE.)             ! Biological grid 
+
+      CALL ice_bio_interp_phy2bio(kideb,kiut,nlay_i, .FALSE.) ! Physical fields
+                                                              ! on the bio grid
+
+!
+!-----------------------------------------------------------------------------!
+! 2) Initialize tracer numbers and names
+!-----------------------------------------------------------------------------!
+!
+      WRITE(numout,*) ' Initialize tracers... '
+      WRITE(numout,*)
+
+      ! Set default tracer values
+      layer_00 = 1
+      cbu_i_bio(:,:)  = 0.
+      cbub_i_bio(:,:) = 0. ;  c_gtot_i(:,:)   = 0.
+      c_w_bio(:)      = 0. ;  mixr_gas(:)     = 0.
+      dmol_gas(:)     = 0.
+
+      flag_active(:)    = .false.    ! Activated ?
+      flag_adsorb(:)    = .false.    ! Adsorbed ?
+      flag_diff(:)      = .false.    ! Diffused ?
+      nn_remp(:)        = 1          ! Squeezing remaping
+      biotr_i_nam(:)    = 'xxx'//zblank      ! Name of the tracer
+      biotr_i_typ(:)    = 'xxx'//zblank      ! Type = algal
+      biotr_i_uni(:)    = 'xxx'//zblank ! Units
+      nn_init(:) = 1
+
+      ! Compute layer limits
+      IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) 
+     &   layer_00 = nlay_bio
+
+      ! Assign Tracer Numbers
+      jn_dsi = 1 
+      jn_din = 2
+      jn_dip = 3 
+      jn_aoc = 4 
+      jn_eoc = 5 
+      jn_co2 = 6  ! 20
+      jn_dic = 7  ! 12 
+      jn_alk = 8  ! 13 
+      jn_ika = 9  ! 14
+      jn_oxy = 10 ! 15
+      jn_nit = 11 ! 16 
+      jn_arg = 12 ! 17
+      jn_cal = 13 ! 21
+
+      ! Assign Tracer names
+      biotr_i_nam(jn_dsi) = 'dSi'//zblank
+      biotr_i_nam(jn_din) = 'dIN'//zblank
+      biotr_i_nam(jn_dip) = 'dIP'//zblank
+      biotr_i_nam(jn_aoc) = 'AoC'//zblank
+      biotr_i_nam(jn_eoc) = 'eoC'//zblank
+      biotr_i_nam(jn_co2) = 'CO2'//zblank
+      biotr_i_nam(jn_dic) = 'DIC'//zblank 
+      biotr_i_nam(jn_alk) = 'Alk'//zblank 
+      biotr_i_nam(jn_ika) = 'Ika'//zblank
+      biotr_i_nam(jn_cal) = 'Cal'//zblank
+      biotr_i_nam(jn_arg) = 'Arg'//zblank
+      biotr_i_nam(jn_oxy) = 'Oxy'//zblank
+      biotr_i_nam(jn_nit) = 'Nit'//zblank
+
+!
+!-----------------------------------------------------------------------------!
+! 3) Read tracer parameters
+!-----------------------------------------------------------------------------!
+!
+
+      WRITE(numout,*) ' Tracer parameters ... '
+      WRITE(numout,*)
+
+      OPEN( unit = numtra , file='tracer.param', status='old' )
+      
+      ! initial values
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+      READ(numtra,*)
+
+      DO jn_read = 1, 13
+
+         READ(numtra,*)  c_read_name(jn_read), zchar, i_dummy1, zdummy2,
+     &                   zdummy3, zdummy4, zdummy5
+
+         DO jn = 1, ntra_bio
+           IF ( c_read_name(jn_read)//zblank .EQ. biotr_i_nam(jn) ) THEN
+               c_nc_name(jn) = zchar
+               nn_init(jn)   = i_dummy1
+               cbu_i_nml(jn) = zdummy2
+               c_w_bio(jn)   = zdummy3
+               mixr_gas(jn)  = zdummy4
+               dmol_gas(jn)  = zdummy5
+           ENDIF
+         END DO
+
+      ENDDO
+
+      CLOSE( numtra )
+
+      WRITE(numout,*)
+      DO jn = 1, ntra_bio
+         WRITE(numout,*) biotr_i_nam(jn), nn_init(jn) , cbu_i_nml(jn), 
+     &                   c_w_bio(jn)    , mixr_gas(jn), dmol_gas(jn)
+      END DO
+
+!
+!-----------------------------------------------------------------------------!
+! 4) Parameterize tracer behaviour
+!-----------------------------------------------------------------------------!
+!
+      ! flag_active determines a tracer is activated in the code
+      ! flag_adsorb is just there for one specific test and should not be activated
+      ! flag_diff tells whether a tracer should be diffused with brine or not
+      ! nn_remp gives the type of remapping - 1 = linear remapping (very diffusive); 2 = "squeezing remapping"
+      ! biotr_i_typ can be either - only gas is useful because flag_diff makes the difference between solutes and particles
+      !    - 'sol' -> solute (like salt)
+      !    - 'prc' -> particulate (e.g. organic matter)
+      !    - 'gas' -> gas
+
+      !------------------------
+      ! DSi : Dissolved silica
+      !------------------------
+      jn = jn_dsi
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'sol'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !------------------------------------
+      ! DIN : dissolved inorganic nitrogen
+      !------------------------------------
+      jn = jn_din
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'sol'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !----------------------------
+      ! DIP : Dissolved phosphorus
+      !----------------------------
+      jn = jn_dip
+      ! Units = ( mmole PO4 m-3 ) or ( micrmol PO4 l-1 )
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'sol'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! AoC : Ice algae organic carbon
+      !--------------------------------------
+      jn = jn_aoc
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .false.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'prc'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! eoC : Detritus organic Carbon
+      !--------------------------------------
+      jn = jn_eoc
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .false.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'prc'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! DIC : Dissolved Inorganic Carbon
+      !--------------------------------------
+      jn = jn_dic
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'sol'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Alk : Total Alkalinity
+      !--------------------------------------
+      jn = jn_alk
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'sol'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! CO2 : aqueous CO2
+      !--------------------------------------
+      jn = jn_co2
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'gas'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Ika : Ikaite
+      !--------------------------------------
+      jn = jn_ika
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .false.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'prc'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Cal : Ca2+
+      !--------------------------------------
+      jn = jn_cal
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'prc'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Arg : ARgon
+      !--------------------------------------
+      jn = jn_arg
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'gas'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Oxy : Oxygen
+      !--------------------------------------
+      jn = jn_oxy
+      flag_active(jn) = .true.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .true.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'gas'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+      !--------------------------------------
+      ! Nit : N2
+      !--------------------------------------
+      jn = jn_nit
+      flag_active(jn) = .false.
+      flag_adsorb(jn) = .false.
+      flag_diff(jn)   = .false.
+      nn_remp(jn)     = 1
+      biotr_i_typ(jn) = 'gas'//zblank
+      biotr_i_uni(jn) = 'mmol_m3'//zblank
+
+!
+!-----------------------------------------------------------------------------!
+! 5) Prepare Netcdf Interpolation if required
+!-----------------------------------------------------------------------------!
+!
+      DO jn = 1, ntra_bio
+
+         IF ( flag_active (jn) .AND. ( nn_init(jn) == 3 ) ) 
+     &      ln_initfile = .TRUE.
+
+      END DO
+            
+      IF ( ln_initfile ) THEN
+
+         !--- Open file
+         !--------------
+         CALL CF_OPEN  (filenc,id) ! open forcing file
+
+         CALL CF_READ1D ( filenc, 'nlay', 1, 1, zini )       ! number of layers
+         n_raw = zini(1)
+
+         DO layer = 1, n_raw                                 ! raw grid
+            CALL CF_READ1D ( filenc, 'z_i', layer, 1, zini)
+            z_raw(layer) = zini(1)
+         END DO
+
+         zb_raw(:) = 0.0                                     ! layer interfaces
+         DO layer = 1, n_raw - 1
+            zb_raw(layer)  = ( z_raw(layer) + z_raw(layer+1) ) / 2.
+         END DO
+         zb_raw(n_raw) = ht_i_b(ji)
+
+         zdh_raw(:) = 0.                                     ! layer thicknesses
+         DO layer = 1, n_raw 
+            zdh_raw(layer) = zb_raw(layer) - zb_raw(layer-1)
+         END DO
+
+         zdh_bio(:) = 0.
+         zdh_bio(1:nlay_bio) = deltaz_i_bio(:)
+
+      ENDIF
+
+      !--------------------------------------
+      ! Assign ice concentrations to cbu_i
+      !--------------------------------------
+      DO jn = 1, ntra_bio 
+
+      IF ( flag_active(jn) ) THEN
+
+         IF ( nn_init(jn) .EQ. 1 )        !--- Initialization conserves namelist concentration 
+     &      cbu_i_bio(jn,layer_00:nlay_bio) = cbu_i_nml(jn)
+
+         IF ( nn_init(jn) .EQ. 2 ) THEN   !--- Initialization conserves namelist concentration times thickness
+            zstock = cbu_i_nml(jn) * ht_i_b(ji)
+            cbu_i_bio(jn,layer_00:nlay_bio) = zstock / h_bio
+         ENDIF
+
+         IF ( nn_init(jn) .EQ. 3 ) THEN   !--- Profile read from nc file
+
+            DO layer = 1, n_raw
+               CALL CF_READ1D ( filenc, c_nc_name(jn), layer, 1, zini )
+               zc_raw(layer) = zini(1)
+            END DO
+
+            zq_raw(1:n_raw) = zc_raw(1:n_raw) * zdh_raw(1:n_raw)
+
+            CALL ice_phy_relay( n_raw , nlay_bio , 1 , 1 ,
+     &                          zdh_raw, zdh_bio, zq_raw , zq1 )
+
+            cbu_i_bio(jn,1:nlay_bio) = zq1(1:nlay_bio) /
+     &                                 deltaz_i_bio(1:nlay_bio)
+
+         ENDIF
+
+      ENDIF
+
+      END DO
+
+      IF ( ln_initfile )
+     &   CALL CF_CLOSE  (filenc) ! close forcing file
+
+!
+!-----------------------------------------------------------------------------!
+! 7) Chl-a (mg/m3)
+!-----------------------------------------------------------------------------!
+!
+      c_molar = 12. ! molar mass of carbon
+      DO layer = 1, nlay_bio
+         chla_i_bio(layer) = cbu_i_bio(4,layer) * chla_c * c_molar
+      END DO
+
+!
+!-----------------------------------------------------------------------------!
+! 8) Zero un used tracers
+!-----------------------------------------------------------------------------!
+!
+      IF ( nn_bio_opt .EQ. 0 ) THEN
+         cbu_i_bio(jn_eoc,:) = 0.0
+         flag_active(jn_eoc) = .FALSE.
+         flag_adsorb(jn_eoc) = .FALSE.
+         flag_diff(jn_eoc)   = .FALSE.
+         c_w_bio(jn_eoc)     = 0.
+         mixr_gas(jn_eoc)    = 0.
+         dmol_gas(jn_eoc)    = 0.
+      ENDIF
+
+!
+!-----------------------------------------------------------------------------!
+! 9) Control prints
+!-----------------------------------------------------------------------------!
+!
+      WRITE(numout,*) '    *** Initial values *** '
+      WRITE(numout,*)
+      DO jn = 1, ntra_bio
+         IF ( flag_active(jn) ) THEN
+            WRITE(numout,*) ' Tracer     : ', biotr_i_nam(jn)
+            WRITE(numout,*) ' ~~~~~~~      '
+            WRITE(numout,*) ' Type       : ', biotr_i_typ(jn)
+            WRITE(numout,*) ' cbu_i_bio  : ', ( cbu_i_bio(jn,jk), 
+     &                   jk = 1, nlay_bio )
+            WRITE(numout,*) ' c_w_bio    : ', c_w_bio(jn)
+            WRITE(numout,*)
+         ENDIF
+      END DO ! jn
+
+      WRITE(numout,*) ' Chla '
+      WRITE(numout,*) ' ~~~~ '
+      WRITE(numout,*) ' chla_i_bio : ', 
+     &                ( chla_i_bio(layer), layer = 1, nlay_bio )
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_bio_ini '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+
+!
+!-----------------------------------------------------------------------------!
+!-- End of ice_bio_ini --
+      RETURN
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_bio2phy.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_bio2phy.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_bio2phy.f	(revision 6)
@@ -0,0 +1,151 @@
+      SUBROUTINE ice_bio_interp_bio2phy(kideb,kiut,nlay_i,ln_write)
+
+! This routine interpolates chlorophyll a
+! from the biological grid to the physical grid
+! (c) Martin Vancoppenolle, May 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jn          , ! : index for tracers
+     &  layer1      , ! : relayering index
+     &  layer2        ! : relayering index
+
+      REAL(8), DIMENSION( 0:nlay_bio ) ::
+     &  z0
+
+      REAL(8), DIMENSION( 0:maxnlay ) ::
+     &  z1
+
+      REAL(8), DIMENSION( nlay_bio ) ::
+     &  zqc         , ! : scalar content on the physical grid (input)
+     &  zthick0       ! : thickness of biological layers
+
+      REAL(8), DIMENSION( maxnlay ) ::
+     &  zq1         , ! : scalar content on the biological grid (output)
+     &  zthick1       ! : thickness of physical layers
+
+      REAL(8), DIMENSION( maxnlay , nlay_bio ) ::
+     &  zweight       ! : relayering matrix
+
+      LOGICAL ::
+     &  ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' *** ice_bio_interp_bio2phy : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+!
+!-----------------------------------------------------------------------------!
+! 1) Grids
+!-----------------------------------------------------------------------------!
+!
+! compute the coordinates of the interfaces of the layers
+      
+      DO ji = kideb, kiut
+      !---------------
+      ! Physical grid
+      !---------------
+      z1(0) = 0.0
+      DO layer = 1, nlay_i
+         z1(layer) = ht_i_b(ji) / nlay_i * layer
+         zthick1(layer) = z1(layer) - z1(layer-1)
+      END DO ! layer
+
+!     !+++++
+!     WRITE(numout,*) ' z1      : ', ( z1(layer1) , 
+!    &                layer1 = 0, nlay_i )
+!     WRITE(numout,*) ' zthick1 : ', ( zthick1(layer1) ,
+!    &                layer1 = 1, nlay_i )
+!     !+++++
+
+      !-----------------
+      ! Biological grid
+      !-----------------
+      z0(0) = 0.0
+      DO layer = 1, nlay_bio
+         z0(layer) = z0(layer-1) + deltaz_i_bio(layer)
+         zthick0(layer) = z0(layer) - z0(layer-1)
+      END DO ! layer
+
+!     !+++++
+!     WRITE(numout,*) ' z0      : ', ( z0(layer1) , 
+!    &                layer1 = 1, nlay_bio )
+!     WRITE(numout,*) ' zthick0 : ', ( zthick0(layer1) , 
+!    &                layer1 = 1, nlay_bio )
+!     !+++++
+!
+!-----------------------------------------------------------------------------!
+! 2) Scalar contents
+!-----------------------------------------------------------------------------!
+!
+      DO layer = 1, nlay_bio
+         zqc(layer) = chla_i_bio(layer) * zthick0(layer)
+      END DO ! layer
+
+!     !+++++
+!     WRITE(numout,*) ' chla_i_bio :', ( chla_i_bio(layer) , 
+!    &                layer = 1, nlay_bio )
+!     WRITE(numout,*) ' zqc     : ', ( zqc(layer) , 
+!    &                layer = 1, nlay_bio )
+!     !+++++
+!
+!-----------------------------------------------------------------------------!
+! 3) Weights 
+!-----------------------------------------------------------------------------!
+!
+      ! weights of old layers on new ones
+      DO layer1 = 1, nlay_i
+         DO layer0 = 1, nlay_bio
+            zweight(layer1,layer0) = MAX ( 0.0 , ( MIN ( z0(layer0) ,
+     &      z1(layer1) ) - MAX ( z0 (layer0-1) , z1(layer1-1) ) ) / 
+     &      zthick0(layer0) )
+!           WRITE(numout,*) ' zweight : ', layer1, layer0, 
+!    &                      zweight(layer1, layer0)
+         END DO
+      END DO
+!
+!-----------------------------------------------------------------------------!
+! 4) Interpolation
+!-----------------------------------------------------------------------------!
+!
+      !---------------
+      ! Chlorophyll a
+      !---------------
+      DO layer1 = 1, nlay_i
+         zq1(layer1) = 0.0
+         DO layer0 = 1, nlay_bio
+            zq1(layer1) = zq1(layer1) + zweight(layer1,layer0) *
+     &                    zqc(layer0)
+         END DO
+      END DO
+!     !+++++
+!     WRITE(numout,*) ' Chlorophyll a : '
+!     WRITE(numout,*) ' zq1     : ', ( zq1(layer1) , 
+!    &                layer1 = 1, nlay_i )
+!     !+++++
+
+      DO layer1 = 1, nlay_i
+         chla_i(layer1) = zq1(layer1) / zthick1(layer1)
+      END DO
+
+      END DO ! ji
+
+!     WRITE(numout,*) ' chla_i  : ', ( chla_i(layer1) , 
+!    &                layer1 = 1, nlay_i )
+
+!     WRITE(numout,*) ' end '
+!     WRITE(numout,*) ' ------------------------------------ '
+!=============================================================================!
+!-- End of ice_bio_interp_bio2phy --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_phy2bio.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_phy2bio.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_interp_phy2bio.f	(revision 6)
@@ -0,0 +1,289 @@
+      SUBROUTINE ice_bio_interp_phy2bio(kideb,kiut,nlay_i,ln_write)
+
+! This routine interpolates salinity, temperature, brine salinity, brine volume
+! on the biological grid
+! (c) Martin Vancoppenolle, May 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  jn          , ! : index for tracers
+     &  layer1      , ! : relayering index
+     &  layer2        ! : relayering index
+
+      REAL(8), DIMENSION( maxnlay ) ::
+     &  zqs         , ! : scalar content on the physical grid (input)
+     &  zqt           ! : scalar content on the physical grid (input)
+
+      REAL(8), DIMENSION( nlay_bio ) ::
+     &  zq1           ! : scalar content on the biological grid (output)
+
+      REAL(8), DIMENSION( nlay_bio , maxnlay ) ::
+     &  zweight       ! : relayering matrix
+
+      REAL(8) ::    
+     &  zaaa        , ! : dummyfactors for the computation of t_i_bio
+     &  zbbb        ,
+     &  zccc        ,
+     &  zdiscrim    ,
+     &  zsum0         ! : conservation test variable
+     &  zsum1         ! : conservation test variable
+      
+      LOGICAL ::
+     &  ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' *** ice_bio_interp_phy2bio : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      DO ji = kideb, kiut
+!
+!-----------------------------------------------------------------------------!
+! 1) Scalar contents
+!-----------------------------------------------------------------------------!
+!
+
+      DO layer = 1, nlay_i
+         zqs(layer)   = s_i_b(ji,layer) * deltaz_i_phy(layer)
+         zqt(layer)   = q_i_b(ji,layer) * deltaz_i_phy(layer)
+      END DO ! layer
+
+      IF ( ln_write ) THEN
+    
+!        WRITE(numout,*) ' s_i_b   : ', ( s_i_b(ji,layer1) , 
+!    &                   layer1 = 1, nlay_i )
+!        WRITE(numout,*) ' q_i_b   : ', ( q_i_b(ji,layer1) , 
+!    &                   layer1 = 1, nlay_i )
+!        WRITE(numout,*) ' t_i_b   : ', ( t_i_b(ji,layer1) , 
+!    &                   layer1 = 1, nlay_i )
+!        WRITE(numout,*) ' zqs     : ', ( zqs(layer1) , 
+!    &                   layer1 = 1, nlay_i )
+!        WRITE(numout,*) ' zqt     : ', ( zqt(layer1) , 
+!    &                   layer1 = 1, nlay_i )
+
+      ENDIF
+ 
+!-----------------------------------------------------------------------------!
+! 2) Weights 
+!-----------------------------------------------------------------------------!
+!
+      DO layer1 = 1, nlay_bio
+         DO layer0 = 1, nlay_i
+            zweight(layer1,layer0) = MAX ( 0.0 , 
+     &      ( MIN ( zb_i_phy(layer0) ,
+     &      zb_i_bio(layer1) ) 
+     &    - MAX ( zb_i_phy (layer0-1) , zb_i_bio(layer1-1) ) ) / 
+     &      deltaz_i_phy(layer0) )
+         END DO
+      END DO
+!
+!-----------------------------------------------------------------------------!
+! 3) Interpolation
+!-----------------------------------------------------------------------------!
+!
+      !--------------
+      ! Ice salinity
+      !--------------
+      DO layer1 = 1, nlay_bio
+         zq1(layer1) = 0.0
+         DO layer0 = 1, nlay_i
+            zq1(layer1) = zq1(layer1) + zweight(layer1,layer0) *
+     &                    zqs(layer0)
+         END DO
+      END DO
+
+      IF ( ln_write ) THEN
+!        WRITE(numout,*) ' Salt contents '
+!        WRITE(numout,*) ' zq1     : ', ( zq1(layer1) , 
+!    &                   layer1 = 1, nlay_bio )
+      ENDIF
+
+      DO layer1 = 1, nlay_bio
+         s_i_bio(layer1) = zq1(layer1) / deltaz_i_bio(layer1)
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' s_i_bio : ', ( s_i_bio(layer1) , 
+     &                   layer1 = 1, nlay_bio )
+      ENDIF
+
+      !--------------
+      ! Heat content
+      !--------------
+      DO layer1 = 1, nlay_bio
+         zq1(layer1) = 0.0
+         DO layer0 = 1, nlay_i
+            zq1(layer1) = zq1(layer1) + zweight(layer1,layer0) *
+     &                    zqt(layer0)
+         END DO
+      END DO
+
+      IF ( ln_write ) THEN
+!        WRITE(numout,*) ' Heat content '
+!        WRITE(numout,*) ' zq1     : ', ( zq1(layer1) , 
+!    &                   layer1 = 1, nlay_bio )
+      ENDIF
+
+      ! Energy of melting
+      DO layer1 = 1, nlay_bio
+         zq1(layer1) = zq1(layer1) / deltaz_i_bio(layer1)
+      END DO
+
+      ! Invert energy of melting to get temperature back
+      DO layer1 = 1, nlay_bio
+         tmelts = - tmut * s_i_bio(layer1) + tpw
+         zaaa = cpg
+         zbbb = (cpw-cpg)*(tmelts-tpw) + zq1(layer1) / rhog
+     &        - lfus
+         zccc = lfus * (tmelts-tpw)
+         zdiscrim = SQRT( zbbb*zbbb - 4.0*zaaa*zccc )
+         t_i_bio(layer1) = tpw + ( - zbbb - zdiscrim ) / (2.0*zaaa)
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' t_i_bio : ', ( t_i_bio(layer1) , 
+     &                   layer1 = 1, nlay_bio )
+      ENDIF
+
+      !--------------
+      ! Brine volume
+      !--------------
+      DO layer1 = 1, nlay_bio
+         e_i_bio(layer1) = - tmut * s_i_bio(layer1) /
+     &                     ( t_i_bio(layer1) - tpw )
+      END DO ! layer1
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' e_i_bio : ', ( e_i_bio(layer1) , 
+     &                   layer1 = 1, nlay_bio )
+      ENDIF
+
+!-----------------------------------------------------------------------------!
+
+      END DO ! ji
+
+!=============================================================================!
+!-- End of ice_bio_interp_phy2bio --
+ 
+      END
+!
+!=============================================================================!
+!=============================================================================!
+!
+
+      SUBROUTINE ice_bio_interp_diffus(kideb,kiut,nlay_i,ln_write)
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk          , ! : index for ice layers
+     &  layer_bio   , ! : 
+     &  layer_phy   , ! : 
+     &  index_mem
+
+      REAL(8), DIMENSION( 0:maxnlay ) :: ! lower interface of the layer
+     &  zz_phy
+
+      REAL(8), DIMENSION( 0:nlay_bio ) :: ! lower interface of the layer
+     &  zz_bio
+
+      LOGICAL ::
+     &  ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' *** ice_bio_interp_diffus : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+!
+!-----------------------------------------------------------------------------!
+! 1) Grids
+!-----------------------------------------------------------------------------!
+!
+! compute the coordinates of the interfaces of the layers
+!
+      zz_phy(0) = 0.
+      DO layer_phy = 1, nlay_i
+         zz_phy(layer_phy) = z_i_phy(layer_phy) + 
+     &                       deltaz_i_phy(layer_phy) / 2.
+      END DO
+
+      zz_bio(0) = 0.
+      DO layer_bio = 1, nlay_bio
+         zz_bio(layer_bio) = z_i_bio(layer_bio) +
+     &                       deltaz_i_bio(layer_bio) / 2.
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zz_phy : ', ( zz_phy(layer_phy), 
+     &                                   layer_phy = 0, nlay_i )
+         WRITE(numout,*) ' zz_bio : ', ( zz_bio(layer_bio), 
+     &                                   layer_bio = 0, nlay_bio )
+      ENDIF
+
+      DO layer_bio = 1, nlay_bio - 1
+         zdist_max = 999.9
+         zdist = zdist_max
+         !WRITE(numout,*) ' '
+         !WRITE(numout,*) ' layer_bio : ', layer_bio
+         DO layer_phy = 1, nlay_i
+            zdist = MIN ( zdist, zz_bio(layer_bio) - zz_phy(layer_phy) )
+            IF ( ( zdist .GE. 0.0 ) .AND. ( zdist .LT. zdist_max ) ) 
+     &      THEN
+               index_mem = layer_phy
+            ENDIF
+         !   WRITE(numout,*) ' layer_phy : ', layer_phy
+         !   WRITE(numout,*) ' zdist : ', zdist
+         !   WRITE(numout,*) ' index_mem ', index_mem
+         END DO ! layer_phy
+         index_mem = MAX ( MIN( index_mem, nlay_i ) , 1 ) ! prevent absurd values sometimes reached in path cases
+         zdummy1 = ( diff_br(index_mem+1) - diff_br(index_mem) ) /
+     &             ( zz_phy(index_mem+1) - zz_phy(index_mem) )
+         zdummy2 = zz_bio(layer_bio) - zz_phy(index_mem)
+ 
+         !WRITE(numout,*) ' End of ze loupe '
+         !WRITE(numout,*) ' index_mem : ', index_mem
+ 
+         diff_br_bio(layer_bio) = diff_br(index_mem) + zdummy1*zdummy2
+ 
+       END DO ! layer_bio
+ 
+       diff_br_bio(nlay_bio) = diff_br(nlay_i)
+
+!     DO layer_bio = 1, nlay_bio
+!        diff_br_bio(layer_bio) = diff_br(layer_bio)
+!     END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' diff_br    : ', ( diff_br(layer_phy), 
+     &                   layer_phy = 1, nlay_i )
+         WRITE(numout,*) ' nlay_i   : ', nlay_i
+         WRITE(numout,*) ' nlay_bio : ', nlay_bio
+         WRITE(numout,*) ' diff_br    : ', ( diff_br(layer_phy), 
+     &                   layer_phy = 1, nlay_i )
+         WRITE(numout,*) ' diff_br_bio : ', ( diff_br_bio(layer_bio),
+     &                   layer_bio = 1, nlay_bio ) 
+      ENDIF
+!      
+!=============================================================================!
+!-- End of ice_bio_interp_diff --
+!
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_param.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_param.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_param.f	(revision 6)
@@ -0,0 +1,304 @@
+      SUBROUTINE ice_bio_param
+
+!
+! This routine reads bio.param
+! (c) Martin Vancoppenolle, Oct 2014
+!
+! version: 3.04
+!
+        
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  numbio = 500  ! : reference number for bio.param
+
+      WRITE(numout,*) ' ** ice_bio_param : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~'
+      WRITE(numout,*) 
+!
+!-----------------------------------------------------------------------------!
+! 1) Reads namelist
+!-----------------------------------------------------------------------------!
+!
+      WRITE(numout,*) ' Biological parameters ... '
+      WRITE(numout,*)
+
+      OPEN( unit = numbio , file='bio.param', status='old' )
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      ! Process switches for biogeochemistry
+      READ(numbio,*) c_grid
+      READ(numbio,*)
+      READ(numbio,*) h_skel
+      READ(numbio,*)
+      READ(numbio,*) e_thr_bal
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) ln_trbo     ! activate basal entrapment for tracers
+      READ(numbio,*)
+      READ(numbio,*) ln_trsi     ! activate snow-ice entrapment for tracers
+      READ(numbio,*)
+      READ(numbio,*) ln_trdiff   ! activate tracer diffusion
+      READ(numbio,*)
+      READ(numbio,*) ln_trremp   ! activate tracer remapping
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_dsi  ! activate DSi limitation
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_no3  ! activate NO3 limitation
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_po4  ! activate PO4 limitation
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_lig  ! activate light limitation
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_tem  ! activate temperature inhibition
+      READ(numbio,*)
+      READ(numbio,*) ln_lim_sal  ! activate brine salinity inhibition
+      READ(numbio,*)
+      READ(numbio,*) ln_lys      ! activate lysis
+      READ(numbio,*)
+      READ(numbio,*) ln_rem      ! activate remineralization
+      READ(numbio,*)
+      READ(numbio,*) ln_syn      ! activate diatom synthesis
+      READ(numbio,*)
+      READ(numbio,*) ln_bubform  ! activate gas bubble formation
+      READ(numbio,*)
+      READ(numbio,*) ln_bubrise  ! activate gas bubble rise
+      READ(numbio,*)
+      READ(numbio,*) ln_gasflux  ! activate gas flux to ATM
+      READ(numbio,*)
+      READ(numbio,*) ln_carbon   ! activate carbon cycle
+      READ(numbio,*)
+      READ(numbio,*) ln_ikaite   ! activate ikaite
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      ! gas exchange parameters
+      READ(numbio,*)
+      READ(numbio,*) i_gasflux        ! type of gas flux formulation
+      READ(numbio,*)
+      READ(numbio,*) brines_ar        ! brines aspect ratio
+      READ(numbio,*)
+      READ(numbio,*) bub_form_rate    ! gas bubble formation rate
+      READ(numbio,*)
+      READ(numbio,*) bub_diss_rate    ! gas bubble dissolution rate
+      READ(numbio,*)
+      READ(numbio,*) h_bl_gas         ! gas bubble dissolution rate
+      READ(numbio,*)
+      READ(numbio,*) e_thr_gasflux    ! brine volume fraction threshold for surface gas flux
+      READ(numbio,*)
+      READ(numbio,*) e_thr_bubrise    ! brine volume fraction permeability for bubble rise
+      READ(numbio,*)
+      READ(numbio,*) sursat_gas       ! %Saturation tolerated in brines
+      READ(numbio,*)
+      READ(numbio,*) nn_carbonate     ! Roy (1) or Mehrbach (2) set of constants
+      READ(numbio,*)
+      READ(numbio,*) caco3_time       ! CaCO3 precipitation/dissolution time constant
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) nn_bio_opt  ! type of biological model
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      ! physiological parameters
+      READ(numbio,*) astar_alg   ! specific att coeff ( m-1 / ( mg chla m-3 ) )
+      READ(numbio,*)
+      READ(numbio,*) fdet_alg    ! fraction of attenuation due to detrital mater compared to algal attenuation (Arrigo)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) pp_presc    ! prescribed primary production (mmol C m-3 s-1)
+      READ(numbio,*)
+      READ(numbio,*) mumax_bio   ! maximal specific growth rate (s-1)
+      READ(numbio,*)
+      READ(numbio,*) klys_bio    ! loss rate
+      READ(numbio,*)
+      READ(numbio,*) krsp_bio    ! respiration time constant
+      READ(numbio,*)
+      READ(numbio,*) krem_bio    ! remineralization time constant
+      READ(numbio,*)
+      READ(numbio,*) frem_bio    ! fraction of diatom loss that is remineralized in Si
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) nn_phs      ! type of photosynthesis parameterization
+      READ(numbio,*)
+      READ(numbio,*) ek_bio      ! light adaptation parameter (muE m-2 s-1)
+      READ(numbio,*)
+      READ(numbio,*) alpha_bio   ! photosynthetic efficiency
+      READ(numbio,*)
+      READ(numbio,*) chla_c      ! chlorophyll to carbon ratio (g/g)
+      READ(numbio,*)
+      READ(numbio,*) Estar       ! Irradiance where PAR is minimum (muE m-2 s-1)
+      READ(numbio,*)
+      READ(numbio,*) nn_lys      ! Type of lysis (1-prescribed, 2-temperature dependent)
+      READ(numbio,*)
+      READ(numbio,*) nn_rem      ! Type of remineralization (1-prescribed, 2-temperature dependent)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) si_c        ! silicate to carbon ratio (mol/mol)
+      READ(numbio,*)
+      READ(numbio,*) no3_c       ! nitrate to carbon ratio (mol/mol)
+      READ(numbio,*)
+      READ(numbio,*) po4_c       ! phosphorus to carbon ratio (mol/mol)
+      READ(numbio,*)
+      READ(numbio,*) oxy_c       ! oxygen quota in algal cells (mol/mol)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*)
+      READ(numbio,*) khs_si_bio  ! half saturatio ct for Si uptake (mmol m-3)
+      READ(numbio,*)
+      READ(numbio,*) khs_n_bio   ! half saturatio ct for NO3 uptake (mmol m-3)
+      READ(numbio,*)
+      READ(numbio,*) khs_p_bio   ! half saturation ct for PO4 uptake (mmol m-3)
+      READ(numbio,*)
+      READ(numbio,*) rg_bio      ! temperature dependence of algal physiology (degC-1)
+      READ(numbio,*)
+      READ(numbio,*) rg_bac      ! temperature dependence of bacterial respiration (degC-1)
+      READ(numbio,*)
+      READ(numbio,*) nn_lim_sal  ! Type of salinity limitation 1=Arrigo, 2=4th order gaussian, 3=sine, 4=gaussian, 5=gaussian with 3rd order arg
+      READ(numbio,*)
+      READ(numbio,*) lim_sal_wid ! Width of salinity limitation (case 4)
+      READ(numbio,*)
+      READ(numbio,*) lim_sal_smax ! Salinity at which limitation equals 1 (case 4)
+
+      CLOSE( numbio )
+
+      ! Writes in the output file
+      WRITE(numout,*) ' c_grid    : ', c_grid
+      WRITE(numout,*) ' h_skel    : ', h_skel
+      WRITE(numout,*) ' e_thr_bal : ', e_thr_bal
+      WRITE(numout,*) ' ln_trbo   : ', ln_trbo
+      WRITE(numout,*) ' ln_trsi   : ', ln_trsi
+      WRITE(numout,*) ' ln_trdiff : ', ln_trdiff
+      WRITE(numout,*) ' ln_trremp : ', ln_trremp
+      WRITE(numout,*) ' ln_lim_dsi: ', ln_lim_dsi
+      WRITE(numout,*) ' ln_lim_no3: ', ln_lim_no3
+      WRITE(numout,*) ' ln_lim_po4: ', ln_lim_po4
+      WRITE(numout,*) ' ln_lim_lig: ', ln_lim_lig
+      WRITE(numout,*) ' ln_lim_tem: ', ln_lim_tem
+      WRITE(numout,*) ' ln_lim_sal: ', ln_lim_sal
+      WRITE(numout,*) ' ln_lys    : ', ln_lys
+      WRITE(numout,*) ' ln_rem    : ', ln_rem
+      WRITE(numout,*) ' ln_syn    : ', ln_syn
+      WRITE(numout,*) ' ln_bubform: ', ln_bubform
+      WRITE(numout,*) ' ln_bubrise: ', ln_bubrise
+      WRITE(numout,*) ' ln_gasflux: ', ln_gasflux
+      WRITE(numout,*) ' ln_carbon : ', ln_carbon
+      WRITE(numout,*) ' ln_ikaite : ', ln_ikaite
+      WRITE(numout,*)
+      WRITE(numout,*) ' nn_init   : ', nn_init
+      WRITE(numout,*) ' cdsi_ini  : ', cdsi_ini
+      WRITE(numout,*) ' cno3_ini  : ', cno3_ini
+      WRITE(numout,*) ' cpo4_ini  : ', cpo4_ini
+      WRITE(numout,*) ' cdaf_ini  : ', cdaf_ini
+      WRITE(numout,*) ' ceoC_ini  : ', ceoC_ini
+      WRITE(numout,*) ' cdic_ini  : ', cdic_ini
+      WRITE(numout,*) ' calk_ini  : ', calk_ini
+      WRITE(numout,*) ' cika_ini  : ', cika_ini
+      WRITE(numout,*) ' coxy_ini  : ', coxy_ini
+      WRITE(numout,*) ' cnit_ini  : ', cnit_ini
+      WRITE(numout,*) ' carg_ini  : ', carg_ini
+      WRITE(numout,*) ' cco2_ini  : ', cco2_ini
+      WRITE(numout,*) ' ccal_ini  : ', ccal_ini
+      WRITE(numout,*) ' cno3_w    : ', cno3_w
+      WRITE(numout,*) ' cpo4_w    : ', cpo4_w
+      WRITE(numout,*) ' cdsi_w    : ', cdsi_w
+      WRITE(numout,*) ' cdaf_w    : ', cdaf_w
+      WRITE(numout,*) ' ceoC_w    : ', ceoC_w
+      WRITE(numout,*) ' cdic_w    : ', cdic_w
+      WRITE(numout,*) ' calk_w    : ', calk_w
+      WRITE(numout,*) ' cika_w    : ', cika_w
+      WRITE(numout,*) ' coxy_w    : ', coxy_w
+      WRITE(numout,*) ' cnit_w    : ', cnit_w
+      WRITE(numout,*) ' carg_w    : ', carg_w
+      WRITE(numout,*) ' cco2_w    : ', cco2_w
+      WRITE(numout,*) ' ccal_w    : ', ccal_w
+      WRITE(numout,*) ' mr_oxy    : ', mr_oxy
+      WRITE(numout,*) ' mr_nit    : ', mr_nit
+      WRITE(numout,*) ' mr_arg    : ', mr_arg
+      WRITE(numout,*) ' mr_co2    : ', mr_co2
+      WRITE(numout,*)
+      WRITE(numout,*) ' i_gasflux : ', i_gasflux
+      WRITE(numout,*) ' brines_ar       : ', brines_ar
+      WRITE(numout,*) ' bub_form_rate   : ', bub_form_rate
+      WRITE(numout,*) ' bub_diss_rate   : ', bub_diss_rate
+      WRITE(numout,*) ' h_bl_gas        : ', h_bl_gas
+      WRITE(numout,*) ' e_thr_gasflux   : ', e_thr_gasflux
+      WRITE(numout,*) ' e_thr_bubrise   : ', e_thr_bubrise
+      WRITE(numout,*) ' sursat_gas      : ', sursat_gas
+      WRITE(numout,*) ' nn_carbonate    : ', nn_carbonate
+      WRITE(numout,*) ' caco3_time      : ', caco3_time
+      WRITE(numout,*)
+      WRITE(numout,*) ' nn_bio_opt: ', nn_bio_opt
+      WRITE(numout,*) ' astar_alg : ', astar_alg
+      WRITE(numout,*) ' fdet_alg  : ', fdet_alg
+      WRITE(numout,*) ' pp_presc  : ', pp_presc
+      WRITE(numout,*) ' mumax_bio : ', mumax_bio   
+      WRITE(numout,*) ' klys_bio  : ', klys_bio
+      WRITE(numout,*) ' krsp_bio  : ', krsp_bio 
+      WRITE(numout,*) ' krem_bio  : ', krem_bio 
+      WRITE(numout,*) ' frem_bio  : ', frem_bio 
+      WRITE(numout,*) ' nn_phs    : ', nn_phs  
+      WRITE(numout,*) ' ek_bio    : ', ek_bio
+      WRITE(numout,*) ' alpha_bio : ', alpha_bio
+      WRITE(numout,*) ' chla_c    : ', chla_c
+      WRITE(numout,*) ' Estar     : ', Estar  
+      WRITE(numout,*) ' nn_lys    : ', nn_lys 
+      WRITE(numout,*) ' nn_rem    : ', nn_rem
+      WRITE(numout,*) ' si_c      : ', si_c
+      WRITE(numout,*) ' no3_c     : ', no3_c
+      WRITE(numout,*) ' po4_c     : ', po4_c
+      WRITE(numout,*) ' oxy_c     : ', oxy_c
+      WRITE(numout,*) ' khs_si_bio: ', khs_si_bio
+      WRITE(numout,*) ' khs_n_bio : ', khs_n_bio
+      WRITE(numout,*) ' khs_p_bio : ', khs_p_bio
+      WRITE(numout,*) ' rg_bio    : ', rg_bio
+      WRITE(numout,*) ' rg_bac    : ', rg_bac
+      WRITE(numout,*) ' nn_lim_sal: ', nn_lim_sal
+      WRITE(numout,*) ' lim_sal_wid  : ', lim_sal_wid
+      WRITE(numout,*) ' lim_sal_smax : ', lim_sal_smax
+      WRITE(numout,*) 
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_bio_param '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+      WRITE(numout,*)
+!
+!-----------------------------------------------------------------------------!
+!-- End of ice_bio_param --
+      RETURN
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_remap.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_remap.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_remap.f	(revision 6)
@@ -0,0 +1,574 @@
+      SUBROUTINE ice_bio_remap(nlay_s,nlay_i,kideb,kiut)
+!-----------------------------------------------------------------------------!
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      REAL(8), DIMENSION( 0:maxnlay+2 ) ::
+     &  z0
+
+      REAL(8), DIMENSION( maxnlay + 2 ) ::
+     &  zq0         , ! : scalar content on the physical grid (input)
+     &  zthick0       ! : thickness of biological layers
+
+      REAL(8), DIMENSION( maxnlay ) ::
+     &  zq1         , ! : scalar content on the biological grid (output)
+     &  zdeltaz
+
+      REAL(8), DIMENSION( nlay_bio , maxnlay ) ::
+     &  zweight       ! : relayering matrix
+
+      INTEGER :: zcase
+      zeps   = 1.0e-20
+
+!==============================================================================!
+
+      WRITE(numout,*) 
+      WRITE(numout,*) ' ice_bio_remap : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~ '
+      WRITE(numout,*)
+      WRITE(numout,*) '    *** Before remapping                   *** '
+      DO jn = 1, ntra_bio
+         IF ( flag_active(jn) ) THEN
+           WRITE(numout,*) ' biotr_i_nam : ', biotr_i_nam(jn)
+           WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn, jk), jk = 1,
+     &                                      nlay_bio )
+         ENDIF
+      END DO
+
+      !--------------------
+      ! Conservation check
+      !--------------------
+      CALL ice_bio_column(kideb,kiut,ntra_bio,mt_i_bio_init,cbu_i_bio,
+     &                    deltaz_i_bio, .FALSE.)
+
+      DO ji = kideb, kiut
+      WRITE(numout,*)
+      WRITE(numout,*) ' Inputs     : '
+      WRITE(numout,*) ' ~~~~~~       '
+      WRITE(numout,*) ' dh_i_surf  : ', dh_i_surf(ji)
+      WRITE(numout,*) ' dh_i_bott  : ', dh_i_bott(ji)
+      WRITE(numout,*) ' dh_snowice : ', dh_snowice(ji)
+!
+!------------------------------------------------------------------------------|
+!  1) Switches                                                                 |
+!------------------------------------------------------------------------------|
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' Switches : '
+      WRITE(numout,*) ' ~~~~~~~~ '
+
+      !----------------------------------
+      ! Biological Grid Type
+      !----------------------------------
+      IF ( ( c_grid .NE. 'SL' ) .AND. ( c_grid .NE. 'BA' ) ) THEN
+         zcase = 1 ! ML / DL cases
+      ELSE
+         zcase = 2 ! SL / BA cases
+      ENDIF
+
+      !----------------------------------
+      ! Surface melt indicator : icsuind
+      !----------------------------------
+      ! ice surface behaviour : computation of icsuind-icsuswi
+      ! icsuind : index which values equals 
+      !           0 if there is nothing
+      !           1 if first layer has started to melt
+      !           2 if first and second layer have started ...
+      !                             etc ...
+      icsuind  =  0  
+      deltah   =  0.0
+      DO layer = 1, nlay_bio
+         IF ( - dh_i_surf(ji) .GT. deltah ) THEN
+            icsuind  =  layer 
+         ENDIF
+         deltah = deltah + deltaz_i_bio(layer)
+      END DO
+
+      !-------------------------------
+      ! Surface melt switch : icsuswi
+      !-------------------------------
+      ! icsuswi : switch which value equals 1 if ice melts at the surface
+      !                                     0 if not
+      icsuswi    =  MAX( 0 , INT( - dh_i_surf(ji) 
+     &              / MAX ( zeps , ABS( dh_i_surf(ji) ) ) ) )
+
+      !--------------------------------
+      ! Ice bottom indicator : icboind
+      !--------------------------------
+      ! icboind : index which values equals 0 if accretion is on the way
+      !                                     1 if last layer has started to melt
+      !                                     2 if penultiem layer has started ...
+      !                                     etc ...
+      icboind  =  0  
+      deltah   =  0.0
+      DO layer = nlay_bio, 1, -1
+         IF ( - dh_i_bott(ji) .GT. deltah ) THEN
+            icboind  =  nlay_bio + 1 - layer 
+         ENDIF
+         deltah = deltah + deltaz_i_bio(layer)
+      END DO
+
+      !-----------------------------
+      ! Ice bottom switch : icboswi
+      !-----------------------------
+      ! icboswi : switch which value equals 1 if accretion of ice is on the way
+      !                                     0 if ablation is on the way
+      icboswi    =  MAX( 0 , INT( dh_i_bott(ji)
+     &              / MAX( zeps , ABS( dh_i_bott(ji) ) ) ) )
+
+      !------------------------------
+      ! Snow ice indicator : snicind
+      !------------------------------
+      ! snow-ice formation : calcul de snicind-snicswi
+      ! snicind : index which values equals 0 if no snow-ice forms
+      !                1 if last layer of snow has started to melt
+      !                2 if penultiem layer ...
+      snicind  =  0
+      deltah   =  0.0
+      DO layer = nlay_s, 1, -1
+         IF ( dh_snowice(ji) .GT. deltah) THEN
+            snicind  =  nlay_s+1-layer
+         ENDIF
+         deltah = deltah + h_s(layer)
+      END DO
+
+      !---------------------------
+      ! Snow ice switch : snicswi
+      !---------------------------
+      ! snicswi : switch which value equals 1 if snow-ice forms
+      !                                     0 if not
+      snicswi    =  MAX( 0 , INT( dh_snowice(ji) /
+     &              MAX( zeps , ABS( dh_snowice(ji) ) ) ) )
+
+      WRITE(numout,*) ' icsuind    : ', icsuind
+      WRITE(numout,*) ' icsuswi    : ', icsuswi
+      WRITE(numout,*) ' icboind    : ', icboind
+      WRITE(numout,*) ' icboswi    : ', icboswi
+      WRITE(numout,*) ' snicind    : ', snicind
+      WRITE(numout,*) ' snicswi    : ', snicswi
+      WRITE(numout,*) 
+!
+!------------------------------------------------------------------------------|
+! 2) Tracer sources
+!------------------------------------------------------------------------------|
+!
+      WRITE(numout,*) ' Tracer sources : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~ '
+      
+      DO jn = 1, ntra_bio
+
+         IF ( flag_active (jn) ) THEN
+
+         c_s_bio(jn)   = 0.0 ! now no concentration in the snow
+         ch_bo_bio(jn) = 0.0
+         ch_si_bio(jn) = 0.0
+
+         IF ( ln_trbo ) 
+     &      ch_bo_bio(jn) = e_skel * c_w_bio(jn) * MAX( dh_i_bott(ji),
+     &                      0.0 )
+
+         IF ( ln_trsi )
+     &      ch_si_bio(jn) = ( ( rhog - rhon ) / rhog * c_w_bio(jn) 
+     &                   + ( rhon / rhog ) * c_s_bio(jn) ) * 
+     &                   MAX( dh_snowice(ji) , 0.0 )
+
+         fcbp(jn) = ch_bo_bio(jn) / ddtb
+         fcsi(jn) = ch_si_bio(jn) / ddtb
+
+         WRITE(numout,*) ' Tracer    : ', biotr_i_nam(jn)
+         WRITE(numout,*) ' ch_bo_bio : ', ch_bo_bio(jn)
+         WRITE(numout,*) ' ch_si_bio : ', ch_si_bio(jn)
+!        WRITE(numout,*) ' c_s_bio   : ', c_s_bio (jn)
+!        WRITE(numout,*) ' c_w_bio: ', c_w_bio(jn)
+!        WRITE(numout,*) ' c_ws_i    : ', 
+!    &                   ( rhog - rhon ) / rhog * c_w_bio(jn)
+
+         ENDIF
+
+      END DO !jn
+!
+!------------------------------------------------------------------------------|
+! 3) Compute new concentrations by remapping tracers
+!------------------------------------------------------------------------------|
+!
+      SELECT CASE (zcase) 
+                
+                 !========================!
+      CASE (1)   !=== MULTI-LAYER CASE ===!
+                 !========================!
+
+      !
+      !------------------------------------------------------------------------|
+      ! 3.1) Old grid: zthick0, z0, zdeltaz
+      !------------------------------------------------------------------------|
+      !
+      WRITE(numout,*) ' Old grid : '
+      WRITE(numout,*) ' ~~~~~~~~~~ '
+
+      !--- Diffusive remapping, compute z0 and zthick0 ---!
+      !
+      ! indexes of the vectors
+      ntop0    =  1
+      nbot0    =  nlay_bio + 1 - icboind + (1 - icsuind) * icsuswi +
+     &            snicswi
+      nbot0    =  MAX(1, MIN( nlay_bio + 1 - icboind + 
+     &            (1-icsuind)*icsuswi
+     &          + snicswi, nlay_bio + 2 ) )
+
+      WRITE(numout,*) ' ntop0     : ', ntop0
+      WRITE(numout,*) ' nbot0     : ', nbot0
+
+      ! Cotes of the top of the layers
+      z0(0)   =  0.0
+      DO layer = 1, nbot0-1
+        limsum    =  ( (icsuswi * (icsuind+layer-1) + 
+     &                 (1-icsuswi)*layer) ) *
+     &                 (1-snicswi) + (layer-1)*snicswi
+         z0(layer) =  icsuswi*dh_i_surf(ji) + snicswi*dh_snowice(ji)
+         DO layer_a = 1, limsum
+            z0(layer) = z0(layer) + deltaz_i_bio(layer_a)
+         END DO
+      END DO
+
+      z0(nbot0)  =  icsuswi*dh_i_surf(ji) + snicswi*dh_snowice(ji) + 
+     &              dh_i_bott(ji)
+
+      DO layer = 1, nlay_bio
+         z0(nbot0) = z0(nbot0) + deltaz_i_bio(layer)
+      END DO
+       
+      z0(1)      =  snicswi * dh_snowice(ji) + (1 - snicswi) * z0(1)
+
+      DO layer = ntop0, nbot0
+         zthick0(layer)  =  z0(layer) - z0(layer-1)
+      END DO
+
+      WRITE(numout,*) ' Old grid, ntop0 : ', ntop0, ' nbot0 : ', nbot0
+      WRITE(numout,*) ' z0      : ', ( z0(layer), layer = 0, nbot0 )
+      WRITE(numout,*) ' zthick0 : ', ( zthick0(layer) ,
+     &                               layer = 1, nbot0 )
+      WRITE(numout,*)
+
+      !--- Squeezing remapping, compute zdeltaz ---!'
+      !
+      zdeltaz(1:nlay_bio) = deltaz_i_bio(:)
+
+      !
+      !-------------------------------------------------------------------------|
+      ! 3.2) New grid   
+      !-------------------------------------------------------------------------|
+      !
+      WRITE(numout,*) ' New grid : '
+      WRITE(numout,*) ' ~~~~~~~~~~ '
+      ! indexes of the vectors
+      ntop1    =  1 
+      nbot1    =  nlay_bio
+      ! cotes and thicknesses
+      CALL ice_bio_grid(kideb,kiut,nlay_i,.TRUE.) ! compute the biological grid
+
+      WRITE(numout,*) ' New grid, ntop1 : ', ntop1, ' nbot1 : ', nbot1
+      WRITE(numout,*) ' zb_i_bio: ', ( zb_i_bio(layer), 
+     &                                 layer = 0, nbot1 )
+      !
+      !------------------------------------------------------------------------|
+      ! 3.3) Weights (diffusive remapping only)
+      !------------------------------------------------------------------------|
+      !
+      WRITE(numout,*)
+      WRITE(numout,*) ' Weights  : '
+      WRITE(numout,*) ' ~~~~~~~~~~ '
+
+      DO layer1 = 1, nlay_bio
+         DO layer0 = 1, nbot0
+            zweight(layer1,layer0) = MAX ( 0.0 , ( MIN ( z0(layer0) ,
+     &      zb_i_bio(layer1) ) 
+     &    - MAX ( z0 (layer0-1) , zb_i_bio(layer1-1) ) ) / 
+     &      zthick0(layer0) )
+!           WRITE(numout,*) ' layer0, layer1 : ', layer0, layer1
+!           WRITE(numout,*) ' zweight        : ', zweight(layer1,layer0)
+         END DO
+      END DO
+      WRITE(numout,*)
+
+      !
+      !------------------------------------------------------------------------|
+      ! 3.4) Tracer remapping
+      !------------------------------------------------------------------------|
+      !
+      WRITE(numout,*) ' Tracer remapping : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~ '
+
+      DO jn = 1, ntra_bio
+
+      IF ( flag_active (jn) ) THEN
+
+         WRITE(numout,*) ' ------------------------------------------'
+         WRITE(numout,*) ' Tracer                  : ', biotr_i_nam(jn)
+         WRITE(numout,*) ' Remapping type  nn_remp : ', nn_remp(jn)
+         WRITE(numout,*) ' ------------------------------------------'
+         WRITE(numout,*)
+
+         !--------------------------------------------------------------------!
+         ! 3.4.1) Compute 'new' tracer contents
+         !--------------------------------------------------------------------!
+
+                                          !=====================!
+         IF ( nn_remp(jn) .EQ. 1 ) THEN   ! Diffusive remapping !
+                                          !=====================!
+         !--------------------!
+         ! Old tracer content !
+         !--------------------!
+
+         WRITE(numout,*) ' Tracer content ...'
+         WRITE(numout,*)
+
+         !--- Inner layers ---!
+         mt_i_bio_init(jn) = 0.0
+
+         DO layer = ntop0, nbot0
+            limsum =  MAX(1,MIN(snicswi*(layer-1) + icsuswi*(layer-1
+     &           +  icsuind)
+     &           + (1-icsuswi)*(1-snicswi)*layer, nlay_bio))
+            zq0(layer) = zthick0(layer) * cbu_i_bio(jn,limsum)
+
+!           WRITE(numout,*) ' limsum : ', limsum
+!           IF ( limsum .GE. 1 ) 
+!    &         WRITE(numout,*) ' cbu_i_bio: ', cbu_i_bio(jn,limsum)
+
+!           WRITE(numout,*) ' zq0    : ', zq0(layer)
+!           WRITE(numout,*) ' zthick0: ', zthick0(layer)
+
+         END DO
+
+         !--- Bottom layer ---!
+         ! bottom layer if ice forms at the bottom
+         zq0(nbot0) = ( 1 - icboswi ) * zq0(nbot0) + icboswi *
+     &                ch_bo_bio(jn)
+
+         !--- Upper layer ---!
+         ! first layer if snow ice forms
+         zq0(1)     =  snicswi * ch_si_bio(jn) 
+     &              + ( 1 - snicswi ) * zq0(1)
+
+!        WRITE(numout,*) ' snicswi   : ', snicswi
+!        WRITE(numout,*) ' c_si_bio  : ', ch_si_bio(jn) / zthick0(1)
+
+         DO layer = ntop0, nbot0
+            mt_i_bio_init(jn) = mt_i_bio_init(jn) +
+     &                          zq0(layer)
+         END DO
+
+         WRITE(numout,*) ' zq0       : ', ( zq0(layer), 
+     &                                    layer = 1, nbot0 )
+         !----------------!
+         ! Remapping      !
+         !----------------!
+
+         WRITE(numout,*) ' Remapping ... ' 
+         WRITE(numout,*)
+
+         DO layer1 = 1, nlay_bio
+            zq1(layer1) = 0.0
+            DO layer0 = 1, nbot0
+               zq1(layer1) = zq1(layer1) + zweight(layer1,layer0) *
+     &                       zq0(layer0)
+            END DO
+         END DO
+
+         ENDIF ! nn_remp
+
+                                          !=====================!
+         IF ( nn_remp(jn) .EQ. 2 ) THEN   ! Squeezing remapping
+                                          !=====================!
+ 
+         WRITE(numout,*) ' Remapping ... ' 
+         WRITE(numout,*)
+
+
+         ! Inner layers
+         DO layer = 1, nlay_bio 
+            zq0(layer) = zdeltaz(layer) * cbu_i_bio(jn,layer)
+         END DO
+
+         ! Surface layer
+         zq0(1)        = zq0(1) + ch_si_bio(jn)
+
+         ! Bottom layer
+         zq0(nlay_bio) = zq0(nlay_bio) + ch_bo_bio(jn)
+
+         ! Tracer content for conservation check
+         mt_i_bio_init(jn) = 0.0
+         DO layer = 1, nlay_bio
+            mt_i_bio_init(jn) = mt_i_bio_init(jn) +
+     &                          zq0(layer)
+         END DO
+
+         zq1(1:nlay_bio) = zq0(1:nlay_bio)
+
+         ENDIF ! nn_remp
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' zq1       : ', ( zq1(layer), 
+     &                                    layer = 1, nlay_bio )
+         WRITE(numout,*)
+
+         !--------------------------------------------------------------------!
+         ! 3.4.2) Retrieve bulk concentration from content
+         !--------------------------------------------------------------------!
+         !
+         DO layer = 1, nlay_bio
+            cbu_i_bio(jn,layer) = zq1(layer) / deltaz_i_bio(layer)
+         END DO ! layer
+      
+      ENDIF ! flag_active
+
+      END DO ! jn
+
+                 !========================!
+      CASE (2)   !=== SL/BAL CASE         !
+                 !========================!
+
+         zdz0 = deltaz_i_bio(nlay_bio)
+
+         CALL ice_bio_grid(kideb,kiut,nlay_i,.TRUE.) ! compute the new biological grid
+
+         DO jn = 1, ntra_bio
+         
+            IF ( flag_active (jn) ) THEN
+      
+            ! Old tracer content
+            zq0(1:nlay_bio-1) = 0.
+            zq0(nlay_bio) = snicswi * ch_si_bio(jn) 
+     &                    + icboswi * ch_bo_bio(jn)
+     &                    + cbu_i_bio(jn,nlay_bio) * zdz0
+
+            ! New tracer content (no loss from melt)
+            zq1(1:nlay_bio-1) = 0.
+            zq1(nlay_bio)     = zq0(nlay_bio)
+
+            ! New bulk concentrations
+            cbu_i_bio(jn,1:nlay_bio-1) = 0.0
+            cbu_i_bio(jn,nlay_bio)     = zq1(nlay_bio) / 
+     &                                   deltaz_i_bio(nlay_bio)
+
+            ENDIF ! flag_active
+
+         END DO ! jn
+
+      END SELECT ! zcase
+
+!
+!-----------------------------------------------------------------------
+! 4) Retrieve brine concentration
+!-----------------------------------------------------------------------
+!
+      !---------------
+      ! Interpolation 
+      !---------------
+      CALL ice_bio_interp_phy2bio(kideb,kiut,nlay_i,.FALSE.) 
+                                          ! interpolation of physical variables
+                                          ! on the biological grid
+      !---------------------
+      ! Brine concentration
+      !---------------------
+      DO jn = 1, ntra_bio
+
+         IF ( flag_active (jn) .AND. flag_diff(jn) ) THEN
+            DO layer = 1, nlay_bio
+               c_i_bio(jn,layer) = cbu_i_bio(jn,layer) / e_i_bio(layer)
+            END DO ! layer
+         ENDIF ! flags
+
+      END DO ! jn
+
+      END DO ! ji
+
+!
+!-----------------------------------------------------------------------
+! 5) Conservation check
+!-----------------------------------------------------------------------
+!
+      !-------------------
+      ! Conservation test
+      !-------------------
+      CALL ice_bio_column(kideb,kiut,ntra_bio,mt_i_bio_final,cbu_i_bio,
+     &                    deltaz_i_bio, .FALSE.)
+      DO jn = 1, ntra_bio
+         IF ( flag_active(jn) ) THEN
+            WRITE(numout,*) ' mt_i_bio_final : ', mt_i_bio_final(jn)
+         ENDIF
+      END DO
+
+      DO jn = 1, ntra_bio
+
+         IF ( flag_active(jn) ) THEN
+
+         ! Flux due to bottom formation
+         f_bogr(jn) =  ch_bo_bio(jn) / ddtb
+         f_sigr(jn) =  ch_si_bio(jn) / ddtb
+         f_bogr(jn) =  0.0
+         f_sigr(jn) =  0.0
+
+         ! Flux due to snow ice formation
+
+         ! Bottom flux ( positive upwards )
+!        f_bo_tra(jn) =
+!        f_bo_tra(jn) = zswitchw * ( - e_i_bio( nlay_bio )
+!    &                * diff_bio * 2.0
+!    &                / deltaz_i_bio(nlay_bio) * ( c_i_bio(jn,nlay_bio)
+!    &                  - c_w_bio(jn) ) )
+!    &                + zswitchs * ( - qsummer * c_i_bio(jn,nlay_bio) )
+!    &                / ddtb
+!    &                * e_i_bio(nlay_bio)
+!        f_su_tra(jn) = zswitchw * 0.0
+!    &                + zswitchs * ( qsummer * c_s_bio(jn) )
+!    &                / ddtb
+         !+++++
+         WRITE(numout,*) ' f_bogr : ', f_bogr(jn)
+         WRITE(numout,*) ' f_sigr : ', f_sigr(jn)
+         !+++++
+
+         ENDIF
+
+      END DO ! jn
+
+      zerror = 1.0e-9
+      CALL ice_bio_conserv(kideb,kiut,ntra_bio,'ice_bio_remap  ',
+     &                     biotr_i_nam, zerror,
+     &                           mt_i_bio_init,mt_i_bio_final,
+     &                           f_bogr, f_sigr, ddtb)
+!     CALL ice_bio_column(kideb,kiut,ntra_bio,ct_i_bio,cbu_i_bio,
+!    &                    deltaz_i_bio, .FALSE.)
+
+!
+!-----------------------------------------------------------------------
+! 9) Final output
+!-----------------------------------------------------------------------
+!
+
+      WRITE(numout,*)
+      WRITE(numout,*) '    *** After remapping                    *** '
+      WRITE(numout,*) '    model output '
+      DO jn = 1, ntra_bio
+         IF ( flag_active(jn) ) THEN
+           WRITE(numout,*) ' biotr_i_nam : ', biotr_i_nam(jn)
+           WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn,jk),
+     &                                      jk = 1, nlay_bio )
+           IF ( flag_diff(jn) ) 
+     &     WRITE(numout,*) ' c_i_bio   : ', ( c_i_bio(jn,jk),
+     &                                      jk = 1, nlay_bio )
+         ENDIF
+      END DO
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_bio_remap '
+
+!==============================================================================|
+! Fin de la routine ice_bio_remap
+      WRITE(numout,*)
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_sms.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_sms.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_bio_sms.f	(revision 6)
@@ -0,0 +1,470 @@
+      SUBROUTINE ice_bio_sms(nlay_i,kideb,kiut)
+!
+!-----------------------------------------------------------------------------!
+!                           *** ice_bio_sms ***
+!     Biological sources minus sinks
+!     (c) Martin Vancoppenolle, LOCEAN, October 2012
+!     
+!     version : source_3.03
+!     status  : in permanent revision :-)
+!
+!=============================================================================!
+!
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER, DIMENSION(3) :: 
+     &   zindex
+
+      REAL, DIMENSION(nlay_bio) ::
+     &   zek,
+     &   zlim_nut
+
+      LOGICAL ::
+     &   ln_write_bio
+
+      ln_write_bio = .TRUE.
+      zeps = 1.0e-14
+      ji = 1
+
+!
+!=============================================================================!
+!
+!-----------------------------------------------------------------------------!
+! 1) Control prints
+!-----------------------------------------------------------------------------!
+!
+      IF ( ln_write_bio ) THEN
+
+         WRITE(numout,*) 
+         WRITE(numout,*) ' ** ice_bio_sms : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+
+         CALL ice_brine
+
+         WRITE(numout,*) ' Initial tracer values   '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~  '
+
+         DO jn = 1, ntra_bio
+            IF ( flag_active(jn) ) THEN
+               WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+               WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer), 
+     &                                         layer = 1, nlay_bio )
+            ENDIF ! flag_active
+         END DO ! jn
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' Parameters '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~  '
+         WRITE(numout,*) ' si_c      : ', si_c
+         WRITE(numout,*) ' no3_c     : ', no3_c
+         WRITE(numout,*) ' po4_c     : ', po4_c
+         WRITE(numout,*) ' mumax_bio : ', mumax_bio   
+         WRITE(numout,*) ' klys_bio  : ', klys_bio
+         WRITE(numout,*) ' khs_si_bio: ', khs_si_bio
+         WRITE(numout,*) ' ek_bio    : ', ek_bio
+         WRITE(numout,*) ' astar_alg : ', astar_alg
+         WRITE(numout,*) ' rg_bio    : ', rg_bio
+         WRITE(numout,*) ' nn_lim_sal: ', nn_lim_sal 
+         WRITE(numout,*) ' lim_sal_wid :', lim_sal_wid
+         WRITE(numout,*) ' lim_sal_smax:', lim_sal_smax
+         WRITE(numout,*) 
+
+      ENDIF ! ln_write_bio
+!
+!-----------------------------------------------------------------------------!
+! 2) Source Minus Sink terms
+!-----------------------------------------------------------------------------!
+!
+
+      ! Reference of the upper layer
+      IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) THEN
+
+         lim_dsi(:) = 0.; lim_no3(:) = 0.; lim_po4(:) = 0.
+         lim_lig(:) = 0.; lim_tem(:) = 0.; lim_sal(:) = 0.
+         lys_bio(:) = 0.; rem_bio(:) = 0.; syn_bio(:) = 0.
+         rsp_bio(:) = 0.; exu_bio(:) = 0.
+
+         lim_dsi(nlay_bio) = 1.; lim_no3(nlay_bio) = 1.
+         lim_po4(nlay_bio) = 1.
+         lim_lig(nlay_bio) = 1.; lim_tem(nlay_bio) = 1.
+         lim_sal(nlay_bio) = 1.
+
+      ELSE
+
+         lim_dsi(:) = 1.; lim_no3(:) = 1.; lim_po4(:) = 1.
+         lim_lig(:) = 1.; lim_tem(:) = 1.; lim_sal(:) = 1.
+         lys_bio(:) = 0.; rem_bio(:) = 0.; syn_bio(:) = 0.
+         rsp_bio(:) = 0.; exu_bio(:) = 0.
+
+      ENDIF
+
+      !------------------------------------------------------------------------
+      ! 2.1 Limitation factors
+      !------------------------------------------------------------------------
+
+      ! 2.1.1 Nutrients & temperature
+      !--------------------------------
+      DO layer = layer_00, nlay_bio
+
+         IF ( ln_lim_dsi ) ! DSi limitation
+     &      lim_dsi(layer) = c_i_bio(1,layer) 
+     &                     / ( khs_si_bio + c_i_bio(1,layer) )
+
+         IF ( ln_lim_no3 ) ! NO3 limitation
+     &      lim_no3(layer) = c_i_bio(2,layer) 
+     &                     / ( khs_n_bio + c_i_bio(2,layer) )
+
+         IF ( ln_lim_po4 ) ! PO4 limitation
+     &      lim_po4(layer) = c_i_bio(3,layer) 
+     &                     / ( khs_p_bio + c_i_bio(3,layer) )
+
+         IF ( ln_lim_dsi .OR. ln_lim_no3 .OR. ln_lim_po4 ) ! Nut limitation
+!    &      zlim_nut(layer) = lim_dsi(layer) * lim_no3(layer)
+!    &                      * lim_po4(layer)
+     &      zlim_nut(layer) = MIN ( lim_dsi(layer) , lim_no3(layer)
+     &                      , lim_po4(layer) )
+
+         IF ( ln_lim_tem ) ! Temperature factor
+     &      lim_tem(layer) = EXP( rg_bio * tc_bio(layer) )
+
+      END DO ! layer
+
+      ! 2.1.2 Brine salinity
+      !----------------------
+      IF ( ln_lim_sal ) THEN
+
+         SELECT CASE ( nn_lim_sal )
+
+            CASE (1) ! Arrigo and Sullivan (1992)
+
+            DO layer = layer_00, nlay_bio
+               zarg = 2.16 - 8.30e-5 * sbr_bio(layer)**2.11
+     &              - 0.55 * LOG( sbr_bio(layer) )
+               lim_sal(layer) = EXP ( - zarg * zarg )
+            END DO
+
+            CASE (2) ! Simple Gaussian ( Martouf and Grozny, 2010 )
+            
+            DO layer = layer_00, nlay_bio
+                zarg = ( sbr_bio(layer) - lim_sal_smax ) /  lim_sal_wid
+                lim_sal(layer) = EXP( - zarg * zarg )
+            END DO
+
+         END SELECT
+
+      ENDIF ! ln_lim_sal
+
+      ! 2.1.3 Light
+      !-------------
+      IF ( ln_lim_lig ) THEN
+
+         SELECT CASE ( nn_phs )
+
+            CASE (1) ! prescribed Ek
+
+               zek(:) = ek_bio
+               chlC_bio(:) = chla_c
+
+            CASE (2) ! Ek depends on chla/C
+
+               zek(:) = mumax_bio / ( alpha_bio * chla_c )
+               chlC_bio(:) = chla_c
+
+            CASE (3) ! full account for limitation factors
+
+               zek(:) = mumax_bio * lim_tem(:) * lim_sal(:) 
+     &                * zlim_nut(:) / ( alpha_bio * chla_c ) 
+               chlC_bio(:) = chla_c
+
+            CASE (4) ! varying chl-a carbon ratio
+
+               zthmin = 0.01  ! min
+               zthmax = 0.05  ! max 
+
+               DO layer = layer_00, nlay_bio
+                  chlC_bio (layer) = ( zthmax - ( zthmax - zthmin ) * 
+     &            MIN( par_bio(layer) / Estar, 1.0 ) ) * zlim_nut(layer)
+               END DO
+
+               zek(:) = mumax_bio * lim_tem(:) * lim_sal(:)
+     &                * zlim_nut(:) / ( alpha_bio * chlC_bio(:) )
+
+         END SELECT
+         
+         DO layer = layer_00, nlay_bio ! Jassby & Platt 76 formulation
+            lim_lig(layer) = TANH ( par_bio(layer) / zek(layer) )
+         END DO
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' lim_lig : ', ( lim_lig(layer), 
+     &                   layer = layer_00, nlay_bio )
+         WRITE(numout,*) ' zlim_nut: ', ( zlim_nut(layer), 
+     &                   layer = layer_00, nlay_bio )
+         WRITE(numout,*) ' par_bio : ', ( par_bio(layer), 
+     &                   layer = layer_00, nlay_bio )
+         WRITE(numout,*) ' zek     : ', ( zek(layer)    , 
+     &                   layer = layer_00, nlay_bio )
+         WRITE(numout,*) ' chlC_bio: ', ( chlC_bio(layer), 
+     &                   layer = layer_00, nlay_bio )
+         WRITE(numout,*)
+
+      ENDIF ! ln_lim_lig
+
+      IF ( .NOT. ln_lim_lig ) chlC_bio(:) = chla_c
+
+      !------------------------------------------------------------------------
+      ! 2.2 Loss & remineralization 
+      !------------------------------------------------------------------------
+
+      ! Exudation is zero
+      exu_bio(:) = 0.0
+
+      DO layer = layer_00, nlay_bio
+
+         ! Respiration (NP, NPDr)
+         ! IF ( ln_rsp ) ...
+         rsp_bio(layer) = krsp_bio * cbu_i_bio(jn_aoc,layer) * 
+     &                    lim_tem(layer)
+
+         ! Lysis (NP, NPDr) 
+         IF ( ln_lys ) THEN
+
+            IF ( nn_lys .GE. 1 )   ! no T-dependence
+     &         lys_bio(layer) = klys_bio * cbu_i_bio(jn_aoc,layer)
+
+            IF ( nn_lys .EQ. 2 )   ! T-dependence
+     &         lys_bio(layer) = lys_bio(layer) * lim_tem(layer)
+
+         ENDIF
+
+      END DO
+
+      ! Remineralization 
+      IF ( ln_rem ) THEN
+
+         SELECT CASE ( nn_bio_opt ) 
+
+         CASE(0) ! NP
+
+            rem_bio(layer_00:nlay_bio) = frem_bio * 
+     &                                   lys_bio(layer_00:nlay_bio)
+
+         CASE(1) ! NPDr
+
+            IF ( nn_rem .GE. 1 )   ! no T-dependence
+     &         rem_bio(layer_00:nlay_bio) = krem_bio * 
+     &                          cbu_i_bio(jn_eoc,layer_00:nlay_bio)
+
+         
+            IF ( nn_rem .EQ. 2 )   ! T-dependence
+     &         rem_bio(layer_00:nlay_bio) = rem_bio(layer_00:nlay_bio) *
+     &                       EXP( rg_bac * tc_bio(layer_00:nlay_bio) )
+
+         END SELECT
+
+      ENDIF
+
+
+      !------------------------------------------------------------------------
+      ! 2.3 Diatom Synthesis
+      !------------------------------------------------------------------------
+
+      DO layer = layer_00, nlay_bio
+   
+         IF ( ln_syn ) THEN
+            ! raw synthesis (in s-1)
+            z_syn = mumax_bio
+     &            * lim_tem(layer) * lim_sal(layer) * lim_lig(layer)
+     &            * zlim_nut(layer)
+
+            ! preclude excessive growth if insufficient nutrient stock
+            zsyn1 = z_syn * cbu_i_bio(jn_aoc,layer) ! normal carbon production rate (mmolC/m3/s)
+            zsyn2 = zsyn1;    zsyn3 = zsyn1;    zsyn4 = zsyn1
+   
+            IF ( ln_lim_dsi )                  ! prevent exhaustion of Si
+     &         zsyn2 = cbu_i_bio(jn_dsi,layer) / ddtb / si_c - zeps 
+  
+            IF ( ln_lim_no3 )                  ! prevent exhaustion of N
+     &         zsyn3 = cbu_i_bio(jn_din,layer) / ddtb / no3_c - zeps
+  
+            IF ( ln_lim_po4 )                  ! prevent exhaustion of P
+     &         zsyn4 = cbu_i_bio(jn_dip,layer) / ddtb / po4_c - zeps
+   
+            ! nutrient stock-limited PP rate
+            syn_bio(layer) = MIN( zsyn1, zsyn2, zsyn3, zsyn4 ) 
+
+         ELSE  ! ln_syn is .FALSE. 
+               ! PP is prescribed to zero everywhere 
+               ! except in the bottom layer
+               ! where it equals pp_presc
+               ! if sun is shining
+
+            IF ( ( layer .EQ. nlay_bio ) .AND. ( fsolgb(ji) .GT. 5.0 ) )
+     &         syn_bio(layer) = pp_presc 
+
+         ENDIF ! ln_syn
+   
+
+      END DO ! layer
+
+      !------------------------------------------------------------------------
+      ! 2.4 Update reservoirs
+      !------------------------------------------------------------------------
+
+      DO layer = layer_00, nlay_bio
+
+         ! DSi uptake
+         zd_dsi1 = si_c * ( rem_bio(layer) + 
+     &             rsp_bio(layer) - syn_bio(layer) ) * ddtb
+         zd_dsi2 = - cbu_i_bio(jn_dsi,layer)        ! Maximum DSi uptake
+         zd_dsi  = MAX ( zd_dsi1, zd_dsi2 )
+
+         ! NO3 uptake
+         zd_no31 = no3_c * ( rem_bio(layer) +
+     &             rsp_bio(layer) - syn_bio(layer) ) * ddtb
+         zd_no32 = - cbu_i_bio(jn_din,layer)        ! Max NO3 uptake
+         zd_no3  = MAX ( zd_no31, zd_no32 )
+
+         ! update PO4
+         zd_po41 = po4_c * ( rem_bio(layer) +
+     &             rsp_bio(layer) - syn_bio(layer) ) * ddtb
+         zd_po42 = - cbu_i_bio(jn_dip,layer)        ! Max PO4 uptake
+         zd_po4  = MAX ( zd_po41, zd_po42 )
+
+         ! update algae
+         zd_daf1 = ( syn_bio(layer) - lys_bio(layer) -
+     &               rsp_bio(layer) - exu_bio(layer) ) * ddtb
+         zd_daf2 = - cbu_i_bio(jn_aoc,layer)        ! Max algal carbon loss
+         zd_daf = MAX ( zd_daf1, zd_daf2 )
+
+         ! update detritus
+         IF ( nn_bio_opt .GE. 1 ) THEN
+            zd_eoc1 = ( lys_bio(layer) + exu_bio(layer) - 
+     &                  rem_bio(layer) ) * ddtb
+            zd_eoc2 = - cbu_i_bio(jn_eoc,layer)     ! Max detrital carbon loss
+            zd_eoc  = MAX( zd_eoc1, zd_eoc2 )
+         ENDIF
+
+         cbu_i_bio(jn_dsi,layer) = cbu_i_bio(jn_dsi,layer) + zd_dsi
+         cbu_i_bio(jn_din,layer) = cbu_i_bio(jn_din,layer) + zd_no3
+         cbu_i_bio(jn_dip,layer) = cbu_i_bio(jn_dip,layer) + zd_po4
+         cbu_i_bio(jn_aoc,layer) = cbu_i_bio(jn_aoc,layer) + zd_daf
+
+         IF ( nn_bio_opt .GE. 1 ) 
+     &      cbu_i_bio(jn_eoc,layer) = cbu_i_bio(jn_eoc,layer) + zd_eoc
+
+         IF ( ln_write_bio ) THEN
+
+            WRITE(numout,*) ' Terms for layer: ', layer
+            WRITE(numout,*) ' ~~~~~~~~~~~~~~~~ '
+            WRITE(numout,*) ' syn_bio   : ', syn_bio(layer)
+            WRITE(numout,*) ' lys_bio   : ', lys_bio(layer)
+            WRITE(numout,*) ' rem_bio   : ', rem_bio(layer)
+            WRITE(numout,*) ' exu_bio   : ', exu_bio(layer)
+            WRITE(numout,*) ' rsp_bio   : ', rsp_bio(layer)
+            WRITE(numout,*) ' lim_dsi   : ', lim_dsi(layer)
+            WRITE(numout,*) ' lim_no3   : ', lim_no3(layer)
+            WRITE(numout,*) ' lim_po4   : ', lim_po4(layer)
+            WRITE(numout,*) ' lim_lig   : ', lim_lig(layer)
+            WRITE(numout,*) ' lim_tem   : ', lim_tem(layer)
+            WRITE(numout,*) ' lim_sal   : ', lim_sal(layer)
+            WRITE(numout,*)
+            WRITE(numout,*) ' tc_bio    : ', tc_bio(layer)  
+            WRITE(numout,*) ' sbr_bio   : ', sbr_bio(layer)  
+            WRITE(numout,*) ' par_bio   : ', par_bio(layer)
+            WRITE(numout,*)
+            WRITE(numout,*) ' zd_dsi    : ', zd_dsi
+            WRITE(numout,*) ' zd_no3    : ', zd_no3
+            WRITE(numout,*) ' zd_po4    : ', zd_po4
+            WRITE(numout,*) ' zd_daf    : ', zd_daf
+            WRITE(numout,*) ' zd_eoc    : ', zd_eoc
+            WRITE(numout,*)
+            WRITE(numout,*) ' dSi       : ', cbu_i_bio(jn_dsi,layer)
+            WRITE(numout,*) ' dIN       : ', cbu_i_bio(jn_din,layer)
+            WRITE(numout,*) ' dIP       : ', cbu_i_bio(jn_dip,layer)
+            WRITE(numout,*) ' AoC       : ', cbu_i_bio(jn_aoc,layer)
+            WRITE(numout,*) ' eoC       : ', cbu_i_bio(jn_eoc,layer)
+            WRITE(numout,*)
+
+         ENDIF ! ln_write_bio
+
+      END DO ! layer
+
+      !------------------------------------------------------------------------
+      ! 2.5 Update DIC, Alk and Oxy
+      !------------------------------------------------------------------------
+
+      DO layer = layer_00, nlay_bio
+
+         zncp  =  - syn_bio(layer) + rsp_bio(layer) + rem_bio(layer)
+
+         IF ( ln_carbon .AND. flag_active(jn_dic) 
+     &                  .AND. flag_active(jn_alk) ) THEN
+
+            zd_dic1   = - zncp * ddtb
+            zd_dic2   = - cbu_i_bio(jn_dic,layer)
+            zd_dic    = MAX( zd_dic1 , zd_dic2 )
+
+            zd_alk1   =   no3_c * zncp * ddtb
+            zd_alk2   = - cbu_i_bio(jn_alk,layer)
+            zd_alk    = MAX( zd_alk1 , zd_alk2 )
+
+            cbu_i_bio(jn_dic,layer) = cbu_i_bio(jn_dic,layer) + zd_dic 
+            cbu_i_bio(jn_alk,layer) = cbu_i_bio(jn_alk,layer) + zd_alk 
+
+            IF ( ln_write_bio ) THEN
+               WRITE(numout,*) ' DIC       : ', cbu_i_bio(jn_dic,layer)
+               WRITE(numout,*) ' Alk       : ', cbu_i_bio(jn_alk,layer)
+            ENDIF
+
+         ENDIF
+
+         IF ( flag_active(jn_oxy) ) THEN
+
+            zd_oxy1   =   oxy_c * zncp * ddtb
+            zd_oxy2   = - cbu_i_bio(jn_oxy,layer)
+            zd_oxy    = MAX( zd_oxy1, zd_oxy2 )
+
+            cbu_i_bio(jn_oxy,layer) = cbu_i_bio(jn_oxy,layer) + zd_oxy
+
+            IF ( ln_write_bio ) THEN
+               WRITE(numout,*) ' Oxy       : ', cbu_i_bio(jn_oxy,layer)
+            ENDIF
+
+         ENDIF
+
+      END DO
+
+!
+!------------------------------------------------------------------------------!
+! X) End of the routine
+!------------------------------------------------------------------------------!
+!
+      WRITE(numout,*)
+      WRITE(numout,*) '    *** After biological sources and sinks *** '
+      WRITE(numout,*) '    model output '
+      DO jn = 1, ntra_bio
+         IF ( flag_active(jn) ) THEN
+           WRITE(numout,*) ' biotr_i_nam : ', biotr_i_nam(jn)
+           WRITE(numout,*) ' cbu_i_bio : ', ( cbu_i_bio(jn, jk), jk = 1,
+     &                                      nlay_bio )
+         ENDIF
+      END DO
+      WRITE(numout,*)
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_bio_sms '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+     
+
+!==============================================================================|
+! Fin de la routine ice_bio_sms
+      WRITE(numout,*)
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_brine.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_brine.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_brine.f	(revision 6)
@@ -0,0 +1,66 @@
+      SUBROUTINE ice_brine   
+
+!------------------------------------------------------------------------------!
+!                               *** ice_brine    ***
+!
+!     This routine computes brine density (kg/m3) and salinity (g/kg)
+!     from K-temperature
+!     in each vertical layer
+!
+!     Refs: Notz (2005) and Vancoppenolle et al (TCD 2015)
+!
+!------------------------------------------------------------------------------!
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+!==============================================================================!
+
+!
+!------------------------------------------------------------------------------!
+! X) Starting the routine
+!------------------------------------------------------------------------------!
+!
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' *** ice_brine : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+      WRITE(numout,*)
+
+!
+!------------------------------------------------------------------------------!
+! X) Brine characteristics
+!------------------------------------------------------------------------------!
+!
+         
+      DO layer = 1, nlay_bio
+         
+         tc_bio(layer)    = t_i_bio(layer) - 273.15                     ! Temperature in celsius
+         zt2 = tc_bio(layer) * tc_bio(layer)
+         zt3 = tc_bio(layer) * zt2
+         
+         sbr_bio(layer)   = -21.4*tc_bio(layer) - 0.886*zt2 -0.0107*zt3 ! Brine 3rd order salinity
+         
+         rhobr_bio(layer) = rho0 + beta_ocs*( sbr_bio(layer)-oce_sal )  ! Brine density
+            
+      END DO
+
+!
+!------------------------------------------------------------------------------!
+! X) End of the routine
+!------------------------------------------------------------------------------!
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_brine '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+      WRITE(numout,*)
+     
+      RETURN
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_carb_chem.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_carb_chem.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_carb_chem.f	(revision 6)
@@ -0,0 +1,482 @@
+      SUBROUTINE ice_carb_chem
+
+!------------------------------------------------------------------------------!
+!                               *** ice_carb_chem ***
+!
+!     This routine re-equilibrates the chemical species of the carbonate system 
+!     given two variables (DIC and Alk, or CO2 and Alk)
+!     
+!     Original code: Zeebe and Wolf-Gladrow, 2001. CO2 in Seawater:
+!                    Equilibrium, Kinetics, Isotopes.
+!       (http://www.soest.hawaii.edu/oceanography/faculty/zeebe_files/CO2_System_in_Seawater/csys.html)
+!
+!     Translation in F90: S. Moreau, P.-Y Barriat, S. Dubinkina, June 2012
+!
+!     Rewriting: M. Vancopppenolle, S. Moreau, Dec 2015
+!
+!     - Remove dummy arrays for T and S (use t_i_bio and sbr_bio instead)
+!     - change the name of the routine
+!     - remove the obsolete declarations
+
+! Present status : c_i_bio(13,*) is wrong... to be continued!!
+!    
+!------------------------------------------------------------------------------!
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      EXTERNAL zgeev ! lapack (computes the eigenvalues of complex nonsymmetric matrix)
+
+       REAL(8), DIMENSION(nlay_bio) :: 
+     &    Kw,                      !: Equilibrium constants
+     &    Kh,
+     &    Kb,
+     &    Ks,
+     &    Kf,
+     &    K1,
+     &    K2
+
+       REAL(8) :: ! define local variables
+     &    h1,
+     &    ztmp,
+     &    ztmp1,
+     &    ztmp2,
+     &    ztmp3,
+     &    ztmp4,
+     &    zbor,
+     &    zT,
+     &    z1T,
+     &    zlogT,
+     &    zT2,
+     &    zT3,
+     &    ztc,
+     &    ztc2,
+     &    ztc3,
+     &    zS12,
+     &    zS,
+     &    zS32,
+     &    zS2,
+     &    zhp 
+
+       LOGICAL ::
+     &   ln_write_bio = .TRUE. 
+
+       REAL(8), DIMENSION(6) :: 
+     &    zpoly 
+
+      INTEGER(4), PARAMETER ::   ! Parameters for H+ retrieval
+     &    n_hp = 5               ! size of the polynom
+
+      REAL(8) :: 
+     &    zb5(2,0:n_hp),
+     &    zrwrk(2*n_hp)
+
+      INTEGER(4) 
+     &    zinfo
+
+!     COMPLEX(16) ::
+      DOUBLE COMPLEX ::
+     &    zA(n_hp+1,n_hp+1),
+     &    zvl(n_hp,n_hp),
+     &    zvr(n_hp,n_hp),
+     &    zwrk(3*n_hp),
+     &    zeigs(n_hp)
+
+!==============================================================================!
+
+      IF ( ln_write_bio ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' ice_carb_chem '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+
+      ENDIF
+
+      CALL ice_brine
+
+      DO layer = 1, nlay_bio
+
+         !------------------------------------------------------------
+         ! 1) Physical inputs (temperature and brine salinity)
+         !------------------------------------------------------------
+
+         ! temperature factors
+         zT    = t_i_bio(layer)
+         z1t   = 1.d0/zT
+         zlogT = LOG(zT)
+         zT2   = zT*zT
+
+         ! Brine salinity factors
+         ztc  = tc_bio(layer)
+         ztc2 = ztc*ztc
+         ztc3 = ztc2 * ztc
+
+         zS12  = SQRT(sbr_bio(layer))
+         zS    = sbr_bio(layer)
+         zS32  = zS12*zS
+         zS2   = zS*zS
+
+         !----------------------------------------------------------------
+         ! 2) Equilibrium constants
+         !----------------------------------------------------------------
+         !
+         !    units: mol/kg-soln 
+         !    set phflag (0:Total), (1:Free)
+
+         !--- Kw (water dissociation constant)
+         !--------------------------------------
+         !
+         !       Millero (1995)(in Dickson and Goyet (1994, Chapter 5, p.18))
+         !       K_w in mol/kg-soln.
+         !       pH-scale: total scale.
+
+         ztmp1 = -13847.26*z1T + 148.96502 - 23.6521*zlogT
+         ztmp2 = ( 118.67*z1T - 5.977 + 1.0495*zlogT)*zs12 - 0.01615*zS
+
+         ztmp = ztmp1 + ztmp2
+
+         Kw(layer)  = EXP(ztmp)
+
+         !--- Kh (Henry's solubility) 
+         !----------------------------
+         !
+         !               CO2(g) <-> CO2(aq.)
+         !               Kh      = [CO2]/ p CO2
+         !
+         !   Weiss (1974)   [mol/kg/atm]
+         !
+
+         ztmp = 9345.17*z1t - 60.2409 + 23.3585*(zlogt - LOG(100.))
+         ztmp = ztmp + zS*( 0.023517 - 2.3656e-4*zT + 4.7036e-7*zT2 )
+
+         Kh(layer) = EXP(ztmp)
+
+         !--- K1 (first acidity constant)
+         !--------------------------------
+         !   [H+].[HCO3-]/[CO2] = K1
+
+         IF ( nn_carbonate .EQ. 1 ) THEN
+            !   Roy et al. (1993) IN: Dickson and Goyet (1994), Ch. 5, p. 14
+            !   pH-scale: 'total'. mol/kg-soln
+  
+            ztmp1 = 2.83655 - 2307.1266*z1t - 
+     &                       1.5529413*zlogt
+            ztmp2 = - ( 0.20760841 + 4.0484 *z1t ) * zs12
+            ztmp3 = 0.08468345*zS - 0.00654208*zS32
+            ztmp4 = LOG( 1. - 0.001005*zS )
+
+            ztmp   = ztmp1 + ztmp2 + ztmp3 + ztmp4
+  
+            K1(layer) = EXP(ztmp)
+
+         ELSE
+            !   Mehrbach et al (1973) refit by Lueker et al. (2000).
+            !   pH-scale: 'total'. mol/kg-soln
+            ztmp      = 3633.86 * z1t - 61.2172 + 9.6777*zlogt - 
+     &                  0.011555*zS + 0.0001152*zS2
+   
+            K1(layer) = 10**(-ztmp)
+
+         ENDIF
+
+        !--- K2 (second acidity constant)
+        !---------------------------------
+        !   [H+].[CO32-]/[HCO3-] = K2
+
+         IF ( nn_carbonate .EQ. 1 ) THEN
+           ! Roy et al 1993, total ph-scale mol/kg-soln
+           ztmp1 = - 9.226508 - 3351.6106*z1t - 0.2005743*zlogt
+           ztmp2 = ( -0.106901773 - 23.9722*z1t ) * zs12
+           ztmp3 = 0.1130822*zs - 8.46934e-3*zs32 + LOG(1.-1.005e-3*zS)
+    
+           ztmp = ztmp1 + ztmp2 + ztmp3
+   
+           K2(layer)  = EXP(ztmp)
+
+         ELSE
+
+           ! Mehrbach et al. (1973) refit by Lueker et al. (2000).
+           ztmp    = 471.78*z1T + 25.9290 - 
+     &               3.16967*zlogT - 
+     &               0.01781*zS + 0.0001122*zS2
+
+           K2(layer)  = 10**(-ztmp)
+
+         ENDIF
+
+         !--- KB (Boron dissociation constant)
+         !-------------------------------------
+         !  Kbor = [H+][B(OH)4-]/[B(OH)3]
+         !  Dickson (1990), IN:Dickson and Goyet, 1994, Chapter 5, p. 14)
+         !  pH-scale: 'total'. mol/kg-soln
+
+         ztmp1  =  ( -8966.90 - 2890.53*zs12 - 77.942 * zS + 
+     &             1.728*zS32 - 0.0996*zS2 )
+         ztmp2  =  148.0248 + 137.1942 * zs12 + 1.62142 * zS
+         ztmp3  = (-24.4344 - 25.085*zs12 - 0.2474*zs)*zlogT
+          
+         ztmp   = ztmp1 * z1t + ztmp2 + ztmp3 + 0.053105*zs12*zT
+
+         Kb(layer) = EXP(ztmp)
+
+      END DO ! layer
+
+      IF ( ln_write_bio ) THEN
+ 
+         WRITE(numout,*)
+         WRITE(numout,*) ' Carbonate system constants '
+         WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+         WRITE(numout,*) ' Kw :',( Kw(layer), layer=layer_00, nlay_bio )
+         WRITE(numout,*)
+         WRITE(numout,*) ' Kh :',( Kh(layer), layer=layer_00, nlay_bio )
+         WRITE(numout,*)
+         WRITE(numout,*) ' K1 :',( K1(layer), layer=layer_00, nlay_bio )
+         WRITE(numout,*)
+         WRITE(numout,*) ' K2 :',( K2(layer), layer=layer_00, nlay_bio )
+         WRITE(numout,*)
+         WRITE(numout,*) ' Kb :',( Kb(layer), layer=layer_00, nlay_bio )
+
+      ENDIF
+  
+      !------------------------------------------------------------------------
+      ! 3) Convert brine concentrations units (mmol/m3 -> mol/kg)
+      !------------------------------------------------------------------------
+      ! mmol/m3 to mol/kg
+      DO layer = 1, nlay_bio
+
+         zunit = 1000. * rhobr_bio(layer)
+
+         c_i_bio(jn_dic,layer) =
+     &      c_i_bio(jn_dic,layer) / zunit
+
+         c_i_bio(jn_alk,layer) =
+     &      c_i_bio(jn_alk,layer) / zunit
+
+      END DO
+
+      ! Alk
+
+      !------------------------------------------------------------------------
+      ! 4) Carbonate system equilibration
+      !------------------------------------------------------------------------
+
+      DO layer = 1, nlay_bio
+
+         !--- polynomial coefficients
+         !----------------------------
+         zbor = 1.*(416.*(sbr_bio(layer)/35.))* 1.e-6      ! Total boron (mol/kg), DOE94
+
+         ! Compute the coefficients of the 5th order polynom for H+
+         ! -> Check Orr et al GMD 2015 and Munhoven et al., GBC2014 for more efficient computations 
+          
+         ! poly   = [p5 p4 p3 p2 p1 p0] 
+         ! test = p5 h⁵ + p4 h⁴ + p3 h³ + p2 h² + p1 h¹ + p0
+
+         zpoly(1)  = - 1.                                        ! p5
+
+         zpoly(2)  = - c_i_bio(jn_alk,layer) -                   ! p4
+     &               Kb(layer) - K1(layer) 
+
+         zpoly(3)  = c_i_bio(jn_dic,layer)*K1(layer) -           ! p3
+     &               c_i_bio(jn_alk,layer)*( Kb(layer) + K1(layer) ) +
+     &               Kb(layer)*zbor + Kw(layer) - 
+     &               Kb(layer)*K1(layer) - K1(layer)*K2(layer) 
+ 
+         ztmp      = c_i_bio(jn_alk,layer)*( Kb(layer)*K1(layer) + 
+     &               2.*K1(layer)*K2(layer)) - c_i_bio(jn_dic,layer)*
+     &               ( Kb(layer)*K1(layer) + K1(layer)*K2(layer) ) +
+     &               Kb(layer)*zbor*K1(layer) 
+
+         zpoly(4)  = ztmp + Kw(layer)*Kb(layer) +                ! p2
+     &               Kw(layer)*K1(layer) - 
+     &               Kb(layer)*K1(layer)*K2(layer)
+
+         ztmp     = ( 2.*c_i_bio(jn_dic,layer) - 
+     &              c_i_bio(jn_alk,layer) + zbor)*
+     &              K1(layer)*K2(layer)*Kb(layer)
+
+         zpoly(5)  = ztmp + ( Kb(layer) + K2(layer) )*           ! p1
+     &               K1(layer)*Kw(layer)
+
+         zpoly(6)  = Kw(layer)*Kb(layer)*K1(layer)*K2(layer)     ! p0
+
+         !--- find roots of the 5th degree monic polynomial
+         !--------------------------------------------------
+         zb5(1,0:n_hp) = zpoly(:)
+         zb5(2,:)      = 0.d0
+
+!        IF ( ln_write_bio ) THEN
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' zb5 - 1 : ', zb5(1,0:n_hp)
+!           WRITE(numout,*) ' zb5 - 2 : ', zb5(2,0:n_hp)
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' zpoly : ', zpoly
+!           WRITE(numout,*)
+!        ENDIF
+
+            ! Setup companion matrix for polynomials
+         DO i = 1, n_hp + 1
+            DO j = 1, n_hp + 1
+               IF ( j .EQ. n_hp+1 ) THEN
+                  zA(i,j) = -DCMPLX(zb5(1, n_hp+1-i),zb5(2,n_hp+1-i))
+               ELSE IF (J.EQ.I-1) THEN
+                  zA(i,j) = DCMPLX(1.d0,0.d0)
+               ELSE
+                  zA(i,j) = DCMPLX(0.d0,0.d0)
+               ENDIF
+            END DO
+         END DO
+
+!         IF ( ln_write_bio ) THEN
+!            WRITE(numout,*)
+!            WRITE(numout,*) ' zA    : ', zA
+!            WRITE(numout,*)
+!         ENDIF
+
+         ! Calculate eigenvalues of companion matrix (LAPACK)
+         ! 'N' -> left eigen vectors are not computed
+         ! 'N' -> right egien vectors are not computer
+         ! n_hp+1 -> order of the matrix A
+         ! A    -> complex matrix, dimension (LDA, N)
+         !         ->IN: complex NxN
+         !         ->OUT: overwritten
+         ! n_hp+1 -> leading dimension of A
+         ! zeigs-> computed eigen values
+         ! zvl   -> dummy (unused here) left eigenvector
+         ! n_hp + 1 -> dimension of eigen vector
+         ! zvr  -> dummy (unused here) left eigenvector
+         ! n_hp + 1 -> dimension of right eigen vector
+         ! zwrk, zrwrk ->  workarray
+         ! 3*n_hp+3 -> size of workarray
+         ! zinfo -> =0 successful work
+         CALL zgeev('N','N',n_hp+1,zA,n_hp+1,zeigs,zvl,n_hp+1,
+     &               zvr,n_hp+1,zwrk,3*n_hp+3,zrwrk,zinfo)
+
+         zhp = MAXVAL( REAL ( zeigs ) )
+             
+          ! Print eigenvalues of companion matrix (roots of the polynom)
+!        IF ( ln_write_bio ) THEN
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' zinfo : ', zinfo
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' zeigs :', ( zeigs(i), i = 1, n_hp )
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' zhp   :', zhp
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' pH      : ', -LOG10( zhp )
+!           WRITE(numout,*)
+!           WRITE(numout,*)
+!        ENDIF
+
+         !--- Retrieve carbonate system diagnostics
+         !--------------------------------------------------
+
+         zhp2                   = zhp * zhp                         ! [H+]^2
+
+         c_i_bio(jn_co2, layer) = c_i_bio(jn_dic, layer) /          ! CO2
+     &                          ( 1. + K1(layer) / zhp + 
+     &                            K1(layer)*K2(layer) / zhp2 )
+
+         CO2aq(layer)           = c_i_bio(jn_co2,layer)             !--- temporary as jn_co2 is bound to disappear
+ 
+         CO32m(layer)           = c_i_bio(jn_dic,layer) /           ! CO32-
+     &                          ( 1. + zhp / K2(layer) + 
+     &                            zhp2 / K1(layer) / K2(layer) )
+
+         HCO3m(layer)           = c_i_bio(jn_dic,layer) /           ! HCO3-
+     &                          ( 1. + zhp / K1(layer) +
+     &                            K2(layer) / zhp )
+
+         pH(layer)              = -LOG10( zhp )
+
+         pCO2(layer)            = CO2aq(layer) / Kh(layer)          ! pCO2 = CO2aq / Kh 
+
+      END DO ! layer
+ 
+      !------------------------------------------------------------------------
+      ! 5) Convert units (mol/kg to mmol/m3), retrieve bulk concentrations
+      !------------------------------------------------------------------------
+
+      DO layer = 1, nlay_bio
+
+         ! mol/kg -> mmol/m3
+         zunit = 1000. * rhobr_bio(layer)
+
+         c_i_bio(jn_dic,layer) = c_i_bio(jn_dic,layer) * zunit !--- dont change DIC and TA, can remove
+         c_i_bio(jn_alk,layer) = c_i_bio(jn_alk,layer) * zunit !--- dont change DIC and TA, can remove
+         c_i_bio(jn_co2,layer) = c_i_bio(jn_co2,layer) * zunit
+         CO2aq(layer)          = CO2aq(layer) * zunit
+         CO32m(layer)          = CO32m(layer) * zunit
+         HCO3m(layer)          = HCO3m(layer) * zunit
+         
+         ! brine -> bulk
+         cbu_i_bio(jn_co2,layer) = c_i_bio(jn_co2,layer)*e_i_bio(layer)
+         CO2aq(layer)            = CO2aq(layer)*e_i_bio(layer)
+         CO32m(layer)            = CO32m(layer)*e_i_bio(layer)
+         HCO3m(layer)            = HCO3m(layer)*e_i_bio(layer)
+
+         ! atm-> muatm
+         pCO2(layer)           = pCO2(layer) * 1.0e6 
+
+      END DO
+
+      !------------------------------------------------------------------------
+      ! 6) Control Print
+      !------------------------------------------------------------------------
+
+      IF ( ln_write_bio ) THEN
+
+         WRITE(numout,*) 
+         WRITE(numout,*) ' ** End of ice_carb_chem '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) '  At time step : ', numit
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+   
+   
+         DO jn = 1, ntra_bio
+
+            IF ( ( jn .EQ. jn_dic ) .OR. ( jn .EQ. jn_alk ) .OR. 
+     &           ( jn .EQ. jn_co2 ) ) THEN
+
+               WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+               WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),
+     &                                           layer = 1, nlay_bio )
+               WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),
+     &                                           layer = 1, nlay_bio )
+            ENDIF
+
+        END DO
+
+        WRITE(numout,*) ' CO2aq : ', 
+     &     ( CO2aq(layer), layer = 1, nlay_bio )
+        WRITE(numout,*) ' CO32- : ', 
+     &     ( CO32m(layer), layer = 1, nlay_bio )
+        WRITE(numout,*) ' HCO3- : ', 
+     &     ( HCO3m(layer), layer = 1, nlay_bio )
+        WRITE(numout,*) ' pH    : ', 
+     &     ( pH(layer), layer = 1, nlay_bio )
+        WRITE(numout,*) ' pCO2  : ', 
+     &     ( pCO2(layer), layer = 1, nlay_bio )
+   
+      ENDIF
+!
+!------------------------------------------------------------------------------!
+! 7) End of the routine
+!------------------------------------------------------------------------------!
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_carb_chem '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+     
+      RETURN
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_cons.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_cons.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_cons.f	(revision 6)
@@ -0,0 +1,419 @@
+      SUBROUTINE ice_th_glohec(eti,ets,etilayer,kideb,kiut,jl, 
+     &                         nlay_s, nlay_i)
+
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_th_glohec *** 
+      !!                 
+      !! ** Purpose :  Compute total heat content for each category
+      !!               Works with 1d vectors only
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-----------------------------------------------------------------------
+      !! * Local variables
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      INTEGER, INTENT(in) ::  
+     &   kideb, kiut,           ! bounds for the spatial loop
+     &   jl                     ! category number
+
+      REAL(8), DIMENSION (nbpt,jpl), INTENT(out) ::   
+     &   eti, ets            ! vertically-summed heat content for ice /snow
+
+      REAL(8), DIMENSION (nbpt,maxnlay), INTENT(out) ::   
+     &   etilayer            ! heat content for ice layers
+
+      REAL(8) ::  
+     &   zdes,               ! snow heat content increment (dummy)
+     &   zeps                ! very small value (1.e-10)
+
+      INTEGER  ::  
+     &   ji,jj,jk            ! loop indices
+
+      !!-----------------------------------------------------------------------
+      eti(:,:) = 0.0
+      ets(:,:) = 0.0
+      zeps     = 1.0e-10
+
+      ! total q over all layers, ice [J.m-2]
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            etilayer(ji,jk) = q_i_b(ji,jk)  
+     &                      * ht_i_b(ji) / nlay_i
+            eti(ji,jl) = eti(ji,jl) + etilayer(ji,jk) 
+         END DO
+      END DO
+
+      ! total q over all layers, snow [J.m-2]
+      DO ji = kideb, kiut
+         zdes = q_s_b(ji,1) * ht_s_b(ji) / nlay_s 
+         ets(ji,jl) = ets(ji,jl) + zdes        
+      END DO
+
+      RETURN
+!------------------------------------------------------------------------------      
+      END SUBROUTINE ice_th_glohec
+
+!==============================================================================
+
+      SUBROUTINE ice_th_enmelt(kideb, kiut, nlay_s, nlay_i)
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_th_enmelt *** 
+      !!                 
+      !! ** Purpose :   Computes sea ice energy of melting q_i (J.m-3)
+      !!
+      !! ** Method  :   Formula (Bitz and Lipscomb, 1999)
+      !!
+      !! history : Martin Vancoppenolle, May 2007
+      !!-------------------------------------------------------------------
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      REAL(8)                 ::       !: goes to trash
+     &   ztmelts               ,       !: sea ice freezing point in K
+     &   zeps 
+
+      INTEGER                 ::     
+     &   ji,                           !: spatial loop index
+     &   jk                            !: vertical index
+
+      LOGICAL                 ::
+     &   ln_write = .FALSE.
+
+      !!-------------------------------------------------------------------
+      zeps = 1.0e-10
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ** ice_th_enmelt : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+         WRITE(numout,*) ' kideb : ', kideb
+         WRITE(numout,*) ' kiut  : ', kiut
+         WRITE(numout,*) ' nlay_s: ', nlay_s
+         WRITE(numout,*) ' nlay_i: ', nlay_i
+      ENDIF
+
+      ! Sea ice energy of melting
+      DO jk = 1, nlay_i
+         DO ji = kideb, kiut
+            ztmelts      =   - tmut * s_i_b(ji,jk) + tpw 
+            q_i_b(ji,jk) = rhog * ( cpg * ( ztmelts - t_i_b(ji,jk) )
+     &                   + lfus*( 1.0 - (ztmelts-tpw) / 
+     &                     MIN((t_i_b(ji,jk)-tpw),-zeps) )  
+     &                   - cpw      * ( ztmelts-tpw  ) ) 
+         END DO !ji
+      END DO !jk
+
+      ! Snow energy of melting
+      DO jk = 1, nlay_s
+         DO ji = kideb,kiut
+            q_s_b(ji,jk) = rhon * ( cpg  * ( tpw - t_s_b(ji,jk) ) + 
+     &                     lfus )
+         END DO !ji
+      END DO !jk
+
+      WRITE(numout,*)
+
+      RETURN
+!------------------------------------------------------------------------------      
+      END SUBROUTINE ice_th_enmelt
+
+!==============================================================================
+
+      SUBROUTINE ice_th_con_dif(kideb,kiut,nlay_s,nlay_i,jl)
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_th_con_dif *** 
+      !!                 
+      !! ** Purpose :   Test energy conservation after heat diffusion
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-------------------------------------------------------------------
+      !! * Local variables
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      REAL(8)                  ::      !: ! goes to trash
+     &   meance,                       !: mean conservation error
+     &   max_cons_err,                 !: maximum tolerated conservation error
+     &   max_surf_err                  !: maximum tolerated surface error
+
+      INTEGER ::                     
+     &   numce                         !: number of points for which conservation
+                                       !  is violated
+      INTEGER  ::  
+     &   ji,jj,jk,                     !: loop indices
+     &   zji, zjj
+
+      LOGICAL  ::
+     &   l_write
+      !!---------------------------------------------------------------------
+
+      max_cons_err =  0.1
+      max_surf_err =  0.001
+      l_write  = .TRUE.
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' ** ice_th_con_dif : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      !--------------------------
+      ! 1) Increment of energy
+      !--------------------------
+      ! vertically integrated
+      DO ji = kideb, kiut
+          dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl)   
+     &                + qt_s_fin(ji,jl) - qt_s_in(ji,jl)
+      END DO
+
+      ! layer by layer
+      DO ji = kideb, kiut
+         DO jk = 1, nlay_i
+            dq_i_layer(ji,jk) =  q_i_layer_fin(ji,jk) - 
+     &                           q_i_layer_in(ji,jk)
+         END DO
+      END DO
+
+      !-------------------------------------------
+      ! 2) Atmospheric heat flux, ice heat budget
+      !-------------------------------------------
+
+      DO ji = kideb, kiut
+          fatm(ji,jl) = ab(ji)*fsolgb(ji) + fratsb(ji)
+     &                + fcsb(ji) + fleb(ji)
+          sum_fluxq(ji,jl) = fc_su(ji) - fc_bo_i(ji)
+     &                + fsolgb(ji)*(1-ab(ji)) - ftroce
+      END DO
+
+      IF ( l_write ) THEN
+         DO ji = kideb, kiut
+             WRITE(numout,*) ' fc_su   : ', fc_su(ji)
+             WRITE(numout,*) ' fc_bo_i : ', fc_bo_i(ji)
+             WRITE(numout,*) ' fsol*io : ', fsolgb(ji)*(1.-ab(ji))
+             WRITE(numout,*) ' ftroce  : ', ftroce
+         END DO
+      ENDIF
+
+      !-----------------------
+      ! 3) Conservation error
+      !-----------------------
+      DO ji = kideb, kiut
+          cons_error(ji,jl) = ABS( dq_i(ji,jl) / ddtb + 
+     &                        sum_fluxq(ji,jl) )
+      END DO
+
+      numce = 0
+      meance = 0.0
+      DO ji = kideb, kiut
+          IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
+              numce = numce + 1
+              meance = meance + cons_error(ji,jl)
+          ENDIF
+      IF (numce .GT. 0 ) meance = meance / numce
+
+      IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
+         WRITE(numout,*) ' Diffusion of heat - large cons. error '
+         WRITE(numout,*) ' Maximum tolerated conservation error : ', 
+     &                     max_cons_err
+         WRITE(numout,*) ' Thickness category : ', jl
+         WRITE(numout,*) ' DIF Mean conservation error ', 
+     &                     meance, numit
+      ENDIF
+
+      ENDDO
+
+      !---------------------------------------------------------
+      ! 4) Surface error due to imbalance between Fatm and Fcsu
+      !---------------------------------------------------------
+      numce  = 0.0
+      meance = 0.0
+
+      DO ji = kideb, kiut
+         surf_error(ji,jl) = ABS ( fatm(ji,jl) - fc_su(ji) )
+         IF ( ( t_su_b(ji) .LT. tpw ) .AND. ( surf_error(ji,jl) .GT.  
+     &          max_surf_err ) ) THEN
+            numce = numce + 1 
+            meance = meance + surf_error(ji,jl)
+         ENDIF
+         IF (numce .GT. 0 ) meance = meance / numce
+
+         IF ( ( t_su_b(ji) .LT. tpw ) .AND. ( surf_error(ji,jl) .GT.  
+     &             max_surf_err ) ) THEN
+            WRITE(numout,*) ' Diffusion of heat - large surface error '
+            WRITE(numout,*) ' Surf_error : ', surf_error(1,jl), 
+     &                      ' (W/m2) '
+            WRITE(numout,*) ' Maximum tolerated surface error : ', 
+     &                     max_surf_err
+            WRITE(numout,*) ' Thickness category : ', jl
+            WRITE(numout,*) ' t_su_b: ', t_su_b(ji) 
+            WRITE(numout,*) ' t_s_b : ', ( t_s_b(ji,layer), 
+     &                      layer = 1, nlay_s )
+            WRITE(numout,*) ' t_i_b : ', ( t_i_b(ji,layer), 
+     &                      layer = 1, nlay_i )
+         ENDIF
+
+      ENDDO
+
+      !-------------------
+      ! 5) Layer by layer
+      !-------------------
+      IF ( l_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Layer by layer ... '
+
+         DO ji = kideb, kiut
+            WRITE(numout,*) ' T_su : ', t_su_b(ji)
+            WRITE(numout,*) ' *** Snow ***    h_s = ',
+     &                  ht_s_b(ji) 
+
+            IF ( ht_s_b(ji) .GT. 0.0 ) THEN
+            zdqs = ( qt_s_fin(ji,jl) - qt_s_in(ji,jl) ) / ddtb
+            WRITE(numout,*) ' Conservation error (W/m2): ', 
+     &                   ABS( zdqs + fc_s(ji,0) - 
+     &                   fc_s(ji,1) + radab_s(1) )
+            ENDIF
+         END DO
+
+         DO ji = kideb, kiut
+            WRITE(numout,*) ' *** Ice ***     h_i = ', ht_i_b(ji) 
+            DO jk = 1, nlay_i
+               WRITE(numout,*) ' LAYER : ', jk
+               WRITE(numout,*) ' Conservation error (W/m2): ', 
+     &            ABS( dq_i_layer(ji,jk) / ddtb + fc_i(ji,jk-1) - 
+     &            fc_i(ji,jk) + radab_i(jk) ) !radab_phy_i(jk) + radab_alg_i(jk) )
+            END DO
+         END DO
+
+      ENDIF
+!
+!------------------------------------------------------------------------------      
+      END SUBROUTINE ice_th_con_dif
+!==============================================================================
+
+      SUBROUTINE ice_th_con_dh(kideb,kiut,nlay_s,nlay_i,jl)
+      !!-----------------------------------------------------------------------
+      !!                   ***  ROUTINE ice_th_con_dh ***  
+      !!                 
+      !! ** Purpose :   Test energy conservation after ice growth and melt
+      !!
+      !! history :
+      !!  9.9  ! 07-04 (M.Vancoppenolle) original code
+      !!-------------------------------------------------------------------
+      !! * Local variables
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      REAL(8)                  ::      !: ! goes to trash
+     &   meance,                       !: mean conservation error
+     &   max_cons_err,                 !: maximum tolerated conservation error
+     &   max_surf_err                  !: maximum tolerated surface error
+
+      INTEGER ::                     
+     &   numce                         !: number of points for which conservation
+                                       !  is violated
+      INTEGER  ::  
+     &   ji,jj,jk,                     !: loop indices
+     &   zji, zjj
+      LOGICAL  ::
+     &   l_write
+
+      !!---------------------------------------------------------------------
+
+      l_write  = .TRUE.
+      max_cons_err =  0.1
+      max_surf_err =  0.001
+
+      WRITE(numout,*) ' ** ice_th_con_dh : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+            
+      !------------------------
+      ! 1) Increment of energy
+      !------------------------
+      DO ji = kideb, kiut ! vertically integrated
+          dq_i(ji,jl) = qt_i_fin(ji,jl) - qt_i_in(ji,jl)   
+     &                + qt_s_fin(ji,jl) - qt_s_in(ji,jl)
+      END DO
+
+      DO ji = kideb, kiut ! layer by layer
+         DO jk = 1, nlay_i
+            dq_i_layer(ji,jk) =  q_i_layer_fin(ji,jk) - 
+     &                           q_i_layer_in(ji,jk)
+         END DO
+      END DO
+
+      !-------------------------------------------
+      ! 2) Atmospheric heat flux, ice heat budget
+      !-------------------------------------------
+      DO ji = kideb, kiut
+          fatm(ji,jl) = fsolgb(ji) + fratsb(ji)
+     &                + fcsb(ji) + fleb(ji)
+          sum_fluxq(ji,jl) = fatm(ji,jl) + fbbqb(ji)
+     &                     - ftroce + fsnic + fprec
+      END DO
+
+      IF ( l_write ) THEN
+         DO ji = kideb, kiut
+            WRITE(numout,*) ' fsolgb : ' , fsolgb(ji)
+            WRITE(numout,*) ' fratsb : ' , fratsb(ji)
+            WRITE(numout,*) ' fcsb   : ' , fcsb(ji)
+            WRITE(numout,*) ' fleb   : ' , fleb(ji)
+            WRITE(numout,*)
+            WRITE(numout,*) ' fatm   : ' , fatm(ji,jl)
+            WRITE(numout,*) ' fbbqb  : ' , fbbqb(ji)
+            WRITE(numout,*) ' ftroce : ' , ftroce
+            WRITE(numout,*) ' fprec  : ' , fprec
+            WRITE(numout,*) ' fsnic  : ' , fsnic
+            WRITE(numout,*)
+            WRITE(numout,*) ' sum_fluxq : ', sum_fluxq(ji,jl)
+            WRITE(numout,*) ' dq_i      : ', dq_i(ji,jl) / ddtb
+         END DO
+      ENDIF
+
+      !-----------------------
+      ! 3) Conservation error
+      !-----------------------
+      IF ( l_write ) WRITE(numout,*) ' kideb, kiut, jl : ', 
+     &   kideb, kiut, jl
+
+      DO ji = kideb, kiut
+         cons_error(ji,jl) = ABS( dq_i(ji,jl) / ddtb + 
+     &                        sum_fluxq(ji,jl) )
+      END DO
+
+      numce = 0
+      meance = 0.0
+      DO ji = kideb, kiut
+         IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
+            numce = numce + 1
+            meance = meance + cons_error(ji,jl)
+         ENDIF
+         IF (numce .GT. 0 ) meance = meance / numce
+
+         IF ( cons_error(ji,jl) .GT. max_cons_err ) THEN
+            WRITE(numout,*) ' Growth and melt - large cons. error '
+            WRITE(numout,*) ' Maximum tolerated conservation error : ', 
+     &                        max_cons_err
+            WRITE(numout,*) ' DH Mean conservation error ', 
+     &                        meance, numit
+         ENDIF
+      ENDDO
+
+!------------------------------------------------------------------------------      
+      END SUBROUTINE ice_th_con_dh
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas.f	(revision 6)
@@ -0,0 +1,335 @@
+      SUBROUTINE ice_gas(nlay_i,kideb,kiut)
+
+!
+!-----------------------------------------------------------------------------!
+!                           *** ice_gas ***
+!     
+!     Nov 2015
+!
+!     Version : source_3.10
+!
+!     to do
+!     - put the computation of solubilities in a subroutine
+!        - check conservation
+!        - brine characteristics to subroutinize    
+!        - missing carbonate chemistry in the end
+!-----------------------------------------------------------------------------!
+
+      USE lib_fortran
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+       REAL(8) :: 
+     &   zsat,
+     &   zsat_diff
+
+       LOGICAL ::
+     &   ln_write_gas = .TRUE.
+
+!==============================================================================!
+
+      IF ( ln_write_gas ) THEN
+
+         WRITE(numout,*) 
+         WRITE(numout,*) ' ** ice_gas : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~ '
+   
+      ENDIF
+      
+!
+!------------------------------------------------------------------------------!
+! 1) Initialize conservation test and gas concentrations
+!------------------------------------------------------------------------------!
+!
+
+      !--- Gas concentrations
+      DO jn = 1, ntra_bio
+
+         ! Brine concentrations
+         IF ( ( flag_active(jn)            ) .AND.
+     &        ( biotr_i_typ(jn) .EQ. 'gas' ) ) THEN
+            DO layer = 1, nlay_bio
+              c_i_bio(jn,layer)   = cbu_i_bio(jn,layer) / e_i_bio(layer)
+            END DO
+         ENDIF
+
+         ! Carbonate chemistry
+         IF ( ln_carbon ) CALL ice_carb_chem
+
+         IF ( ( flag_active(jn)            ) .AND.
+     &        ( biotr_i_typ(jn) .EQ. 'gas' ) ) THEN
+            DO layer = 1, nlay_bio
+              c_gtot_i(jn,layer)  = cbu_i_bio(jn,layer) + 
+     &                              cbub_i_bio(jn,layer)
+            END DO
+
+         ENDIF
+
+      END DO
+
+      !--- Conservation test
+      CALL ice_gas_column( ntra_bio , c_gtot_i, deltaz_i_bio, .TRUE.,  
+     &                     mt_i_gas_init )
+
+      DO jn = 1, ntra_bio
+
+         IF ( ( flag_active(jn)            ) .AND.
+     &        ( biotr_i_typ(jn) .EQ. 'gas' ) .AND. 
+     &        ln_write_gas                   ) THEN
+
+           WRITE(numout,*)
+           WRITE(numout,*) ' *** Initial values  *** '
+           WRITE(numout,*) ' --- time step --- : ', numit
+
+           WRITE(numout,*) ' --- Tracer    --- :   ', biotr_i_nam(jn)
+           WRITE(numout,*) 'c_i_bio  : ',c_i_bio(jn,layer_00:nlay_bio)
+           WRITE(numout,*) 'cbu_i_bio: ',cbu_i_bio(jn,layer_00:nlay_bio)
+           WRITE(numout,*) 'cbub_i_bio: ',
+     &                     cbub_i_bio(jn,layer_00:nlay_bio)
+           WRITE(numout,*) 'c_gtot_i : ',c_gtot_i(jn,layer_00:nlay_bio)
+           WRITE(numout,*)
+           WRITE(numout,*) ' mt_i_gas_init : ', mt_i_gas_init(jn)
+
+         ENDIF
+
+      END DO
+      
+!
+!------------------------------------------------------------------------------!
+! 2) Bubble formation and dissolution
+!------------------------------------------------------------------------------!
+!
+
+                          !---------------------------
+      CALL ice_gas_solu   ! Saturation concentrations
+                          !---------------------------
+                  
+      IF ( ln_bubform ) THEN
+      
+         IF ( ln_write_gas ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' *** Bubble formation and dissolution *** '
+            WRITE(numout,*)
+         ENDIF
+         
+          DO jn = 1, ntra_bio
+          
+             IF ( flag_active(jn) .AND. 
+     &         ( biotr_i_typ(jn) .EQ. 'gas' ) ) THEN
+      
+                IF ( ln_write_gas ) THEN
+                   WRITE(numout,*) ' Tracer number : ', jn
+                   WRITE(numout,*) ' --- ', biotr_i_nam(jn)
+                ENDIF
+      
+                DO layer = 1, nlay_bio
+                
+                   zsat      = csat_gas(jn,layer) * sursat_gas
+                   zsat_diff = zsat - c_i_bio(jn,layer)    ! undersaturation
+                   
+                   ! bubble formation or dissolution rate
+                   IF ( zsat_diff .LE. 0 ) THEN  ! sursaturation
+                      zbub_rate = bub_form_rate
+                   ELSE
+                      zbub_rate = bub_diss_rate
+                   ENDIF
+                   
+                   ! change in bulk bubble concentration
+                   zd_cbri = zsat_diff * zbub_rate * ddtb
+                   zd_cbri = MAX( -c_i_bio(jn,layer), zd_cbri )         ! cannot exhaust brines
+                   zd_cbri = MIN( cbub_i_bio(jn,layer)/e_i_bio(layer),  ! cannot exhaust gas bubbles
+     &                            zd_cbri )
+                   c_i_bio(jn,layer) = c_i_bio(jn,layer) + zd_cbri
+                
+                   ! change in bulk bubble concentration
+                   zd_cbub = - zd_cbri*e_i_bio(layer)
+                   cbub_i_bio(jn,layer) = cbub_i_bio(jn,layer) + zd_cbub
+ 
+                   ! Update bulk concentration
+                   cbu_i_bio(jn,layer) =e_i_bio(layer)*c_i_bio(jn,layer)
+ 
+                   ! Diagnostic % saturation ratio
+                   pc_sat(jn,layer) = c_i_bio(jn,layer) / 
+     &                                csat_gas(jn,layer) * 100.
+ 
+                   ! Update DIC for CO2
+                   IF ( jn .EQ. jn_co2 ) 
+     &               cbu_i_bio(jn_dic,layer) = 
+     &                  cbu_i_bio(jn_dic,layer) - zd_cbub
+             
+                END DO ! layer
+          
+             ENDIF ! flags, biotr_i_typ
+             
+          END DO ! ntra_bio
+!
+       ENDIF ! ln_bubform
+
+!
+!------------------------------------------------------------------------------!
+! 3) Bubble rise
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_bubrise ) THEN
+      
+         IF ( ln_write_gas ) THEN
+            WRITE(numout,*)
+            WRITE(numout,*) ' *** Bubble rise *** '
+         ENDIF
+         
+         f_bub(:) = 0.
+          
+         IF ( ln_write_gas ) WRITE(numout,*) ' *** immediate rise'
+         
+             DO jn = 1, ntra_bio
+         
+                IF ( flag_active(jn) .AND. 
+     &             ( biotr_i_typ(jn) .EQ. 'gas' ) ) THEN
+     
+                   IF ( ln_write_gas ) THEN
+                      WRITE(numout,*) ' Tracer number : ', jn
+                      WRITE(numout,*) ' --- ', biotr_i_nam(jn)
+                   ENDIF
+                   
+                   DO layer = nlay_bio, 1, -1
+                   
+                   zswitch = 0. ! by default, bubbles rise
+                   
+                   ! i_imper_layer: identifies the first impermeable layer above "layer"
+                   ! if no such layer, then i_imper_layer = 0 and gas get out of the ice
+                   ! via f_bub
+                   
+                   i_imper_layer = 0
+                   
+                   IF ( e_i_bio(layer) .LE. e_thr_bubrise ) THEN 
+                      i_imper_layer = layer
+                   ELSE
+                      DO layer_2 = layer - 1, 1, -1 ! find a layer above
+                       IF ( ( zswitch .LE. 0 ) .AND. 
+     &                    ( e_i_bio(layer_2) .LT. e_thr_bubrise ) ) THEN
+                            zswitch = 1.
+                            i_imper_layer = MAX(i_imper_layer, layer_2)
+                       ENDIF ! e_i_bio
+                      END DO ! layer2
+                   ENDIF
+
+                   ! Transfer gas among layers
+                   IF ( ( i_imper_layer .GT. 0 ) .AND. 
+     &                  ( i_imper_layer .NE. layer ) ) THEN ! in-ice bubble transfer
+                      cbub_i_bio(jn,i_imper_layer) = ! add gas in the impermeable layer
+     &                cbub_i_bio(jn,i_imper_layer)+cbub_i_bio(jn,layer)
+                      cbub_i_bio(jn,layer) = 0.      ! remove gas from the permeable layer
+                   ENDIF
+                   
+                   IF ( i_imper_layer .EQ. 0 ) THEN ! ice-atmosphere bubble transfer
+                      f_bub(jn) = f_bub(jn) + cbub_i_bio(jn,layer) *
+     &                deltaz_i_bio(layer) / ddtb
+                      cbub_i_bio(jn,layer) = 0.      ! remove gas from the permeable layer
+                   ENDIF ! i_imper_layer
+                 
+                 END DO
+                
+                ENDIF ! flag_active, biotr_i_typ
+                
+             END DO ! jn
+         
+      ENDIF ! ln_bubrise
+
+!
+!------------------------------------------------------------------------------!
+! 4) Update total gas concentration
+!------------------------------------------------------------------------------!
+!
+
+      DO jn = 1, ntra_bio
+         
+         IF ( ( flag_active(jn)            ) .AND. 
+     &        ( biotr_i_typ(jn) .EQ. 'gas' ) .AND.
+     &        ln_write_gas ) THEN
+
+         DO layer = 1, nlay_bio  ! dégazage des couches 2 à nlay_bio
+            c_gtot_i(jn,layer) = cbu_i_bio(jn,layer) + 
+     &                           cbub_i_bio(jn,layer)  
+         END DO
+
+         WRITE(numout,*) '    *** After ice_gas *** '
+
+         WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+         WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' cbub_i_bio : ', ( cbub_i_bio(jn,layer), ! concentration of tracers in bubbles in bulk ice
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*) ' c_gtot_i : ', ( c_gtot_i(jn,layer),   ! concentration of tracers in bubbles + bulk ice
+     &                                   layer = 1, nlay_bio )
+         WRITE(numout,*)
+         
+         ENDIF
+         
+      ENDDO
+
+!
+!------------------------------------------------------------------------------!
+! 4) Conservation test and output
+!------------------------------------------------------------------------------!
+!
+
+      CALL ice_gas_column( ntra_bio , c_gtot_i, deltaz_i_bio, .TRUE.,  
+     &                     mt_i_gas_final )
+
+      IF ( ln_write_gas ) THEN
+         DO jn = 1, ntra_bio
+            WRITE(numout,*) ' tracer         : ', biotr_i_nam(jn)
+            WRITE(numout,*) ' mt_i_gas_init  : ', mt_i_gas_init(jn)
+            WRITE(numout,*) ' mt_i_gas_final : ', mt_i_gas_final(jn)
+         END DO
+      ENDIF
+
+      DO jn = 1, ntra_bio
+         zfbub = f_bub(jn) * ddtb
+         WRITE(numout,*) ' tracer : ', biotr_i_nam(jn)
+         WRITE(numout,*) ' zfbub  : ', zfbub
+
+      IF ( ABS( mt_i_gas_init(jn) - mt_i_gas_final(jn) - zfbub ) 
+     &                                            .GT. 1.0e-10 )
+     &   THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' ALERT!!! TOTAL GAS NOT CONSERVED '
+         WRITE(numout,*) '      at time step : ', numit
+         WRITE(numout,*) '         tracer    : ', jn
+         WRITE(numout,*) ' mt_i_gas_init     : ', mt_i_gas_init(jn)
+         WRITE(numout,*) ' mt_i_gas_final    : ', mt_i_gas_final(jn)
+         WRITE(numout,*) ' diff    : ', mt_i_gas_init(jn) - 
+     &                                  mt_i_gas_final(jn) - zfbub
+         WRITE(numout,*) ' zfbub   : ', zfbub
+         WRITE(numout,*)
+      ENDIF
+      ENDDO
+      
+!
+!------------------------------------------------------------------------------!
+! x) Update DIC and carbonate chemistry
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_carbon ) CALL ice_carb_chem
+
+!------------------------------------------------------------------------------!
+! X) End of the routine
+!------------------------------------------------------------------------------!
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_gas '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+     
+
+!==============================================================================|
+! Fin de la routine ice_gas
+      WRITE(numout,*)
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_column.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_column.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_column.f	(revision 6)
@@ -0,0 +1,58 @@
+      SUBROUTINE ice_gas_column( ntra, zc_i, zdeltaz, ln_write, 
+     &                           zmt_i )
+
+      ! gas conservation 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+
+      INTEGER :: 
+     &  jk            ! : index for ice layers
+     &  jn            ! : index for tracers
+
+      REAL(8), DIMENSION(ntra_bio_max)          :: 
+     &   zmt_i                                     ! Total gas content (./m2)
+      REAL(8), DIMENSION(ntra_bio_max,nlay_bio) ::
+     &   zc_i                                      ! Input total concentrations (./m3)
+      REAL(8), DIMENSION(nlay_bio)              ::
+     &   zdeltaz                                   ! Input layer thicknesses
+      LOGICAL                                   ::
+     &   ln_write                                  ! Write or not
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** ice_gas_column : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+
+         WRITE(numout,*) ' nlay_bio : ', nlay_bio
+         WRITE(numout,*) ' ntra     : ', ntra
+         !DO jn = 1, ntra
+         !   WRITE(numout,*) ' zc_i  : ', zc_i(jn,1:nlay_bio)
+         !END DO
+
+      ENDIF
+
+      zmt_i(:) = 0.0
+
+      DO jn = 1, ntra
+         DO jk = 1, nlay_bio
+            zmt_i(jn) = zmt_i(jn) + zc_i(jn,jk) *
+     &      zdeltaz(jk)
+         END DO
+
+         ! IF ( ln_write ) THEN
+         !   WRITE(numout,*) ' jn    : ', jn
+         !   WRITE(numout,*) ' zmt_i : ', zmt_i(jn)
+         ! ENDIF
+ 
+      END DO
+
+      RETURN
+
+!=============================================================================!
+!-- End of ice_gas_column --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_solu.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_solu.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_gas_solu.f	(revision 6)
@@ -0,0 +1,322 @@
+      SUBROUTINE ice_gas_solu
+
+!------------------------------------------------------------------------------!
+!                               *** ice_gas_solu ***
+!
+!     This routine computes for Argon, Oxygen, CO2 and Nitrogen
+!     -  Saturation concentration (csat_gas, mmol/m3)
+!     -  Solubility (sol_gas, mmol/m3/atm)
+!     in each vertical layer
+!
+!     Refs
+!        Argon: Hamme and Emerson (2004)
+!        Oxygen: Garcia and Gordon (1992)
+!        CO2: Sarmiento and Gruber (2006), Weiss (1974)
+!        N2: Sarmiento and Gruber (2006) and references therein
+!     
+!     Original code (in ice_gas.f): S. Moreau, M. Vancoppenolle, 2012-2015
+!
+!     Rewriting: M. Vancopppenolle, Nov 2015
+!
+!     Present status : 
+!        - code for Ar, not for N2 and O2
+!        - should put mixing ratios in the namelist
+!------------------------------------------------------------------------------!
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      REAL(8), DIMENSION(nlay_bio) ::  
+     &   ztc,                      ! Celsius temperature
+     &   ztlog                     ! Re-scaled temperature
+
+       LOGICAL ::
+     &   ln_write_gas = .TRUE.
+      
+!==============================================================================!
+
+!
+!------------------------------------------------------------------------------!
+! X) Starting the routine
+!------------------------------------------------------------------------------!
+!
+
+      IF ( ln_write_gas ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** ice_gas_solu : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+
+      ENDIF
+     
+      ji = 1
+      zpatm      = psbqb(ji) / 101325.                         ! atmospheric pressure in atmospheres
+
+      CALL ice_brine
+      
+      IF ( ln_write_gas ) THEN
+         WRITE(numout,*) ' ztc   : ', ztc(1:nlay_bio)
+         WRITE(numout,*) ' sbr_bio  : ', sbr_bio(1:nlay_bio)
+         WRITE(numout,*) ' rhobr_bio: ', rhobr_bio(1:nlay_bio)
+         WRITE(numout,*)
+      ENDIF
+
+      DO jn = 1, ntra_bio
+
+         IF ( flag_active(jn) .AND. ( biotr_i_typ(jn) .EQ. 'gas' ) ) 
+     &   THEN 
+
+!
+!------------------------------------------------------------------------------!
+! X) Celsius temperature and rescaled temperature
+!------------------------------------------------------------------------------!
+!
+         
+         DO layer = 1, nlay_bio
+         
+            ztc(layer)     = tc_bio(layer)                            ! temperature in celsius
+         
+            ztlog(layer)  = LOG( ( 298.15 - ztc(layer) ) /            ! rescaled log temperature
+     &                           ( 273.15 + ztc(layer) ) )
+            
+         END DO
+
+!        
+!------------------------------------------------------------------------------!
+! X) Saturation concentrations
+!------------------------------------------------------------------------------!
+!                                                   !-------
+         IF ( biotr_i_nam(jn) .EQ. 'Arg' ) THEN    ! Argon
+                                                   !-------
+
+           IF ( ln_write_gas ) THEN
+              WRITE(numout,*) ' --- Argon ...'
+           ENDIF
+
+           ! Hamme and Emerson, 2004
+           ! form ln C = AO + A1 * Ts + A2 * Ts^2 + A3 * Ts^3
+           !           + S ( B0 + B1 * Ts + B2 * Ts^2 )
+           ! Ts = f(Tc), Tc in Celsius, S in pss
+
+           !--- Polynomial coefficients (mumol/kg, Table 4)
+           za0 = 2.79150     ; za1 = 3.17609     ; za2 = 4.13116
+           za3 = 4.90379
+           zb0 = -6.96233e-3 ; zb1 = -7.66670e-3 ; zb2 = -1.16888e-2
+
+           DO layer = 1, nlay_bio
+
+              !--- Rescaled log temperature powers
+              zt  = ztlog(layer)
+              zt2 = zt * zt
+              zt3 = zt * zt2
+               
+              !--- Saturation concentration at equilibrium with a moist atmosphere at 1-atm pressure
+              zln_csat = za0 + za1*zt + za2*zt2 + za3*zt3 +
+     &                 ( zb0 + zb1*zt + zb2*zt2 ) * sbr_bio(layer)
+     
+              csat_gas(jn,layer) = EXP( zln_csat )                     ! in mumol/kg
+
+              csat_gas(jn,layer) = csat_gas(jn,layer) *                ! in mmol/m3
+     &                             rhobr_bio(layer) / 1000. 
+     
+           END DO
+           
+         ENDIF     ! 'Arg'
+         
+                                                   !-----------
+         IF ( biotr_i_nam(jn) .EQ. 'Oxy' ) THEN    ! di-Oxygen
+                                                   !-----------
+         
+           IF ( ln_write_gas ) THEN
+              WRITE(numout,*) ' --- Oxygen ...'
+           ENDIF
+        
+           ! Garcia and Gordon, L&O 1992
+           ! form ln C = f(S,T), eq 8 page 1310 (! small mistake in the equation, extra-term)
+
+           !--- Polynomial coefficients (mumol/kg, Table 1, last column)
+           za0_sat_oxy = 5.80818;   za1_sat_oxy = 3.20684
+           za2_sat_oxy = 4.11890;   za3_sat_oxy = 4.93845
+           za4_sat_oxy = 1.01567;   za5_sat_oxy = 1.41575
+           zb0_sat_oxy = -7.01211e-3;   zb1_sat_oxy = -7.25958e-3
+           zb2_sat_oxy = -7.933343e-3;  zb3_sat_oxy = -5.54491e-3
+           zc0_sat_oxy = -1.32412e-7
+
+           DO layer = 1, nlay_bio
+           
+               !--- Rescaled log temperature powers
+               zt   = ztlog(layer)   
+               zt2  = zt * zt
+               zt3  = zt2 * zt
+               zt4  = zt2 * zt2
+               zt5  = zt2 * zt3
+
+               !--- Saturation concentration at equilibrium with a moist atmosphere at 1-atm pressure
+               zln_csat = ( za0_sat_oxy + za1_sat_oxy * zt + 
+     &                      za2_sat_oxy * zt2 +             
+     &                      za3_sat_oxy * zt3 +
+     &                      za4_sat_oxy * zt4 +
+     &                      za5_sat_oxy * zt5 +
+     &                      sbr_bio(layer) * 
+     &                      ( zb0_sat_oxy + zb1_sat_oxy * zt +
+     &                      zb2_sat_oxy * zt2 +
+     &                      zb3_sat_oxy * zt3 ) +
+     &                      zc0_sat_oxy *
+     &                      sbr_bio(layer) * sbr_bio(layer) )
+     
+               csat_gas(jn,layer) = EXP(zln_csat)                   ! mumol/kg
+               
+               csat_gas(jn,layer) = csat_gas(jn,layer) *            ! in mmol/m3
+     &                              rhobr_bio(layer) / 1000. 
+
+           END DO
+            
+         ENDIF     ! 'Oxy'
+         
+                                                   !-------------
+         IF ( biotr_i_nam(jn) .EQ. 'Nit' ) THEN    ! di-Nitrogen
+                                                   !-------------
+    
+            IF ( ln_write_gas ) THEN
+               WRITE(numout,*) ' --- Nitrogen ...'
+            ENDIF                                           
+                                                   
+            ! Sarmiento and Gruber (2006, page 74) and references therein
+            ! form ...
+
+            !--- Polynomial coefficients (mumol/kg)
+            za0_sat_nit = 6.42931
+            za1_sat_nit = 2.92704
+            za2_sat_nit = 4.32531
+            za3_sat_nit = 4.69149
+            zb0_sat_nit = -0.00744129
+            zb1_sat_nit = -0.00802566
+            zb2_sat_nit = -0.0146775
+
+            DO layer = 1, nlay_bio
+
+               !--- Rescaled log temperature powers
+               zts  = ztlog(layer) 
+               zts2 = zts * zts
+               zts3 = zts2 * zts
+
+               zln_csat = za0_sat_nit + za1_sat_nit * zts +  
+     &                    za2_sat_nit * zts2 +                   
+     &                    za3_sat_nit * zts3                     
+     &                  + sbr_bio(layer) *
+     &                  ( zb0_sat_nit + zb1_sat_nit * zts +
+     &                    zb2_sat_nit * zts2 )
+     
+               csat_gas(jn,layer) = EXP(zln_csat)                   ! mumol/kg
+                                                      
+               csat_gas(jn,layer) = csat_gas(jn,layer) *            ! in mmol/m3
+     &                              rhobr_bio(layer) / 1000. 
+
+            END DO ! layer
+
+         ENDIF     ! 'Nit'
+         
+                                                   !-------------
+         IF ( biotr_i_nam(jn) .EQ. 'CO2' ) THEN    ! CO2
+                                                   !-------------
+                                                   
+            IF ( ln_write_gas ) THEN
+               WRITE(numout,*) ' --- CO2 ...'
+            ENDIF                                           
+
+           ! Sarmiento and Gruber, 2006 (Weiss, 1974 with total ph scale)
+           ! form C = mix_rat * exp[ f(S,T) ], Table 3.2.2
+
+           za0_sat_CO2 = -160.7333;   za1_sat_CO2 = 215.4152
+           za2_sat_CO2 = 89.8920;     za3_sat_CO2 = -1.47759
+
+           zb0_sat_CO2 = 0.029941;    zb1_sat_CO2 = -0.027455
+           zb2_sat_CO2 = 0.0053407
+
+           DO layer = 1, nlay_bio
+        
+               !--- temperature powers
+               zt     = t_i_bio(layer)                             ! Temperature (K)
+               z100_t = 100. / zt
+               zt_100 = zt / 100.
+               zt_100_2 = zt_100 * zt_100
+
+               zsat_CO2 = mixr_gas(jn) *
+     &                  EXP ( za0_sat_CO2 +       
+     &                        za1_sat_CO2 * z100_t +           ! zsat_CO2 is the CO2 concentration at saturation
+     &                        za2_sat_CO2 * log (zt_100) +     ! zsat_CO2 is in mol/kg
+     &                        za3_sat_CO2 *  zt_100_2    +
+     &                        sbr_bio(layer) *
+     &                      ( zb0_sat_CO2 + 
+     &                        zb1_sat_CO2 * zt_100 +
+     &                        zb2_sat_CO2 * zt_100_2 ) )
+     
+               csat_gas(jn,layer) = zsat_CO2 * rhobr_bio(layer) * 1000. ! mmol/m3
+
+!              WRITE(numout,*) '--------------------------- '
+!              WRITE(numout,*) ' jn, layer: ', jn,layer
+!              WRITE(numout,*) ' mixr_gas : ', mixr_gas(jn)
+!              WRITE(numout,*) ' rhobr_bio: ', rhobr_bio(layer)
+!              WRITE(numout,*) ' zsat_CO2 : ', zsat_CO2
+!              WRITE(numout,*) ' zt       : ', zt
+!              WRITE(numout,*) ' z100_t   : ', z100_t
+!              WRITE(numout,*) ' zt_100   : ', zt_100
+!              WRITE(numout,*) ' zt_100_2 : ', zt_100_2
+!              WRITE(numout,*) ' csat_gas : ', csat_gas(jn,layer)
+!              WRITE(numout,*) '--------------------------- '
+
+            END DO ! layer
+            
+         ENDIF     ! 'CO2'
+
+         WRITE(numout,*) ' ---> csat_gas: ', csat_gas(jn,:)
+         WRITE(numout,*)
+
+!------------------------------------------------------------------------------!
+
+         ENDIF ! flags
+      END DO ! jn
+      
+!
+!------------------------------------------------------------------------------!
+! X) Solubility and partial pressure
+!------------------------------------------------------------------------------!
+!
+      DO jn = 1, ntra_bio
+      
+         sol_gas(jn,:) = 0.
+
+         IF ( flag_active(jn) .AND. ( biotr_i_typ(jn) .EQ. 'gas' ) ) 
+     &   THEN 
+
+            sol_gas(jn,:) = csat_gas(jn,:) / mixr_gas(jn) ! solubility, ./m3/atm
+
+            IF ( ln_write_gas ) THEN
+               WRITE(numout,*) ' Tracer number : ', jn
+               WRITE(numout,*) ' --- ', biotr_i_nam(jn)
+               WRITE(numout,*) ' sol_gas(jn,:) : ', sol_gas(jn,:)
+            ENDIF
+         
+         ENDIF
+
+      END DO
+!
+!------------------------------------------------------------------------------!
+! X) End of the routine
+!------------------------------------------------------------------------------!
+!
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_gas_solu '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+      WRITE(numout,*)
+     
+      RETURN
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_ikaite.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_ikaite.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_ikaite.f	(revision 6)
@@ -0,0 +1,183 @@
+      SUBROUTINE ice_ikaite(nlay_i)
+
+!------------------------------------------------------------------------------!
+!                               *** ice_ikaite ***
+!
+!     This routine computes precipitation / dissolution of ikaite 
+!     and impacts on DIC, Alk and Ca2+
+!
+!     Ref: Moreau et al (JGR2015)
+!     
+!     Original code: S. Moreau, M. Vancoppenolle, 2012-2015
+!     Rewriting: M. Vancopppenolle, Nov 2015
+!
+!     Solubility product formulation is valid until -9C
+!     The fit is not monotonic below -9C, so we may experience problems 
+!     with ikaite below -9C
+!
+!------------------------------------------------------------------------------!
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+      
+       REAL(8), DIMENSION(nlay_bio) :: 
+     &    Kspi
+
+       LOGICAL ::
+     &   ln_write_bio = .TRUE.
+
+!==============================================================================!
+
+!
+!---------------------------------------------------------------------
+! 1) Starting the routine
+!---------------------------------------------------------------------
+!
+
+      IF ( ln_write_bio ) THEN
+
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** ice_ikaite : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** Initial values before CaCO3 precip/diss '
+         WRITE(numout,*) '        at time step : ', numit
+
+      ENDIF
+      
+      CALL ice_brine     ! get brine salinity and density
+      
+      CALL ice_carb_chem ! get CO32m 
+
+      DO jn = 1, ntra_bio
+
+         ! Brine / Total gas concentrations
+         DO layer = 1, nlay_bio
+             c_i_bio(jn,layer)   = cbu_i_bio(jn,layer) / e_i_bio(layer)
+         END DO
+
+         IF ( ln_write_bio ) THEN
+
+            WRITE(numout,*)
+            WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+            WRITE(numout,*) ' c_i_bio: ', ( c_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                    layer = 1, nlay_bio )
+            WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                      layer = 1, nlay_bio )
+            WRITE(numout,*) 
+         ENDIF
+      END DO
+      
+!
+!------------------------------------------------------------------------------!
+! 2) Solubility product
+!------------------------------------------------------------------------------!
+!
+      ! Ref: Papadimitriou et al. (GCA 2013)
+      ! fit valid until -9 degC
+      ! non monotonic (at all) below this value
+      ! we may have to regularize this
+      
+      DO layer = 1, nlay_bio
+
+          zT  = t_i_bio(layer)
+
+          IF ( zt .LE. 273.15-9.) zT = 273.15-9. ! asked stathys papadim what to do here
+
+          zpKsp = - 15489.09608 + 623443.70216 / zT +
+     &             2355.14596 * log(zT)
+
+          Kspi(layer) = 10.**(-zpKsp)     ! (mol/kg)^2 of brine
+          
+          ! Conversion into (mmol/m3)^2
+          Kspi(layer) = Kspi(layer) * 1.0e6 * 
+     &                  rhobr_bio(layer) * rhobr_bio(layer)
+
+      END DO
+        
+      WRITE(numout,*) ' Kspi : ', Kspi(1:nlay_bio)
+      
+!
+!------------------------------------------------------------------------------!
+! 3) Calcification / Dissolution
+!------------------------------------------------------------------------------!
+!
+
+      DO layer = 1, nlay_bio
+
+         zcal = c_i_bio(jn_cal,layer)
+         ! zcal = 311.765 * sbr_bio(layer) --> approach not valid because Ca2+ changes a lot in brine in winter
+
+         ! Brine concentration of CO32-
+         zco32m_br  = co32m(layer) / e_i_bio(layer)
+         zco32m_sat = Kspi(layer)  / zcal
+         
+         ! Saturation state (omega) in brine
+         zomega = zco32m_br * zcal / Kspi(layer)
+         
+         ! Precipitation / dissolution
+         zd_ika = ddtb / caco3_time * ( zco32m_br - zco32m_sat )
+         zd_ika = MAX( MIN(zd_ika, zco32m_br), -c_i_bio(jn_ika,layer) ) ! calcification cannot exceed CO32- stock
+                                                                        ! dissolution cannot exceed ikaite stock 
+         zd_ika = zd_ika * e_i_bio(layer)                               ! bulk calcification 
+
+         ! Update ikaite, dic, alk and calcium bulk concentrations
+         cbu_i_bio(jn_ika,layer) = cbu_i_bio(jn_ika,layer) + zd_ika
+         cbu_i_bio(jn_dic,layer) = cbu_i_bio(jn_dic,layer) - zd_ika
+         cbu_i_bio(jn_alk,layer) = cbu_i_bio(jn_alk,layer) - 2.*zd_ika
+         cbu_i_bio(jn_cal,layer) = cbu_i_bio(jn_cal,layer) - zd_ika
+
+         ! Retrieve brine concentrations
+         c_i_bio(jn_ika,layer) = cbu_i_bio(jn_ika,layer)/e_i_bio(layer)
+         c_i_bio(jn_dic,layer) = cbu_i_bio(jn_dic,layer)/e_i_bio(layer)
+         c_i_bio(jn_alk,layer) = cbu_i_bio(jn_alk,layer)/e_i_bio(layer)
+         c_i_bio(jn_cal,layer) = cbu_i_bio(jn_cal,layer)/e_i_bio(layer)
+
+         ! diagnostic rate of formation and saturation state
+         ika_rate(layer)  = zd_ika / ddtb
+         ika_omega(layer) = zomega
+
+         WRITE(numout,*) ' layer, zd_ika : ', layer, zd_ika
+
+      END DO
+      
+!
+!------------------------------------------------------------------------------!
+! 5) End of the routine
+!------------------------------------------------------------------------------!
+!
+
+      WRITE(numout,*) 
+      WRITE(numout,*) ' ** After CaCO3 precipitation : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      WRITE(numout,*)
+
+       DO jn = 1, ntra_bio
+
+         IF ( ( jn .EQ. jn_dic ) .OR.
+     &        ( jn .EQ. jn_alk ) .OR.
+     &        ( jn .EQ. jn_cal ) .OR.
+     &        ( jn .EQ. jn_ika ) ) THEN
+            WRITE(numout,*) ' Tracer :   ', biotr_i_nam(jn)
+            WRITE(numout,*) ' c_i_bio  : ', ( c_i_bio(jn,layer),    ! concentration of tracers in brines (mmol m-3)
+     &                                        layer = 1, nlay_bio )
+            WRITE(numout,*) ' cbu_i_bio: ', ( cbu_i_bio(jn,layer),  ! concentration of tracers in bulk ice
+     &                                        layer = 1, nlay_bio )
+         ENDIF
+
+      END DO
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_ikaite '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+     
+
+!==============================================================================|
+! End of ice_ikaite
+
+      WRITE(numout,*)
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_output.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_output.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_output.f	(revision 6)
@@ -0,0 +1,1065 @@
+      SUBROUTINE ice_output(nlay_i,nlay_s)
+
+!=============================================================================!
+! ice_output : Creates and write in the ice output file
+! (c) Martin Vancoppenolle, Xavier Fettweis, UCL-ASTR, June 2007
+!=============================================================================!
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+      INCLUDE 'forcing.com'
+
+      CHARACTER(len=10) :: 
+     &   filenc='ice.out.nc'
+      CHARACTER(len=1) ::
+     &   c1
+      CHARACTER(len=4) ::
+     &   c4
+
+      REAL, DIMENSION(nend)     :: dimval
+      REAL, DIMENSION(nlay_i)   :: dimval2
+      REAL, DIMENSION(nlay_bio) :: dimval3
+      REAL, DIMENSION(nlay_s)   :: dimval4
+      REAL, DIMENSION(nlay_i)   :: dummy_vector
+
+!=============================================================================!
+
+      WRITE(numout,*) ' ice_output : '
+      WRITE(numout,*) ' ~~~~~~~~~~ : '
+      WRITE(numout,*)                    , c_bio_model
+!
+!-----------------------------------------------------------------------------!
+! 1) File definition
+!-----------------------------------------------------------------------------!
+!
+      IF ( numit .EQ. nstart ) THEN
+
+         WRITE(numout,*) ' Initialization of the NetCdf file : '
+         !---------------------
+         ! File initialization
+         !---------------------
+         CALL CF_INI_FILE(filenc,"Output NETCDF for S(L)IMCO")
+
+         !---------------------
+         ! Dimensions creation
+         !---------------------
+         ! time 
+         !------
+         DO i = nstart , nend
+            dimval(i) = REAL(i) 
+         ENDDO
+      !  WRITE(numout,*) ' dimval : ', ( dimval(i), i = nstart, nend )
+         IF ( ddtb .EQ. 60 ) 
+     &      CALL CF_CREATE_DIM("time"    ,"min"     ,nitrun,
+     &      dimval(nstart:nend))
+         IF ( ddtb .EQ. 600) 
+     &      CALL CF_CREATE_DIM("time"    ,"10min"     ,nitrun,
+     &      dimval(nstart:nend))
+         IF ( ddtb .EQ. 3600 ) 
+     &      CALL CF_CREATE_DIM("time"    ,"hours"     ,nitrun,
+     &      dimval(nstart:nend))
+         IF ( ddtb .EQ. 86400 ) 
+     &      CALL CF_CREATE_DIM("time"    ,"days"     ,nitrun,
+     &      dimval(nstart:nend))
+         IF ( ddtb .EQ. 21600 ) 
+     &      CALL CF_CREATE_DIM("time"    ,"6h"      ,nitrun,
+     &      dimval(nstart:nend))
+         WRITE(numout,*) ' time dimension created '
+
+         ! snow vertical coordinate (moving)
+         !-----------------------------------
+         DO i = 1, nlay_s
+            dimval4(i) = REAL(i)
+         ENDDO
+         CALL CF_CREATE_DIM("z_s_p"   ,"m"       ,nlay_s,
+     &   dimval4(1:nlay_s))
+         WRITE(numout,*) ' z_s_p dimension created '
+
+         ! physical vertical coordinate (moving)
+         !---------------------------------------
+         DO i = 1, nlay_i
+            dimval2(i) = REAL(i)
+         ENDDO
+         CALL CF_CREATE_DIM("z_i_p"   ,"m"       ,nlay_i,
+     &   dimval2(1:nlay_i))
+         WRITE(numout,*) ' z_i_p dimension created '
+
+!        ! biological vertical coordinate (moving)
+!        !-----------------------------------------
+         DO i = 1, nlay_bio 
+            dimval3(i) = REAL(i)
+         ENDDO
+         CALL CF_CREATE_DIM("z_i_b"   ,"m"       ,nlay_bio,
+     &   dimval3(1:nlay_bio))
+         WRITE(numout,*) ' z_i_b dimension created '
+
+         !--------------------
+         ! Variables creation
+         !--------------------
+         ! Times
+         !-------
+         CALL CF_CREATE_VAR("numt","Time step",
+     .                   "nts","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("doy","Day Of Year",
+     .                   "nts","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("ts_m","Time step in months",
+     .                   "mon","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("ts_d","Time step in days",
+     .                   "y","time","-","-","-" )
+
+         ! Grids
+         !-------
+         CALL CF_CREATE_VAR("z_ip","Vertical cote, physics",
+     .                   "m","time","z_i_p","-","-" )
+
+         CALL CF_CREATE_VAR("z_ib","Vertical cote, biology",
+     .                   "m","time","z_i_b","-","-" )
+
+         IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) 
+     &      CALL CF_CREATE_VAR("hbio","Biologically active layer",
+     &                   "m","time","-","-","-" )
+       
+
+         ! Ice / snow thickness and variations
+         !-------------------------------------
+         CALL CF_CREATE_VAR("h_i","Ice thickness",
+     .                   "m","time","-","-","-" )
+         WRITE(numout,*) ' h_i dimension created '
+
+         CALL CF_CREATE_VAR("dhib","Bottom accretion",
+     .                   "cm/day","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("dhisu","Surface ice melt",
+     .                   "cm/day","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("dhisi","Snow ice formation",
+     .                   "cm/day","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("dhs","Snow variations",
+     .                   "cm/day","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("h_s","Snow depth   ",
+     .                   "m","time","-","-","-" )
+         WRITE(numout,*) ' h_s dimension created '
+
+         CALL CF_CREATE_VAR("uml","Surface ocean layer",
+     .                   "m","time","-","-","-" )
+         WRITE(numout,*) ' uml dimension created '
+
+         ! Inner ice variables  
+         !---------------------
+         CALL CF_CREATE_VAR("t_i","Ice Temperature",
+     .                   "C","time","z_i_p","-","-" )
+         WRITE(numout,*) ' t_i dimension created '
+
+         CALL CF_CREATE_VAR("s_i","Ice Salinity",
+     .                   "g/kg","time","z_i_p","-","-" )
+         WRITE(numout,*) ' s_i dimension created '
+
+         CALL CF_CREATE_VAR("e_i","Brine volume",
+     .                   "%","time","z_i_p","-","-" )
+         WRITE(numout,*) ' e_i dimension created '
+
+         CALL CF_CREATE_VAR("e_i_bio","Brine volume bio",
+     .                   "%","time","z_i_p","-","-" )
+         WRITE(numout,*) ' e_i_bio dimension created '
+
+         CALL CF_CREATE_VAR("t_i_bio","Temperature bio",
+     .                   "C","time","z_i_p","-","-" )
+         WRITE(numout,*) ' t_i_bio dimension created '
+
+         CALL CF_CREATE_VAR("s_i_bio","Salinity bio",
+     .                   "g/kg","time","z_i_p","-","-" )
+         WRITE(numout,*) ' s_i_bio dimension created '
+
+         CALL CF_CREATE_VAR("sbr_bio","Sbr bio",
+     .                   "g/kg","time","z_i_p","-","-" )
+         WRITE(numout,*) ' sbr_bio dimension created '
+
+         CALL CF_CREATE_VAR("ra","Rayleigh number",
+     .                   "-","time","z_i_p","-","-" )
+         WRITE(numout,*) ' Ra dimension created '
+
+         CALL CF_CREATE_VAR("diff","Salt diffusivity", 
+     .                   "m2/s","time","z_i_p","-","-" )
+         WRITE(numout,*) ' Diff dimension created '
+
+         CALL CF_CREATE_VAR("t_s","Snow Temperature",
+     .                   "C","time","z_s_p","-","-" )
+         WRITE(numout,*) ' t_s dimension created '
+
+         CALL CF_CREATE_VAR("t_su","Surface Temperature",
+     .                   "C","time","-","-","-" )
+         WRITE(numout,*) ' t_su dimension created '
+
+         CALL CF_CREATE_VAR("fsb","Ice-ocean bd salt flux",
+     .                   "kgNaCl/m2/s","time","-","-","-" )
+         WRITE(numout,*) ' fsb  dimension created '
+
+         CALL CF_CREATE_VAR("fsbp","Ice-ocean se salt flux",
+     .                   "kgNaCl/m2/s","time","-","-","-" )
+         WRITE(numout,*) ' fsbp dimension created '
+
+         CALL CF_CREATE_VAR("oce_sal","Ocean Salinity",
+     .                   "kgNaCl/dm3","time","-","-","-" )
+         WRITE(numout,*) ' oce_sal dimension created '
+
+         ! Forcing
+         !---------
+         CALL CF_CREATE_VAR("albe","Surface albedo",
+     .                   "/","time","-","-","-" )
+         CALL CF_CREATE_VAR("F_sw","Incoming solar",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("Fswn","Net solar",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("Flwd","Incoming longwave",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("Flwu","Emitted longwave",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("F_sh","Sensible heat flux",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("F_lh","Latent heat flux",
+     .                   "W.m-2","time","-","-","-" )
+         CALL CF_CREATE_VAR("Tair","Air temperature ",
+     .                   "C","time","-","-","-" )
+         CALL CF_CREATE_VAR("qair","Air humidity    ",
+     .                   "kg/kg","time","-","-","-" )
+         CALL CF_CREATE_VAR("wspd","Wind speed",
+     .                   "m/s","time","-","-","-" )
+         CALL CF_CREATE_VAR("qsfc","Surface humidity", 
+     .                   "kg/kg","time","-","-","-" )
+         CALL CF_CREATE_VAR("tdew","Relative air humidity", 
+     .                   "%","time","-","-","-" )
+         CALL CF_CREATE_VAR("cldf","Cloud fraction",
+     .                   "0-1","time","-","-","-" )
+         CALL CF_CREATE_VAR("sfal","Snowfall rate",
+     .                   "m/s","time","-","-","-" )
+         CALL CF_CREATE_VAR("pres","Atmospheric pressure", 
+     .                   "Pa","time","-","-","-" )
+
+         ! Radiative transfer 
+         !--------------------
+         CALL CF_CREATE_VAR("T_is","Transmitted rad flx through ice",
+     .                   "W.m-2","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("T_oc","Transmitted rad flux to ocean",
+     .                   "W.m-2","time","-","-","-" )
+
+         CALL CF_CREATE_VAR("A_s","Absorbed rad flux by snow",
+     .                   "W.m-2","time","z_s_p","-","-" )
+
+         CALL CF_CREATE_VAR("A_ib","Absorbed rad in ice by algae",
+     .                   "W.m-2","time","z_i_p","-","-" )
+
+         CALL CF_CREATE_VAR("A_ip","Absorbed rad in ice physically",
+     .                   "W.m-2","time","z_i_p","-","-" )
+
+         IF ( c_bio_model .EQ. 'KRILL' ) THEN
+
+         ! Biological variables
+         !----------------------
+         DO jn = 1, ntra_bio
+
+         IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"d",
+     &        "Brine cc., "//TRIM(biotr_i_nam(jn)),
+     &        TRIM(biotr_i_uni(jn)),"time","z_i_b","-","-" )
+         WRITE(numout,*) ' Brine tracer conc created ', 
+     &   TRIM(biotr_i_nam(jn))//"d"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"b",
+     &        "Bulk cc., "//TRIM(biotr_i_nam(jn)),
+     &        TRIM(biotr_i_uni(jn)),"time","z_i_b","-","-" )
+         WRITE(numout,*) ' Brine tracer conc created ',
+     &   TRIM(biotr_i_nam(jn))//"b"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"t",
+     &        "Total content, "//TRIM(biotr_i_nam(jn)),
+     &        TRIM(biotr_i_uni(jn))//".m","time","-","-","-" )
+         WRITE(numout,*) ' Total tracer content created ',
+     &   TRIM(biotr_i_nam(jn))//"t"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"w",
+     &        "UML cc., "//TRIM(biotr_i_nam(jn)),
+     &        TRIM(biotr_i_uni(jn))//"m","time","-","-","-" )
+         WRITE(numout,*) ' UML tracer cc. created ',
+     &   TRIM(biotr_i_nam(jn))//"w"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn)),
+     &        "Ice-ocean "//TRIM(biotr_i_nam(jn))//" diffusive flux",
+     &        TRIM(biotr_i_uni(jn))//".m/s","time","-","-","-")
+         WRITE(numout,*) ' Tracer flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"t"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn))//"b",
+     &        "Ice-ocean "//TRIM(biotr_i_nam(jn))//" basal flux",
+     &        TRIM(biotr_i_uni(jn))//".m/s","time","-","-","-")
+         WRITE(numout,*) ' Tracer flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"t"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn))//"si",
+     &        "Ice-ocean "//TRIM(biotr_i_nam(jn))//" snow ice flux",
+     &        TRIM(biotr_i_uni(jn))//".m/s","time","-","-","-")
+         WRITE(numout,*) ' Tracer flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"t"
+         ENDIF
+
+         IF ( flag_active(jn) ) THEN
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn))//"bmax",
+     &        "Ice-ocean "//TRIM(biotr_i_nam(jn))//" maximal flux",
+     &        TRIM(biotr_i_uni(jn))//".m/s","time","-","-","-")
+         WRITE(numout,*) ' Tracer flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"t"
+         ENDIF
+
+         ! Gas flux
+         IF ( flag_active(jn) .AND. ( biotr_i_typ(jn) .EQ. 'gas' ) )
+     &   THEN
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"bub",
+     &        "Bubble cc., "//biotr_i_nam(jn),
+     &        TRIM(biotr_i_uni(jn)),"time","z_i_b","-","-" )
+         WRITE(numout,*) ' Bubble concentration dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"bu_bub"
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn))//"_atm",
+     &        "Ice-atmos "//TRIM(biotr_i_nam(jn))//" diffusive flux",
+     &        biotr_i_uni(jn)//"/m2/s","time","-","-","-")
+         WRITE(numout,*) ' Tracer gas flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"flux"
+     
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR("F"//TRIM(biotr_i_nam(jn))//"_bub",
+     &        "Ice-atmos, "//TRIM(biotr_i_nam(jn))//" bubble flux",
+     &        TRIM(biotr_i_uni(jn))//"/m2/s","time","-","-","-")
+         WRITE(numout,*) 'Surface bubble flux dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"bub_flux"
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"_trvel",
+     &        "Ice-atmos "//TRIM(biotr_i_nam(jn))//" transfer velocity",
+     &        TRIM(biotr_i_uni(jn))//"m/s","time","-","-","-")
+         WRITE(numout,*) ' At-ice gas transfer vel. dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"_trvel"
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         CALL CF_CREATE_VAR(TRIM(biotr_i_nam(jn))//"pc_sat",
+     &        "%sat, "//TRIM(biotr_i_nam(jn)),
+     &        TRIM(biotr_i_uni(jn)),"time","z_i_b","-","-" )
+         WRITE(numout,*) ' %sat dimension created ',
+     &   TRIM(biotr_i_nam(jn))//"pc_sat"
+
+         ENDIF ! gases
+
+         END DO ! jn
+
+         !------------------
+         ! Carbonate system
+         !------------------
+         IF ( ln_carbon ) THEN
+
+         CALL CF_CREATE_VAR("CO2aq", "Bulk aqueous CO2 concentration", 
+     .                   "mmol m-3","time","z_i_b","-","-" )
+         WRITE(numout,*) ' CO2aq created '
+
+         CALL CF_CREATE_VAR("CO32m", "Bulk CO32- concentration", 
+     .                   "mmol m-3","time","z_i_b","-","-" )
+         WRITE(numout,*) ' CO32m created '
+
+         CALL CF_CREATE_VAR("HCO3m", "Bulk HCO3m concentration", 
+     .                   "mmol m-3","time","z_i_b","-","-" )
+         WRITE(numout,*) ' HCO3m created '
+
+         CALL CF_CREATE_VAR("pH",    "Brine pH",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' brine pH created'
+
+         CALL CF_CREATE_VAR("pCO2",  "Brine pCO2",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' brine pCO2 created'
+
+         ENDIF
+
+
+         ! Chlorophyll a
+         CALL CF_CREATE_VAR("Chla_bio", "Chlorophyll a on bio grid",
+     &        "mmol.m-3","time","z_i_b","-","-")
+         WRITE(numout,*) ' Chla bio created '
+
+         ! Chlorophyll a
+         CALL CF_CREATE_VAR("ChlC_bio", "Chl/C",
+     &        "mmol.m-3","time","z_i_b","-","-")
+         WRITE(numout,*) ' ChlC_bio created '
+
+         CALL CF_CREATE_VAR("Chla_phy", "Chlorophyll a on phy grid",
+     &        "mmol.m-3","time","z_i_p","-","-" )
+         WRITE(numout,*) ' Chla phy created '
+
+         ! PAR
+         CALL CF_CREATE_VAR("PAR","PAR on phy grid - top of layers",
+     &                      "µE.m-2.s-1","time","z_i_p","-","-" )
+         WRITE(numout,*) ' PAR created '
+
+         ! PAR
+         CALL CF_CREATE_VAR("PAR_bio","PAR on bio grid - top of layers",
+     &                      "µE.m-2.s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' PAR_BIO created '
+
+         ENDIF ! c_bio_model 
+
+         IF ( c_bio_model .EQ. 'KRILL' ) THEN
+
+         IF ( ln_ikaite ) THEN
+         
+         CALL CF_CREATE_VAR("ika_rate","CaCO3 precip/dissol rate",
+     .                   "mmol CaCO3 m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' CaCO3 precip/dissol rate created '
+
+         CALL CF_CREATE_VAR("ika_omega","CaCO3 saturation state",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' CaCO3 saturation state created '
+
+         ENDIF
+
+         IF ( flag_active(4) ) THEN
+         ! Sources and sinks
+         CALL CF_CREATE_VAR("syn","Algal synthesis",
+     .                   "mmol C m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Algal growth created '
+
+         CALL CF_CREATE_VAR("rsp","Algal respiration",
+     .                   "mmol C m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Algal respiration created '
+
+         CALL CF_CREATE_VAR("lys","Algal lysis",
+     .                   "mmol C m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Algal lysis created '
+
+         CALL CF_CREATE_VAR("rem","Remineralization",
+     .                   "mmol C m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Remineralization created '
+
+         CALL CF_CREATE_VAR("lim_lig","Light limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Light limitation created '
+
+         CALL CF_CREATE_VAR("lim_dsi","DSi limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' DSi limitation created '
+
+         CALL CF_CREATE_VAR("lim_no3","NO3 limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' NO3 limitation created '
+
+         CALL CF_CREATE_VAR("lim_po4","PO4 limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' NO3 limitation created '
+
+         CALL CF_CREATE_VAR("lim_tem","Temp limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Temp limitation created '
+
+         CALL CF_CREATE_VAR("lim_sal","Sal limitation",
+     .                   "-","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Sal limitation created '
+         
+         CALL CF_CREATE_VAR("divf_si","Flux divergence silicate",
+     .                   "mmol Si m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Flux divergence silicate created '
+
+         CALL CF_CREATE_VAR("divf_n","Flux divergence nitrate",
+     .                   "mmol N m-3 s-1","time","z_i_b","-","-" )
+         WRITE(numout,*) ' Flux divergence nitrate created '
+
+         ENDIF ! flag_active
+
+         ENDIF ! c_bio_model
+
+         !---------------
+         ! File creation
+         !---------------
+         CALL CF_CREATE_FILE(filenc)
+
+      ENDIF
+
+!
+!-----------------------------------------------------------------------------!
+! 2) Write in the netcdf
+!-----------------------------------------------------------------------------!
+!
+      WRITE(numout,*) ' Write into the NetCdf file '
+      ji = 1
+      !-----------
+      ! Open file
+      !-----------
+      CALL CF_OPEN  (filenc,id)
+      !-------------------
+      ! Write in the file
+      !-------------------
+      ! Time
+      !------
+      CALL CF_WRITE (filenc, 'numt', numit-nstart+1, 
+     &               1, 1, 1, REAL(numit))
+      CALL CF_WRITE (filenc, 'doy', numit-nstart+1, 
+     &               1, 1, 1, REAL(doy))
+      CALL CF_WRITE (filenc, 'ts_m', numit-nstart+1, 
+     &               1, 1, 1, REAL(numit)/86400.0*REAL(ddtb)/30.0)
+      CALL CF_WRITE (filenc, 'ts_d', numit-nstart+1, 
+     &               1, 1, 1, REAL(numit)/86400.*REAL(ddtb) )
+
+      ! Grids
+      !-------
+      ! vertical cotes, physical
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL( ht_i_b(ji) ) / REAL( nlay_i ) * 
+     &                       ( REAL( layer ) - 1./2. )
+      END DO
+      CALL CF_WRITE (filenc, 'z_ip', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! vertical cotes, biological
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL( z_i_bio(layer) )
+      END DO
+      CALL CF_WRITE (filenc, 'z_ib', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      IF ( ( c_grid .EQ. 'SL' ) .OR. ( c_grid .EQ. 'BA' ) ) 
+     &   CALL CF_WRITE (filenc, 'hbio ', numit-nstart+1, 
+     &               1, 1, 1, REAL(h_bio))
+
+      ! Ice / snow thickness and variations
+      !-------------------------------------
+      CALL CF_WRITE (filenc, 'h_i ', numit-nstart+1, 
+     &               1, 1, 1, REAL(ht_i_b(ji)))
+      CALL CF_WRITE (filenc, 'dhib', numit-nstart+1, 
+     &               1, 1, 1, 
+     &               REAL(dh_i_bott(ji) / ddtb * 86400.0 * 100.0) )
+      CALL CF_WRITE (filenc, 'dhisu', numit-nstart+1, 
+     &               1, 1, 1, 
+     &               REAL(dh_i_surf(ji) / ddtb * 86400.0 * 100.0) )
+      WRITE(numout,*) ' ice output, dh_snowice1: ', dh_snowice(ji)
+      CALL CF_WRITE (filenc, 'dhisi', numit-nstart+1, 
+     &               1, 1, 1, 
+     &               REAL(dh_snowice(ji) / ddtb * 86400.0 * 100.0) )
+      WRITE(numout,*) ' ice output, dh_snowice2: ', 
+     &               REAL(dh_snowice(ji) / ddtb * 86400.0 * 100.0)
+
+      CALL CF_WRITE (filenc, 'h_s ', numit-nstart+1, 
+     &               1, 1, 1, REAL(ht_s_b(ji)))
+      CALL CF_WRITE (filenc, 'dhs', numit-nstart+1, 
+     &               1, 1, 1, 
+     &               REAL(dh_s_tot(ji) / ddtb * 86400.0 * 100.0) )
+      CALL CF_WRITE (filenc, 'uml ', numit-nstart+1, 
+     &               1, 1, 1, REAL(ht_w_b(ji)))
+      CALL CF_WRITE (filenc, 't_su', numit-nstart+1, 
+     &               1, 1, 1, REAL(t_su_b(ji) - 
+     &               273.16) )
+      CALL CF_WRITE (filenc, 'fsb', numit-nstart+1, 
+     &               1, 1, 1, REAL(fsb) )
+      CALL CF_WRITE (filenc, 'fsbp', numit-nstart+1, 
+     &               1, 1, 1, REAL(fsbp) )
+
+      CALL CF_WRITE (filenc, 'oce_sal', numit-nstart+1, 
+     &               1, 1, 1, REAL(oce_sal) )
+
+      ! Forcing
+      !---------
+      CALL CF_WRITE (filenc, 'Flwd', numit-nstart+1, 1, 1, 1, 
+     &               REAL( ratbqb(ji) ) )
+      CALL CF_WRITE (filenc, 'Flwu', numit-nstart+1, 1, 1, 1, 
+     &               - REAL(fratsb(ji) - ratbqb(ji)) )
+      CALL CF_WRITE (filenc, 'F_sw', numit-nstart+1, 1, 1, 1, 
+     &               REAL(fsolgb(ji) / ( 1.0 - albgb(ji) ) ) )
+      CALL CF_WRITE (filenc, 'Fswn', numit-nstart+1, 1, 1, 1, 
+     &               REAL(fsolgb(ji) ) )
+      CALL CF_WRITE (filenc, 'F_sh', numit-nstart+1, 1, 1, 1, 
+     &               REAL(fcsb(ji)) )
+      CALL CF_WRITE (filenc, 'F_lh', numit-nstart+1, 1, 1, 1, 
+     &               REAL(fleb(ji)) )
+      CALL CF_WRITE (filenc, 'albe', numit-nstart+1, 1, 1, 1, 
+     &               REAL(albgb(ji)) )
+
+      CALL CF_WRITE (filenc, 'Tair', numit-nstart+1, 1, 1, 1, 
+     &               REAL(tabqb(ji) - 273.15 ))
+      CALL CF_WRITE (filenc, 'qair', numit-nstart+1, 1, 1, 1, 
+     &               REAL(qabqb(ji)) )
+      CALL CF_WRITE (filenc, 'wspd', numit-nstart+1, 1, 1, 1, 
+     &               REAL(vabqb(ji)) )
+      CALL CF_WRITE (filenc, 'qsfc', numit-nstart+1, 1, 1, 1, 
+     &               REAL(qsfcb(ji)) )
+      CALL CF_WRITE (filenc, 'tdew', numit-nstart+1, 1, 1, 1, 
+     &               REAL(tdewb(ji))*100.0 )
+      CALL CF_WRITE (filenc, 'cldf', numit-nstart+1, 1, 1, 1, 
+     &               REAL(cldqb(ji)) )
+      CALL CF_WRITE (filenc, 'sfal', numit-nstart+1, 1, 1, 1, 
+     &               REAL(hnpbqb(ji)/ddtb) )
+      CALL CF_WRITE (filenc, 'pres', numit-nstart+1, 1, 1, 1, 
+     &               REAL(psbqb(ji)) )
+
+      ! Inner ice variables  
+      !---------------------
+      ! temperatures
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL(t_i_b(ji,layer) - 273.16 )
+      END DO
+      CALL CF_WRITE (filenc, 't_i ', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! salinity
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL( s_i_b(ji,layer) )
+      END DO
+      CALL CF_WRITE (filenc, 's_i ', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! brine volume
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL ( - tmut * s_i_b(ji,layer) / 
+     &                         ( t_i_b(ji,layer) - 273.16) ) * 100.0
+      END DO
+      CALL CF_WRITE (filenc, 'e_i ', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! brine volume bio
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL ( - tmut * s_i_bio(layer) / 
+     &                         ( t_i_bio(layer) - 273.16) ) * 100.0
+      END DO
+      CALL CF_WRITE (filenc, 'e_i_bio ', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+     
+      ! temperature bio
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = t_i_bio(layer) - 273.16
+      END DO
+      CALL CF_WRITE (filenc, 't_i_bio ', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! brine volume bio
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = s_i_bio(layer)
+      END DO
+      CALL CF_WRITE (filenc, 's_i_bio ', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! brine salinity bio
+      DO layer = 1, nlay_bio
+!        dummy_vector(layer) = - ( t_i_bio(layer) - 273.16 ) / tmut
+         ztc = ( t_i_bio(layer) - 273.15 )
+         zt2 = ztc * ztc            ;   zt3 = zt2 * ztc
+         dummy_vector(layer) = -21.4*ztc -0.886*zt2 - 0.0170*zt3
+      END DO
+      CALL CF_WRITE (filenc, 'sbr_bio ', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Rayleigh number
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = rayleigh(layer)
+      END DO
+      CALL CF_WRITE (filenc, 'ra', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+     
+      ! Salt diffusivity in brine
+      DO layer = 1, nlay_i
+         dummy_vector(layer) =diff_br(layer)
+      END DO
+      CALL CF_WRITE (filenc, 'diff', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! snow temperature
+      DO layer = 1, nlay_s
+         dummy_vector(layer) = REAL(t_s_b(ji,layer) - 273.16 )
+      END DO
+      CALL CF_WRITE (filenc, 't_s ', numit-nstart+1, nlay_s, 1, 1, 
+     &               dummy_vector )
+
+      ! Radiative transfer
+      !--------------------
+      ! Transmitted radiation in the ice
+      CALL CF_WRITE (filenc, 'T_is', numit-nstart+1, 
+     &               1, 1, 1, REAL(ftrice) )
+      CALL CF_WRITE (filenc, 'T_oc', numit-nstart+1, 
+     &               1, 1, 1, REAL(ftroce) )
+      ! Absorbed radiation in snow, physically
+      DO layer = 1, nlay_s
+         dummy_vector(layer) = REAL(radab_s(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'A_s', numit-nstart+1, nlay_s, 1, 1, 
+     &               dummy_vector )
+      ! Absorbed radiation in ice, physically
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL(radab_phy_i(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'A_ip', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+      ! Absorbed radiation in ice, biologically
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL(radab_alg_i(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'A_ib', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      IF ( c_bio_model .EQ. 'KRILL' ) THEN 
+
+      ! Biological variables  
+      !----------------------
+      ! tracer brine concentration
+      DO jn = 1, ntra_bio
+
+         ! tracer brine concentration
+         IF ( flag_diff(jn) .AND. flag_active(jn) ) THEN
+            DO layer = 1, nlay_bio
+               dummy_vector(layer) = REAL( c_i_bio(jn,layer) )
+            END DO
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      ( dummy_vector(layer), layer = 1, nlay_bio )
+            CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"d", 
+     &                     numit-nstart+1, nlay_bio, 1, 1, 
+     &                     dummy_vector )
+         ENDIF
+
+         ! tracer bulk ice concentration
+         IF ( flag_active(jn) ) THEN
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL( cbu_i_bio(jn,layer) )
+         END DO
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   ( dummy_vector(layer), layer = 1, nlay_bio )
+
+         CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"b", 
+     &                  numit-nstart+1, nlay_bio, 1, 1, 
+     &                  dummy_vector )
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( ct_i_bio(jn) )
+
+         CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"t",
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( ct_i_bio(jn) ) )
+     
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( c_w_bio(jn) )
+
+         CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"w",
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( c_w_bio(jn) ) )
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( fcb(jn) )
+
+         CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn)),
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( fcb(jn) ) )
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( fcbp(jn) )
+
+         CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn))//"b",
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( fcbp(jn) ) )
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( fcsi(jn) )
+
+         CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn))//"si",
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( fcsi(jn) ) )
+
+         WRITE(numout,*) ' Tracer number : ', jn
+         WRITE(numout,*) ' dummy_vector : ', 
+     &                   REAL( fcb_max(jn) )
+
+         CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn))//"bmax",
+     &                  numit-nstart+1, 1, 1, 1, 
+     &                  REAL( fcb_max(jn) ) )
+
+         IF ( biotr_i_typ(jn) .EQ. 'gas' ) THEN
+            WRITE(numout,*) ' GAS '
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      REAL( fgas(jn) )
+
+            CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn))//"_atm",
+     &                     numit-nstart+1, 1, 1, 1, 
+     &                     REAL( fgas(jn) ) )
+
+            DO layer = 1, nlay_bio
+               dummy_vector(layer) = REAL( cbub_i_bio(jn,layer) )
+            END DO
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      ( dummy_vector(layer), layer = 1, nlay_bio )
+            CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"bub", 
+     &                     numit-nstart+1, nlay_bio, 1, 1, 
+     &                     dummy_vector )
+     
+            DO layer = 1, nlay_bio
+               dummy_vector(layer) = REAL( pc_sat(jn,layer) )
+            END DO
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      ( dummy_vector(layer), layer = 1, nlay_bio )
+            CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"pc_sat", 
+     &                     numit-nstart+1, nlay_bio, 1, 1, 
+     &                     dummy_vector )
+
+            WRITE(numout,*) ' GAS '
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      REAL( f_bub(jn) )
+
+            CALL CF_WRITE (filenc, "F"//TRIM(biotr_i_nam(jn))//"_bub",
+     &                     numit-nstart+1, 1, 1, 1, 
+     &                     REAL( f_bub(jn) ) )
+
+            WRITE(numout,*) ' GAS '
+            WRITE(numout,*) ' Tracer number : ', jn
+            WRITE(numout,*) ' dummy_vector : ', 
+     &                      REAL( gas_trvel(jn) )
+
+            CALL CF_WRITE (filenc, TRIM(biotr_i_nam(jn))//"_trvel",
+     &                     numit-nstart+1, 1, 1, 1, 
+     &                     REAL( gas_trvel(jn) ) )
+
+         ENDIF ! biotr_i_typ
+
+         ENDIF ! flag_active
+      END DO ! jn
+
+      !------------------
+      ! Carbonate system
+      !------------------
+      IF ( ln_carbon ) THEN
+
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL(CO2aq(layer))
+         END DO
+         CALL CF_WRITE (filenc, 'CO2aq', numit-nstart+1, nlay_i, 1, 1,
+     &                  dummy_vector )
+
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL(CO32m(layer))
+         END DO
+         CALL CF_WRITE (filenc, 'CO32m', numit-nstart+1, nlay_i, 1, 1,
+     &                  dummy_vector )
+
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL(HCO3m(layer))
+         END DO
+         CALL CF_WRITE (filenc, 'HCO3m', numit-nstart+1, nlay_i, 1, 1,
+     &                  dummy_vector )
+
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL(pH(layer))
+         END DO
+         CALL CF_WRITE (filenc, 'pH', numit-nstart+1, nlay_i, 1, 1,
+     &                  dummy_vector )
+
+         DO layer = 1, nlay_bio
+            dummy_vector(layer) = REAL(pCO2(layer))
+         END DO
+         CALL CF_WRITE (filenc, 'pCO2', numit-nstart+1, nlay_i, 1, 1,
+     &                  dummy_vector )
+
+      ENDIF
+
+      ! Chla, physical grid
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL(chla_i(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'Chla_phy', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! ChlC_bio            
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(ChlC_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'ChlC_bio', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! Chla, biological grid
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(chla_i_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'Chla_bio', numit-nstart+1, nlay_bio, 1, 1,
+     &               dummy_vector )
+
+      ! PAR
+      DO layer = 1, nlay_i
+         dummy_vector(layer) = REAL(par(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'PAR', numit-nstart+1, nlay_i, 1, 1, 
+     &               dummy_vector )
+
+      ! PAR_bio
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(par_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'PAR_bio', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ENDIF
+
+
+      IF ( c_bio_model .EQ. 'KRILL' ) THEN
+
+      !-------------------
+      ! Sources and sinks
+      !-------------------
+      
+      IF ( ln_ikaite ) THEN
+
+      ! CaCO3 precipitation / dissolution rate
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(ika_rate(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'ika_rate', numit-nstart+1, nlay_bio, 1,1, 
+     &               dummy_vector )
+
+      ! CaCO3 saturation state
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(ika_omega(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'ika_omega', numit-nstart+1, nlay_bio, 1,1,
+     &               dummy_vector )
+
+      ENDIF ! ln_ikaite
+
+      IF ( flag_active(4) ) THEN
+
+      ! synthesis
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(syn_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'syn', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! respiration
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(rsp_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'rsp', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! lysis
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lys_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lys', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! remineralization
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(rem_bio(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'rem', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Light limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_lig(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_lig', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! DSi limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_dsi(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_dsi', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! NO3 limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_no3(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_no3', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! PO4 limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_po4(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_po4', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Temperature limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_tem(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_tem', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Salinity limitation
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(lim_sal(layer))
+      END DO
+      CALL CF_WRITE (filenc, 'lim_sal', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Flux divergence, silicate
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(diag_divf_bio(1,layer))
+      END DO
+      CALL CF_WRITE (filenc, 'divf_si', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ! Flux divergence, nitrate
+      DO layer = 1, nlay_bio
+         dummy_vector(layer) = REAL(diag_divf_bio(7,layer))
+      END DO
+      CALL CF_WRITE (filenc, 'divf_n', numit-nstart+1, nlay_bio, 1, 1, 
+     &               dummy_vector )
+
+      ENDIF ! flag_active
+
+      ENDIF ! c_bio_model
+
+      !------------
+      ! Close file
+      !------------
+      CALL CF_CLOSE (filenc)
+!
+!-----------------------------------------------------------------------------!
+!
+      WRITE(numout,*) 
+
+      END SUBROUTINE
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_grid.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_grid.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_grid.f	(revision 6)
@@ -0,0 +1,102 @@
+      SUBROUTINE ice_phy_grid(kideb,kiut,nlay,zht_i,ln_write,snoorice)
+
+! This routine creates thermodynamical vertical grid
+! (c) Martin Vancoppenolle, May 2007
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk            ! : index for ice layers
+
+      CHARACTER(len=3) :: 
+     &   snoorice     ! : message indicating whether we have to compute ice or snow
+
+      LOGICAL ::
+     &   ln_write
+
+!=============================================================================!
+
+      IF ( ln_write ) THEN
+         ji = 1
+         WRITE(numout,*) ' *** ice_phy_grid : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+         WRITE(numout,*) ' ht_i_b : ', zht_i
+         WRITE(numout,*) ' nlay   : ', nlay   
+         WRITE(numout,*) ' which? : ', snoorice
+      ENDIF
+
+      DO ji = kideb, kiut
+
+      !---------------------------
+      ! layer thickness
+      !---------------------------
+      IF ( snoorice .EQ. 'ice' ) THEN
+         DO layer = 1, nlay
+            deltaz_i_phy(layer) = zht_i / nlay
+         END DO
+      ENDIF
+
+      IF ( snoorice .EQ. 'sno' ) THEN
+         DO layer = 1, nlay
+            deltaz_s_phy(layer) = zht_i / nlay
+         END DO
+      ENDIF
+
+      !---------------------------
+      ! layer cotes
+      !---------------------------
+      IF ( snoorice .EQ. 'ice' ) THEN
+         z_i_phy(1)  = deltaz_i_phy(1) / 2.0
+         DO layer = 2, nlay
+            z_i_phy(layer)  = z_i_phy(layer-1) + ( deltaz_i_phy(layer-1)
+     &                      + deltaz_i_phy(layer) ) / 2.0
+         END DO
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' deltaz_i_phy : ', ( deltaz_i_phy(layer),  
+     &                      layer = 1, nlay )
+            WRITE(numout,*) ' z_i_phy      : ', ( z_i_phy(layer),  
+     &                      layer = 1, nlay )
+            WRITE(numout,*) ' end '
+         ENDIF
+
+      ENDIF
+
+      IF ( snoorice .EQ. 'sno' ) THEN
+         z_s_phy(1)  = deltaz_s_phy(1) / 2.0
+         DO layer = 2, nlay
+            z_s_phy(layer)  = z_s_phy(layer-1) + ( deltaz_s_phy(layer-1)
+     &                      + deltaz_s_phy(layer) ) / 2.0
+         END DO
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' deltaz_s_phy : ', ( deltaz_s_phy(layer),  
+     &                      layer = 1, nlay )
+            WRITE(numout,*) ' z_s_phy      : ', ( z_s_phy(layer),  
+     &                      layer = 1, nlay )
+            WRITE(numout,*) ' end '
+         ENDIF
+
+      ENDIF
+
+      !-----------------------------------------------------------------------!
+      ! Layer boundaries
+      !-----------------------------------------------------------------------!
+      zb_i_phy(0) = 0.0
+      DO layer = 1, nlay
+         zb_i_phy(layer) = zb_i_phy(layer-1) + deltaz_i_phy(layer)
+      END DO ! layer
+
+      END DO ! ji
+
+!=============================================================================!
+!-- End of ice_phy_grid --
+ 
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_ini.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_ini.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_ini.f	(revision 6)
@@ -0,0 +1,173 @@
+      SUBROUTINE ice_phy_ini(kideb,kiut, nlay_s, nlay_i)
+
+      ! BIO-LIM1D, 2008 (M. Vancoppenolle)
+      ! update 2014, v3.04
+
+      ! This routine initializes ice variables
+      
+!------------------------------------------------------------------------------!
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      CHARACTER(len=10) :: 
+     &   filenc='init.nc'
+
+      REAL(4)        zini(1)  ! forcing field dummy array
+      REAL(4)        zzi(maxnlay), zti(maxnlay), zsi(maxnlay) ! forcing field dummy array
+      REAL(4)        zdsi(maxnlay), zno3(maxnlay), zpo4(maxnlay)
+      REAL(4)        zdaf(maxnlay)
+
+      REAL(8), DIMENSION (maxnlay) :: 
+     &   zsh_i0              ,   !: old ice salt content (ppt.m-2)
+     &   zsh_i1                  !: new ice salt content (ppt.m-2)
+
+      REAL(8), DIMENSION (maxnlay) :: 
+     &   zqh_i0              ,   !: old ice heat content (J.m-2)
+     &   zqh_i1                  !: new ice heat content (J.m-2)
+
+      REAL(8), DIMENSION (maxnlay+2) ::
+     &   zthick0                 !: thickness of old layers
+
+      WRITE(numout,*) ' * ice_phy_ini : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~'
+      WRITE(numout,*) 
+
+      zeps = 1.0e-10
+      ji = 1
+
+!
+!------------------------------------------------------------------------------|
+!  1) Case of a NETCDF file
+!------------------------------------------------------------------------------|
+!
+      !-----------
+      ! Open file
+      !-----------
+      CALL CF_OPEN  (filenc,id) ! open forcing file
+
+      !-----------
+      ! Read data
+      !-----------
+      zn = 0.0
+      CALL CF_READ1D ( filenc, 'nlay', 1, 1, zini )
+      zn = REAL(zini(1))
+
+      zj_d = 0.0
+      CALL CF_READ1D ( filenc, 'j_d', 1, 1, zini )
+      zj_d = REAL(zini(1))
+
+      CALL CF_READ1D ( filenc, 'h_s', 1, 1, zini)
+      ht_s_b(ji) = REAL(zini(1))
+       
+
+      CALL CF_READ1D ( filenc, 'h_i', 1, 1, zini)
+      ht_i_b(ji) = REAL(zini(1))
+
+      CALL CF_READ1D ( filenc, 't_s', 1, 1, zini)
+      t_s_b(ji,1) = REAL(zini(1))
+
+      CALL CF_READ1D ( filenc, 't_su', 1, 1, zini)
+      t_su_b(ji) = REAL(zini(1))
+
+      DO layer = 1, INT(zn)
+         CALL CF_READ1D ( filenc, 'z_i', layer, 1, zini)
+         zzi(layer) = zini(1)
+         CALL CF_READ1D ( filenc, 't_i', layer, 1, zini)
+         zti(layer) = zini(1)
+         CALL CF_READ1D ( filenc, 's_i', layer, 1, zini)
+         zsi(layer) = zini(1)
+      END DO
+
+      CALL CF_CLOSE (filenc) ! close nc file
+
+      t_bo_b(ji)   =  273.15-tmut*oce_sal 
+
+      !----------------------
+      ! Interpolate profiles
+      !----------------------
+
+            !------
+            ! Snow
+            !------
+            CALL ice_phy_grid(1,1,nlay_s,ht_s_b(ji), .FALSE., "sno" )   ! compute the physical grid
+
+            !-----
+            ! Ice
+            !-----
+            CALL ice_phy_grid(1,1,nlay_i,ht_i_b(ji), .FALSE., "ice" )   ! compute the physical grid
+
+            ! grid indexes for redistribution
+            ntop0  = 1 
+            nbot0  = INT(zn)
+            ntop1  = 1
+            nbot1  = nlay_i
+
+            !--- Salinity
+            zm0(0) = 0.0         ! layer interfaces cotes
+            DO layer = 1, nbot0-1
+               zm0(layer) = REAL( zzi(layer) + zzi(layer+1) ) / 2.
+            END DO
+            zm0(nbot0) = ht_i_b(ji)
+
+            DO layer = 1, nbot0  !layer thickness and salt content
+               zthick0(layer) = zm0(layer)-zm0(layer-1)
+               zsh_i0(layer) = rhog*zthick0(layer)*REAL(zsi(layer)) !mass of salt
+            END DO
+
+            CALL ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , 
+     &                       zthick0, deltaz_i_phy, zsh_i0 , zsh_i1 )
+
+            DO layer = 1, nlay_i
+               s_i_b(ji,layer) = zsh_i1(layer) / 
+     &         (rhog*deltaz_i_phy(layer))
+            END DO
+
+            DO layer = 1, nbot0  ! heat content
+               ztmelts    =   - tmut * REAL(zsi(layer)) + tpw 
+               zq         = rhog * ( cpg * ( ztmelts -REAL(zti(layer)) )
+     &                      + lfus*( 1.0 - (ztmelts-tpw) / 
+     &                        MIN( (REAL( zti(layer) ) -tpw),-zeps) )  
+     &                      - cpw      * ( ztmelts-tpw  ) ) 
+               zqh_i0(layer) = zq * zthick0(layer)
+           END DO
+           CALL ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , 
+     &                       zthick0, deltaz_i_phy, zqh_i0 , zqh_i1 )
+
+           DO layer = 1, nlay_i
+              zq = zqh_i1(layer) / MAX( deltaz_i_phy(layer) , zeps )
+              ztmelts = -tmut*s_i_b(ji,layer) + tpw
+              aaa = cpg
+              bbb = (cpw-cpg)*(ztmelts-tpw) + zq / rhog - lfus
+              ccc = lfus * (ztmelts-tpw)
+              discrim = SQRT( bbb*bbb - 4.0*aaa*ccc )
+              t_i_b(ji,layer) = tpw + (- bbb - discrim) / ( 2.0*aaa )
+           END DO
+
+!
+!------------------------------------------------------------------------------|
+! x) Write in output file
+!------------------------------------------------------------------------------|
+
+            WRITE(numout,*) ' --- Initial values --- '
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' Surface temperature t_su : ', t_su_b(ji)
+            WRITE(numout,*) ' Basal   temperature t_bo : ', t_bo_b(ji)
+            WRITE(numout,*) ' Snow temperature    t_s  : ', t_s_b(ji,1)
+            WRITE(numout,*) ' Ice temperatures    t_i  : ', 
+     &                      ( t_i_b(ji,jk), jk = 1, nlay_i )
+            WRITE(numout,*) ' Ice salinities      s_i  : ', 
+     &                      ( s_i_b(ji,jk), jk = 1, nlay_i )
+            WRITE(numout,*) ' Ice thickness       ht_i_b : ', ht_i_b(ji)
+            WRITE(numout,*) ' Snow depth          ht_s_b : ', ht_s_b(ji)
+            WRITE(numout,*) ' '
+
+!------------------------------------------------------------------------------|
+!- end of ice_phy_ini
+!
+      RETURN
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_param.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_param.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_param.f	(revision 6)
@@ -0,0 +1,278 @@
+      SUBROUTINE ice_phy_param
+
+        !!------------------------------------------------------------------
+        !!                ***  ROUTINE ice_phy_param ***
+        !! ** Purpose :
+        !!           Defines physical constants & params of the model
+        !! ** Method  :
+        !!           Definitions !!! 
+        !!
+        !! ** Arguments :
+        !!           n99
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References : Vancoppenolle et al., JGR 2007
+        !!
+        !! ** History :
+        !!       (1) CLIO, Goosse and Fichefet, JGR, 1999.
+        !!       (2) LIM-1D, Vancoppenolle et al., JGR, 2007.
+        !!       (3) BIO-LIM, Martin Vancoppenolle, 2008
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+      INCLUDE 'type.com'
+      INCLUDE 'const.com'
+      INCLUDE 'para.com'
+      INCLUDE 'ice.com'
+
+      ! name of the experiment
+      CHARACTER(len=8) exp_id
+
+      ! Formats for reading the initial salinity profile
+      CHARACTER(len=1) zc1
+      CHARACTER(len=2) zc2
+      CHARACTER(len=7) zformat1
+      CHARACTER(len=7) zformat2
+      CHARACTER(len=8) zformat3
+
+!
+!-----------------------------------------------------------------------
+!  1 ) Lecture des parametres du run
+!-----------------------------------------------------------------------
+!
+      WRITE(numout,*) ' * ice_phy_param : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~'
+
+      OPEN(unit=10,file='run.param',status='old')
+
+      READ(10,*)
+      READ(10,*)
+      READ(10,*)
+      READ(10,*)
+      READ(10,*)
+      READ(10,*)
+      READ(10,*) exp_id     ! name of the experiment
+      READ(10,*)
+      READ(10,*) ddtb       ! time step
+      READ(10,*)
+      READ(10,*) nstart     ! number of the first iteration
+      READ(10,*)
+      READ(10,*) nend       ! number of the last iteration
+      READ(10,*)
+      READ(10,*) nyear      ! initial year
+      READ(10,*)
+      READ(10,*) nfr_out    ! output frequency
+      READ(10,*)
+      READ(10,*) rlat       ! latitude
+      READ(10,*) 
+      READ(10,*) c_bio_model ! biological model
+      READ(10,*) 
+      WRITE(numout,*) ' Type of biological model ( c_bio_model ) : ', 
+     &                  c_bio_model
+      WRITE(numout,*)
+
+      nitrun    = nend - nstart + 1
+
+      CLOSE(10)
+!
+!-----------------------------------------------------------------------
+!  2 ) Mathematical constants
+!-----------------------------------------------------------------------
+!
+      c_zero  = 0.d0              ! zero
+      one     = 1.d0              ! one
+      pi     = 4.0 * atan(one)    ! pi
+      radian = pi / 180.0         ! conversion degrees to radians
+
+!------------------------------------------------------------------------------
+!  3 ) Physical constants
+!------------------------------------------------------------------------------
+
+      !-----------------------
+      ! Fundamental constants
+      !-----------------------
+      gpes   = 9.80d0             ! gravity
+      stefan = 5.6697d-08         ! stefan-boltzmann constant
+      vkarmn = 0.40d0             ! von karmann constant
+      cevap  = 2.5d+06            ! heat transfer coefficient for latent heat... check!!!
+      zemise = 0.97d0             ! R, sea water emissivity (remove also)
+
+      !---------------
+      ! Ocean physics
+      !---------------
+      tpw     = 273.16d0          ! water triple point
+      rho0    = 1025.0            ! ocean mean density
+      cpw     = 3.99d+03          ! seawater specific heat
+      oce_sal = 34.0              ! 34. is the control
+
+      visc_br = 1.79e-3           ! dynamic viscosity of water at 0C 
+      beta_ocs= 0.81              ! regulates density changes due to changes in salinity
+
+      !-----------------
+      ! Sea ice physics
+      !-----------------
+ 
+      !-- thermal properties
+      tfsn   = 273.16d0           ! snow melting point
+      tfsg   = 273.16d0           ! sea ice melting point
+      xkn    = 0.31d0             ! 0.31d0 ISPOL Olivier Lecomte communication ! ref value 0.31d0 ! snow thermal conductivity
+      xkg    = 2.034d0            ! pure ice thermal conductivity
+      rhog   = 917.0              ! sea ice density
+      rhon   = 330.d0             ! O. Lecomte says 355 could be used
+      cpg    = 2.062d+03          ! sea ice specific heat (J/kg/K)
+      lfus   = 3.335d+05          ! pure ice latent heat (J/kg)
+      lvap   = 2.501e+06          ! latent heat of vaporization of water (0°C J/kg)
+      lsub   = lfus  + lvap       ! sublimation latent heat
+      tmut   = 0.054d0            ! rate between seawater freezing point and salinity (linear model)
+      betak1 = 0.09d0             ! first Pringle th. cond. constant
+      betak2 = 0.011d0            ! second Pringle th. cond. constant
+!     emig   = 0.99d0             ! surface emissivity (read later)
+
+      !---------------------------
+      ! Model physical parameters
+      !---------------------------
+      OPEN(unit=25,file='icephys.param', status='old')
+
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)                  
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*) 
+      READ(25,*)                 
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)                
+      READ(25,*) n_i              ! number of layers in the ice
+      READ(25,*)
+      READ(25,*) n_s              ! number of layers in the snow
+      READ(25,*)
+      READ(25,*) parsub           ! switch for sublimation or not
+      READ(25,*)
+      READ(25,*) ln_evap          ! switch for snow evaporation or not
+      READ(25,*)                  !
+      READ(25,*) tabq_ano         ! Prescribed air temperature anomalies
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*) ln_grd           ! gravity drainage or not
+      READ(25,*)
+      READ(25,*) ln_flu           ! flushing or not
+      READ(25,*)
+      READ(25,*) ln_flo           ! flooding or not
+      READ(25,*)
+      READ(25,*) flu_beta         ! fraction of meltwater percolating
+      READ(25,*)
+      READ(25,*) e_thr_flu        ! permeability threshold for flushing
+      READ(25,*)
+      READ(25,*) frtr_si_phy      ! fractionation coeff in snow ice
+      READ(25,*)
+      READ(25,*) d_br_mol         ! molecular diffusivity of brine
+      READ(25,*)
+      READ(25,*) d_br_tur         ! turbulent diffusivity of brine
+      READ(25,*)
+      READ(25,*) ra_c             ! critical rayleigh number over which convection starts
+      READ(25,*)
+      READ(25,*) ra_smooth        ! coefficient to smooth the hyperbolic tangential for ra_c
+      READ(25,*)
+      READ(25,'(a2)') gravdr      ! type of gravity drainage
+      READ(25,*)
+      READ(25,*) delta_cw         ! Cox and weeks gravity drainage parameter
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*)
+      READ(25,*) emig
+      READ(25,*)
+      READ(25,*) fpar_fsw
+      READ(25,*)
+      READ(25,*) qpar_fsw
+      READ(25,*)
+      READ(25,*) c_rad_scheme
+      READ(25,*)
+      READ(25,*) c_rad_discr 
+      READ(25,*)
+      READ(25,*) rad_inot_s_dry   ! surface transmission parameter, dry snow
+      READ(25,*)
+      READ(25,*) rad_inot_s_wet   ! surface transmission parameter, wet snow
+      READ(25,*)
+      READ(25,*) rad_inot_i_dry   ! surface transmission parameter, dry ice
+      READ(25,*)
+      READ(25,*) rad_inot_i_wet   ! surface transmission parameter, wet ice
+      READ(25,*)
+      READ(25,*) h_not_s          ! SSL thickness, snow
+      READ(25,*)
+      READ(25,*) h_not_i          ! SSL thickness, ice
+      READ(25,*)
+      READ(25,*) rad_kappa_s_su_d ! surface extinction coefficient, dry snow
+      READ(25,*)
+      READ(25,*) rad_kappa_s_su_m ! surface extinction coefficient, melting snow
+      READ(25,*)
+      READ(25,*) rad_kappa_i_su_d ! surface extinction coefficient, cold ice
+      READ(25,*)
+      READ(25,*) rad_kappa_i_su_m ! surface extinction coefficient, melting ice
+      READ(25,*)
+      READ(25,*) rad_kappa_s_de_d ! depth extinction coefficient, dry snow
+      READ(25,*)
+      READ(25,*) rad_kappa_s_de_m ! depth extinction coefficient, wet snow
+      READ(25,*)
+      READ(25,*) rad_kappa_i_de_d ! attenuation coefficient, cold ice
+      READ(25,*)
+      READ(25,*) rad_kappa_i_de_m ! attenuation coefficient, melting ice
+      READ(25,*)
+
+      WRITE(numout,*) ' n_i        :', n_i
+      WRITE(numout,*) ' n_s        :', n_s
+      WRITE(numout,*) ' parsub     :', parsub
+      WRITE(numout,*) ' ln_evap    :', ln_evap
+      WRITE(numout,*) ' tabq_ano   :', tabq_ano
+      WRITE(numout,*) ' ln_grd     :', ln_grd
+      WRITE(numout,*) ' ln_flu     :', ln_flu
+      WRITE(numout,*) ' ln_flo     :', ln_flo
+      WRITE(numout,*) ' flu_beta   :', flu_beta
+      WRITE(numout,*) ' frtr_si_phy:', frtr_si_phy
+      WRITE(numout,*) ' d_br_mol   :', d_br_mol
+      WRITE(numout,*) ' d_br_tur   :', d_br_tur
+      WRITE(numout,*) ' ra_c       :', ra_c
+      WRITE(numout,*) ' ra_smooth  :', ra_smooth
+      WRITE(numout,*) ' gravdr     :', gravdr
+      WRITE(numout,*) ' delta_cw   :', delta_cw
+      WRITE(numout,*) ' emig        :', emig
+      WRITE(numout,*) ' fpar_fsw    :', fpar_fsw
+      WRITE(numout,*) ' qpar_fsw    :', qpar_fsw
+      WRITE(numout,*) ' c_rad_scheme:', c_rad_scheme
+      WRITE(numout,*) ' c_rad_discr: ', c_rad_discr
+      WRITE(numout,*) ' rad_inot_s_dry : ', rad_inot_s_dry
+      WRITE(numout,*) ' rad_inot_s_wet : ', rad_inot_s_wet
+      WRITE(numout,*) ' rad_inot_i_dry : ', rad_inot_i_dry
+      WRITE(numout,*) ' rad_inot_i_wet : ', rad_inot_i_wet
+      WRITE(numout,*) ' h_not_s    : ', h_not_s
+      WRITE(numout,*) ' h_not_i    : ', h_not_i
+      WRITE(numout,*) ' rad_kappa_s_su_d : ', rad_kappa_s_su_d
+      WRITE(numout,*) ' rad_kappa_s_su_m : ', rad_kappa_s_su_m
+      WRITE(numout,*) ' rad_kappa_i_su_d : ', rad_kappa_i_su_d
+      WRITE(numout,*) ' rad_kappa_i_su_m : ', rad_kappa_i_su_m
+      WRITE(numout,*) ' rad_kappa_s_de_d : ', rad_kappa_s_de_d
+      WRITE(numout,*) ' rad_kappa_s_de_m : ', rad_kappa_s_de_m
+      WRITE(numout,*) ' rad_kappa_i_de_d : ', rad_kappa_i_de_d
+      WRITE(numout,*) ' rad_kappa_i_de_m : ', rad_kappa_i_de_m
+      WRITE(numout,*)
+
+      CLOSE(25)
+
+!------------------------------------------------------------------------------
+      RETURN
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_relay.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_relay.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_relay.f	(revision 6)
@@ -0,0 +1,139 @@
+      SUBROUTINE ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , !zl0,zl1,
+     &                          hl0, hl1, ql0, ql1 )
+
+      !!------------------------------------------------------------------
+      !!                ***         ROUTINE ice_phy_relay     ***
+      !!
+      !! ** Purpose :
+      !! This routine redistributes the scalar quantity ql0 - distributed on layers of
+      !! lower boundary limit zl0 - onto new scalars ql1 on a new grid - described by 
+      !! zl1.
+      !!       rl01(i,j) represents linear weights of old layers into the new ones.
+      !!       index of top layer --> ntop0/1
+      !!       index of bottom layer --> nbot0/1
+      !!
+      !! ** Method  : Relayering
+      !!           
+      !! ** Steps
+      !!
+      !! ** Arguments
+      !!
+      !! ** Inputs / Outputs
+      !!
+      !! ** External
+      !!
+      !! ** References : Vancop. et al., 2007
+      !!
+      !! ** History  : 
+      !!    (12-2002) Martin Vancop. First test
+      !!    (06-2003) Martin Vancop. LIM1D
+      !!    (06-2008) Martin Vancop. BIO-LIM
+      !!    (09-2008) Martin Vancop. Explicit gravity drainage
+      !!
+      !!------------------------------------------------------------------
+
+      INCLUDE 'para.com'
+      INCLUDE 'type.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+ 
+      REAL(8), DIMENSION ( maxnlay ) ::
+     &  ql0         !: old scalar
+
+      REAL(8), DIMENSION ( maxnlay + 2 ) ::
+     &  hl0         !: old layer thickness 
+
+      REAL(8), DIMENSION ( maxnlay ) ::
+     &  ql1      ,  !: new scalar
+     &  hl1         !: old layer thickness 
+
+      REAL(8), DIMENSION ( 0:maxnlay ) ::
+     &  zl0      ,  !: old layer interfaces
+     &  zl1         !: new layer interfaces
+
+      REAL(8), DIMENSION ( nbot1, nbot0 ) ::
+     &  rl01        !: relayering matrix
+
+      INTEGER ::
+     &  layer1   ,  !: first layer index
+     &  layer2      !: second layer index
+
+      LOGICAL ::
+     &  ln_write
+      zlimit = 1.0e-10   !: limiting factor to avoid divisions per 0
+      ln_write = .FALSE.
+      ql1(:) = 0.0
+!
+!==============================================================================!
+
+        zl0(0)     = 0.0
+        zl0(ntop0) = hl0(ntop0)
+        DO layer0 = ntop0+1, nbot0
+           zl0(layer0) = zl0(layer0-1) + hl0(layer0)
+        END DO
+
+        zl1(0)     = 0.0
+        zl1(ntop1) = hl1(ntop1)
+        DO layer1 = ntop1+1, nbot1
+           zl1(layer1) = zl1(layer1-1) + hl1(layer1)
+        END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ** ice_phy_relay : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) 
+         WRITE(numout,*) ' Input... '
+         WRITE(numout,*) ' ql0 : ', ( ql0(jk), jk = 1, nbot0 )
+         WRITE(numout,*) ' nbot0 : ', nbot0 
+         WRITE(numout,*) ' nbot1 : ', nbot1 
+         WRITE(numout,*) ' ntop0 : ', ntop0
+         WRITE(numout,*) ' ntop1 : ', ntop1
+         WRITE(numout,*) ' zl0   : ', ( zl0(jk), jk = ntop0, nbot0 )
+         WRITE(numout,*) ' zl1   : ', ( zl1(jk), jk = ntop1, nbot1 )
+         WRITE(numout,*) ' hl0   : ', ( hl0(layer0), 
+     &                                layer0 = ntop0, nbot0 )
+         WRITE(numout,*) ' hl1   : ', ( hl1(layer1), 
+     &                                layer1 = ntop1, nbot1 )
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  1) Relayering procedure                                                     |
+!------------------------------------------------------------------------------|
+!
+        !---------
+        ! weights
+        !---------
+        DO layer1 = ntop1, nbot1
+           DO layer0 = ntop0, nbot0
+               rl01(layer1,layer0) = MAX( 0.0 , ( MIN(zl0(layer0), 
+     &         zl1(layer1)) - MAX(zl0(layer0-1), zl1(layer1-1) ) ) / 
+     &         MAX( hl0(layer0) , zlimit ) ) 
+               IF (ln_write) WRITE(numout,*) ' Weight : ', 
+     &                       layer0, layer1, rl01(layer1,layer0)
+           END DO
+        END DO
+
+        !-------------
+        ! new scalars
+        !-------------
+        IF (ln_write) WRITE(numout,*) ' Redistribution of the scalar '
+        DO layer1 = ntop1, nbot1
+           ql1(layer1) = 0.0
+           DO layer0 = ntop0, nbot0
+     
+              ql1(layer1) = ql1(layer1) + 
+     &                         rl01(layer1,layer0) * ql0(layer0)
+              IF (ln_write) WRITE(numout,*) ' ql1 : ', ql1(layer1)
+              IF (ln_write) WRITE(numout,*) ' ql0 : ', ql0(layer0)
+              IF (ln_write) WRITE(numout,*) ' rl01: ', 
+     &                      rl01(layer1,layer0)
+           END DO
+        END DO
+
+        IF (ln_write) WRITE(numout,*) ' ql1 : ', 
+     &                ( ql1(jk), jk = ntop1, nbot1 )
+
+        RETURN
+!------------------------------------------------------------------------------!
+      END SUBROUTINE
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_remap.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_remap.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_phy_remap.f	(revision 6)
@@ -0,0 +1,601 @@
+      SUBROUTINE ice_phy_remap(nlay_s,nlay_i,kideb,kiut)
+
+!!-----------------------------------------------------------------------------
+!! ** Purpose :
+!!              This routine redistributes heat content and salt mass
+!!              on the new grid
+!!
+!!
+!! ** Method  : Linear redistribution
+!!           
+!! ** Steps   : switches, snow, ice heat content, ice salt content
+!!
+!! ** Arguments
+!!
+!! ** Inputs / Outputs
+!!
+!! ** External
+!!
+!! ** References
+!!
+!! ** History  : (05-2003) Martin Vancoppenolle, LIM1D
+!!               (05-2008) Martin Vancoppenolle, LLN, revision BIOLIM
+!!               (09-2009) Martin Vancoppenolle, LLN, restructuration BIOLIM
+!!-----------------------------------------------------------------------------
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      ! Local Variables
+      REAL(8), DIMENSION (maxnlay) :: 
+     &   zsh_i0              ,   !: old ice salt content (ppt.m-2)
+     &   zsh_i1                  !: new ice salt content (ppt.m-2)
+
+      REAL(8), DIMENSION (maxnlay) :: 
+     &   zqh_i0              ,   !: old ice heat content (J.m-2)
+     &   zqh_i1                  !: new ice heat content (J.m-2)
+
+      REAL(8), DIMENSION (maxnlay) :: 
+     &   zqh_s0              ,   !: old snow heat content (J.m-2)
+     &   zqh_s1                  !: new snow heat content (J.m-2)
+
+      REAL(8), DIMENSION( maxnlay ) ::
+     &  zthick1                  !: thickness of physical layers
+
+      REAL(8), DIMENSION (maxnlay+2) ::
+     &   zthick0                 !: thickness of old layers
+      LOGICAL ::
+     &   ln_write, ln_con
+
+      ! Local Constants
+      zeps   = 1.0e-20
+
+      ln_write = .TRUE.
+      ln_con   = .TRUE.
+
+      s_i_b(1,:) = sn_i_b(:) ! update salinity
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ** ice_phy_remap : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) 
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  CONSERVATION CHECKS                                                         |
+!------------------------------------------------------------------------------|
+!
+
+      ji = 1
+      IF ( ln_con ) THEN
+         CALL ice_sal_column(kideb,kiut,z_ms_i_ini,s_i_b(1,1:nlay_i),
+     &                       deltaz_i_phy, nlay_i, .FALSE. )
+         ! salt content loss due to ice melt
+         zfmelt = ( s_i_b(ji,1) * dh_i_surf(ji) + s_i_b(ji,nlay_i) * 
+     &              MIN(dh_i_bott(ji),0.0) ) / ddtb
+      ENDIF
+
+      zqt_s_ini = 0.0 ! total heat content in snow (initial value)
+      zqt_i_ini = 0.0 ! total heat content in ice  (initial value)
+      zqt_s_fin = 0.0 ! total heat content in snow (final value)
+      zqt_i_fin = 0.0 ! total heat content in ice  (final value)
+      zqt_ini   = 0.0 ! total heat content snow + ice (initial value)
+      zqt_fin   = 0.0 ! total heat content snow + ice (final value)
+
+      DO 10 ji = kideb, kiut
+!
+!------------------------------------------------------------------------------|
+!  SWITCHES                                                                    |
+!------------------------------------------------------------------------------|
+!
+      ! snow surface behaviour : calcul de snind-snswi
+      ! snind : index tel que sa valeur est 0 si la neige s'accrète
+      !                1 si la 1ere couche est entamée par la fonte
+      !                2 si la 2eme ....
+      !                                  etc ...
+      snind    =  0  
+      deltah   =  0.0
+      DO layer = 1, nlay_s
+         IF ( - dh_s_tot(ji) .GT. deltah ) THEN
+            snind  =  layer 
+         ENDIF
+         deltah = deltah + deltaz_s_phy(layer)
+      END DO
+
+      ! snswi : switch which value equals 1 if snow melts
+      !                                 0 if not
+      snswi    =  MAX(0,INT(-dh_s_tot(ji)/MAX(zeps,ABS(dh_s_tot(ji)))))
+
+      ! ice surface behaviour : computation of icsuind-icsuswi
+      ! icsuind : index which values equals 0 if there is nothing
+      !                                 1 if first layer has started to melt
+      !                                 2 if first and second layer have started ...
+      !                                 etc ...
+      icsuind    =  0  
+      deltah   =  0.0
+      DO layer = 1, nlay_i
+         IF  ( -dh_i_surf(ji).GT.deltah) THEN
+            icsuind  =  layer 
+         ENDIF
+         deltah = deltah + deltaz_i_phy(layer)
+      END DO
+
+      ! icsuswi : switch which value equals 1 if ice melts at the surface
+      !                                   0 if not
+      icsuswi    =  max(0,int(-dh_i_surf(ji)
+     &              /max(zeps,abs(dh_i_surf(ji)))))
+
+      ! ice bottom behaviour : computation of icboind-icboswi
+      ! icboind : index which values equals 0 if accretion is on the way
+      !                                     1 if last layer has started to melt
+      !                               2 if penultiem layer has started ...
+      !                               etc ...
+      icboind    =  0  
+      deltah   =  0.0
+      DO layer = nlay_i, 1, -1
+         IF (-dh_i_bott(ji) .GT. deltah) THEN
+            icboind  =  nlay_i+1-layer 
+         ENDIF
+         deltah = deltah + deltaz_i_phy(layer)
+      END DO
+
+      ! icboswi : switch which value equals 1 if accretion of ice is on the way
+      !                                         0 if ablation is on the way
+      icboswi    =  max(0,int(dh_i_bott(ji)
+     &              /max(zeps,abs(dh_i_bott(ji)))))
+
+      ! snow-ice formation : calcul de snicind-snicswi
+      ! snicind : index which values equals 0 if no snow-ice forms
+      !                1 if last layer of snow has started to melt
+      !                          2 if penultiem layer ...
+      snicind    =  0
+      deltah   =  0.0
+      DO layer = nlay_s, 1, -1
+         IF ( dh_snowice(ji) .GT. deltah ) THEN
+            snicind  =  nlay_s+1-layer
+         ENDIF
+         deltah = deltah + deltaz_s_phy(layer)
+      END DO
+
+      ! snicswi : switch which value equals 1 if snow-ice forms
+      !                                     0 if not
+      snicswi    =  max(0,int(dh_snowice(ji)/
+     &              max(zeps,abs(dh_snowice(ji)))))
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Switches ... '
+         WRITE(numout,*) '  snind   : ', snind
+         WRITE(numout,*) '  snswi   : ', snswi
+         WRITE(numout,*) '  icsuind : ', icsuind
+         WRITE(numout,*) '  icsuswi : ', icsuswi
+         WRITE(numout,*) '  icboind : ', icboind
+         WRITE(numout,*) '  icboswi : ', icboswi
+         WRITE(numout,*) '  snicind : ', snicind
+         WRITE(numout,*) '  snicswi : ', snicswi
+         WRITE(numout,*) 
+      ENDIF
+
+!------------------------------------------------------------------------------!
+
+      !------------------------------!
+      !                              !
+      !     SNOW redistribution      ! 
+      !                              !
+      !------------------------------!
+
+!
+!------------------------------------------------------------------------------|
+!      S-1) 'Old' snow cotes
+!------------------------------------------------------------------------------|
+!
+      !
+      ! by 'old', I mean that layers coming from accretion are included, and 
+      ! that surface layers which were partly melted are reduced ...
+
+      ! indexes of the vectors
+      ntop0    =  1
+      nbot0    =  nlay_s+1-snind+(1-snicind)*snicswi
+
+      ! cotes of the top of the layers
+      zm0(0)   =  0.0
+      DO layer = 1, nbot0-1
+         limsum    =  snswi*(layer+snind-1) + (1-snswi)*(layer-1)
+         limsum    =  MIN( limsum , nlay_s )
+         zm0(layer) =  dh_s_tot(ji)
+         DO layer_a = 1, limsum
+            zm0(layer) = zm0(layer) + deltaz_s_phy(layer_a)
+         END DO
+      END DO
+
+      zm0(nbot0) =  dh_s_tot(ji) - snicswi*dh_snowice(ji)
+      DO layer = 1, nlay_s
+        zm0(nbot0) = zm0(nbot0) + deltaz_s_phy(layer)
+      END DO
+      zm0(1)     =  dh_s_tot(ji)*(1-snswi) + snswi*zm0(1)
+
+      ! thicknesses
+      DO layer = ntop0, nbot0
+         zthick0(layer)  =  zm0(layer) - zm0(layer-1)
+      END DO
+!
+!------------------------------------------------------------------------------|
+!      S-2) 'Old' enthalpies
+!------------------------------------------------------------------------------|
+!
+      ! enthalpies
+      zqh_s0(1) =  rhon * ( cpg * ( tpw - (1 - snswi) * tabqb(ji) - ! fallen snow
+     &             snswi * t_s_b(ji,1) ) + lfus )* zthick0(1) 
+      zqt_s_ini = zqt_s_ini + zqh_s0(1)
+
+      DO layer = 2, nbot0 ! remaining snow
+         limsum = (1-snswi)*(layer-1) + snswi*(layer+snind-1)
+         limsum = MIN( limsum, nlay_s )
+         zqh_s0(layer) = rhon*( cpg*(tpw - t_s_b(ji,limsum)) + lfus) 
+     &            *zthick0(layer)
+         zswitch   = 1.0 - MAX (0.0, SIGN ( 1.0d0, zeps - ht_s_b(ji) ) )
+         zqt_s_ini = zqt_s_ini + ( 1 - snswi ) * zqh_s0(layer) * zswitch
+         WRITE(numout,*) 'limsum : ', limsum
+      END DO
+      zqt_ini = zqt_s_ini
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Snow redistribution ... '
+         WRITE(numout,*) ' ntop0 : ', ntop0
+         WRITE(numout,*) ' nbot0 : ', nbot0
+         WRITE(numout,*) ' zm0   : ', ( zm0(layer), layer = 0, nbot0)
+         WRITE(numout,*) ' zqh_s0: ', ( zqh_s0(layer), layer = 1, nbot0)
+         WRITE(numout,*) ' q_s_b1: ', q_s_b(ji,1)
+         WRITE(numout,*)
+      ENDIF
+
+      !-----------------------------------------
+      ! snow enthalpy lost in sea ice formation
+      !-----------------------------------------
+      zqsnow     =  0.0
+      zdeltah    =  0.0
+
+      DO layer =  nlay_s, 1, -1
+         zhsnow    =  MAX(0.0,dh_snowice(ji)-zdeltah)
+         zqsnow    =  zqsnow + q_s_b(ji,layer) * zhsnow
+      END DO
+
+!
+!------------------------------------------------------------------------------|
+!      S-3) New snow grid
+!------------------------------------------------------------------------------|
+!
+      ! indexes of the vectors
+      ntop1    =  1
+      nbot1    =  nlay_s
+
+      ! cotes and thicknesses
+      CALL ice_phy_grid( kideb , kiut , nlay_s , ht_s_b(ji), .FALSE., 
+     &                   "sno" )
+!
+!------------------------------------------------------------------------------|
+!      S-4) New snow enthalpy
+!------------------------------------------------------------------------------|
+!
+      CALL ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , 
+     &                    zthick0, deltaz_s_phy, zqh_s0 , zqh_s1 )
+
+      zqt_s_fin = 0.0 ! total heat content
+!
+!------------------------------------------------------------------------------|
+!      S-5) Recover snow temperature
+!------------------------------------------------------------------------------|
+!
+      WRITE(numout,*) ' Recover snow temperature '
+      WRITE(numout,*) ' nlay_s  : ', nlay_s
+      WRITE(numout,*) ' ji      : ', ji
+      WRITE(numout,*) ' ht_s_b  : ', ht_s_b(ji)
+      WRITE(numout,*) ' tpw     : ', tpw
+      WRITE(numout,*) ' rhon    : ', rhon
+      DO layer = 1, nlay_s
+         isnow   = INT( 1.0 - MAX( 0.0 , SIGN( 1.0d0, - ht_s_b(ji) ) ))
+         WRITE(numout,*) ' isnow : ', isnow
+         t_s_b(ji,layer)  =  isnow * ( tpw - ( zqh_s1(layer) / rhon / 
+     &                       MAX( deltaz_s_phy(layer) , zeps ) - lfus )
+     &                       / cpg ) +
+     &                       ( 1.0 - isnow ) * tpw
+         WRITE(numout,*) ' zqh_s1: ', zqh_s1(layer)
+         WRITE(numout,*) ' deltaz_s_phy : ', deltaz_s_phy(layer)
+         WRITE(numout,*) ' zeps         : ', zeps
+         WRITE(numout,*) ' lfus         : ', lfus
+         WRITE(numout,*) ' cpg          : ', cpg 
+         WRITE(numout,*) ' t_s_b        : ', t_s_b(ji,layer)
+         zqt_s_fin = zqt_s_fin + zqh_s1(layer)
+         q_s_b(ji,layer) = isnow * zqh_s1(layer) / 
+     &                     MAX( deltaz_s_phy(layer) , zeps )
+      END DO
+      WRITE(numout,*) ' t_s_b        : ', t_s_b(ji,1)
+      zqt_fin = zqt_s_fin
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Heat conservation, ice_th_remap , snow '
+         WRITE(numout,*) ' zqt_s_fin : ', zqt_s_fin
+         WRITE(numout,*) ' zqt_s_ini : ', zqt_s_ini
+         WRITE(numout,*) ' TS1. zqt_s_fin - zqt_s_ini : ', 
+     &                   zqt_s_fin - zqt_s_ini
+         WRITE(numout,*)
+      ENDIF
+
+!------------------------------------------------------------------------------!
+ 
+      !------------------------------!
+      !                              !
+      !     ICE redistribution       ! 
+      !                              !
+      !------------------------------!
+
+!------------------------------------------------------------------------------!
+
+!
+!------------------------------------------------------------------------------!
+!  I-1) Old ice grid                                                           !
+!------------------------------------------------------------------------------!
+!
+      ! indexes of the vectors
+      ntop0    =  1
+      nbot0    =  MAX(1, MIN( nlay_i + 1 - icboind + (1-icsuind)*icsuswi
+     &                      + snicswi, nlay_i + 2 ) )
+
+      ! cotes of the top of the layers
+      zm0(0)   =  0.0
+      DO layer = 1, nbot0-1
+         limsum    =  ((icsuswi*(icsuind+layer-1) + (1-icsuswi)*layer))*
+     &               (1-snicswi) + (layer-1)*snicswi
+         zm0(layer)=  icsuswi*dh_i_surf(ji) + snicswi*dh_snowice(ji)
+         DO layer_a = 1, limsum
+            zm0(layer) = zm0(layer) + deltaz_i_phy(layer_a)
+         END DO
+      END DO
+
+      zm0(nbot0) =  icsuswi*dh_i_surf(ji) + snicswi*dh_snowice(ji) + 
+     &              dh_i_bott(ji)
+      DO layer = 1, nlay_i
+         zm0(nbot0) = zm0(nbot0) + deltaz_i_phy(layer)
+      END DO
+      zm0(1)     =  snicswi*dh_snowice(ji) + (1-snicswi)*zm0(1)
+
+      ! thicknesses
+      DO layer = ntop0, nbot0
+         zthick0(layer)  =  zm0(layer) - zm0(layer-1)
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Ice redistribution ... '
+         WRITE(numout,*) ' ntop0 : ', ntop0
+         WRITE(numout,*) ' nbot0 : ', nbot0
+         WRITE(numout,*) ' zm0   : ', ( zm0(layer), layer = 0, nbot0)
+         WRITE(numout,*) ' zthick0: ', ( zthick0(layer), layer = ntop0, 
+     &                                  nbot0)
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  I-2) Old ice heat content                                                   |
+!------------------------------------------------------------------------------|
+!
+      !-------------------------
+      ! sources of heat content
+      !-------------------------
+      !- new ice
+      tmelts = - tmut * s_i_new + tpw
+      zqh_i_new =  rhog * ( cpg * ( tmelts - t_bo_b(ji) ) 
+     &             + lfus * ( 1.0 - ( tmelts - tpw ) /
+     &             ( t_bo_b(ji) - tpw ) ) - cpw * ( tmelts - tpw ) )
+     &             * zthick0(nbot0)
+
+      !- snow ice
+      zqh_i_sni =  rho0 * cpw * ( tpw - t_bo_b(ji) ) * dh_snowice(ji) * 
+     &            ( rhog - rhon ) / rhog * snicswi  ! generally positive
+      fsnic  =  - zqh_i_sni / ddtb
+      zqh_i_sni =  zqsnow + zqh_i_sni
+
+      !----------------------
+      ! sea ice heat content
+      !----------------------
+      zqh_i0(:) = 0.0
+      !- internal ice layers
+      DO layer = ntop0, nbot0
+          limsum = MAX( 1 , MIN( snicswi*(layer-1) 
+     &           + icsuswi * ( layer - 1 +  icsuind )
+     &           + ( 1 - icsuswi ) * ( 1 - snicswi ) * layer, nlay_i ) )
+          zqh_i0(layer) = q_i_b(ji,limsum) * zthick0(layer)
+          WRITE(numout,*) ' limsum : ', limsum, ' layer : ', layer
+      END DO
+        
+      !- boundary values 
+      zqh_i0(1)     =  snicswi * zqh_i_sni + ( 1 - snicswi ) * zqh_i0(1)
+      zqh_i0(nbot0) =  ( 1 - icboswi ) * zqh_i0(nbot0) + 
+     &                 icboswi * zqh_i_new
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zqh_i_new: ', zqh_i_new
+         WRITE(numout,*) ' zqh_i_sni: ', zqh_i_sni
+         WRITE(numout,*) ' zqh_i0: ', ( zqh_i0(layer), layer = ntop0, 
+     &                                  nbot0)
+      ENDIF
+
+      DO layer = ntop0, nbot0
+         zqt_i_ini = zqt_i_ini + zqh_i0(layer) 
+      END DO
+
+      zqt_ini = zqt_ini + zqt_i_ini ! includes zqsnic and zqsnow
+
+!
+!------------------------------------------------------------------------------|
+!  I-3) Old ice salt content                                                   |
+!------------------------------------------------------------------------------|
+!
+      ! basal new ice salt content
+      zsh_i_new = e_skel * oce_sal * MAX ( dh_i_bott(ji), 0.0 )
+      ! snow ice salt content
+      s_i_snic  =  ( rhog - rhon ) / rhog * oce_sal * 
+     &              frtr_si_phy ! snow ice salinity
+      zsh_i_sni = s_i_snic * dh_snowice(ji)
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' Salt sources : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' zsh_i_new : ', zsh_i_new
+         WRITE(numout,*) ' zsh_i_sni : ', zsh_i_sni
+      ENDIF
+
+      zsh_i0(:) = 0.0
+
+      DO layer = ntop0, nbot0
+          limsum =  snicswi*(layer-1) + icsuswi*(layer-1+icsuind)
+     &            + (1-icsuswi)*(1-snicswi)*layer
+          limsum =  MAX(1,MIN(snicswi*(layer-1) + icsuswi*(layer-1
+     &           +  icsuind)
+     &           + (1-icsuswi)*(1-snicswi)*layer, nlay_i))
+          zsh_i0(layer) = s_i_b(ji,limsum)*zthick0(layer)
+      END DO
+
+      zsh_i0(nbot0) =  (1-icboswi)* zsh_i0(nbot0) + icboswi * zsh_i_new
+      zsh_i0(1)     =  snicswi * zsh_i_sni + ( 1 - snicswi ) * zsh_i0(1)
+     
+!     z_ms_i_ini = 0.0
+!     DO layer = ntop0, nbot0
+!        z_ms_i_ini = z_ms_i_ini + zsh_i0(layer)
+!     END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' frtr_si_phy:', frtr_si_phy
+         WRITE(numout,*) ' oce_sal  : ', oce_sal
+         WRITE(numout,*) ' s_i_snic : ', s_i_snic
+         WRITE(numout,*) ' zsh_i0   : ', zsh_i0(ntop0:nbot0)
+         WRITE(numout,*)
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  I-4) New ice profile                                                        |
+!------------------------------------------------------------------------------|
+!
+      ! indexes of the vectors
+      ntop1    =  1 
+      nbot1    =  nlay_i
+
+      ! cotes and thicknesses
+      CALL ice_phy_grid( kideb , kiut , nlay_i , ht_i_b(ji), .FALSE., 
+     &                   "ice" )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' z_i_phy : ', ( z_i_phy(layer), 
+     &                   layer = ntop1, nbot1 )
+         WRITE(numout,*) ' deltaz_i_phy : ', ( deltaz_i_phy(layer), 
+     &                   layer = ntop1, nbot1 )
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  I-5) Redistribute ice heat content                                          |
+!------------------------------------------------------------------------------|
+!
+      ! Remapping ice enthalpy
+      CALL ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , 
+     &                    zthick0, deltaz_i_phy, zqh_i0 , zqh_i1 )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zqh_i1 : ',( zqh_i1(layer), layer = ntop1,
+     &                                  nbot1)
+         WRITE(numout,*)
+      ENDIF
+
+      DO layer = ntop1, nbot1
+         zqt_i_fin = zqt_i_fin + zqh_i1(layer) 
+      END DO
+
+      zqt_fin = zqt_fin + zqt_i_fin ! includes zqsnic and zqsnow
+!
+!------------------------------------------------------------------------------|
+!  I-6) Redistribute ice salt content                                          |
+!------------------------------------------------------------------------------|
+!
+      CALL ice_phy_relay( nbot0 , nbot1 , ntop0 , ntop1 , 
+     &                    zthick0, deltaz_i_phy, zsh_i0 , zsh_i1 )
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zsh_i1   : ', zsh_i1(ntop0:nbot0)
+         WRITE(numout,*)
+      ENDIF
+
+!
+!------------------------------------------------------------------------------|
+!  I-7) Heat conservation test                                                 |
+!------------------------------------------------------------------------------|
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Heat conservation, ice_th_remap , 
+     &   sea ice... '
+         WRITE(numout,*) ' zqt_i_fin : ', zqt_i_fin
+         WRITE(numout,*) ' zqt_i_ini : ', zqt_i_ini
+         WRITE(numout,*) ' TI1. zqt_i_fin - zqt_i_ini : ', 
+     &                   zqt_i_fin - zqt_i_ini
+         WRITE(numout,*)
+         WRITE(numout,*) ' - Heat conservation, total ... '
+         WRITE(numout,*) ' zqt_ini         : ', zqt_ini
+         WRITE(numout,*) ' zqt_fin         : ', zqt_fin
+         WRITE(numout,*) ' zqt_fin-zqt_ini : ', zqt_fin-zqt_ini
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  I-8) Recover energy of melting, salinity and temperature                    |
+!------------------------------------------------------------------------------|
+!
+      DO layer = 1, nlay_i
+         q_i_b(ji,layer) = zqh_i1(layer) / 
+     &                     MAX( deltaz_i_phy(layer) , zeps )
+      END DO
+
+      DO layer = 1, nlay_i
+         s_i_b(ji,layer) = zsh_i1(layer) / MAX( deltaz_i_phy(layer) , 
+     &                     zeps )
+      END DO
+
+      DO layer = 1, nlay_i
+         tmelts = -tmut*s_i_b(ji,layer) + tpw
+         aaa = cpg
+         bbb = (cpw-cpg)*(tmelts-tpw) + q_i_b(ji,layer)/ rhog
+     &       - lfus 
+         ccc = lfus * (tmelts-tpw)
+         discrim = SQRT( bbb*bbb - 4.0*aaa*ccc )
+         t_i_b(ji,layer) = tpw + (- bbb - discrim) / ( 2.0*aaa )
+      END DO
+!
+!------------------------------------------------------------------------------|
+!  I-9) Salt conservation test                                                 |
+!------------------------------------------------------------------------------|
+!
+      CALL ice_sal_column(kideb,kiut,z_ms_i_fin,s_i_b(ji,1:nlay_i),
+     &                    deltaz_i_phy, nlay_i, .FALSE.)
+      IF ( ln_write ) WRITE(numout,*) ' z_ms_i_fin : ',
+     &                z_ms_i_fin
+
+      ! Flux due to bottom and snow ice formation
+      zfgrml = zsh_i_new / ddtb
+      zfsigr = zsh_i_sni / ddtb
+
+      zfgrml = zfgrml + zfmelt
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zfgrml : ', zfgrml
+         WRITE(numout,*) ' zfsigr : ', zfsigr
+      ENDIF
+
+      zerror = 1.0e-9
+      CALL ice_sal_conserv(kideb,kiut,'ice_phy_remap: ',zerror,
+     &                           z_ms_i_ini,z_ms_i_fin,
+     &                           zfgrml, zfsigr, ddtb)
+
+ 10   CONTINUE
+
+      RETURN
+
+!-------------------------------------------------------------------------------
+! Fin de la routine ice_th_remap
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_rad.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_rad.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_rad.f	(revision 6)
@@ -0,0 +1,529 @@
+      SUBROUTINE ice_rad(nlay_s,nlay_i,kideb,kiut)
+
+!=============================================================================!
+!
+!     ice_rad : 
+!
+!     Transmission / absorption of radiation
+!     through the snow-ice system
+!
+!     (c) v1.0 Martouf, UCL-ASTR, June 2007. Nadal Federer 1 set partout
+!         v2.0 Oct 2011: clarification of snow and the SSL.
+!                        Les diables n'y sont pas
+!
+!     Practically, downwelling radiation decreases exponentially
+!     through the snow-ice surface, except near the surface
+!     The uppermost portion of the snow is highly scattering (Perovich,
+!     J. Glaciol., 2007). For sea ice, if melt has occured, a
+!     a highly scattering layer is formed near the surface (Light et
+!     al., JGR 2008). This layer is referred to as "Surface Scattering Layer" (SSL)
+!
+!     We assume that the surface layer, both in snow and ice, absorbs
+!     all near infrared radiation, so that the remaining radiation is
+!     only in the visible part of the SW spectrum.
+!
+!     Here, snow and sea ice are represented as a highly-scattering
+!     surface layer (thickness h_not_s / h_not_i) and a deeper layer
+!
+!     The surface layer has radiative properties zrad_kappa_i_su_x,
+!     zrad_kappa_s_su_x, 
+!     Depth has radiative properties zrad_kappa_s_de_x,
+!     zrad_kappa_i_de_x
+!
+!     Algae and detritus also absorb radiation
+! 
+!     If sea ice is snow covered the SSL has a depth equal to zero
+!
+!     2 schemes for the SSL are used
+!     ... more ...
+!
+!     2 discretizations for radiative transfer are coded
+!     ... more ...
+!
+!=============================================================================!
+!
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+!-----------------------------------------------------------------------------!
+
+! Local variables
+      REAL(8), DIMENSION(maxnlay) ::  
+     &   zkappa_alg , !: extinction coefficient for algae 
+     &   zkappa_det   !: extinction coefficient for detritus 
+
+      LOGICAL :: ln_write
+
+      zeps = 1.0e-20
+
+      ln_write = .FALSE.
+!==============================================================================!
+ 
+      WRITE(numout,*)
+      WRITE(numout,*) ' ** ice_rad : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~ '
+      WRITE(numout,*) ' c_rad_scheme : ', c_rad_scheme
+      WRITE(numout,*) ' c_rad_discr  : ', c_rad_discr
+      WRITE(numout,*) ' h_not_s: ', h_not_s
+      WRITE(numout,*) ' h_not_i: ', h_not_i
+
+      WRITE(numout,*)
+
+      DO ji = kideb, kiut
+!
+!------------------------------------------------------------------------------!
+!  1) Surface transmission parameter                                           !
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Surface transmission parameter '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+      ENDIF
+
+      !--------------------------------
+      ! Snow and surface melt switches
+      !--------------------------------
+      ! Is there snow or not ?
+      isnow   = INT( 1.0 - MAX( 0.0 , SIGN( 1.0d0 , - ht_s_b(ji) ) ) )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' Test isnow ', ji
+         WRITE(numout,*) ' ht_s_b : ', ht_s_b(ji)
+         WRITE(numout,*) ' SIGN   : ', SIGN( 1.0d0 , - ht_s_b(ji) )
+         WRITE(numout,*) ' MAX    : ', MAX( 0.0 , 
+     &                                 SIGN( 1.0d0 , - ht_s_b(ji) ) )
+         WRITE(numout,*) ' ARG    : ', 1.0 - MAX( 0.0 , SIGN( 1.0d0 , 
+     &                                 - ht_s_b(ji) ) )
+      ENDIF
+
+      ! Melting or not
+      imelt_su = INT( MAX( 0.0 , SIGN( 1.0d0 , t_su_b(ji)-tpw) ) )  ! 1 if surface melt
+      imelt_sn = INT( MAX( 0.0 , SIGN( 1.0d0 , t_s_b(ji,1)-tpw) ) ) ! 1 if snow melts
+      imelt = 0
+      IF ( ( imelt_su .EQ. 1 ) .OR. ( imelt_sn .EQ. 1 ) ) imelt = 1
+
+      !-----------------------------------
+      ! Surface transmissivity i_o (inot) 
+      !-----------------------------------
+      IF ( c_rad_scheme .EQ. 'INOT' ) THEN
+         z_inot_vis_snow = rad_inot_s_dry * ( 1.0 - imelt ) +
+     &                     rad_inot_s_wet * imelt
+         z_inot_vis_ice  = rad_inot_i_dry * ( 1.0 - imelt ) +
+     &                     rad_inot_i_wet * imelt
+         z_inot_vis = isnow * z_inot_vis_snow + 
+     &                ( 1.0 - isnow ) * z_inot_vis_ice
+!        z_inot_vis = isnow * rad_inot_s + ( 1.0 - isnow ) * rad_inot_i
+         z_inot     = z_inot_vis * fpar_fsw
+      ENDIF
+      IF ( c_rad_scheme .EQ. 'EXTC' ) THEN
+         z_inot = 1.0
+      ENDIF
+      ab(ji) = 1.0 - z_inot ! used in other routines
+
+      !-------------------------------------------
+      ! Solar radiation transmitted below the SSL
+      !-------------------------------------------
+      ftrice      =  fsolgb(ji) * ( 1.0 - ab(ji) )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' isnow : ', isnow
+         WRITE(numout,*) ' imelt : ', imelt
+         WRITE(numout,*) ' z_inot: ', z_inot
+         WRITE(numout,*) ' ab    : ', ab(ji)
+         WRITE(numout,*) ' ftrice : ', ftrice
+      ENDIF
+!
+!------------------------------------------------------------------------------!
+!  2) Extinction coefficients
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Extinction coefficients '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~'
+         WRITE(numout,*)
+      ENDIF
+
+      zmurad = 0.656 ! angle factor
+      zchla = 0.0    ! temporary value of chla in mg/m-3
+
+      ! Chlorophyll a interpolation
+      IF ( c_bio_model .EQ. 'KRILL' ) THEN 
+         CALL ice_bio_interp_bio2phy(kideb,kiut,nlay_i,.FALSE.)
+      ELSE
+         DO layer = 1, nlay_bio
+            chla_i(layer) = 0.0
+         END DO
+      ENDIF
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' chla_i : ', 
+     &                   ( chla_i(layer), layer = 1, nlay_i )
+         WRITE(numout,*)
+      ENDIF
+
+      ! chlorophyll and detritus extinction coefficients
+      DO layer = 1, nlay_i
+         zchla = chla_i(layer)
+         zkappa_alg(layer) = zchla * astar_alg / zmurad
+         zkappa_det(layer) = zkappa_alg(layer) * fdet_alg
+      END DO
+
+      ! snow and ice extinction coefficients
+      IF ( c_rad_scheme .EQ. 'INOT' ) THEN
+         zrad_kappa_s_su = 0.0
+         zrad_kappa_i_su = 0.0
+      ENDIF
+      IF ( c_rad_scheme .EQ. 'EXTC' ) THEN
+         zrad_kappa_s_su = ( 1 - imelt ) * rad_kappa_s_su_d +
+     &                     imelt * rad_kappa_s_su_m
+         zrad_kappa_i_su = ( 1 - imelt ) * rad_kappa_i_su_d + 
+     &                     imelt * rad_kappa_i_su_m
+      ENDIF
+
+      ! deep snow extinction coefficient
+      zrad_kappa_s_de = ( 1 - imelt ) * rad_kappa_s_de_d +
+     &                  imelt * rad_kappa_s_de_m
+
+      ! deep ice extinction coefficient
+      zrad_kappa_i_de = ( 1 - imelt ) * rad_kappa_i_de_d +
+     &                  imelt * rad_kappa_i_de_m
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zrad_kappa_s_su : ', zrad_kappa_s_su
+         WRITE(numout,*) ' zrad_kappa_s_de : ', zrad_kappa_s_de
+         WRITE(numout,*) ' zrad_kappa_i_de : ', zrad_kappa_i_de
+         WRITE(numout,*) ' zrad_kappa_i_su : ', zrad_kappa_i_su
+
+         WRITE(numout,*) ' zkappa_alg : ', ( zkappa_alg(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zkappa_det : ', ( zkappa_det(layer), 
+     &                   layer = 1, nlay_i )
+      ENDIF
+!
+!------------------------------------------------------------------------------!
+!  3) Radiation transmitted through / absorbed by snow                         !
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Radiation absorption in snow '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+      ENDIF
+
+      radtr_s(0) =  ftrice
+      zdh1   = MIN( h_not_s, ht_s_b(ji) )
+      zdh2   = MIN( MAX( ht_s_b(ji) - h_not_s, 0. ), ht_s_b(ji) )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ftrice : ', ftrice
+         WRITE(numout,*) ' zdh1   : ', zdh1
+         WRITE(numout,*) ' zdh2   : ', zdh2
+      ENDIF
+
+      ! scheme based on transmission
+      ! other scheme based on transmission, more exact, the other one seems
+      ! not to work for high transmission coefficient and small SSL
+      IF ( c_rad_discr .EQ. 'TRA' ) THEN
+         zi1        = radtr_s(0) * EXP( -zrad_kappa_s_su * zdh1 )
+         radtr_s(1) = zi1 * EXP( -zrad_kappa_s_de * zdh2 )
+         radab_s(1) = radtr_s(0) - radtr_s(1)
+         IF ( ln_write) WRITE(numout,*) ' zi1    : ', zi1
+      ENDIF
+
+      ! scheme based on absorption
+      IF ( c_rad_discr  .EQ. 'ABS' ) THEN
+         zrada1 = radtr_s(0) * zdh1 * zrad_kappa_s_su * 
+     &            EXP( - zrad_kappa_s_su * zdh1 )
+         zi1    = radtr_s(0) - zrada1
+         zrada2 = zi1 * zdh2 * zrad_kappa_s_de * 
+     &            EXP( - zrad_kappa_s_de * zdh2 )
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' zrada1 : ', zrada1
+            WRITE(numout,*) ' zi1    : ', zi1
+            WRITE(numout,*) ' zrada2 : ', zrada2
+         ENDIF
+
+         radab_s(1) = zrada1 + zrada2
+         radtr_s(1) = radtr_s(0) - radab_s(1)
+      ENDIF
+         
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ht_s_b : ', ht_s_b(ji)
+         WRITE(numout,*) ' radtr_s : ', 
+     &                   ( radtr_s(layer) , layer = 0, nlay_s )
+         WRITE(numout,*) ' radab_s : ', 
+     &                   ( radab_s(layer) , layer = 1, nlay_s )
+      ENDIF
+!
+!------------------------------------------------------------------------------!
+!  4) Radiation transmitted through / absorbed by ice                          !
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' Radiation absorption in ice '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*)
+      ENDIF
+
+      ! transmitted at the upper ice layer
+      radtr_i(0) = isnow * radtr_s(nlay_s) + ( 1. - isnow ) * ftrice
+      ! thickness of surface SSL in sea ice is zero if there is no snow
+      zh_ssl = isnow * 0. + ( 1. - isnow ) * h_not_i 
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zh_ssl : ', zh_ssl
+      ENDIF
+      
+      ! radiation absorbed physically and biologically in each layer
+      zz0 = 0.
+      zz1 = 0.
+      DO layer = 1, nlay_i
+         zz1 = zz1 + deltaz_i_phy(layer)
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' zz0     : ', zz0
+            WRITE(numout,*) ' zz1     : ', zz1
+         ENDIF
+
+         zdh1    = MIN ( MAX ( zh_ssl - zz0 , 0. ) , 
+     &                   deltaz_i_phy(layer) )  ! part of the ice layer belonging to the SSL
+         zdh2    = MIN ( MAX ( zz1 - zh_ssl , 0. ) , 
+     &                   deltaz_i_phy(layer) )  ! part of the ice layer belonging to the deep ice
+         zz0 = zz1
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' zh_ssl  : ', zh_ssl        
+            WRITE(numout,*) ' zz1-zh_ssl ',zz1 - zh_ssl 
+            WRITE(numout,*) ' deltaz_i_phy : ', deltaz_i_phy(layer)
+
+            WRITE(numout,*) ' '
+            WRITE(numout,*) ' layer : ', layer
+            WRITE(numout,*) ' zdh1  : ', zdh1
+            WRITE(numout,*) ' zdh2  : ', zdh2
+            WRITE(numout,*) ' deltaz_i_phy : ', deltaz_i_phy(layer)
+            WRITE(numout,*) ' '
+         ENDIF
+
+         ! Extinction coefficient in the SSL
+         zkappa1_phy = zrad_kappa_i_su + zkappa_det(layer)  ! physical extinction in SSL
+         zkappa1     = zkappa1_phy     + zkappa_alg(layer)  ! total extinction
+
+         ! Extinction coefficient deeper in the ice
+         zkappa2_phy = zrad_kappa_i_de + zkappa_det(layer)  ! physical extinction at depth
+         zkappa2     = zkappa2_phy     + zkappa_alg(layer)  ! total extinction at depth
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' zkappa1_phy : ', zkappa1_phy
+            WRITE(numout,*) ' zkappa1     : ', zkappa1
+            WRITE(numout,*) ' zkappa2_phy : ', zkappa2_phy
+            WRITE(numout,*) ' zkappa2     : ', zkappa2
+         ENDIF
+
+         !------------------------------
+         ! Scheme based on transmission
+         !------------------------------
+         IF ( c_rad_discr .EQ. 'TRA' ) THEN
+            zi1         = radtr_i(layer-1) * EXP ( -zkappa1*zdh1 )
+            WRITE(numout,*) ' Discretization : ', 'TRA'
+            WRITE(numout,*) ' zi1 : ', zi1
+            WRITE(numout,*)
+
+            ! transmitted radiation
+            radtr_i(layer) =  zi1 * EXP( -zkappa2 * zdh2 )
+            ! absorbed radiation
+            radab_i(layer) =  radtr_i(layer-1) - radtr_i(layer)
+
+            ! physically absorbed
+            radab_phy_i(layer) = radab_i(layer) * deltaz_i_phy(layer)
+     &                 * ( zkappa1_phy * zdh1 / MAX( zkappa1, zeps)
+     &                   + zkappa2_phy * zdh2 / MAX( zkappa2, zeps) )
+
+            IF ( ln_write ) THEN
+               WRITE(numout,*) ' deltaz_i_phy : ', deltaz_i_phy(layer)
+               WRITE(numout,*) ' zkappa2      : ', zkappa2
+               WRITE(numout,*) ' zkappa2_phy  : ', zkappa2_phy
+               WRITE(numout,*) ' zdh2         : ', zdh2
+               WRITE(numout,*) ' radab_i      : ', radab_i(layer)
+               WRITE(numout,*) ' zkappa1      : ', zkappa1
+               WRITE(numout,*) ' zkappa1_phy  : ', zkappa1_phy
+               WRITE(numout,*) ' zdh1         : ', zdh1
+            ENDIF
+
+            ! biologically absorbed
+            radab_alg_i(layer) = zkappa_alg(layer) * radab_i(layer) 
+     &                         / deltaz_i_phy(layer)
+     &                         * ( zdh1 / MAX ( zkappa1, zeps )
+     &                           + zdh2 / MAX ( zkappa2, zeps ) )
+
+         ENDIF
+
+         !----------------------------
+         ! Scheme based on absorption
+         !----------------------------
+         IF ( c_rad_discr .EQ. 'ABS' ) THEN
+            zdummy      = radtr_i(layer-1) * zdh1 *
+     &                    EXP( - zkappa1 * zdh1 )
+            zrada1_phy  = zkappa1_phy * zdummy                 ! physically absorbed
+            zrada1_alg  = zkappa_alg(layer) * zdummy           ! biologically absorbed
+            zrada1      = zrada1_phy + zrada1_alg              ! total absorption
+            zi1         = radtr_i(layer-1) - zrada1            ! radiance available below the SSL
+
+            IF ( ln_write) THEN
+               WRITE(numout,*) ' Discretization : ', 'ABS'
+               WRITE(numout,*) ' zi1 : ', zi1
+               WRITE(numout,*)
+               WRITE(numout,*) ' zdummy      : ', zdummy
+               WRITE(numout,*) ' zrada1_phy  : ', zrada1_phy
+               WRITE(numout,*) ' zrada1_alg  : ', zrada1_alg
+               WRITE(numout,*) ' zrada1      : ', zrada1
+            ENDIF
+
+            zdummy      = zi1 * zdh2 * EXP ( - zkappa2 * zdh2 )
+            zrada2_phy  = zkappa2_phy * zdummy                 ! physically absorbed
+            zrada2_alg  = zkappa_alg(layer) * zdummy           ! biologically absorbed
+            zrada2      = zrada2_phy + zrada2_alg              ! total absorption
+
+            IF ( ln_write) THEN
+               WRITE(numout,*) ' zdummy      : ', zdummy
+               WRITE(numout,*) ' zrada2_phy  : ', zrada2_phy
+               WRITE(numout,*) ' zrada2_alg  : ', zrada2_alg
+               WRITE(numout,*) ' zrada2      : ', zrada2
+            ENDIF
+
+            ! Cumulated absorption
+            radab_phy_i(layer) = zrada1_phy + zrada2_phy
+            radab_alg_i(layer) = zrada1_alb + zrada2_alg
+            radab_i(layer)     = radab_phy_i(layer) + radab_alg_i(layer)
+
+            ! Transmission below the layer
+            radtr_i(layer)     = radtr_i(layer-1) - radab_phy_i(layer)
+     &                                         - radab_alg_i(layer)
+         ENDIF
+
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' radab_phy_i : ', radab_phy_i(layer)
+            WRITE(numout,*) ' radab_alg_i : ', radab_alg_i(layer)
+            WRITE(numout,*) ' radab_i     : ', radab_i(layer)
+            WRITE(numout,*) ' sum of both : ', radab_phy_i(layer) 
+     &                                       + radab_alg_i(layer)
+            WRITE(numout,*) ' radtr_i     : ', radtr_i(layer)
+         ENDIF
+
+      END DO
+
+      ! radiation sent to the ocean
+      ftroce = radtr_i(nlay_i)
+       
+!
+!------------------------------------------------------------------------------!
+!  5) PAR (phy and bio grids)
+!------------------------------------------------------------------------------!
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' PAR '
+         WRITE(numout,*) ' ~~~~'
+         WRITE(numout,*)
+      ENDIF
+      ! PAR on phy grid (top of each layer)
+      ! this choice was made to minimize sensitivity to grid type at comparable resolution)
+
+      IF ( ln_write ) WRITE(numout,*) ' * physical grid ... '
+
+      WRITE(numout,*) ' qpar_fsw : ', qpar_fsw
+      WRITE(numout,*) ' fpar_fsw : ', fpar_fsw
+
+      DO layer = 1, nlay_i
+         par(layer)         = qpar_fsw / fpar_fsw * radtr_i(layer-1)
+      END DO
+
+!     ! PAR on bio grid (top of each layer)
+      IF ( ln_write ) WRITE(numout,*) ' * biological grid ... '
+
+      DO layer_bio = 1, nlay_bio
+         ! identify in which layer the upper boundary of the bio layer is
+         DO layer_phy = 1, nlay_bio
+            zzb = zb_i_bio(layer_bio-1)
+            zzf1 = zb_i_phy(layer_phy-1)
+            zzf2 = zb_i_phy(layer_phy)
+            IF ( ( zzb .GE. zzf1 ) .AND. ( zzb .LT. zzf2 ) ) 
+     &         zindex = layer_phy
+         END DO
+         zm    = ( radtr_i(zindex) - radtr_i(zindex-1) ) / 
+     &           ( zb_i_phy(zindex) - zb_i_phy(zindex-1) )
+         zdh   = zb_i_bio(layer_bio-1) - zb_i_phy(zindex-1)
+         zdrad = zm * zdh
+         par_bio(layer_bio) = radtr_i(zindex-1) + zdrad  ! at the upper interface of the layer
+
+!        IF ( ln_write ) THEN
+!           WRITE(numout,*)
+!           WRITE(numout,*) ' layer    : ', layer_bio
+!           WRITE(numout,*) ' zindex   : ', zindex
+!           WRITE(numout,*) ' zb_i_bio : ', zb_i_bio(layer_bio-1)
+!           WRITE(numout,*) ' zb_i_phy : ', zb_i_phy(zindex-1), 
+!    &                                   zb_i_phy(zindex)
+!           WRITE(numout,*) ' radtr_i  : ', radtr_i(zindex-1),
+!    &                                   radtr_i(zindex)
+!           WRITE(numout,*) ' In W/m2 ... '
+!           WRITE(numout,*) ' par_bio  : ', par_bio(layer_bio)
+!        ENDIF
+
+         par_bio(layer_bio) = par_bio(layer_bio) * qpar_fsw / fpar_fsw
+
+!        IF ( ln_write ) THEN
+!           WRITE(numout,*) ' In microE/m2/s ... '
+!           WRITE(numout,*) ' par_bio  : ', par_bio(layer_bio)
+!        ENDIF
+
+      END DO
+         
+!
+!------------------------------------------------------------------------------!
+!  6) Conservation check
+!------------------------------------------------------------------------------!
+!
+      sumrad = radab_s(1)
+      DO layer = 1, nlay_i
+         sumrad = sumrad + radab_i(layer) 
+      END DO
+      WRITE(numout,*) ' Conservation check '
+      WRITE(numout,*) ' ftrice - ftroce : ', ftrice-ftroce
+      WRITE(numout,*) ' sumrad          : ', sumrad
+
+      ! Final write
+      WRITE(numout,*)
+      WRITE(numout,*) ' i0     : ', 1.0-ab(ji)
+      WRITE(numout,*) ' ftrice : ', ftrice
+      WRITE(numout,*) ' ftroce : ', ftroce
+      WRITE(numout,*) ' radtr_i : ', 
+     &                ( radtr_i(layer) , layer = 0, nlay_i )
+      WRITE(numout,*) ' radab_phy_i : ', 
+     &                ( radab_phy_i(layer) , layer = 1, nlay_i )
+      WRITE(numout,*) ' radab_alg_i : ', 
+     &                ( radab_alg_i(layer) , layer = 1, nlay_i )
+      WRITE(numout,*) ' par     : ', ( par(layer), layer = 1, nlay_i )
+      WRITE(numout,*) ' par_bio : ', ( par_bio(layer), 
+     &                                 layer = 1, nlay_bio )
+
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' End of ice_rad '
+      WRITE(numout,*) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
+
+      END DO !ji
+
+!==============================================================================!
+! end of the subroutine
+
+      END SUBROUTINE
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_column.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_column.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_column.f	(revision 6)
@@ -0,0 +1,50 @@
+      SUBROUTINE ice_sal_column( kideb,kiut,zmt_i,zs_i,zdeltaz,nlay_i,
+     &                           ln_write )
+
+      !-----------------------------------------------------------------------!
+      ! This routine sums the mass of salt over the whole sea ice column
+      ! (c) Martin Vancoppenolle, September 2008
+      !-----------------------------------------------------------------------!
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+
+      INTEGER :: 
+     &  ji          , ! : index for space
+     &  jk            ! : index for ice layers
+
+      REAL(8) ::
+     &   zmt_i        ! : total mass of salt
+      REAL(8), DIMENSION(maxnlay) ::
+     &   zs_i         ! : bulk salinity
+      REAL(8), DIMENSION(maxnlay) ::
+     &   zdeltaz      ! : thickness of the layers
+
+      LOGICAL ::
+     &   ln_write
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' *** ice_sal_column : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' kideb : ', kideb
+         WRITE(numout,*) ' kiut  : ', kiut 
+         WRITE(numout,*) ' zmt_i : ', zmt_i
+         WRITE(numout,*) ' zs_i  : ', ( zs_i(jk), jk = 1, nlay_i )
+         WRITE(numout,*) ' zdeltaz:', ( zdeltaz(jk), jk = 1, nlay_i )
+      ENDIF
+
+      zmt_i = 0.0
+      DO jk = 1, nlay_i
+         zmt_i = zmt_i + zs_i(jk) * zdeltaz(jk)
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zmt_i : ', zmt_i
+      ENDIF
+
+
+      !=============================================================================!
+      !-- End of ice_sal_column --
+      RETURN
+
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_conserv.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_conserv.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_conserv.f	(revision 6)
@@ -0,0 +1,72 @@
+      SUBROUTINE ice_sal_conserv(kideb,kiut,message,err,
+     &                           zmb0,zmb1,zfb,zfsu,zdt)
+
+!=============================================================================!
+
+! This routine tests conservation of the mass of salt
+! (c) Martin Vancoppenolle, September 2008
+ 
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+
+      CHARACTER(len=15) :: 
+     &   message       ! : message indicating the name of the routine calling
+
+      REAL(8) ::
+     &   err
+
+      REAL(8) ::
+     &   zmb0 ,
+     &   zmb1 ,
+     &   zfb  ,
+     &   zfsu
+
+      REAL(8) ::
+     &   zdt 
+         
+      INTEGER :: 
+     &   ji          , ! : index for space
+     &   jk          , ! : index for ice layers
+     &   jn            ! : index for tracers
+
+      REAL(8) ::
+     &   zdm           ! : actual mass variation
+     &   zdmf
+
+!=============================================================================!
+
+      WRITE(numout,*) ' ice_sal_conserv : '
+      WRITE(numout,*) ' ~~~~~~~~~~~~~~~ '
+      WRITE(numout,*) ' message     : ', message
+      WRITE(numout,*) ' error       : ', err
+      WRITE(numout,*) ' kideb, kiut : ', kideb, kiut
+      WRITE(numout,*) ' ddtb        : ', zdt
+      WRITE(numout,*) ' ms_i_init  : ', zmb0
+      WRITE(numout,*) ' ms_i_final : ', zmb1
+
+      zdm = ( zmb1 - zmb0 ) / zdt
+      zdmf = zfb + zfsu
+
+      WRITE(numout,*) ' Actual mass variation zdm       : ', zdm
+      WRITE(numout,*) ' Mass variation from fluxes zdmf : ', zdmf
+      WRITE(numout,*) ' Sal conserv error : ', ABS(zdm-zdmf)
+
+      WRITE(503,*) zmb1, ABS(zdm-zdmf)*zdt
+         
+      IF ( ABS ( zdm - zdmf ) .GT. err ) THEN
+         WRITE(numout,*) ' Conservation error after ', message
+         WRITE(numout,*) ' Error                           : ', 
+     &                   ABS( zdm - zdmf )
+         WRITE(numout,*) ' Actual mass variation zdm       : ', zdm
+         WRITE(numout,*) ' Mass variation from fluxes zdmf : ', zdmf
+         WRITE(numout,*)
+         WRITE(numout,*) ' ms_i_init       : ', zmb0
+         WRITE(numout,*) ' ms_i_final      : ', zmb1
+!           WRITE(numout,*) ' s_i_b     : ', ( s_i_b(ji,layer), 
+!    &                      layer = 1, nlay_i )
+      ENDIF
+      RETURN
+
+!=============================================================================!
+!-- End of ice_sal_conserv --
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff.f	(revision 6)
@@ -0,0 +1,552 @@
+      SUBROUTINE ice_sal_diff(nlay_i,kideb,kiut)
+
+      !!------------------------------------------------------------------
+      !!                ***         ROUTINE ice_sal_diff      ***
+      !!
+      !! ** Purpose :
+      !!        This routine computes new salinities in the ice
+      !!
+      !! ** Method  : Vertical salinity profile computation 
+      !!              Resolves brine transport equation
+      !!           
+      !! ** Steps
+      !!
+      !! ** Arguments
+      !!
+      !! ** Inputs / Outputs
+      !!
+      !! ** External
+      !!
+      !! ** References : Vancop. et al., 2008
+      !!
+      !! ** History  : 
+      !!    (06-2003) Martin Vancop. LIM1D
+      !!    (06-2008) Martin Vancop. BIO-LIM
+      !!    (09-2008) Martin Vancop. Explicit gravity drainage
+      !!
+      !!------------------------------------------------------------------
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      REAL(8), DIMENSION(nlay_i) ::  
+     &   z_ms_i             ,    !: mass of salt times thickness 
+     &   z_sbr_i                 !: brine salinity
+
+      REAL(8), DIMENSION(nlay_i) ::  !: dummy factors for tracer equation
+     &   za                 ,    !: all
+     &   zb                 ,    !: gravity drainage
+     &   zc                 ,    !: upward advective flow
+     &   ze                 ,    !: downward advective flow
+     &   zind               ,    !: independent term in the tridiag system
+     &   zindtbis           ,    !:
+     &   zdiagbis                !:
+
+      REAL(8), DIMENSION(nlay_i,3) :: !: dummy factors for tracer equation
+     &   ztrid                   !: tridiagonal matrix
+
+      REAL(8) ::  
+     &   zdummy1            ,    !: dummy factors
+     &   zdummy2            ,    !: 
+     &   zdummy3            ,    !: 
+     &   zswitchs           ,    !: switch for summer drainage
+     &   zeps      = 1.0e-20     !: numerical limit
+
+      ! Rayleigh number computation
+      REAL(8) ::
+     &   ze_i_min           ,    !: minimum brine volume
+     &   zcp                ,    !: temporary scalar for sea ice specific heat
+     &   zk                 ,    !: temporary scalar for sea ice thermal conductivity
+     &   zalphara                !: multiplicator for diffusivity
+
+      REAL(8), DIMENSION(nlay_i) ::  
+     &   zsigma             ,    !: brine salinity at layer interfaces
+     &   zperm              ,    !: permeability
+     &   zpermin            ,    !: minimum permeability
+     &   zrhodiff           ,    !: density difference
+     &   zlevel             ,    !: height of the water column
+     &   zthdiff                 !: thermal diffusivity
+
+      INTEGER ::  
+     &   layer2             ,    !: layer loop index
+     &   indtr                   !: index of tridiagonal system
+
+      CHARACTER(len=4)      ::  
+     &   bc = 'conc'             !: Boundary condition 'conc' or 'flux'
+
+      REAL(8) ::  
+     &   z_ms_i_ini         ,    !: initial mass of salt
+     &   z_ms_i_fin         ,    !: final mass of salt
+     &   z_fs_b             ,    !: basal flux of salt
+     &   z_fs_su            ,    !: surface flux of salt
+     &   z_dms_i                 !: mass variation       
+
+      LOGICAL ::
+     &   ln_write           ,
+     &   ln_con             ,
+     &   ln_sal
+
+      ln_write = .TRUE.  ! write outputs
+      ln_con   = .TRUE.  ! conservation check
+      ln_sal   = .TRUE.  ! compute salinity variations or not
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' ** ice_sal_diff : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' ln_sal = ', ln_sal
+         WRITE(numout,*) ' ln_grd = ', ln_grd
+         WRITE(numout,*) ' ln_flu = ', ln_flu
+         WRITE(numout,*) ' ln_flo = ', ln_flo
+      ENDIF
+      WRITE(numout,*) " nlay_i : ", nlay_i
+
+      IF ( ln_sal ) THEN
+!
+!------------------------------------------------------------------------------|
+! 1) Initialization
+!------------------------------------------------------------------------------|
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Initialization ... '
+      ENDIF
+
+      DO 10 ji = kideb, kiut
+
+      ! brine diffusivity
+      diff_br(:) = 0.0
+
+      !---------------------------
+      ! Brine volume and salinity
+      !---------------------------
+      DO layer = 1, nlay_i
+         e_i_b(layer) = - tmut * s_i_b(ji,layer) / ( t_i_b(ji,layer) 
+     &                - tpw )
+         z_sbr_i(layer) = s_i_b(ji,layer) / e_i_b(layer)
+      END DO
+
+      !--------------------
+      ! Conservation check
+      !--------------------
+      IF ( ln_con ) THEN 
+         CALL ice_sal_column( kideb , kiut , z_ms_i_ini , 
+     &                    s_i_b(1,1:nlay_i),
+     &                    deltaz_i_phy, nlay_i, .FALSE. )
+      ENDIF ! ln_con
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' nlay_i      : ', nlay_i
+         WRITE(numout,*) ' kideb       : ', kideb
+         WRITE(numout,*) ' kiut        : ', kiut 
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' deltaz_i_phy : ', ( deltaz_i_phy(layer),  
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_i_phy      : ', ( z_i_phy(layer),  
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' s_i_b       : ', ( s_i_b    (ji,layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' t_i_b       : ', ( t_i_b    (ji,layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' e_i_b       : ', ( e_i_b      (layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_sbr_i     : ', ( z_sbr_i    (layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*)
+      ENDIF ! ln_write
+
+ 10   CONTINUE
+
+!
+!------------------------------------------------------------------------------|
+! 2) Rayleigh-number-based diffusivity
+!------------------------------------------------------------------------------|
+!
+! Diffusivity is a function of the local Rayleigh number
+! see Notz and Worster, JGR 2008
+! Diffusivity, layer represents the interface'
+! between layer and layer-1 '
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Rayleigh-number based diffusivity ... '
+         WRITE(numout,*) ' '
+      ENDIF
+
+      DO 20 ji = kideb, kiut 
+
+      !-----------------------------------------
+      ! Brine salinity between layer interfaces
+      !-----------------------------------------
+      DO layer = 1, nlay_i - 1
+         zdummy1 = t_i_b(ji,layer) + deltaz_i_phy(layer) / 2. * 
+     &             ( t_i_b(ji,layer+1) - t_i_b(ji,layer) ) /
+     &             ( z_i_phy(layer+1) - z_i_phy(layer) ) - tpw
+         zsigma(layer) = - zdummy1 / tmut
+      END DO
+      zsigma(nlay_i) = - ( t_i_b(ji,nlay_i) - tpw ) / tmut
+
+      !--------------------
+      ! Density difference
+      !--------------------
+      DO layer = 1, nlay_i  
+         zrhodiff(layer) = - beta_ocs * ( oce_sal - zsigma(layer) )
+      END DO
+
+      !------------------------------------------
+      ! Minimum permeability under current level
+      !------------------------------------------
+      DO layer = 1, nlay_i
+         ze_i_min = 99999.0 
+         DO layer2 = layer, nlay_i
+            ze_i_min = MIN( ze_i_min , e_i_b(layer2) )
+            zpermin(layer) = 1.0e-17 * ( ( 1000. * ze_i_min )**3.1 )
+         END DO
+      END DO ! layer
+
+      !------------------------------------------------
+      ! length of the water column under current level
+      !------------------------------------------------
+      DO layer = nlay_i, 1, -1
+         zlevel(layer) = 0.0
+         DO layer2 = layer, nlay_i
+            zlevel(layer) = zlevel(layer) + deltaz_i_phy(layer2)
+         END DO
+      END DO
+      zlevel(nlay_i) = deltaz_i_phy(nlay_i) / 2.0
+
+      !---------------------
+      ! Thermal diffusivity
+      !---------------------
+      zkimin = 0.1
+      DO layer = 1, nlay_i - 1
+         zdummy1 = t_i_b(ji,layer) + deltaz_i_phy(layer) / 2. * 
+     &             ( t_i_b(ji,layer+1) - t_i_b(ji,layer) ) /
+     &             ( z_i_phy(layer+1) - z_i_phy(layer) ) - tpw
+         zdummy2 = s_i_b(ji,layer) + deltaz_i_phy(layer) / 2. * 
+     &             ( s_i_b(ji,layer+1) - s_i_b(ji,layer) ) /
+     &             ( z_i_phy(layer+1) - z_i_phy(layer) )
+         zcp = cpg + lfus * tmut * zdummy2 / 
+     &        MAX( zdummy1 * zdummy1 , zeps )
+         zk = xkg + betak1 * zdummy2 / 
+     &        MIN( -zeps , zdummy1 ) - betak2 * zdummy1
+         zk = MAX( zk, zkimin )
+         zthdiff(layer) = zk / ( rhog * zcp )
+      END DO
+
+      zcp = cpg + lfus * tmut * s_i_b(ji,nlay_i) / 
+     &     MAX( ( t_i_b(ji,nlay_i) - tpw ) * ( t_i_b(ji,nlay_i) - tpw ),
+     &     zeps )
+      zk = xkg + betak1 * s_i_b(ji,nlay_i) / 
+     &     MIN( -zeps , t_i_b(ji,nlay_i) - tpw ) 
+     &   - betak2 * ( t_i_b(ji,nlay_i) - tpw )
+      zk = MAX( zk, zkimin )
+      zthdiff(nlay_i) = zk / ( rhog * zcp )
+
+      !-----------------
+      ! Rayleigh number
+      !-----------------
+      DO layer = 1, nlay_i
+         rayleigh(layer) = gpes * MAX(zrhodiff(layer),0.0) * 
+     &                     zpermin(layer) * zlevel(layer) / 
+     &                     ( zthdiff(layer) * visc_br )
+      END DO
+
+      !-------------------
+      ! Brine Diffusivity
+      !-------------------
+      DO layer = 1, nlay_i
+         zalphara = ( TANH( ra_smooth * ( rayleigh(layer) - ra_c ) ) 
+     &            + 1 ) / 2.0
+         diff_br(layer) = ( 1.0 - zalphara ) * d_br_mol + 
+     &                    zalphara * ( d_br_tur )
+         IF ( .NOT. ln_grd ) diff_br(layer) = 0.
+      END DO
+
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zsigma   : ', ( zsigma(layer),  
+     &                   layer = 1, nlay_i)
+         WRITE(numout,*) ' zrhodiff : ', ( zrhodiff(layer),
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zpermin : ', ( zpermin(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zthdiff  : ', ( zthdiff(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zlevel  : ', ( zlevel(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' rayleigh      : ', ( rayleigh(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' diff_br  : ', ( diff_br(layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*)
+      ENDIF
+
+ 20   CONTINUE
+
+!
+!------------------------------------------------------------------------------|
+! 3) Flooding and flushing velocities
+!------------------------------------------------------------------------------|
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Flooding and flushing velocities '
+         WRITE(numout,*) ' '
+      ENDIF
+
+      DO 30 ji = kideb, kiut 
+         !-----------------------
+         ! Permeability switches
+         !-----------------------
+         ! Permeability switch = 1 if brine volume fraction > e_thr_flu
+         zswitch_per = 1.0
+         zbvmin   = 1.0
+         DO layer = 1, nlay_i
+            zbvmin = MIN( e_i_b(layer) , zbvmin ) ! minimum brine volume
+         END DO
+         IF ( zbvmin .LT. e_thr_flu ) zswitch_per = 0.0
+
+         ! Summer switch = 1 if Tsu ge tpw and min brine volume superior than e_thr_flu
+         zswitchs = MAX( 0.0, SIGN ( 1.0d0, t_su_b(ji) - tpw ) ) ! 0 if winter, 1 if summer
+         zswitchs = zswitchs * zswitch_per
+
+         !-------------------
+         ! Flooding velocity
+         !-------------------
+         zdhitot = dh_i_surf(ji) + dh_i_bott(ji) + dh_snowice(ji)
+         zdhstot = dh_s_melt(ji)
+         w_flood = ( ( rho0 - rhog ) / rho0 * zdhitot - 
+     &             rhon / rho0 * zdhstot ) / ddtb * zswitch_per
+         IF ( w_flood .GT. 0 ) THEN
+            z_flood = 0.0
+         ELSE
+            z_flood = 1.0
+         ENDIF
+         IF ( .NOT. ln_flo ) w_flood = 0.
+
+         !------------------
+         ! Percolating flux
+         !------------------
+         ! Percolating flow ( rho dh * beta * switch / rho0 )
+         qsummer = ( - rhog * MIN ( dh_i_surf(ji) , 0.0 ) 
+     &               - rhon * MIN ( dh_s_tot(ji)  , 0.0 ) )  
+         qsummer = qsummer * flu_beta * zswitchs / 1000.0 ! 1000 is a ref density for brine
+   
+         w_flush = qsummer / ddtb / e_i_b(1)
+
+         IF ( .NOT. ln_flu ) THEN
+            w_flush = 0.
+            qsummer = 0.
+         ENDIF
+   
+         IF ( ln_write ) THEN
+            WRITE(numout,*) ' zswitchs : ', zswitchs
+            WRITE(numout,*) ' w_flush          : ', w_flush
+            WRITE(numout,*) ' w_flood          : ', w_flood
+         ENDIF
+
+ 30   CONTINUE
+!
+!------------------------------------------------------------------------------|
+! 4) Compute dummy factors for tracer diffusion equation
+!------------------------------------------------------------------------------|
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Compute dummy factors for tracer diffusion'
+         WRITE(numout,*) ' '
+      ENDIF
+
+      DO 40 ji = kideb, kiut 
+      !----------------
+      ! za factors
+      !----------------
+      DO layer = 1, nlay_i
+         za(layer) = ddtb / ( deltaz_i_phy(layer) * e_i_b(layer) )
+      END DO
+
+      !--------------------
+      ! zb, zc, ze factors
+      !--------------------
+      DO layer = 1, nlay_i - 1
+         ! interpolate brine volume at the interface between layers
+         zdummy1 = ( e_i_b(layer + 1 ) - e_i_b(layer) ) /  
+     &             ( z_i_phy(layer + 1) - z_i_phy(layer) )
+         zdummy2 = deltaz_i_phy(layer) / 2.0
+         zdummy3 = e_i_b(layer) + zdummy1 * zdummy2
+         zb(layer) = zdummy3 * diff_br(layer) / 
+     &               ( z_i_phy(layer + 1) - z_i_phy(layer) )
+         zc(layer) = w_flood * zdummy3 * z_flood
+         ze(layer) = ( w_flood * ( 1. - z_flood ) + w_flush ) * zdummy3
+! old qsummer scheme
+!        ze(layer) = ( w_flood * ( 1. - z_flood ) ) * zdummy3 + 
+!    &               zswitchs * qsummer / ddtb
+      END DO
+
+      ! Fixed boundary condition (imposed cc.)
+      zb(nlay_i) = 2. * e_i_b(nlay_i) / 
+     &             deltaz_i_phy(nlay_i) * diff_br(nlay_i)
+      zc(nlay_i) = w_flood * e_i_b(nlay_i) * z_flood
+      ze(nlay_i) = ( w_flood * ( 1. - z_flood ) + w_flush ) * 
+     &             e_i_b(nlay_i)
+!     ze(nlay_i) = ( w_flood * ( 1. - z_flood ) ) * e_i_b(nlay_i) +
+!    &               zswitchs * qsummer / ddtb
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' -Dummy factors '
+         WRITE(numout,*) ' za       : ', ( za (layer),
+     &                   layer = 1, nlay_i)
+         WRITE(numout,*) ' zb       : ', ( zb (layer),
+     &                   layer = 1, nlay_i)
+         WRITE(numout,*) ' zc       : ', ( zc (layer),
+     &                   layer = 1, nlay_i)
+         WRITE(numout,*) ' ze       : ', ( ze (layer),
+     &                   layer = 1, nlay_i)
+      ENDIF
+
+ 40   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 5) Tridiagonal system terms for tracer diffusion equation
+!-----------------------------------------------------------------------
+!
+      DO 50 ji = kideb, kiut 
+
+      !----------------
+      ! first equation
+      !----------------
+      ztrid(1,1) = 0.0
+      ztrid(1,2) = 1.0 + za(1) * ( zb(1) + ze(1) )
+      ztrid(1,3) = za(1) * ( -zb(1) + zc(1) )
+      zind(1)    = z_sbr_i(1)
+
+      !-----------------
+      ! inner equations
+      !-----------------
+      DO layer = 2, nlay_i - 1
+         ztrid(layer,1) = - za(layer) * ( zb(layer-1) + ze(layer-1) )
+         ztrid(layer,2) = 1.0 + za(layer) * ( zb(layer) + 
+     &                    ze(layer) + zb(layer-1) - zc(layer-1) )
+         ztrid(layer,3) = za(layer) * ( -zb(layer) + zc(layer) )
+         zind(layer)    = z_sbr_i(layer)
+      END DO
+
+      !----------------
+      ! last equation
+      !----------------
+      WRITE(numout,*) " nlay_i : ", nlay_i
+      ztrid(nlay_i,1) = - za(nlay_i) * ( zb(nlay_i-1) + ze(nlay_i-1) )
+      ztrid(nlay_i,2) = 1.0 + za(nlay_i) * ( zb(nlay_i) +
+     &                  ze(nlay_i) +  zb(nlay_i-1) - zc(nlay_i-1) )
+      ztrid(nlay_i,3) = 0.
+      zind(nlay_i)    = z_sbr_i(nlay_i) + za(nlay_i) * ( zb(nlay_i) 
+     &                - zc(nlay_i) ) * oce_sal
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' -Tridiag terms, winter ... '
+         WRITE(numout,*)
+         DO layer = 1, nlay_i
+            WRITE(numout,*) ' layer : ', layer
+            WRITE(numout,*) ' ztrid   : ', ztrid(layer,1), 
+     &                      ztrid(layer,2), ztrid(layer,3)
+            WRITE(numout,*) ' zind    : ', zind(layer)
+         END DO
+      ENDIF
+
+ 50   CONTINUE
+
+!
+!-----------------------------------------------------------------------
+! 6) Solving the tridiagonal system
+!-----------------------------------------------------------------------
+!
+      DO 60 ji = kideb, kiut 
+
+      ! The tridiagonal system is solved with Gauss elimination
+      ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+      ! McGraw-Hill 1984.	
+
+      zindtbis(1) =  zind(1)
+      zdiagbis(1) =  ztrid(1,2)
+
+      DO layer = 2, nlay_i
+         zdiagbis(layer)  =  ztrid(layer,2) - ztrid(layer,1) *
+     &                       ztrid(layer-1,3) / zdiagbis(layer-1)
+         zindtbis(layer)  =  zind(layer) - ztrid(layer,1) *
+     &                       zindtbis(layer-1) / zdiagbis(layer-1)
+      END DO
+
+      ! Recover brine salinity 
+      z_sbr_i(nlay_i)     =  zindtbis(nlay_i) / zdiagbis(nlay_i) 
+      DO layer = nlay_i - 1 , 1 , -1
+         z_sbr_i(layer)   =  ( zindtbis(layer) - ztrid(layer,3)*
+     &                       z_sbr_i(layer+1)) / zdiagbis(layer)
+      END DO
+      ! Recover ice salinity
+      DO layer = 1, nlay_i
+         sn_i_b(layer)  =  z_sbr_i(layer) * e_i_b(layer)
+!        s_i_b(ji,layer)  =  z_sbr_i(layer) * e_i_b(layer)
+      END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' -Solving the tridiagonal system ... '
+         WRITE(numout,*)
+         WRITE(numout,*) ' zdiagbis: ', ( zdiagbis(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zindtbis: ', ( zdiagbis(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_sbr_i : ', ( z_sbr_i(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' sn_i_b   : ', ( sn_i_b(layer) , 
+     &                   layer = 1, nlay_i )
+      ENDIF
+
+ 60   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 7) Mass of salt conserved ?
+!-----------------------------------------------------------------------
+!
+      DO 70 ji = kideb, kiut 
+
+      ! Final mass of salt
+      CALL ice_sal_column( kideb , kiut , z_ms_i_fin , 
+     &                    sn_i_b(1:nlay_i),
+     &                    deltaz_i_phy, nlay_i, .FALSE. )
+
+      ! Bottom flux ( positive upwards for conservation routine )
+      zfb      =  - e_i_b(nlay_i) * 
+     &             ( diff_br(nlay_i) * 2.0 / deltaz_i_phy(nlay_i) * 
+     &             ( z_sbr_i(nlay_i) - oce_sal ) + w_flood * ( z_flood *
+     &             oce_sal + ( 1. - z_flood ) * z_sbr_i(nlay_i) ) )
+     &            - e_i_b(nlay_i) * w_flush * z_sbr_i(nlay_i)
+!    &            - qsummer * z_sbr_i(nlay_i) / ddtb
+
+      fsb = - zfb * rhog / 1000. ! ice-ocean salt flux is positive downwards
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' fsb : ', fsb
+         WRITE(numout,*)
+      ENDIF
+
+      ! Surface flux of salt
+      zfsu     = 0.0
+
+      ! conservation check
+      zerror = 1.0e-15
+      CALL ice_sal_conserv(kideb,kiut,'ice_sal_diff : ',zerror,
+     &                           z_ms_i_ini,z_ms_i_fin,
+     &                           zfb   , zfsu  , ddtb)
+
+ 70   CONTINUE
+
+      ENDIF ! ln_sal
+!
+!------------------------------------------------------------------------------|
+! End of la sous-routine
+      WRITE(numout,*)
+      END SUBROUTINE 
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff_CW.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff_CW.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_sal_diff_CW.f	(revision 6)
@@ -0,0 +1,452 @@
+      SUBROUTINE ice_sal_diff_CW(nlay_i,kideb,kiut)
+
+      !!------------------------------------------------------------------
+      !!                ***         ROUTINE ice_sal_diff      ***
+      !!
+      !! ** Purpose :
+      !!        This routine computes new salinities in the ice
+      !!
+      !! ** Method  : Vertical salinity profile computation 
+      !!              Resolves brine transport equation
+      !!           
+      !! ** Steps
+      !!
+      !! ** Arguments
+      !!
+      !! ** Inputs / Outputs
+      !!
+      !! ** External
+      !!
+      !! ** References : Vancop. et al., 2008
+      !!
+      !! ** History  : 
+      !!    (06-2003) Martin Vancop. LIM1D
+      !!    (06-2008) Martin Vancop. BIO-LIM
+      !!    (09-2008) Martin Vancop. Explicit gravity drainage
+      !!
+      !!------------------------------------------------------------------
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      REAL(8), DIMENSION(nlay_i) ::  
+     &   z_ms_i             ,    !: mass of salt times thickness 
+     &   z_sbr_i                 !: brine salinity
+
+      REAL(8), DIMENSION(nlay_i) ::  !: dummy factors for tracer equation
+     &   za                 ,    !: winter
+     &   zb                 ,   
+     &   ze                 ,    !: summer
+     &   zf                 ,   
+     &   zind               ,    !: independent term in the tridiag system
+     &   zindw              ,    !: independent term in the tridiag system
+     &   zinds              ,    !: independent term in the tridiag system
+     &   zindtbis           ,    !:
+     &   zdiagbis           ,    !:
+     &   zflux                   !: flux of tracer under layer i
+
+      REAL(8), DIMENSION(nlay_i,3) :: !: dummy factors for tracer equation
+     &   ztrid              ,    !: tridiagonal matrix
+     &   ztridw             ,    !: tridiagonal matrix, winter
+     &   ztrids                  !: tridiagonal matrix, summer
+
+      REAL(8) ::  
+     &   zdummy1            ,    !: dummy factors
+     &   zdummy2            ,    !: 
+     &   zdummy3            ,    !: 
+     &   zswitch_open       ,    !: switch for brine network open or not
+     &   zswitchw           ,    !: switch for winter drainage 
+     &   zswitchs           ,    !: switch for summer drainage
+     &   zeps      = 1.0e-20     !: numerical limit
+
+      ! Rayleigh number computation
+      REAL(8) ::
+     &   ze_i_min           ,    !: minimum brine volume
+     &   zc                 ,    !: temporary scalar for sea ice specific heat
+     &   zk                 ,    !: temporary scalar for sea ice thermal conductivity
+     &   zalphara                !: multiplicator for diffusivity
+
+      REAL(8), DIMENSION(nlay_i) ::  
+     &   zsigma             ,    !: brine salinity at layer interfaces
+     &   zperm              ,    !: permeability
+     &   zpermin            ,    !: minimum permeability
+     &   zrhodiff           ,    !: density difference
+     &   zlevel             ,    !: height of the water column
+     &   zthdiff            ,    !: thermal diffusivity
+     &   zgrad_t                 !: temperature gradient in the ice
+
+      INTEGER ::  
+     &   layer2             ,    !: layer loop index
+     &   indtr                   !: index of tridiagonal system
+
+      CHARACTER(len=4)      ::  
+     &   bc = 'conc'             !: Boundary condition 'conc' or 'flux'
+
+      REAL(8) ::  
+     &   z_ms_i_ini         ,    !: initial mass of salt
+     &   z_ms_i_fin         ,    !: final mass of salt
+     &   z_fs_b             ,    !: basal flux of salt
+     &   z_fs_su            ,    !: surface flux of salt
+     &   z_dms_i                 !: mass variation       
+
+      LOGICAL ::
+     &   ln_write           ,
+     &   ln_con             ,
+     &   ln_sal             ,
+     &   ln_be              ,
+     &   ln_gd              ,
+     &   ln_fl
+
+      ln_write = .TRUE.  ! write outputs
+      ln_con   = .TRUE.  ! conservation check
+      ln_sal   = .TRUE.  ! compute salinity variations or not
+      ln_be    = .TRUE.  ! compute brine expulsion or not
+      ln_gd    = .TRUE.  ! compute gravity drainage or not
+      ln_fl    = .TRUE.  ! compute flushing or not
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' ** ice_sal_diff_CW : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' Cox and weeks based gravity drainage '
+         WRITE(numout,*) ' ln_sal = ', ln_sal
+      ENDIF
+
+      IF ( ln_sal ) THEN
+!
+!------------------------------------------------------------------------------|
+! 1) Initialization
+!------------------------------------------------------------------------------|
+!
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Initialization ... '
+      ENDIF
+
+      DO 10 ji = kideb, kiut
+
+      ! gravity drainage parameter (Cox and Weeks 88)
+      zeta            = 20.
+
+      ! brine diffusivity
+      diff_br(:) = 0.0
+
+      !---------------------------
+      ! Brine volume and salinity
+      !---------------------------
+      DO layer = 1, nlay_i
+         e_i_b(layer) = - tmut * s_i_b(ji,layer) / ( t_i_b(ji,layer) 
+     &                - tpw )
+         z_sbr_i(layer) = s_i_b(ji,layer) / e_i_b(layer)
+      END DO
+
+      !----------
+      ! Switches
+      !----------
+      ! summer switch = 1 if Tsu ge tpw and min brine volume superior than e_thr_flu
+      zswitchs = MAX( 0.0, SIGN ( 1.0d0, t_su_b(ji) - tpw ) ) ! 0 si hiver 1 si ete
+      zbvmin   = 1.0
+      DO layer = 1, nlay_i
+         zbvmin = MIN( e_i_b(layer) , zbvmin ) ! minimum brine volume
+      END DO
+      IF ( zbvmin .LT. e_thr_flu ) zswitchs = 0.0
+
+      ! winter switch
+      zswitchw = 1.0 - zswitchs
+
+      !------------------
+      ! Percolating flux
+      !------------------
+      ! Percolating flow ( rho dh * beta * switch / rhow )
+      qsummer = ( - rhog * MIN ( dh_i_surf(ji) , 0.0 ) 
+     &            - rhon * MIN ( dh_s_tot(ji)  , 0.0 ) )  
+      qsummer = qsummer * flu_beta * zswitchs / 1000.0
+
+      !--------------------
+      ! Conservation check
+      !--------------------
+      IF ( ln_con ) THEN 
+         CALL ice_sal_column( kideb , kiut , z_ms_i_ini , 
+     &                    s_i_b(1,1:nlay_i),
+     &                    deltaz_i_phy, nlay_i, .FALSE. )
+      ENDIF ! ln_con
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' nlay_i      : ', nlay_i
+         WRITE(numout,*) ' kideb       : ', kideb
+         WRITE(numout,*) ' kiut        : ', kiut 
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' deltaz_i_phy : ', ( deltaz_i_phy(layer),  
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_i_phy      : ', ( z_i_phy(layer),  
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' s_i_b       : ', ( s_i_b    (ji,layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' t_i_b       : ', ( t_i_b    (ji,layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' e_i_b       : ', ( e_i_b      (layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_sbr_i     : ', ( z_sbr_i    (layer), 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*)
+         WRITE(numout,*) ' zswitchs : ', zswitchs
+         WRITE(numout,*) ' zswitchw : ', zswitchw
+         WRITE(numout,*) 
+      ENDIF ! ln_write
+
+ 10   CONTINUE
+
+!
+!------------------------------------------------------------------------------|
+! 2) Gravity drainage as from Cox and Weeks (1988)
+!------------------------------------------------------------------------------|
+!
+      IF ( zswitchw .EQ. 1.0 ) THEN
+
+      DO 20 ji = kideb, kiut
+
+         !----------------------
+         ! temperature gradient
+         !----------------------
+         z_h_lay    = ht_i_b(ji) / nlay_i
+         zgrad_t(1) = 2. * ( t_i_b(ji,1) - ( ht_s_b(ji)*t_i_b(ji,1) +
+     &                z_h_lay*t_s_b(ji,1) ) / 
+     &                ( z_h_lay + ht_s_b(ji) ) ) / z_h_lay
+
+         DO layer = 2, nlay_i - 1
+            zgrad_t(layer) = ( t_i_b(ji,layer+1) - t_i_b(ji,layer-1) ) /
+     &                       z_h_lay
+         END DO
+         zgrad_t(nlay_i) = - 2.*( t_i_b(ji,nlay_i) - t_bo_b(ji) ) /
+     &                       z_h_lay
+
+         IF ( ln_write ) WRITE(numout,*) ' zgrad_t : ', 
+     &                   ( zgrad_t(layer), layer = 1, nlay_i )
+
+         igrd = 1 ! switch for gravity drainage ( 1 if yes )
+         zdummysb = - FLOAT(igrd) * rhog / 1000. * ht_i_b(ji) ! salt flux [ kg NaCl.m-2.s-1 ]
+         zdsdt = 0.0
+         DO layer = nlay_i, 1, -1
+            IF ( e_i_b(layer) .LE. e_thr_flu ) igrd = 0
+            IF ( zgrad_t(layer) .LE. 0 )   igrd = 0 ! temperature gradient must
+                                                    ! be directed downwards
+            zds_grd = MIN ( 0.0, delta_cw * ( 1.0 - zeta * e_i_b(layer)
+     &              * zgrad_t(layer) * ddtb * igrd ) )
+            sn_i_b(layer) = s_i_b(ji,layer) + zds_grd
+            zdsdt = zdsdt + FLOAT(igrd) * zds_grd / ddtb / FLOAT(nlay_i)
+         END DO
+         fsb = zdummysb * zdsdt
+
+ 20   CONTINUE
+
+      ENDIF ! zswitchw
+
+!
+!------------------------------------------------------------------------------|
+! 3) Compute dummy factors for tracer diffusion equation
+!------------------------------------------------------------------------------|
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' - Compute dummy factors for tracer diffusion'
+         WRITE(numout,*) ' '
+      ENDIF
+
+      DO 30 ji = kideb, kiut 
+         
+      !----------------
+      ! Winter factors
+      !----------------
+      IF ( zswitchw .EQ. 1. ) THEN
+         za(:) = 0.0
+         zb(:) = 0.0
+      ENDIF
+
+      !----------------------
+      ! Summer factors
+      !----------------------
+      ! ze factors
+      DO layer = 1, nlay_i
+         ze(layer) = qsummer * zswitchs / 
+     &               ( e_i_b(layer) * deltaz_i_phy(layer) )
+      END DO ! layer
+
+      ! zf factors
+      ! could remove those, they are totally useless!!! ;-)
+      DO layer = 1, nlay_i - 1
+         zf(layer) = 1./2. * deltaz_i_phy(layer) / 
+     &               ( z_i_phy(layer+1)  - z_i_phy(layer) )
+      END DO ! layer
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*)
+         WRITE(numout,*) ' -Summer factors '
+         WRITE(numout,*) ' ze : ', ( ze(layer), layer = 1, nlay_i ) 
+         WRITE(numout,*) ' zf : ', ( zf(layer), layer = 1, nlay_i ) 
+      ENDIF
+
+ 30   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 4) Tridiagonal system terms for tracer diffusion equation, winter
+!-----------------------------------------------------------------------
+!
+      DO 40 ji = kideb, kiut 
+
+         ztridw(:,:) = 0.
+
+ 40   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 5) Tridiagonal system terms for tracer diffusion equation, summer
+!-----------------------------------------------------------------------
+!
+      DO 50 ji = kideb, kiut 
+
+      DO layer = 1, nlay_i
+         ztrids(layer,1) = - ze(layer)
+         ztrids(layer,2) = 1.0 + ze(layer)
+         ztrids(layer,3) = 0.0
+         zinds(layer) = z_sbr_i(layer)
+      END DO
+      ztrids(1,1) = 0.0
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' -Tridiag terms, summer ... '
+         WRITE(numout,*)
+         DO layer = 1, nlay_i
+            WRITE(numout,*) ' layer : ', layer
+            WRITE(numout,*) ' ztrids   : ', ztrids(layer,1), 
+     &                ztrids(layer,2), ztrids(layer,3)
+            WRITE(numout,*) ' zinds     : ',zinds(layer)
+         END DO
+      ENDIF
+
+ 50   CONTINUE
+      
+!
+!-----------------------------------------------------------------------
+! 6) Partitionning tridiag system between summer and winter
+!-----------------------------------------------------------------------
+!
+      DO 60 ji = kideb, kiut 
+
+      DO indtr = 1, 3
+         DO layer = 1, nlay_i
+            ztrid(layer,indtr) = zswitchs * ztrids(layer,indtr)
+         END DO ! layer
+      END DO ! indtr
+
+      DO layer = 1, nlay_i
+         zind(layer) = zswitchs * zinds(layer)
+      END DO ! layer
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' -Tridiag terms...'
+         WRITE(numout,*)
+         WRITE(numout,*) ' zswitchw : ', zswitchw
+         WRITE(numout,*) ' zswitchs : ', zswitchs
+         DO layer = 1, nlay_i
+            WRITE(numout,*) ' layer    : ', layer
+            WRITE(numout,*) ' ztrid    : ', ztrid(layer,1), 
+     &                        ztrid(layer,2), ztrid(layer,3)
+            WRITE(numout,*) ' zind     : ', zind(layer)
+         END DO ! layer
+      ENDIF
+
+ 60   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 7) Solving the tridiagonal system
+!-----------------------------------------------------------------------
+!
+      DO 70 ji = kideb, kiut 
+
+      ! The tridiagonal system is solved with Gauss elimination
+      ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+      ! McGraw-Hill 1984.	
+
+      zindtbis(1) =  zind(1)
+      zdiagbis(1) =  ztrid(1,2)
+
+      DO layer = 2, nlay_i
+         zdiagbis(layer)  =  ztrid(layer,2) - ztrid(layer,1) *
+     &                       ztrid(layer-1,3) / zdiagbis(layer-1)
+         zindtbis(layer)  =  zind(layer) - ztrid(layer,1) *
+     &                       zindtbis(layer-1) / zdiagbis(layer-1)
+      END DO
+
+      ! Recover brine salinity 
+      z_sbr_i(nlay_i)     =  zindtbis(nlay_i) / zdiagbis(nlay_i) 
+      DO layer = nlay_i - 1 , 1 , -1
+         z_sbr_i(layer)   =  ( zindtbis(layer) - ztrid(layer,3)*
+     &                       z_sbr_i(layer+1)) / zdiagbis(layer)
+      END DO
+      ! Recover ice salinity
+      IF ( zswitchs .EQ. 1.0 ) THEN
+      DO layer = 1, nlay_i
+         sn_i_b(layer)  =  z_sbr_i(layer) * e_i_b(layer)
+!        s_i_b(ji,layer)  =  z_sbr_i(layer) * e_i_b(layer)
+      END DO
+      ENDIF
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) 
+         WRITE(numout,*) ' -Solving the tridiagonal system ... '
+         WRITE(numout,*)
+         WRITE(numout,*) ' zdiagbis: ', ( zdiagbis(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' zindtbis: ', ( zdiagbis(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' z_sbr_i : ', ( z_sbr_i(layer) , 
+     &                   layer = 1, nlay_i )
+         WRITE(numout,*) ' sn_i_b   : ', ( sn_i_b(layer) , 
+     &                   layer = 1, nlay_i )
+      ENDIF
+
+ 70   CONTINUE
+!
+!-----------------------------------------------------------------------
+! 8) Mass of salt conserved ?
+!-----------------------------------------------------------------------
+!
+      DO 80 ji = kideb, kiut 
+
+      ! Final mass of salt
+      CALL ice_sal_column( kideb , kiut , z_ms_i_fin , 
+     &                    sn_i_b(1:nlay_i),
+     &                    deltaz_i_phy, nlay_i, .FALSE. )
+
+      ! Bottom flux ( positive upwards )
+      zswitch_open = 0.0
+      IF ( e_i_b(nlay_i) .GE. e_thr_flu ) zswitch_open = 1.0
+      zfb      = zswitchw * ( - e_i_b( nlay_i ) ! had a minus before
+     &                * diff_br(nlay_i) * 2.0
+     &                / deltaz_i_phy(nlay_i) * ( z_sbr_i(nlay_i)
+     &                  - oce_sal ) ) * zswitch_open
+     &                + zswitchs * ( - qsummer * z_sbr_i(nlay_i) )
+     &                / ddtb
+
+      zflux(nlay_i) = zfb
+
+      ! Surface flux of salt
+      zfsu     = zswitchw * 0.0
+
+      ! conservation check
+      CALL ice_sal_conserv(kideb,kiut,'ice_sal_diff : ',zerror,
+     &                           z_ms_i_ini,z_ms_i_fin,
+     &                           zfb   , zfsu  , ddtb)
+
+ 80   CONTINUE
+
+      ENDIF ! ln_sal
+!
+!------------------------------------------------------------------------------|
+! End of la sous-routine
+      WRITE(numout,*)
+      END SUBROUTINE 
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th.f	(revision 6)
@@ -0,0 +1,162 @@
+      SUBROUTINE ice_th(nlay_i,nlay_s)
+
+        !!------------------------------------------------------------------
+        !!                ***         ROUTINE ice_th       ***
+        !! ** Purpose :
+        !!           Ice thermodynamics 
+        !! ** Method  :
+        !!    This routine calls the thermodynamic and biological routines
+        !!
+        !! ** Arguments :
+        !!           nlay_i, nlay_s
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!
+        !! ** External : 
+        !!
+        !! ** References : Vancoppenolle et al., JGR 2007
+        !!
+        !! ** History :
+        !!       (1) CLIO, Goosse and Fichefet, JGR, 1999.
+        !!       (2) LIM-1D, Vancoppenolle et al., JGR, 2007.
+        !!       (3) BIO-LIM, Martin Vancoppenolle, 2008
+        !!
+        !!------------------------------------------------------------------
+        !! * Arguments
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+      INCLUDE 'bio.com'
+
+      ! Energy conservation
+      LOGICAL con_i
+
+      zeps0 = 1.0e-16
+      zeps1 = 1.0e-20
+      zeps2 = 1.0e-04
+
+      con_i = .true. ! conservation check in the ice or not
+      jl = 1         ! category number (temporary)
+      ji = 1         ! ji index
+
+      WRITE(numout,*) ' * ice_th : '
+      WRITE(numout,*) ' ~~~~~~~~~~ '
+      WRITE(numout,*) 
+      WRITE(numout,*) ' nlay_i : ', nlay_i
+      WRITE(numout,*) ' nlay_s : ', nlay_s
+      WRITE(numout,*) 
+!
+!-------------------------------------------------------------------------------
+!  1) Initialize sea ice
+!-------------------------------------------------------------------------------
+!
+
+      IF ( numit .EQ. nstart ) THEN
+         CALL ice_phy_ini( 1 , 1 , nlay_s, nlay_i)
+
+         IF ( c_bio_model .EQ. 'KRILL' )
+     &   CALL ice_bio_ini( 1 , 1 , nlay_i )                     ! Bio initialization - KRILL
+
+      ENDIF
+!
+!-------------------------------------------------------------------------------
+!  2) Consistency & Energetic checks
+!-------------------------------------------------------------------------------
+!
+
+      DO layer = 1, nlay_s
+         t_s_b(ji,layer)  =  MIN( tpw , t_s_b(ji,layer) )
+      END DO
+
+      DO layer = 1, nlay_i
+         tmelts           =  - tmut*s_i_b(ji,layer) + tpw
+         t_i_b(ji,layer)  =  MIN(tmelts,t_i_b(ji,layer))
+      END DO
+
+      CALL ice_th_enmelt(1,1, nlay_s, nlay_i) ! ice enthalpy
+
+      ! Initialize total heat content
+      IF ( con_i ) CALL ice_th_glohec( qt_i_in , qt_s_in ,              
+     &                                 q_i_layer_in , 1 , 1 , jl, 
+     &                                 nlay_s , nlay_i )
+!
+!-------------------------------------------------------------------------------
+!  3) Model routines
+!-------------------------------------------------------------------------------
+!
+      CALL forcing                                              ! Compute forcing
+
+      CALL ice_rad( nlay_s , nlay_i , 1 , 1 )                   ! Radiative transfer
+
+      CALL ice_th_diff( nlay_s , nlay_i , 1 , 1 )               ! Heat diffusion
+
+      IF ( con_i ) THEN                                         ! Conservation test
+         CALL ice_th_glohec( qt_i_fin , qt_s_fin , q_i_layer_fin ,
+     &                       1 , 1 , jl , nlay_s , nlay_i )
+         CALL ice_th_con_dif( 1 , 1 , nlay_s , nlay_i , jl )
+      ENDIF
+
+      IF ( gravdr .EQ. 'CW' )
+     &   CALL ice_sal_diff_CW(nlay_i,1,1)                       ! Salt transport (Cox and Weeks)
+
+      IF ( gravdr .EQ. 'RA' )
+     &   CALL ice_sal_diff(nlay_i,1,1)                          ! Salt transport (Rayleigh-number based)
+
+      IF ( ( c_bio_model .EQ. 'KRILL' ) .AND. ln_trdiff )
+     &   CALL ice_bio_diff( 1 , 1 , nlay_i )                    ! Bio transport
+
+      IF ( c_bio_model .EQ. 'KRILL' )
+     &   CALL ice_bio_sms(nlay_i,1,1)                           ! KRILL source minus sinks
+     
+      IF ( ln_ikaite ) 
+     &   CALL ice_ikaite(nlay_i)                                ! Ikaite precipitation and dissolution
+
+      CALL ice_gas(nlay_i,1,1)                                  ! Gases
+
+      CALL ice_th_dh(nlay_s,nlay_i,1,1)                         ! Growth and melt
+
+      CALL ice_phy_remap(nlay_s,nlay_i,1,1)                     ! Remap heat and salt
+
+      IF ( con_i ) THEN                                         ! Heat and salt conservation test
+         CALL ice_th_glohec( qt_i_fin , qt_s_fin , q_i_layer_fin ,
+     &                       1 , 1 , jl, nlay_s, nlay_i )
+         CALL ice_th_con_dh(1,1,nlay_s,nlay_i,jl)
+      ENDIF
+
+      IF ( ln_trremp )      
+     &   CALL ice_bio_remap(nlay_s, nlay_i, 1, 1)               ! Remap tracers
+
+      CALL ice_bio_column(kideb,kiut,ntra_bio,ct_i_bio,cbu_i_bio,
+     &                    deltaz_i_bio, .FALSE.)
+      
+      !---------------
+      ! Chlorophyll a
+      !---------------
+      IF ( c_bio_model .EQ. 'KRILL' ) THEN
+         DO layer = 1, nlay_bio
+            chla_i_bio(layer) = cbu_i_bio(4,layer) * chlC_bio(layer) *
+     &                          c_molar
+         END DO
+      ENDIF ! c_bio_model
+
+      IF ( c_bio_model .NE. 'NOBIO' ) 
+     &   WRITE(numout,*) ' chla_i_bio : ', ( chla_i_bio(layer), 
+     &                   layer = 1, nlay_bio )
+
+!-------------------------------------------------------------------------------
+!  4) Outputs 
+!-------------------------------------------------------------------------------
+!
+      !---------------
+      ! Netcdf Output
+      !---------------
+      CALL ice_output(nlay_i,nlay_s)
+
+      RETURN
+!
+!------------------------------------------------------------------------------
+!- end of ice_th
+      END
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_dh.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_dh.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_dh.f	(revision 6)
@@ -0,0 +1,512 @@
+      SUBROUTINE ice_th_dh(nlay_s,nlay_i,kideb,kiut)
+       !!------------------------------------------------------------------
+       !!                ***         ROUTINE ice_th_dh         ***
+       !! ** Purpose :
+       !!           This routine determines variations of ice and snow thicknesses.
+       !! ** Method  :
+       !!           Ice/Snow surface melting arises from imbalance in surface fluxes
+       !!           Bottom accretion/ablation arises from flux budget
+       !!           Snow thickness can increase by precipitation and decrease by 
+       !!              sublimation
+       !!           If snow load excesses Archmiede limit, snow-ice is formed by
+       !!              the flooding of sea-water in the snow
+       !! ** Steps  
+       !!           1) Compute available flux of heat for surface ablation
+       !!           2) Compute snow and sea ice enthalpies
+       !!           3) Surface ablation and sublimation
+       !!           4) Bottom accretion/ablation
+       !!           5) Case of Total ablation
+       !!           6) Snow ice formation
+       !!
+       !! ** Inputs / Outputs
+       !!
+       !! ** External
+       !!
+       !! ** References : Bitz and Lipscomb, JGR 99
+       !!                 Fichefet T. and M. Maqueda 1997, 
+       !!                 J. Geophys. Res., 102(C6), 12609-12646   
+       !!                 Vancoppenolle, Fichefet and Bitz, GRL 2005
+       !!                 Vancoppenolle et al., OM08
+       !!
+       !! ** History  : 
+       !!   original code    01-04 (LIM)
+       !!   original routine
+       !!               (05-2003) M. Vancoppenolle, Louvain-La-Neuve, Belgium
+       !!               (05-2008) BIO-LIM
+       !!
+       !!------------------------------------------------------------------
+       !! * Arguments
+       !!------------------------------------------------------------------
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      ! Local Variables
+      DIMENSION zrchu1(nbpt), zrchu2(nbpt), zqsat(nbpt), z_f_surf(nbpt) 
+      DIMENSION zdeltah(maxnlay)
+      LOGICAL l_write
+
+      zqt_s_ini = 0.0
+      zqt_s_fin = 0.0
+      zdqt_s    = 0.0
+      zqt_i_ini = 0.0
+      zqt_i_fin = 0.0
+      zdqt_i    = 0.0
+      s_i_max   = 15.0
+
+      ! Local Constants
+      zeps = 1.0e-20
+      l_write = .TRUE.
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' ** ice_th_dh : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~ '
+         WRITE(numout,*) 
+      ENDIF
+!
+!------------------------------------------------------------------------------|
+!  1) Calculate available heat for surface ablation         
+!------------------------------------------------------------------------------|
+!
+      DO 20 ji = kideb, kiut
+      
+      z_f_surf(ji)  = fratsb(ji) + fleb(ji) + fcsb(ji) - fc_su(ji)
+     &              + ab(ji)*fsolgb(ji)
+      z_f_surf(ji)  = MAX(c_zero,z_f_surf(ji))
+      z_f_surf(ji)  = z_f_surf(ji)*MAX(c_zero,
+     &                SIGN(one,t_su_b(ji)-tfs(ji)))
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' Available heat for surface ablation ... '
+         WRITE(numout,*) 
+         WRITE(numout,*) ' z_f_surf : ', z_f_surf(ji)
+         WRITE(numout,*) ' fratsb   : ', fratsb(ji)
+         WRITE(numout,*) ' fleb     : ', fleb(ji)
+         WRITE(numout,*) ' fcsb     : ', fcsb(ji)
+         WRITE(numout,*) ' fc_su    : ', fc_su(ji)
+         WRITE(numout,*) ' ab       : ', ab(ji) 
+         WRITE(numout,*) ' fsolgb   : ', fsolgb(ji)
+         WRITE(numout,*)
+         WRITE(numout,*) ' ht_i_b    : ', ht_i_b(ji)
+         WRITE(numout,*) ' ht_s_b    : ', ht_s_b(ji)
+         WRITE(numout,*) ' t_su_b   : ', t_su_b(ji)
+         WRITE(numout,*)
+      ENDIF
+
+ 20   CONTINUE
+
+!
+!------------------------------------------------------------------------------|
+!  2) Snowfall and surface melt                                                |
+!------------------------------------------------------------------------------|
+!
+      DO 40 ji = kideb, kiut
+
+      ! total snow heat content for conservation
+      zqt_s_ini = q_s_b(ji,1) * ht_s_b(ji)
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' Surface ablation and sublimation ... '
+         WRITE(numout,*) 
+         WRITE(numout,*) ' zqt_s_ini : ', zqt_s_ini / ddtb
+         WRITE(numout,*) ' ht_s_b    : ', ht_s_b(ji)
+         WRITE(numout,*) ' q_s_b(1)  : ', q_s_b(ji,1)
+         WRITE(numout,*)
+      ENDIF
+
+      !----------
+      ! Snowfall
+      !----------
+      dh_s_prec(ji)    =  hnpbqb(ji)
+      dh_s_melt(ji)    =  0.0
+      zqprec           =  rhon * ( cpg * ( tpw - tabqb(ji) ) + lfus )
+
+      ! Conservation update
+      zqt_s_ini        =  zqt_s_ini + zqprec*hnpbqb(ji)
+      fprec            =  - zqprec * hnpbqb(ji) / ddtb
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' snow falls! '
+         WRITE(numout,*) ' dh_s_prec : ', dh_s_prec(ji)
+         WRITE(numout,*) ' flux of h : ',
+     &                   zqprec*hnpbqb(ji) / ddtb
+         WRITE(numout,*) ' zqt_s_ini : ', zqt_s_ini / ddtb
+         WRITE(numout,*)
+      ENDIF
+
+      !-----------
+      ! Snow melt
+      !-----------
+      ! Energy available for surface melt
+      zqfont_su =  ( z_f_surf(ji) + f_s_im(ji) ) * ddtb 
+      IF ( l_write ) THEN 
+         WRITE(numout,*) ' snow melts! '
+         WRITE(numout,*) ' z_f_surf(ji) : ', z_f_surf(ji)
+         WRITE(numout,*) ' f_s_im       : ', f_s_im(ji)
+         WRITE(numout,*) ' zqfont_su    : ', zqfont_su
+      ENDIF
+
+      ! Melt of fallen snow
+      zdeltah(1)       =  MIN( 0.0 , - zqfont_su / 
+     &                    MAX( zqprec , zeps ) )
+      zqfont_su        =  MAX( 0.0 , - dh_s_prec(ji) - zdeltah(1) ) * 
+     &                    zqprec
+      zdeltah(1)       =  MAX( - dh_s_prec(ji), zdeltah(1) )
+      dh_s_melt(ji)    =  dh_s_melt(ji) + zdeltah(1)
+
+      ! Melt / evaporation of snow
+      zswi_evap = 0
+      WRITE(numout,*) ' ln_evap : ', ln_evap
+      WRITE(numout,*) ' tdewb   : ', tdewb(ji)
+      IF ( ln_evap .AND. ( qsfcb(ji) .GT. qabqb(ji) ) .AND.
+     &     tdewb(ji) .LT. 1. ) zswi_evap = 1
+      
+      DO layer = 1, nlay_s ! in case of melting of more than 1 layer
+         zlvap = zswi_evap * rhon * ( lvap + cpg * ( tabqb(ji) - tpw ) ) ! MV new evaporation
+
+!        zdeltah(layer) =  - zqfont_su / q_s_b(ji,layer)
+         zdeltah(layer) =  - zqfont_su / ( q_s_b(ji,layer) + zlvap )
+         zqfont_su      = MAX( c_zero, - deltaz_s_phy(layer) - 
+     &                    zdeltah(layer) ) * 
+!    &                    q_s_b(ji,layer) !MV new evaporation
+     &                    ( q_s_b(ji,layer) + zlvap )
+         zdeltah(layer) = MAX( zdeltah(layer), - deltaz_s_phy(layer) )
+         dh_s_melt(ji) =  dh_s_melt(ji) + zdeltah(layer) !resulting melt of snow    
+      END DO
+
+      dh_s_tot(ji)     =  dh_s_melt(ji) + dh_s_prec(ji)
+
+      ! old and new snow thicknesses
+      hsold            =  ht_s_b(ji)
+      hsnew            =  ht_s_b(ji) + dh_s_tot(ji)
+
+      ! if snow is still present zhn = 1, else zhn = 0
+      zhn              =  1.0 - MAX( c_zero , SIGN( one , - hsnew ) )
+      ht_s_b(ji)       =  MAX( c_zero , hsnew )
+
+      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+      ! Conservation test for snow
+      zqt_s_fin = q_s_b(ji,1) * ht_s_b(ji)
+      zdqt_s = zqt_s_fin - zqt_s_ini
+
+      WRITE(numout,*)
+      WRITE(numout,*) ' Conservation in snow... '
+      WRITE(numout,*) ' dh_s_melt : ', dh_s_melt(ji)
+      WRITE(numout,*) ' dh_s_prec : ', dh_s_prec(ji)
+      WRITE(numout,*) ' ht_s_b    : ', ht_s_b(ji)
+      WRITE(numout,*) ' zqt_s_ini : ', zqt_s_ini / ddtb
+      WRITE(numout,*) ' zqt_s_fin : ', zqt_s_fin / ddtb
+      WRITE(numout,*) ' zdqt_s    : ', zdqt_s / ddtb
+      WRITE(numout,*) ' z_f_surf  : ', - z_f_surf(ji)
+      IF ( zqt_s_fin.GT.0.0 ) THEN
+         cons_err = ABS(zdqt_s / ddtb  + z_f_surf(ji) )
+      ELSE
+         cons_err = ABS(zqt_s_ini / ddtb + zdqt_s / ddtb )
+      ENDIF
+      WRITE(numout,*) ' Cons error, snow : ', cons_err
+      WRITE(numout,*)
+      !++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+      !------------------
+      ! Ice surface melt
+      !------------------
+      IF ( l_write ) WRITE(numout,*) ' ice melts!  '
+
+      zzf_surf = zqfont_su / ddtb
+      zdqt_i            = 0.0
+      dh_i_surf(ji)     =  0.0
+      DO layer = 1, nlay_i
+         zdeltah(layer) =  - zqfont_su / q_i_b(ji,layer)
+         zqfont_su      =  MAX( c_zero , - deltaz_i_phy(layer) 
+     &                  - zdeltah(layer) ) *  q_i_b(ji,layer)
+         zdeltah(layer) =  MAX( zdeltah(layer) , - deltaz_i_phy(layer) )
+         dh_i_surf(ji)  =  dh_i_surf(ji) + zdeltah(layer) !resulting melt of ice
+         zdqt_i         = zdqt_i  + zdeltah(layer) * q_i_b(ji,layer) 
+     &                  / ddtb
+      END DO
+
+      cons_err = ABS( zzf_surf + zdqt_i )
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' Conservation in sea ice, surface '
+         WRITE(numout,*) ' dh_i_surf: ', dh_i_surf(ji)
+         WRITE(numout,*) ' ht_i_b   : ', ht_i_b(ji)
+         WRITE(numout,*) ' zzf_surf : ', zzf_surf
+         WRITE(numout,*) ' zdqt_i   : ', zdqt_i
+         WRITE(numout,*) ' Cons error, ice : ', cons_err
+         WRITE(numout,*)
+      ENDIF
+      
+!
+!------------------------------------------------------------------------------|
+!  3) Sublimation at the surface                                               |
+!------------------------------------------------------------------------------|
+!
+      !------------------
+      ! Snow sublimation
+      !------------------
+
+      !------------------
+      ! Ice sublimation
+      !------------------
+
+      !-------------------
+      ! Snow condensation
+      !-------------------
+
+      ! THIS IS DEFINITELY WRONG SINCE LATENT HEAT IS ALREADY COUNTED TO
+      ! remove heat from the snow pack
+!     ! 4.3) Snow/ice sublimation
+!     !
+!     ! If fleb is negative, snow condensates at the surface.
+!     !
+      dh_s_subl(ji)    =  + parsub*fleb(ji)/(rhon*lsub)*ddtb
+      dh_s_tot(ji)     =  dh_s_tot(ji) + dh_s_subl(ji)
+      zdhcf            =  ht_s_b(ji) + dh_s_subl(ji) 
+      ht_s_b(ji)       =  MAX(c_zero,zdhcf)
+      dh_s_tot(ji)     =  ht_s_b(ji) - hsold
+      dh_i_subl(ji)    =  - MAX(c_zero,-zdhcf)*rhon/rhog
+
+      dh_i_surf(ji)    =  dh_i_surf(ji) + dh_i_subl(ji)
+
+      hsnew            =  ht_s_b(ji)
+
+      IF ( ht_s_b(ji) .LE. 0.0 ) THEN
+         dh_s_tot(ji) =  MAX( 0.0 , dh_s_tot(ji) )
+      ENDIF
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' Snow sublimation ... '
+         WRITE(numout,*) ' '
+         WRITE(numout,*) ' parsub : ', parsub
+         WRITE(numout,*) ' dh_s_subl : ', dh_s_subl(ji)
+         WRITE(numout,*) ' dh_i_subl : ', dh_i_subl(ji)
+      ENDIF
+
+ 40   CONTINUE
+!
+!------------------------------------------------------------------------------|
+!  4) Basal growth and melt                                                    |
+!------------------------------------------------------------------------------|
+!
+      DO 50 ji = kideb, kiut
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' Basal growth and melt ... '
+         WRITE(numout,*) 
+         WRITE(numout,*) ' fbbqb     : ', fbbqb(ji)
+         WRITE(numout,*) ' fc_bo_i   : ', fc_bo_i(ji)
+         WRITE(numout,*)
+      ENDIF
+
+      ! formation / melting of ice at the base is determined by the balance of
+      ! the conductive heat flux in the ice (fc_bo_i), and the heat fluxes 
+      ! from the ocean (fbbqb). Conductive heat flux is positive 
+      ! downwards and fbbq is positive to the ice, i.e., upwards.
+      ! Melt/formation rate is modulated by the enthalpy of the bottom ice layer. 
+      ! accretion of ice at the base
+
+      !--------------
+      ! Basal growth
+      !--------------
+      ! Initial value (tested 1D, can be anything between 1 and 20)
+      s_i_new      = 10.0
+      num_iter_max = 10
+
+      ! the growth rate (dh_i_bott) is function of the new ice
+      ! heat content (q_i_b(nlay_i+1)). q_i_b depends on the new ice
+      ! salinity (snewice). snewice depends on dh_i_bott
+      ! it converges quickly, so, no problem
+
+      ! Iterative procedure
+      IF ( ( fc_bo_i(ji) + fbbqb(ji) ) .LT. 0.0 ) THEN
+
+         IF ( l_write ) WRITE(numout,*) ' Energy available for 
+     &                                    basal growth : ',
+     &                  fc_bo_i(ji) + fbbqb(ji)
+
+         DO iter = 1, num_iter_max
+               tmelts             =   - tmut * s_i_new + tpw ! Melting point in K
+               q_i_b(ji,nlay_i+1) = rhog*( cpg*(tmelts-t_bo_b(ji))
+     &                 + lfus*( 1.0-(tmelts-tpw)
+     &                 / (t_bo_b(ji) - tpw) )
+     &                 - cpw*(tmelts-tpw) ) 
+
+               ! Bottom growth rate = - F*dt / q
+               dh_i_bott(ji)    =  - ddtb*(fc_bo_i(ji) + fbbqb(ji) )
+     &                             / q_i_b(ji,nlay_i+1)
+               !
+               ! New ice salinity ( Cox and Weeks, JGR, 1988 )
+               !
+               ! zswi2  (1) if dh_i_bott/rdt .GT. 3.6e-7
+               ! zswi12 (1) if dh_i_bott/rdt .LT. 3.6e-7 and .GT. 2.0e-8
+               ! zswi1  (1) if dh_i_bott/rdt .LT. 2.0e-8
+               !
+               zgrr   = MIN( 1.0e-3, 
+     &                  MAX ( dh_i_bott(ji) / ddtb , zeps ) )
+               zswi2  = MAX( 0.0 , SIGN( 1.0d0 , zgrr - 3.6e-7 ) )
+               zswi12 = MAX( 0.0 , SIGN( 1.0d0 , zgrr - 2.0e-8 ) ) * 
+     &                  ( 1.0 - zswi2 )
+               zswi1  = 1. - zswi2 * zswi12
+               zfracs = zswi1  * 0.12 +   
+     &                  zswi12 * ( 0.8925 + 0.0568 * 
+     &                  LOG( 100.0 * zgrr ) ) +  
+     &                  zswi2  * 0.26 /   
+     &                  ( 0.26 + 0.74 * EXP ( - 724300.0 * zgrr ) )
+               zfracs = 1.
+               zds     = zfracs * oce_sal - s_i_new
+               s_i_new = zfracs * oce_sal
+
+               ! the brine volume in the skeletal layer is equal to f
+               e_skel  = zfracs
+
+               ! salt flux due to initial salt entrapment
+               fsbp = oce_sal * ( 1. - zfracs ) * dh_i_bott(ji) / ddtb *
+     &                rhog / 1000.
+
+!              WRITE(numout,*)
+!              WRITE(numout,*) ' ddtb      : ', ddtb
+!              WRITE(numout,*) ' zgrr      : ', zgrr
+!              WRITE(numout,*) ' zswi12    : ', zswi12
+!              WRITE(numout,*) ' zswi1     : ', zswi1
+!              WRITE(numout,*) ' zswi2     : ', zswi2
+!              WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
+!              WRITE(numout,*) ' oce_sal   : ', oce_sal
+!              WRITE(numout,*) ' zfracs    : ', zfracs 
+!              WRITE(numout,*) ' s_i_new   : ', s_i_new
+!              WRITE(numout,*)
+
+         END DO ! iter
+      ENDIF ! fc_bo_i
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' e_skel : ', e_skel
+         WRITE(numout,*)
+      ENDIF
+
+      ! Final values
+      IF ( (fc_bo_i(ji)+fbbqb(ji)) .LT. 0.0 ) THEN
+      ! New ice salinity must not exceed 15 psu
+         zoldsinew   = s_i_new
+! TEST MARTIN NOV 2010 this line should be removed in future versions
+         s_i_new     = MIN( s_i_new , s_i_max )
+         ! Metling point in K
+         tmelts             =   - tmut * s_i_new + tpw
+         ! New ice heat content (Bitz and Lipscomb, 1999)
+         q_i_b(ji,nlay_i+1) = rhog*( cpg*(tmelts-t_bo_b(ji))
+     &                 + lfus*( 1.0-(tmelts-tpw)
+     &                 / (t_bo_b(ji) - tpw) )
+     &                 - cpw*(tmelts-tpw) ) 
+         dh_i_bott(ji)    =  - ddtb*(fc_bo_i(ji) + fbbqb(ji) )
+     &                    / q_i_b(ji,nlay_i+1)
+         IF ( l_write ) WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
+
+      ENDIF 
+
+      !-----------------
+      ! Basal melt
+      !-----------------
+      IF ( ( fc_bo_i(ji) + fbbqb(ji) ) .GE. 0.0 ) THEN
+
+         IF ( l_write ) WRITE(numout,*) ' Energy available for 
+     &                                    basal melt   : ',
+     &                  fc_bo_i(ji) + fbbqb(ji)
+
+         zqfont_bo   = ddtb * ( fc_bo_i(ji) + fbbqb(ji) )
+         zzf_base    = zqfont_bo / ddtb
+         zdqt_i      = 0.0
+
+         IF ( l_write ) WRITE(numout,*) ' zqfont_bo : ', zqfont_bo
+
+         dh_i_bott(ji)     =  0.0
+         DO layer = nlay_i, 1, -1
+            zdeltah(layer) =  - zqfont_bo / q_i_b(ji,layer)
+            zqfont_bo      =  MAX ( 0.0 , - deltaz_i_phy(layer) -
+     &                        zdeltah(layer) )
+     &                     *  q_i_b(ji,layer)
+            dh_i_bott(ji)  =  dh_i_bott(ji) + zdeltah(layer)
+            zdqt_i         =  zdqt_i + zdeltah(layer) * 
+     &                        q_i_b(ji,layer) / ddtb
+         END DO
+
+         IF ( l_write ) WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
+
+         cons_err = ABS( zzf_base + zdqt_i )
+
+         IF ( l_write ) THEN
+            WRITE(numout,*) ' Conservation in sea ice, base '
+            WRITE(numout,*) ' dh_i_bott: ', dh_i_bott(ji)
+            WRITE(numout,*) ' ht_i_b   : ', ht_i_b(ji)
+            WRITE(numout,*) ' zzf_base : ', zzf_base
+            WRITE(numout,*) ' zdqt_i   : ', zdqt_i
+!           WRITE(numout,*) ' Conservation error  ice surface : ', 
+!    &                      cons_err
+!           WRITE(numout,*)
+         ENDIF
+
+      ENDIF
+
+      ! It can be than an internal temperature is greater than melt point
+      ! then, see lim3 for correction
+
+      ! new ice thickness
+      zhgnew         = ht_i_b(ji) + dh_i_surf(ji) + dh_i_bott(ji)
+      old_ht_i_b(ji) = ht_i_b(ji)
+
+      ht_i_b(ji) = zhgnew
+
+ 50   CONTINUE
+
+!
+!------------------------------------------------------------------------------|
+!  5) Formation of snow-ice                                                    |
+!------------------------------------------------------------------------------|
+!
+      ! When snow load excesses Archimede's limit, snow-ice interface goes down
+      ! under sea-level, flooding of seawater transforms snow into ice
+      ! dh_snowice is positive for the ice
+
+      DO 70 ji = kideb, kiut
+
+      dh_snowice(ji) = MAX( c_zero , ( rhon * ht_s_b(ji) + (rhog -rho0 )
+     &                 * ht_i_b(ji)) / ( rhon + rho0 - rhog ) )
+        
+      zhgnew         = MAX( zhgnew , zhgnew + dh_snowice(ji) )
+      zhnnew         = MIN( ht_s_b(ji) , ht_s_b(ji) - dh_snowice(ji) )
+
+      ht_s_b(ji)  = zhnnew
+      ht_i_b(ji)  = zhgnew
+
+      IF ( l_write ) THEN
+         WRITE(numout,*) ' dh_snowice : ', dh_snowice(ji)
+         WRITE(numout,*)
+         WRITE(numout,*) ' At the end of the routine ... '
+         WRITE(numout,*) ' ht_s_b : ', ht_s_b(ji)
+         WRITE(numout,*) ' ht_i_b : ', ht_i_b(ji)
+      ENDIF
+
+      ! give a minimum snow depth
+      zhsnmin        = 1.0e-10
+      isnow = 0
+      IF ( ht_s_b(ji) .GT. zhsnmin ) isnow = 1
+      ht_s_b(ji) = isnow * ht_s_b(ji)
+
+      !--- Remove ---
+      WRITE(numout,*) ' dh_i_bott : ', dh_i_bott(ji)
+      WRITE(numout,*) ' dh_i_surf : ', dh_i_surf(ji)
+      WRITE(numout,*) ' dh_i_snowice : ', dh_snowice(ji)
+      WRITE(numout,*) ' dh_s_melt : ', dh_s_melt(ji)
+      !--- Remove ---
+
+ 70   CONTINUE
+
+      RETURN
+
+!------------------------------------------------------------------------------|
+! Fin de la subroutine ice_th_dh
+      END SUBROUTINE
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_diff.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_diff.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/ice_th_diff.f	(revision 6)
@@ -0,0 +1,675 @@
+      SUBROUTINE ice_th_diff(nlay_s,nlay_i,kideb,kiut)
+        !!------------------------------------------------------------------
+        !!                ***         ROUTINE ice_th_diff       ***
+        !! ** Purpose :
+        !!   This routine determines the time evolution of snow and sea-ice 
+        !!   temperature profiles.
+        !! ** Method  :
+        !!       This is done by solving the heat equation diffusion with
+        !!       a Neumann boundary condition at the surface and a Dirichlet one
+        !!       at the bottom. Solar radiation is partially absorbed into the ice.
+        !!       The specific heat and thermal conductivities depend on ice salinity
+        !!       and temperature to take into account brine pocket melting. The 
+        !!       numerical
+        !!       scheme is an iterative Crank-Nicolson on a non-uniform multilayer grid 
+        !!       in the ice and snow system.
+        !!       The successive steps of this routine are
+        !!       Vertical grid
+        !!           1.  Thermal conductivity at the interfaces of the ice layers
+        !!           2.  Internal absorbed radiation
+        !!           3.  Scale factors due to non-uniform grid
+        !!           4.  Kappa factors
+        !!           Then iterative procedure begins
+        !!           5.  specific heat in the ice
+        !!           6.  eta factors
+        !!           7.  surface flux computation
+        !!           8.  tridiagonal system terms
+        !!           9.  solving the tridiagonal system with Gauss elimination
+        !!           Iterative procedure ends according to a criterion on evolution
+        !!           of temperature
+        !!
+        !! ** Arguments :
+        !!           kideb , kiut : Starting and ending points on which the 
+        !!                         the computation is applied
+        !!
+        !! ** Inputs / Ouputs : (global commons)
+        !!           surface temperature : t_su_b
+        !!           ice/snow temperatures   : t_i_b, t_s_b
+        !!           ice salinities          : s_i_b
+        !!           number of layers in the ice/snow: nlay_i, nlay_s
+        !!           total ice/snow thickness : ht_i_b, ht_s_b
+        !!
+        !! ** External : 
+        !!
+        !! ** References :
+        !!
+        !! ** History :
+        !!           (02-2003) Martin Vancoppenolle, Louvain-la-Neuve, Belgium
+        !!
+
+      USE lib_fortran
+
+      INCLUDE 'type.com'
+      INCLUDE 'para.com'
+      INCLUDE 'const.com'
+      INCLUDE 'ice.com'
+      INCLUDE 'thermo.com'
+
+      ! Local variables
+      INTEGER    numeqmin, numeqmax, numeq
+      DIMENSION  ztcond_i(0:nlay_i),
+     &           zkappa_s(0:nlay_s),
+     &           zkappa_i(0:nlay_i),ztstemp(0:nlay_s),ztitemp(0:nlay_i),
+     &           zspeche_i(0:nlay_i),ztsold(0:nlay_s),ztiold(0:nlay_i),
+     &           zeta_s(0:nlay_s),zeta_i(0:nlay_i),ztrid(2*maxnlay+1,3),
+     &           zindterm(2*maxnlay+1),zindtbis(2*maxnlay+1),
+     &           zdiagbis(2*maxnlay+1),ykn(nbpt),ykg(nbpt),
+     &           zrchu1(nbpt),zrchu2(nbpt),zqsat(nbpt)
+
+      LOGICAL :: ln_write
+      
+      ! Local constants	
+      zeps      =  1.0d-20
+      zg1s      =  2.0
+      zg1       =  2.0
+      zbeta     =  0.117   ! factor for thermal conductivity
+      zerrmax   =  1.0d-11 ! max error at the surface
+
+      ! new lines
+      zerrmax   = 1.0e-4
+      nconv_max = 50
+
+      ln_write = .TRUE.
+
+      DO 5 ji = kideb, kiut
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ** ice_th_diff : '
+         WRITE(numout,*) ' ~~~~~~~~~~~~~~~~ '
+         WRITE(numout,*) ' nlay_i: ', nlay_i
+         WRITE(numout,*) ' nlay_s: ', nlay_s
+         WRITE(numout,*) ' t_su_b: ', t_su_b(ji) 
+         WRITE(numout,*) ' t_s_b : ', ( t_s_b(ji,layer), 
+     &                         layer = 1, nlay_s )
+         WRITE(numout,*) ' t_i_b : ', ( t_i_b(ji,layer), 
+     &                         layer = 1, nlay_i )
+         WRITE(numout,*) ' t_bo_b : ', t_bo_b(ji)
+         WRITE(numout,*) ' ht_i_b : ', ht_i_b(ji)
+         WRITE(numout,*) ' ht_s_b : ', ht_s_b(ji)
+      ENDIF
+
+      ! Switches 
+      ! isnow equals 1 if snow is present and 0 if absent
+      isnow   = int(1.0-max(0.0,sign(1.0d0,-ht_s_b(ji))))
+      ! imelt equals 1 if surface is melting and 0 if not
+      imelt   = int(max(0.0,sign(1.0d0,t_su_b(ji)-tpw)))
+
+      tfs(ji)   = real(isnow)*tfsn+ (1.0-real(isnow))*tfsg
+
+      ! Oceanic  heat flux and precipitations
+      fbbqb(ji) = oce_flx 
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' isnow : ', isnow
+         WRITE(numout,*) ' imelt : ', imelt
+         WRITE(numout,*) ' tfs   : ', tfs(ji)
+      ENDIF
+
+ 5    CONTINUE
+!
+!------------------------------------------------------------------------------
+!  1) Thermal conductivity at the ice interfaces
+!------------------------------------------------------------------------------ 
+!
+      ! Pringle et al., JGR 2007 formula
+      ! 2.11 + 0.09 S/T - 0.011.T
+
+      DO 10 ji = kideb, kiut
+
+      ! thermal conductivity in the snow
+      ykn(ji)  =  xkn
+      zkimin   =  0.1
+
+      ztcond_i(0)     = xkg + betak1*s_i_b(ji,1) 
+     &                   / MIN( -zeps , t_i_b(ji,1) - tpw ) 
+     &                   - betak2* ( t_i_b(ji,1) - tpw )
+      ztcond_i(0)     = MAX( ztcond_i(0) , zkimin )
+
+      DO layer = 1, nlay_i-1
+         ztcond_i(layer) = xkg + betak1*( s_i_b(ji,layer)   
+     &                      + s_i_b(ji,layer+1) ) / MIN(-zeps,
+     &                        t_i_b(ji,layer)+t_i_b(ji,layer+1)-2.0*tpw)
+     &                      - betak2 * 0.5 * ( t_i_b(ji,layer) +  ! bugfix fred dupont add 0.5
+     &                        t_i_b(ji,layer+1) - 2.0*tpw )
+         ztcond_i(layer) = MAX( ztcond_i(layer) , zkimin )
+      END DO
+
+      ztcond_i(nlay_i)   = xkg + betak1*s_i_b(ji,nlay_i) / 
+     &                        MIN( -zeps , t_bo_b(ji) - tpw ) 
+     &                      - betak2 * ( t_bo_b(ji) - tpw )
+      ztcond_i(nlay_i)   = MAX( ztcond_i(nlay_i) , zkimin )
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' ztcond_i : ', ztcond_i(0:nlay_i)
+      ENDIF
+
+ 10   CONTINUE
+!
+!------------------------------------------------------------------------------
+!  3) kappa factors                                                             
+!------------------------------------------------------------------------------ 
+!
+      DO 30 ji = kideb, kiut
+      ! snow
+      zkappa_s(0)         = ykn(ji)/max(zeps,deltaz_s_phy(1))
+      do layer = 1, nlay_s-1
+         zkappa_s(layer)  = 2.0*ykn(ji)/
+     &   max(zeps,deltaz_s_phy(layer)+deltaz_s_phy(layer+1))
+      end do
+      zkappa_s(nlay_s)    = ykn(ji)/max(zeps,deltaz_s_phy(nlay_s))
+
+      ! ice
+      zkappa_i(0) = ztcond_i(0)/max(zeps,deltaz_i_phy(1))
+      do layer = 1, nlay_i-1
+         zkappa_i(layer)  = 2.0*ztcond_i(layer)/
+     &   max(zeps,deltaz_i_phy(layer)+deltaz_i_phy(layer+1)) 
+      end do
+      zkappa_i(nlay_i) = ztcond_i(nlay_i) / 
+     &                   MAX(zeps,deltaz_i_phy(nlay_i))
+
+      ! interface
+      zkappa_s(nlay_s)   = 2.0*ykn(ji)*ztcond_i(0)/max(zeps,
+     &             (ztcond_i(0)*deltaz_s_phy(nlay_s) + 
+     &             ykn(ji)*deltaz_i_phy(1)))
+      zkappa_i(0)        = zkappa_s(nlay_s)*real(isnow) 
+     &                     + zkappa_i(0)*(1.0-real(isnow))
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' nlay_s   : ', nlay_s
+         WRITE(numout,*) ' zkappa_s : ', zkappa_s(0:nlay_s)
+         WRITE(numout,*) ' zkappa_i : ', zkappa_i(0:nlay_i)
+      ENDIF
+
+ 30   CONTINUE
+!
+!------------------------------------------------------------------------------|
+!  4) iterative procedure begins                                               |
+!------------------------------------------------------------------------------|
+!
+      DO 40 ji = kideb, kiut
+
+        !------------------------------
+        ! keeping old values in memory
+        !------------------------------
+
+        ztsuold =  t_su_b(ji)
+        t_su_b(ji) = min(t_su_b(ji),tfs(ji)-0.00001)
+        DO layer = 1, nlay_s
+           ztsold(layer)    =  t_s_b(ji,layer)
+        END DO
+        DO layer = 1, nlay_i
+           ztiold(layer)    = t_i_b(ji,layer)
+           ti_old(layer)    = ztiold(layer)
+        END DO
+
+      nconv     =  0
+
+ 40   CONTINUE
+
+        !------------------------------
+        ! Beginning of the loop
+        !------------------------------
+      
+      zerrit = 10000.0
+
+!     DO WHILE ( zerrit .GT. zerrmax )
+      DO WHILE ( ( zerrit .GT. zerrmax ) .AND. ( nconv < nconv_max ) )
+
+      do 42 ji = kideb, kiut
+  
+!45   CONTINUE
+
+        nconv   =  nconv+1
+
+        ztsutemp = t_su_b(ji)
+        DO layer = 1, nlay_s
+           ztstemp(layer) = t_s_b(ji,layer)
+        END DO
+        DO layer = 1, nlay_i
+           ztitemp(layer) = t_i_b(ji,layer)
+        END DO
+
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' zerrit   : ', zerrit
+         WRITE(numout,*) ' nconv    : ', nconv 
+         WRITE(numout,*) ' t_s_b    : ', t_s_b(ji,1)
+         WRITE(numout,*) ' t_i_b    : ', ( t_i_b(ji,layer), layer = 1,
+     &                                     nlay_i )
+      ENDIF
+
+!
+!------------------------------------------------------------------------------|
+!  5) specific heat in the ice                                                 |
+!------------------------------------------------------------------------------|
+!
+      DO layer = 1, nlay_i
+         zspeche_i(layer) = cpg + lfus*tmut*s_i_b(ji,layer)/ 
+     &   MAX((t_i_b(ji,layer)-tpw)*(ztiold(layer)-tpw),zeps)
+      END DO
+!
+!------------------------------------------------------------------------------|
+!  6) eta factors                                                              |
+!------------------------------------------------------------------------------|
+!
+      DO layer = 1, nlay_s
+         zeta_s(layer) = ddtb / max(rhon*cpg*deltaz_s_phy(layer),zeps)
+      END DO
+
+      DO layer = 1, nlay_i
+        zeta_i(layer) = ddtb / max(rhog*deltaz_i_phy(layer) * 
+     &                  zspeche_i(layer)
+     &                  ,zeps)
+      END DO
+
+!
+!------------------------------------------------------------------------------|
+!  7) surface flux computation                                                 |
+!------------------------------------------------------------------------------|
+!
+      t_su_b(ji) = min(t_su_b(ji),tfs(ji))
+      imelt   = int(max(0.0,sign(1.0d0,t_su_b(ji)-tpw)))
+      ! pressure of water vapor saturation (Pa)
+      es         =  611.0*10.0**(9.5*(t_su_b(ji)-273.16)/
+     &              (t_su_b(ji)-7.66))
+      ! net longwave radiative flux
+! MV BUG
+!     fratsb(ji) = emig*(ratbqb(ji)-
+!    &             stefan*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)*t_su_b(ji))
+      fratsb(ji) = ratbqb(ji) - emig *
+     &             stefan*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)
+      ! sensible and latent heat flux
+      CALL flx(ht_i_b(ji),t_su_b(ji),tabqb(ji),qabqb(ji),fcsb(ji),
+     &         fleb(ji),qsfcb(ji),zrchu1(ji),zrchu2(ji),vabqb(ji),zref)
+      fcsb(ji)   =  -fcsb(ji)
+      fleb(ji)   =  MIN( -fleb(ji) , 0.0 ) ! always negative, as precip 
+                                           ! energy already added
+
+!     qsfcb(ji)  = zqsat(ji)
+
+      ! intermediate variable
+      zssdqw     =  qsfcb(ji)*qsfcb(ji)*psbqb(ji)/
+     &              (0.622*es)*alog(10.0)*9.5*
+     &              ((273.16-7.66)/(t_su_b(ji)-7.66)**2.0)
+      ! derivative of the surface atmospheric net flux
+          dzf    =  -4.0*emig*stefan*t_su_b(ji)
+     &              *t_su_b(ji)*t_su_b(ji)
+     &              -(zrchu1(ji)+zrchu2(ji)*zssdqw)
+      ! surface atmospheric net flux
+          zf     =  ab(ji)*fsolgb(ji)+fratsb(ji)
+     &              +fcsb(ji)+fleb(ji)
+      
+!
+!------------------------------------------------------------------------------|
+!  8) tridiagonal system terms                                                 |
+!------------------------------------------------------------------------------|
+!
+      ! layer denotes the number of the layer in the snow or in the ice
+      ! numeq denotes the reference number of the equation in the tridiagonal
+      ! system, terms of tridiagonal system are indexed as following :
+      ! 1 is subdiagonal term, 2 is diagonal and 3 is superdiagonal one
+
+      ! ice interior terms (top equation has the same form as the others)
+      DO numeq = 1, maxnlay
+         ztrid(numeq,1) = 0.0
+         ztrid(numeq,2) = 0.0
+         ztrid(numeq,3) = 0.0
+         zindterm(numeq) = 0.0
+         zindtbis(numeq) = 0.0
+         zdiagbis(numeq) = 0.0
+      END DO
+      DO numeq = nlay_s + 2, nlay_s + nlay_i 
+           layer = numeq - nlay_s - 1
+           ztrid(numeq,1)   =  - zeta_i(layer)*zkappa_i(layer-1)
+           ztrid(numeq,2)   =  1.0 + zeta_i(layer)*(zkappa_i(layer-1) +
+     &                       zkappa_i(layer))
+           ztrid(numeq,3)   =  - zeta_i(layer)*zkappa_i(layer)
+           zindterm(numeq)  =  ztiold(layer) + zeta_i(layer)*
+!    &                      ( radab_phy_i(layer) + radab_alg_i(layer) )
+     &                         radab_i(layer)
+      END DO
+      ! ice bottom terms
+      numeq   =  nlay_s + nlay_i + 1
+      ztrid(numeq,1)  =  - zeta_i(nlay_i)*zkappa_i(nlay_i-1)   
+      ztrid(numeq,2)  =  1.0 + zeta_i(nlay_i)*( zkappa_i(nlay_i)*zg1
+     &                   + zkappa_i(nlay_i-1) )
+      ztrid(numeq,3)  =  0.0
+      zindterm(numeq) =  ztiold(nlay_i) + zeta_i(nlay_i)*
+!    &                   ( radab_phy_i(nlay_i) + radab_alg_i(nlay_i) 
+     &                   ( radab_i(nlay_i)
+     &                   + zkappa_i(nlay_i)*zg1
+     &                   *t_bo_b(ji) )
+
+      IF (ht_s_b(ji).GT.0.0) THEN
+!
+!------------------------------------------------------------------------------|
+!  snow-covered cells                                                          |
+!------------------------------------------------------------------------------|
+!
+      ! snow interior terms (bottom equation has the same form as the others)
+      do numeq = 3, nlay_s + 1
+           layer =  numeq - 1
+           ztrid(numeq,1)   =  - zeta_s(layer)*zkappa_s(layer-1)
+           ztrid(numeq,2)   =  1.0 + zeta_s(layer)*( zkappa_s(layer-1) +
+     &                         zkappa_s(layer) )
+           ztrid(numeq,3)   =  - zeta_s(layer)*zkappa_s(layer)
+           zindterm(numeq)  =  ztsold(layer) + zeta_s(layer)*
+     &                         radab_s(layer)
+      end do
+      
+      ! case of only one layer in the ice (ice equation is altered)
+      if (nlay_i.eq.1) then
+         ztrid(nlay_s+2,3)    =  0.0
+         zindterm(nlay_s+2)   =  zindterm(nlay_s+2) + zkappa_i(1)*
+     &                           t_bo_b(ji) 
+      endif
+
+      IF (t_su_b(ji).LT.tpw) THEN
+!
+!------------------------------------------------------------------------------|
+!  case 1 : no surface melting - snow present                                  |
+!------------------------------------------------------------------------------|
+!
+      zdifcase    =  1.0
+      numeqmin    =  1
+      numeqmax    =  nlay_i + nlay_s + 1
+
+      ! surface equation
+      ztrid(1,1) = 0.0
+      ztrid(1,2) = dzf - zg1s*zkappa_s(0)
+      ztrid(1,3) = zg1s*zkappa_s(0)
+      zindterm(1) = dzf*t_su_b(ji) - zf
+
+      ! first layer of snow equation
+      ztrid(2,1)  =  - zkappa_s(0)*zg1s*zeta_s(1)
+      ztrid(2,2)  =  1.0 + zeta_s(1)*(zkappa_s(1) + zkappa_s(0)*zg1s)
+      ztrid(2,3)  =  - zeta_s(1)* zkappa_s(1)
+      zindterm(2) =  ztsold(1) + zeta_s(1)*radab_s(1)
+
+      else
+!
+!------------------------------------------------------------------------------|
+!  case 2 : surface is melting - snow present                                  |
+!------------------------------------------------------------------------------|
+!
+      zdifcase    =  2.0
+      numeqmin    =  2
+      numeqmax    =  nlay_i + nlay_s + 1
+
+      ! first layer of snow equation
+      ztrid(2,1)  =  0.0
+      ztrid(2,2)  =  1.0 + zeta_s(1)*(zkappa_s(1) + zkappa_s(0)*zg1s)
+      ztrid(2,3)  =  - zeta_s(1)*zkappa_s(1)
+      zindterm(2) =  ztsold(1) + zeta_s(1)*(radab_s(1) + zkappa_s(0)*
+     &               zg1s*t_su_b(ji))
+
+      ENDIF
+      ELSE
+!
+!------------------------------------------------------------------------------|
+!  cells without snow                                                          |
+!------------------------------------------------------------------------------|
+!
+      IF (t_su_b(ji).lt.tpw) THEN
+!
+!------------------------------------------------------------------------------|
+!  case 3 : no surface melting - no snow                                       |
+!------------------------------------------------------------------------------|
+!
+      zdifcase    =  3.0
+      numeqmin    =  nlay_s + 1
+      numeqmax    =  nlay_i + nlay_s + 1
+
+      ! surface equation	
+      ztrid(numeqmin,1)   =  0.0
+      ztrid(numeqmin,2)   =  dzf - zkappa_i(0)*zg1    
+      ztrid(numeqmin,3)   =  zkappa_i(0)*zg1
+      zindterm(numeqmin)  =  dzf*t_su_b(ji) - zf
+
+      ! first layer of ice equation
+      ztrid(numeqmin+1,1) =  - zkappa_i(0)*zg1*zeta_i(1)
+      ztrid(numeqmin+1,2) =  1.0 + zeta_i(1)*(zkappa_i(1) + zkappa_i(0)*
+     &                       zg1)  
+      ztrid(numeqmin+1,3) =  - zeta_i(1)*zkappa_i(1)  
+      zindterm(numeqmin+1)=  ztiold(1) + zeta_i(1)*radab_i(1) ! ( radab_phy_i(1) +
+!     &                       radab_alg_i(1) )
+
+      ! case of only one layer in the ice (surface & ice equations are altered)
+      if (nlay_i.eq.1) then
+      ztrid(numeqmin,1)    =  0.0
+      ztrid(numeqmin,2)    =  dzf - zkappa_i(0)*2.0
+      ztrid(numeqmin,3)    =  zkappa_i(0)*2.0
+
+      ztrid(numeqmin+1,1)  =  -zkappa_i(0)*2.0*zeta_i(1)
+      ztrid(numeqmin+1,2)  =  1.0 + zeta_i(1)*(zkappa_i(0)*2.0 + 
+     &                        zkappa_i(1))
+      ztrid(numeqmin+1,3)  =  0.0
+
+      zindterm(numeqmin+1) =  ztiold(1) + zeta_i(1)*
+!    &                      ( radab_phy_i(1) + radab_alg_i(1) +
+     &                      ( radab_i(1) +
+     &                        zkappa_i(1)*t_bo_b(ji) )
+      endif
+
+      else
+!
+!------------------------------------------------------------------------------|
+!  case 4 : surface is melting - no snow                                       |
+!------------------------------------------------------------------------------|
+!
+      zdifcase    =  4.0
+      numeqmin    =  nlay_s + 2
+      numeqmax    =  nlay_i + nlay_s + 1
+
+      ! first layer of ice equation
+      ztrid(numeqmin,1) =  0.0
+      ztrid(numeqmin,2) =  1.0 + zeta_i(1)*(zkappa_i(1) + zkappa_i(0)*
+     &                       zg1)  
+      ztrid(numeqmin,3) =  - zeta_i(1)* zkappa_i(1)
+      zindterm(numeqmin)  =  ztiold(1) + zeta_i(1)* ( radab_i(1) +  !(radab_phy_i(1) + 
+!    &                       radab_alg_i(1) +
+     &                       zkappa_i(0)*zg1*t_su_b(ji) )
+
+      ! case of only one layer in the ice (surface & ice equations are altered)
+      if (nlay_i.eq.1) then
+         ztrid(numeqmin,1)  =  0.0
+         ztrid(numeqmin,2)  =  1.0 + zeta_i(1)*(zkappa_i(0)*2.0 + 
+     &                         zkappa_i(1))
+         ztrid(numeqmin,3)  =  0.0
+         zindterm(numeqmin) =  ztiold(1) + zeta_i(1)*
+!    &                         (radab_phy_i(1) + radab_alg_i(1)
+     &                         ( radab_i(1) + 
+     &                         + zkappa_i(1)*t_bo_b(ji) ) 
+     &                         + t_su_b(ji)*zeta_i(1)*zkappa_i(0)*2.0
+      endif
+
+      endif
+      endif
+!
+!------------------------------------------------------------------------------|
+!  9) tridiagonal system solving                                               |
+!------------------------------------------------------------------------------|
+!
+      ! solving the tridiagonal system with Gauss elimination
+      ! Thomas algorithm, from Computational fluid Dynamics, J.D. ANDERSON, 
+      ! McGraw-Hill 1984.	
+      ! computing temporary results
+      zindtbis(numeqmin) =  zindterm(numeqmin)
+      zdiagbis(numeqmin) =  ztrid(numeqmin,2)
+
+      do numeq = numeqmin+1, numeqmax
+         zdiagbis(numeq)  =  ztrid(numeq,2) - ztrid(numeq,1)*
+     &                       ztrid(numeq-1,3)/zdiagbis(numeq-1)
+         zindtbis(numeq)  =  zindterm(numeq) - ztrid(numeq,1)*
+     &                       zindtbis(numeq-1)/zdiagbis(numeq-1)
+      end do
+
+      ! ice temperatures
+      t_i_b(ji,nlay_i)    =  zindtbis(numeqmax)/zdiagbis(numeqmax)
+!     do numeq = nlay_i + nlay_s + 1, nlay_s + 2, -1
+      do numeq = nlay_i + nlay_s, nlay_s + 2, -1
+         layer    =  numeq - nlay_s - 1
+         t_i_b(ji,layer)  =  (zindtbis(numeq) - ztrid(numeq,3)*
+     &                       t_i_b(ji,layer+1))/zdiagbis(numeq)
+      end do
+
+      ! snow temperatures      
+      if (ht_s_b(ji).gt.0.0) then
+      t_s_b(ji,nlay_s)  =  (zindtbis(nlay_s+1) - ztrid(nlay_s+1,3)*
+     &                     t_i_b(ji,1))/zdiagbis(nlay_s+1)
+          if (nlay_s.gt.1) then 
+          do numeq = nlay_s, 2, -1
+             layer    =  numeq - 1
+             t_s_b(ji,layer)  =  (zindtbis(numeq) - ztrid(numeq,3)*
+     &                         t_s_b(ji,layer+1))/zdiagbis(numeq)
+          end do
+          endif
+      endif
+
+      ! surface temperature
+      if (t_su_b(ji).lt.tfs(ji)) then
+         t_su_b(ji) =  ( zindtbis(numeqmin) - ztrid(numeqmin,3)*
+     &                  ( real(isnow)*t_s_b(ji,1) + 
+     &                  (1.0-real(isnow))*t_i_b(ji,1) ) ) /
+     &                  zdiagbis(numeqmin)
+      endif
+!
+!--------------------------------------------------------------------------
+!   10) Has the scheme converged ?, end of the iterative procedure        |
+!--------------------------------------------------------------------------
+!
+      ! we verify that nothing has started to melt
+      t_su_b(ji)          = MIN( t_su_b(ji) , tfs(ji) )
+      DO layer  =  1, nlay_i
+         ztmelt_i         = MIN( -tmut*s_i_b(ji,layer) + tpw ,
+     &                           273.149999999d0) 
+         t_i_b(ji,layer)  = MIN( t_i_b(ji,layer) ,ztmelt_i )
+      END DO
+
+      ! zerrit is a residual which has to be under zerrmax
+      zerrit   =  ABS(t_su_b(ji)-ztsutemp)            
+      DO layer = 1, nlay_s
+         zerrit   =  MAX(zerrit,ABS(t_s_b(ji,layer) 
+     &            -  ztstemp(layer)))
+      END DO
+      DO layer = 1, nlay_i
+         zerrit  =  max(zerrit,abs(t_i_b(ji,layer) - ztitemp(layer)))
+      END DO
+
+ 42   CONTINUE
+
+      END DO
+
+      DO 45 ji = kideb, kiut
+      ! compute available energy for internal melt
+         f_s_im(ji) = 0.
+         DO layer = 1, nlay_s
+            IF ( t_s_b(ji,layer) .GE. tfs(ji) ) THEN
+               f_s_im(ji) = - rhon * ( cpg*( tfs(ji) - t_s_b(ji,layer)))
+     &                    * ht_s_b(ji) / ddtb
+               t_s_b(ji,layer)  =  MIN( t_s_b(ji,layer) ,tfs(ji) )
+            ENDIF
+         END DO
+
+ 45   CONTINUE
+!
+!--------------------------------------------------------------------------
+!   11) Heat conduction fluxes                                            |
+!--------------------------------------------------------------------------
+!
+
+      DO 50 ji = kideb, kiut
+      ! surface conduction flux
+      fc_su(ji)    =  - real(isnow)*zkappa_s(0)*zg1s*(t_s_b(ji,1) - 
+     &            t_su_b(ji)) 
+     &            - (1.0-real(isnow))*zkappa_i(0)*zg1*
+     &            (t_i_b(ji,1) - t_su_b(ji))
+
+      ! bottom conduction flux
+      fc_bo_i(ji)  =  - zkappa_i(nlay_i)*
+     &            ( zg1*(t_bo_b(ji) - t_i_b(ji,nlay_i)) )
+
+      ! internal conduction fluxes : snow
+      !--upper snow value
+      fc_s(ji,0) = - isnow* 
+     &             zkappa_s(0) * zg1s * ( t_s_b(ji,1) - 
+     &             t_su_b(ji) )
+      !--basal snow value
+      fc_s(ji,1) = - isnow* 
+     &             zkappa_s(1) * ( t_i_b(ji,1) - 
+     &             t_s_b(ji,1) )
+
+      ! internal conduction fluxes : ice
+      !--upper layer
+      fc_i(ji,0) =  - isnow *   ! interface flux if there is snow
+     &         ( zkappa_i(0)  * ( t_i_b(ji,1) - t_s_b(ji,nlay_s ) ) )
+     &         - ( 1.0 - isnow ) * ( zkappa_i(0) * 
+     &           zg1 * ( t_i_b(ji,1) - t_su_b(ji) ) ) ! upper flux if no
+      !--internal ice layers
+      DO layer = 1, nlay_i - 1
+         fc_i(ji,layer) = - zkappa_i(layer) * ( t_i_b(ji,layer+1) - 
+     &                      t_i_b(ji,layer) )
+      END DO
+      !--under the basal ice layer
+      fc_i(ji,nlay_i) = fc_bo_i(ji)
+
+      ! case of only one layer in the ice
+      IF (nlay_i.EQ.1) THEN
+         fc_su(ji) = -real(isnow)*(zkappa_s(0)*(zg1s*(t_s_b(ji,1)-
+     &                         t_su_b(ji))))
+     &           -(1.0-real(isnow))*zkappa_i(0)*zg1*(t_i_b(ji,1)-
+     &           t_su_b(ji))
+         fc_bo_i(ji) = -zkappa_i(nlay_i)*zg1*
+     &                  (t_bo_b(ji)-t_i_b(ji,nlay_i))
+      ENDIF
+!
+!--------------------------------------------------------------------------
+!   12) Update atmospheric heat fluxes and energy of melting              |
+!--------------------------------------------------------------------------
+!
+      ! pressure of water vapor saturation (Pa)
+      es         =  611.0*10.0**(9.5*(t_su_b(ji)-273.16)/
+     &              (t_su_b(ji)-7.66))
+      ! net longwave radiative flux
+! MV BUG
+!     fratsb(ji) = emig*(ratbqb(ji)-
+!    &             stefan*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)*t_su_b(ji))
+      fratsb(ji) = ratbqb(ji) - emig *
+     &             stefan*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)*t_su_b(ji)
+      ! sensible and latent heat flux
+      CALL flx(ht_i_b(ji),t_su_b(ji),tabqb(ji),qabqb(ji),fcsb(ji),
+     &         fleb(ji),qsfcb(ji),zrchu1(ji),zrchu2(ji),vabqb(ji),zref)
+
+      fcsb(ji)   =  -fcsb(ji)
+      fleb(ji)   =  MIN( -fleb(ji) , 0.0 ) ! always negative, as precip 
+                                           ! energy already added
+
+      ! ice energy of melting
+      CALL ice_th_enmelt(kideb, kiut, nlay_s, nlay_i) 
+      
+      IF ( ln_write ) THEN
+         WRITE(numout,*) ' nconv : ', nconv
+         WRITE(numout,*) ' zerrit : ', zerrit
+         WRITE(numout,*) ' t_su_b: ', t_su_b(ji) 
+         WRITE(numout,*) ' t_s_b : ', ( t_s_b(ji,layer), 
+     &                      layer = 1, nlay_s )
+         WRITE(numout,*) ' t_i_b : ', ( t_i_b(ji,layer), 
+     &                      layer = 1, nlay_i )
+         WRITE(numout,*) ' t_bo_b : ', t_bo_b(ji)
+         WRITE(numout,*)
+      ENDIF
+
+ 50   CONTINUE
+!
+!------------------------------------------------------------------------------
+! End of ice_th_diff
+      END SUBROUTINE
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.f	(revision 6)
@@ -0,0 +1,3069 @@
+C--VERSION:2005.04.08
+C modified by Martin Vancoppenolle for use with LIM1D
+C read of forcing
+
+C  -----------------------------------------------------------------------
+C             libUN : User level NetCDF READ / WRITE routines
+C
+C                     by Philippe Marbaix and Xavier Fettweis
+C
+C              Compatible with NetCDF version 3.x (or above).
+C  -----------------------------------------------------------------------
+
+C   User-frendly interface :
+C   ------------------------
+
+c   CF_INI_FILE   : Initialization of the netcf file  
+c   CF_CREATE_DIM : Create axis/dimensions
+c   CF_CREATE_VAR : Create variables
+c   CF_CREATE_FILE: Write the netcdf file
+c   CF_WRITE      : Write variables
+c   CF_READ3D/2D  : Read variables
+c   CF_OPEN       : Open  netcdf file
+c   CF_CLOSE      : Close netcdf file
+ 
+C   Main routines :
+C   ---------------
+
+c     UNscreate   : General file creation routine,
+c                    defining multiple dimensions + attributes
+
+c     UNwrite     : General variables writting routine
+c                    (also updates 'range' attribute and variable if present)
+c                   Note: Use UNlwrite to write 2D planes in 3D variables
+
+c     UN(s)read   : Reading routine (grid coordinates + variable)
+
+C   Complementary routines :
+C   ------------------------
+
+c     UNparam     : set optional parameters of libUN functions
+c     UNwopen     : re-open file for writting
+c     UNropen     : open file for reading
+c     UNgtime     : Find time index for a given time value
+c     UNgindx     : Generalization of UNgtime: find value in any 1D data.   
+c     UNfindx     : modified version of UNgindx safe for non-monotonic data
+c     UNclose     : close the NetCDF file
+c     UNwratt     : Real attributes writting 
+c     UNwcatt     : Characters attributes creation & writing
+
+C   Double Precision :
+C   ------------------
+
+c     To be in double precision, type this 
+c     > sed "s/REAL\*4/REAL\*8/g"      libUN.f  > libUN1.f
+c     > sed "s/\_REAL/\_DOUBLE/g"      libUN1.f > libUN2.f
+c     > sed "s/NF\_FLOAT/NF\_DOUBLE/g" libUN2.f > libUNd.f
+c     > rm -f libUN1.f libUN2.f
+
+C  -----------------------------------------------------------------------
+
+
+C    +---------------------------+---------------------------------------+
+C    +  Subroutine CD_INI_FILE : + Initialize the netcdf file            +
+C    +---------------------------+---------------------------------------+
+
+      SUBROUTINE CF_INI_FILE (filename, filetitle)
+
+c     Input :
+c     =======
+
+c     filename  = name  of the netcdf file
+c     filetitle = title in the netcdf file
+
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) filename,filetitle  
+
+      CF_attnam(1) = 'actual_range'
+      CF_attnum(1) = 2
+
+      CF_varnbrtot =  0 ! Initialization
+      CF_dimnbrtot = -1 ! Initialization
+
+      CF_filenam   = filename
+      CF_filetit   = filetitle
+
+      END SUBROUTINE CF_INI_FILE
+
+
+C    +-----------------------------+-------------------------------------+
+C    +  Subroutine CF_CREATE_DIM : + Create dimensions/axis              +
+C    +-----------------------------+-------------------------------------+
+
+      SUBROUTINE CF_CREATE_DIM (dimname,dimunits,dimdim,vallues)
+
+c     Input :
+c     =======
+
+c     dimname  = name of the axis/dimension
+c     dimunits = units of the axis/dimension
+c     dimdim   = dimensions of the axis/dimension
+c     vallues  = vallues of the axis/dimension
+
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) dimname,dimunits
+      
+      INTEGER        dimdim,i
+      REAL*4         vallues(dimdim)
+
+      CF_dimnbrtot                 = CF_dimnbrtot + 1
+
+      CF_dimnbrtot                 = max(0,CF_dimnbrtot)
+
+      CF_dimnam(CF_dimnbrtot)      = dimname
+      CF_dimnamuni(CF_dimnbrtot)   = dimunits    
+      CF_dim(CF_dimnbrtot)         = dimdim
+ 
+      do i = 1,dimdim
+      CF_dimval(i,CF_dimnbrtot)    = vallues(i)
+      enddo   
+    
+      END SUBROUTINE CF_CREATE_DIM
+
+C    +-----------------------------+-------------------------------------+
+C    +  Subroutine CF_CREATE_VAR : + Create variables			 +
+C    +-----------------------------+-------------------------------------+
+
+      SUBROUTINE CF_CREATE_VAR (varname,vartitle,varunits,varaxe4,
+     .                          varaxe1,varaxe2,varaxe3)
+
+c     Input :
+c     =======
+
+c     varname  = name of the variable
+c     vartitle = title of the variable
+c     varunits = units of the variable
+c     varaxeX  = axes used by the variable (T,X,Y,Z)
+
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) varname,vartitle,varunits
+      CHARACTER *(*) varaxe1,varaxe2,varaxe3,varaxe4
+      
+      CF_varnbrtot                 = max (0,CF_varnbrtot + 1)
+
+      CF_varnam(CF_varnbrtot)      = varname
+      CF_varnamdim(1,CF_varnbrtot) = varaxe1
+      CF_varnamdim(2,CF_varnbrtot) = varaxe2
+      CF_varnamdim(3,CF_varnbrtot) = varaxe3
+      CF_varnamdim(4,CF_varnbrtot) = varaxe4
+      CF_varnamuni(CF_varnbrtot)   = varunits
+      CF_vardes(CF_varnbrtot)      = vartitle
+
+      END SUBROUTINE CF_CREATE_VAR
+
+C    +--------------------------------------+----------------------------+
+C    +  Subroutine CF_CREATE_VAR_VIA_FILE : + Create variables           +
+C    +--------------------------------------+----------------------------+
+
+      SUBROUTINE CF_CREATE_VAR_VIA_FILE (filename)
+
+c     Input :
+c     =======
+
+c     filename  = name of the file containing informations
+c                 about the variables 
+
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+      CHARACTER*200 filename
+      
+      CHARACTER*120 tmpvar
+
+      OPEN(unit=999,status='old',file=filename)
+
+980   CONTINUE
+      READ (999,'(A120)',end=990) tmpvar
+
+      IF (tmpvar(1:4).eq.'    ') THEN
+       CF_varnbrtot = max (0,CF_varnbrtot + 1)
+         READ (tmpvar,'(4x,5A9,A12,A50)')
+     .         CF_varnam(CF_varnbrtot),
+     .         CF_varnamdim(1,CF_varnbrtot),
+     .         CF_varnamdim(2,CF_varnbrtot),
+     .         CF_varnamdim(3,CF_varnbrtot),
+     .         CF_varnamdim(4,CF_varnbrtot),
+     .         CF_varnamuni(CF_varnbrtot),
+     .         CF_vardes(CF_varnbrtot)
+      ENDIF
+
+      GOTO 980
+990   CONTINUE
+
+      END SUBROUTINE CF_CREATE_VAR_VIA_FILE
+
+C    +------------------------------+------------------------------------+
+C    +  Subroutine CF_CREATE_FILE : + Create the netcdf file             +
+C    +------------------------------+------------------------------------+
+
+      SUBROUTINE CF_CREATE_FILE (filename)
+
+c     Input :
+c     =======
+
+c     filename  = name  of the netcdf file
+
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) filename  
+
+      INTEGER        i,j,id
+
+      INTEGER        UN1_dim(0:CF_dimnbrtot)
+
+      REAL           UN1_dimval(CF_dimmaxlen,0:CF_dimnbrtot)
+
+      CHARACTER*31   UN1_dimnam(0:CF_dimnbrtot),
+     .               UN1_dimnamuni(0:CF_dimnbrtot) 
+
+      if(filename.ne.CF_filenam)then
+       write(6,*) "ERROR: not "//CF_filenam
+       stop
+      endif
+   
+      DO i=0,CF_dimnbrtot
+       UN1_dim(i)       = CF_dim(i)
+       UN1_dimnam(i)    = CF_dimnam(i)
+       UN1_dimnamuni(i) = CF_dimnamuni(i)
+       DO j=1,CF_dim(i)
+        UN1_dimval(j,i) = CF_dimval(j,i)
+       END DO
+      END DO
+
+      call UNscreate (CF_filenam,CF_filetit,CF_dimnbrtot,UN1_dim,
+     .                CF_dimmaxlen, UN1_dimnam ,UN1_dimnamuni,
+     .                UN1_dimval,
+     .                CF_varmaxnbr,CF_varnbrtot,CF_varnam,
+     .                CF_varnamdim,CF_varnamuni,CF_vardes,
+     .                CF_attnbr,CF_attnam,CF_attnum,id)
+      
+      call UNclose   (id)   
+
+
+      END SUBROUTINE CF_CREATE_FILE
+
+C    +------------------------+------------------------------------------+
+C    +  Subroutine CF_WRITE : + Writes variables                         +
+C    +------------------------+------------------------------------------+
+
+
+      SUBROUTINE CF_WRITE (FILEname, VARname , itime,
+     &                    Ni,  Nj, Nlev, var)
+
+c     Input :
+c     =======
+
+c     FILEname    = name of the netcdf file
+c     VARname     = name of variables
+c     itime       = index on time axis
+c     Ni,Nj,Nlev  = X,Y,Z dimension
+c     var         = array of vallues of the variable 
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) FILEname,VARname  
+      INTEGER        itime
+      INTEGER        Ni,  Nj, Nlev,fileid 
+      REAL*4         var(Ni, Nj, Nlev)
+
+      if(CF_filenamopened.ne.FILEname) then
+      CALL UNwopen (FILEname,fileid)
+      else
+      fileid = CF_fileidopened
+      endif
+
+      CALL UNwrite (fileid,VARname ,itime,Ni,  Nj, Nlev, var)  
+
+      if(CF_filenamopened.ne.FILEname) then
+      call UNclose (fileid)
+      endif
+
+      END SUBROUTINE CF_WRITE
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine CF_READ1D : + Read variables                          +
+C**  +-------------------------+-----------------------------------------+
+
+      SUBROUTINE CF_READ1D (FILEname, VARname , itime,
+     .                      N, var)
+      ! routine added by martin vancoppenolle to read 1D arrays
+
+c     Input :
+c     =======
+
+c     FILEname    = name of the netcdf file
+c     VARname     = name of variables
+c     itime       = index on time axis
+c     N           = X dimension
+
+c     Output :
+c     ========
+
+c     var         = array of values of the variable 
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) FILEname,VARname
+      CHARACTER*31   var_units,filetitle  
+      INTEGER        N, itime,level
+      REAL*4         var(N)
+
+      INTEGER        i,j,fileid
+
+      if(CF_filenamopened.ne.FILEname) then
+      CALL UNropen (FILEname,fileid,filetitle)
+      else
+      fileid = CF_fileidopened
+      endif
+
+      CALL UNsread (fileid, VARname, itime, 1, 1, 1,
+     &              N , 1 , 1,var_units, var)          
+
+      if(CF_filenamopened.ne.FILEname) then
+      call UNclose (fileid)
+      endif
+
+      END SUBROUTINE CF_READ1D
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine CF_READ2D : + Read variables                          +
+C**  +-------------------------+-----------------------------------------+
+
+      SUBROUTINE CF_READ2D (FILEname, VARname , itime,
+     .                      Ni,  Nj, Nlev, var)
+
+
+c     Input :
+c     =======
+
+c     FILEname    = name of the netcdf file
+c     VARname     = name of variables
+c     itime       = index on time axis
+c     Ni,Nj,Nlev  = X,Y,Z dimension
+
+c     Output :
+c     ========
+
+c     var         = array of vallues of the variable 
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) FILEname,VARname
+      CHARACTER*31   var_units,filetitle  
+      INTEGER        Ni,  Nj, Nlev,itime,level
+      REAL*4         var(Ni, Nj)
+
+      INTEGER        i,j,fileid
+
+      if(CF_filenamopened.ne.FILEname) then
+      CALL UNropen (FILEname,fileid,filetitle)
+      else
+      fileid = CF_fileidopened
+      endif
+
+      CALL UNsread (fileid, VARname, itime, Nlev, 1, 1,
+     &              Ni , Nj , 1,var_units, var)          
+
+      if(CF_filenamopened.ne.FILEname) then
+      call UNclose (fileid)
+      endif
+
+      END SUBROUTINE CF_READ2D
+
+C    +-------------------------+-----------------------------------------+
+C    +  Subroutine CF_READ3D : + Read variables                          +
+C    +-------------------------+-----------------------------------------+
+
+
+      SUBROUTINE CF_READ3D (FILEname, VARname , itime,
+     .                      Ni,  Nj, Nlev, var)
+
+c     Input :
+c     =======
+
+c     FILEname    = name of the netcdf file
+c     VARname     = name of variables
+c     itime       = index on time axis
+c     Ni,Nj,Nlev  = X,Y,Z dimension
+
+c     Output :
+c     ========
+
+c     var         = array of vallues of the variable 
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      CHARACTER *(*) FILEname,VARname
+      CHARACTER*31   var_units,filetitle  
+      INTEGER        Ni,  Nj, Nlev,itime,level 
+      REAL*4         var(Ni, Nj,Nlev)
+
+      INTEGER        i,j,fileid
+
+      if(CF_filenamopened.ne.FILEname) then
+      CALL UNropen (FILEname,fileid,filetitle)
+      else
+      fileid = CF_fileidopened
+      endif
+
+      CALL UNsread (fileid, VARname, itime, 0, 1, 1,
+     &              Ni , Nj , Nlev,var_units, var)          
+
+      if(CF_filenamopened.ne.FILEname) then
+      call UNclose (fileid)
+      endif
+
+      END SUBROUTINE CF_READ3D
+
+C**  +------------------------+------------------------------------------+
+C**  +  Subroutine CF_CLOSE : + Close the file                           +
+C**  +------------------------+------------------------------------------+
+
+      SUBROUTINE CF_CLOSE (FILEname)
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+   
+      CHARACTER*(*) FILEname
+
+      if(FILEname.eq.CF_filenamopened)then
+      call UNclose (CF_fileidopened)
+      else
+      print *,FILEname//" not opened"
+      endif
+  
+      CF_filenamopened = ""
+      CF_fileidopened  = 0
+
+      END SUBROUTINE CF_CLOSE
+
+C**  +-----------------------+-------------------------------------------+
+C**  +  Subroutine CF_OPEN : + open the file                             +
+C**  +-----------------------+-------------------------------------------+
+
+      SUBROUTINE CF_OPEN (FILEname,FILEid)
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+  
+      INTEGER       FILEid 
+
+      CHARACTER*(*) FILEname
+
+      call UNwopen (FILEname,FILEid)
+     
+      CF_filenamopened = FILEname
+      
+      CF_fileidopened  = FILEid
+
+      END SUBROUTINE CF_OPEN
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNscreate : +                                         +
+C**  +-------------------------+                                         +
+C**  +  * Purpose :                                                      +
+C**  +     Create a NetCDF file, general version.                        +
+C**  +     (Staggered grids + other extensions to UNcreate)              +
+C**  +                                                                   +
+C**  +  * How it works : calling routine must provide                    +
+C**  +    -a list of dimensions                                          +
+C**  +     (size of each dimens., names, units and values of coordinates)+
+C**  +    -a list of variables                                           +
+C**  +     (units, number of dimensions, names of selected dimensions)   +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +  -------                                                          +
+C**  +                                                                   +
+C**  +  General :                                                        +
+C**  +   FILEnam          [char]: Name of the file to be created.        +
+C**  +   title            [char]: Title attribute                        +
+C**  +                                                                   +
+C**  +  Dimensions:                                                      +
+C**  +   TND                    : Total Number of SPATIAL dimensions     +
+C**  +                            Notice : Set "time" to dimension No 0  +
+C**  +   DFdim(0:TND)           : # discrete values for each dimension   +
+C**  +                            Notice : DFdim(0).eq.0                 +
+C**  +                            -> UNLIMITED TIME (coord. not defined) +
+C**  +                               WARNING: In this case, the NetCDF   +
+C**  +                               use a temporary space to duplicate  +
+C**  +                               the file -> NOT RECOMMENDED         +
+C**  +   MXdim                  : Maximum value of DFdim, = arrays size  +
+C**  +   NAMdim(0:TND)    [char]: Name of dimensions, except time        +
+C**  +   UNIdim(0:TND)    [char]: Units of dimensions (attribute)        +
+C**  +   VALdim(MXdim,0:TND)[R4]: Values of coordinate for each dimension+
+C**  +                                                                   +
+C**  +  Variables:                                                       +
+C**  +   Dvs                    : Variable's definitions array sizes,    +
+C**  +   Nvs                    : Number of defined variables(Nvs.le.Dvs)+
+C**  +   name_vs (Dvs)    [char]: name of variable.                      +
+C**  +   unit_vs (Dvs)    [char]: physical units of variable (attribute) +
+C**  +   Sdim_vs (4,Dvs)  [char]: name of Selected dims (in above list)  +
+C**  +                            Blanked or '-' elements = not used     +
+C**  +   lnam_vs (Dvs)    [char]: Long_name attribute (descript. of var.)+
+C**  +                                                                   +
+C**  +  List of real attributes to all variables:                        +
+C**  +   Nra                    : Number of Real Attributes (.ge.1 !)    +  
+C**  +   NAMrat(Nra)      [char]: NAMes of Real ATtributes  (''=none)    +
+C**  +                            (initial value= 0; set it with UNwratt)+
+C**  +   Nvals(Nra)             : Number of values of these attributes.  +
+C**  +   ! Currently limited to 1 value (scalar) or 2 (2 elements vector)+
+C**  +   ! EXCEPTION: Setting the last attribute name to '[var]_range'   +
+C**  +                does create a variable (!) for level-by-level range+
+C**  +                (very usefull for 3D + time fields)                +
+C**  +                                                                   +
+C**  +  NB : [char] variables may have any length.                       +
+C**  +       blanks characters are NOT ALLOWED in any variable,          +
+C**  +          except the "title".                                      +
+C**  +          and the NetCDF variables defined here are always real*4  +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +  --------                                                         +
+C**  +   FILEid                 : Index of the NetCDF file (remains open)+
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNscreate (FILEnam, title,
+     &      TND, DFdim, MXdim, NAMdim, UNIdim, VALdim, 
+     &      Dvs, Nvs, name_vs, Sdim_vs, unit_vs, lnam_vs,
+     &      Nra, NAMrat, Nvals,
+     &      FILEid )
+
+C +
+      IMPLICIT NONE
+ 
+      INCLUDE 'libUN.inc'
+
+C +
+      INTEGER icheck, MXND
+C     ** Maximum number of dimensions 
+      parameter (MXND = 100) 
+
+C +   INPUT:      
+C +   - - -
+      CHARACTER *(*) FILEnam
+      CHARACTER *(*) title  
+
+      INTEGER        TND, DFdim(0:TND), MXdim
+      CHARACTER *(*) NAMdim(0:TND)   
+      CHARACTER *(*) UNIdim(0:TND)
+      REAL*4         VALdim(MXdim,0:TND)
+
+      INTEGER        Nvs, Dvs
+      CHARACTER *(*) name_vs(Dvs)
+      CHARACTER *(*) Sdim_vs(4,Dvs)
+      CHARACTER *(*) unit_vs(Dvs)
+      CHARACTER *(*) lnam_vs(Dvs)
+
+      INTEGER        Nra
+      CHARACTER *(*) NAMrat(Nra)
+      CHARACTER*24   Host,Fdate
+      CHARACTER*200  tmpchar
+      INTEGER        Nvals(Nra)
+
+C +   OUTPUT:    
+C +   - - - -
+      INTEGER FILEid 
+
+C +   LOCAL:
+C +   - - -
+      INTEGER        VARSIZE
+      EXTERNAL       VARSIZE
+      CHARACTER*(30) tmpchr
+      INTEGER        dimDID(0:MXND)
+      INTEGER        dimVID(0:MXND), vsVID, vrVID
+      INTEGER        dID(4), start(4), count(4), rdID(2)
+      INTEGER        mimaID
+      INTEGER        stride(4),imap(4)
+      INTEGER        Ndim_vs
+      INTEGER        ivs, igd, idi, ira, itmp
+      INTEGER        Nlen
+      INTEGER        dNlen(0:MXND)  
+      INTEGER        Ierro, TTerr, ii,jj
+      REAL*4         zero1(1), zero2(2)
+      
+      icheck= 0 !Debugging level
+
+
+C*    0. Initialisations
+C     ------------------
+      IF (icheck.ge.1) WRITE(*,*) 'UNscreate : Begin'
+
+C +   Routines which opens a file must reset libUN internals:
+      CALL UNparam('RESET_PARAMS_',0.0)
+
+      DO ii = 1,4
+        stride(ii) = 1
+      ENDDO
+      zero1(1) = 0.
+      zero2(1) = 0.
+      zero2(2) = 0.
+      TTerr = 0 !Total of error flags
+
+      IF (TND .gt. MXND) THEN
+        write(*,*)'UNscreate - Error: so much dimensions ?',TND
+      END IF
+
+C     Create a NetCDF file and enter define mode :
+C     --------------------------------------------
+      IF (icheck.ge.2) WRITE(*,*) 'FILEnam :', FILEnam
+
+C     ** getting FILEnam [char] size :
+      Nlen = VARSIZE(FILEnam)
+
+      Ierro=NF_CREATE(FILEnam(1:Nlen), NF_CLOBBER , FILEid)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+C     ** identif.                       =>overwrite =error
+
+C*    Time coordinate definition.
+C     ---------------------------
+
+C     ** Define dimension :    
+      IF (icheck.ge.3) WRITE(*,*) '# time iters.:', DFdim(0)
+      IF (DFdim(0).eq.0.) THEN
+        Ierro=NF_DEF_DIM(FILEid , 'time', NF_UNLIMITED, dimDID(0))
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+      ELSE
+        Ierro=NF_DEF_DIM(FILEid , 'time', DFdim(0), dimDID(0))
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+      END IF
+      dNlen(0)= 4  ! 4 characters in the name 'time'...
+      IF (NAMdim(0)(1:4).ne.'time') THEN
+        WRITE(*,*) 'Sorry, NAMdim(0) must be ''time'' .'
+        STOP
+      END IF
+       
+C     ** Define variable for the time coordinate values :
+      dID(1)    = dimDID(0)
+      Ierro=NF_DEF_VAR(FILEid , 'time', NF_FLOAT,1 , dID,  dimVID(0))
+C     **      ^^^^^^^^^^ FILEid  var name  type  dims  DIMid VARid  
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+      TTerr = TTerr + ABS(Ierro)
+
+
+C     Spatial coordinates definitions : DIMS and VARs (locations).
+C     ------------------------------------------------------------
+C
+      DO igd = 1,TND            !** BEGIN LOOP over all spatial dims
+        IF (icheck.ge.3) WRITE(*,*) '  spatial dim:', NAMdim(igd)
+        
+C       ** getting NAMdim [char] size :
+        Nlen = VARSIZE(NAMdim(igd)) 
+        dNlen(igd) = Nlen  !For further use of NAMdim
+
+        Ierro=NF_DEF_DIM(FILEid    , NAMdim(igd)(1:Nlen),
+     &                     DFdim(igd),dimDID(igd))
+C       **line1 ^^^^^^^^^^ FILEid    | dim name            
+C       **line2            # values  | VARid
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+
+        dID(1)     = dimDID(igd)  
+        Ierro=NF_DEF_VAR(FILEid    , NAMdim(igd)(1:Nlen),
+     &                     NF_FLOAT  ,    1  , dID     ,dimVID(igd))
+C       **line1 ^^^^^^^^^^ FILEid    | dim name            
+C       **line2            type      | #dims | dimsIDs | VARid 
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+
+      END DO                    !** END   LOOP over all spatial dims
+
+C     Special coordinate definition: MinMax (for [var]_range)
+C     -------------------------------------------------------
+      IF (NAMrat(Nra)(1:11).eq.'[var]_range') THEN
+
+        Ierro=NF_DEF_DIM(FILEid, 'MinMax', 2, mimaID)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+      ENDIF
+
+C     Define the fields. 
+C     ------------------
+
+      DO ivs = 1,Nvs             !**BEGIN LOOP on var. num.
+        IF (icheck.ge.3)
+     &    WRITE (*,*) 'Defining variable ',name_vs(ivs)
+
+
+C       Set space and time dimensions
+C       - - - - - - - - - - - - - - -
+C        ** Initialise number of dimensions :
+         Ndim_vs= 0 
+
+         DO idi = 1, 4           !** BEGIN LOOP on var dims.
+         IF  (Sdim_vs(idi,ivs)(1:1).ne.' '
+     &   .and.Sdim_vs(idi,ivs)(1:1).ne.'-') THEN !**skip undefined. 
+
+C         ** getting Sdim_vs [char] size :
+          Nlen =  VARSIZE(Sdim_vs(idi,ivs))
+
+C         ** Searching for the dimension index from its name (Sdim_vs)    
+          igd = 0
+          DO WHILE (Sdim_vs(idi,ivs)(1:Nlen)
+     &        .ne. NAMdim(igd)(1:dNlen(igd)) )
+            IF (igd.eq.TND) THEN 
+              write(*,*)'UNscreate-ERROR: Dimension not found:',
+     &              Sdim_vs(idi,ivs)(1:Nlen)
+              STOP
+            END IF
+            igd = igd + 1
+          END DO               
+C         ** Construct the dimensions id's for that variable (ivs):
+          IF (icheck.ge.3)
+     &       WRITE (*,*) 'using dimension ',NAMdim(igd), dimDID(igd)
+          Ndim_vs      = Ndim_vs + 1
+          dID(Ndim_vs) = dimDID(igd) 
+
+        END IF
+        END DO                   !** END   LOOP on var dims.
+
+C       Define our special [var]_range field for 4D variables
+C       - - - - - - - - - - - - - - - - - - - - - - - - - - -
+        IF  (Ndim_vs.eq.4 
+     &  .and.NAMrat(Nra)(1:11).eq.'[var]_range') THEN 
+
+          Nlen = VARSIZE(name_vs(ivs))
+          rdID(1)  = dID (3)  !(4D variable, 3th dim = level)
+          rdID(2)  = mimaID   !(for min, max)
+          tmpchr = name_vs(ivs)(1:Nlen)//'_range'
+          itmp   = Nlen + 6
+          Ierro =  NF_DEF_VAR(FILEid,tmpchr(1:itmp),
+     &                        NF_FLOAT, 2, rdID, vrVID)
+          IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+          TTerr = TTerr + ABS(Ierro)
+
+        ENDIF
+
+C       Define fields :
+C       - - - - - - - -
+        Nlen = VARSIZE(name_vs(ivs))
+        Ierro=NF_DEF_VAR(FILEid , name_vs(ivs)(1:Nlen),
+     &                     NF_FLOAT, Ndim_vs, dID     , vsVID)
+C       **line1 ^^^^^^^^^^ FILEid | variable name
+C       **line2            type   | #dims   | dimsIDs | VARid
+        IF (Ierro.NE.NF_NOERR) 
+     &      CALL HANDLE_ERR('UNscreate (field)', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+
+
+C     Set the variable's attributes : 
+C     -------------------------------
+
+C       ** Units: 
+C       - - - - - 
+C       ** getting unit_vs [char] size :
+        Nlen = VARSIZE(unit_vs(ivs))
+
+        Ierro=  NF_PUT_ATT_TEXT(FILEid , vsVID ,'units',
+     &                          Nlen   ,unit_vs(ivs)(1:Nlen))
+c       **line1 ^^^^^^^^^^^^^^^ FILEid |var.id | attr.name
+C       **line2                 length | attr.value
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+        
+C       ** Special case : units = sigma 
+C       - - - - - - - - - - - - - - - -
+C       In this case, CV convention advises to write the following
+C        attribute :  positive = down
+C
+        Nlen = VARSIZE(lnam_vs(ivs))
+
+        IF ( unit_vs(ivs)(1:Nlen) .EQ. '[sigma]'
+     &  .OR. unit_vs(ivs)(1:Nlen) .EQ. 'sigma_level' ) THEN
+          IF (icheck.ge.3) THEN
+            WRITE(*,*) 'Unit = sigma -> setting positive attr'
+          ENDIF   
+
+          Ierro=  NF_PUT_ATT_TEXT(FILEid , vsVID ,'positive',
+     &                            4      ,'down')
+c         **line1 ^^^^^^^^^^^^^^^ FILEid |var.id | attr.name
+C         **line2                 length | attr.value
+          IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        ENDIF
+
+C       ** "long_name":
+C       - - - - - - - -
+        Nlen = VARSIZE(lnam_vs(ivs))
+
+        IF (icheck.ge.3)
+     &    WRITE (*,*) 'Write long_name ',lnam_vs(ivs)(1:Nlen)
+
+        Ierro=NF_PUT_ATT_TEXT(FILEid , vsVID ,'long_name',
+     &                          Nlen  ,lnam_vs(ivs)(1:Nlen)     )
+
+        do jj=1,Nlen
+          if(lnam_vs(ivs)(jj:jj).eq." ") lnam_vs(ivs)(jj:jj)="_"
+          if(lnam_vs(ivs)(jj:jj).eq.".") lnam_vs(ivs)(jj:jj)="_"
+          if(lnam_vs(ivs)(jj:jj).eq."(") lnam_vs(ivs)(jj:jj)="_"
+          if(lnam_vs(ivs)(jj:jj).eq.")") lnam_vs(ivs)(jj:jj)="_"
+          if(lnam_vs(ivs)(jj:jj).eq."/") lnam_vs(ivs)(jj:jj)="_"
+        enddo
+
+        Ierro=NF_PUT_ATT_TEXT(FILEid , vsVID ,'standard_name',
+     &                          Nlen  ,lnam_vs(ivs)(1:Nlen)     )
+
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+
+
+C       ** From the list of real attributes (input argument) : 
+C       - - - - - - - - - - - - - - - - - - - - - - - - - - - 
+C
+        DO ira = 1, Nra
+        IF (NAMrat(ira)(1:1).ne.' ') THEN
+        IF (NAMrat(ira)(1:11).eq.'valid_range') THEN 
+
+C         ** The "valid_range" special attribute  :
+          Ierro=NF_PUT_ATT_REAL(FILEid  ,vsVID ,'valid_range' ,
+     &                          NF_FLOAT,2     , ValRange)
+          TTerr = TTerr + ABS(Ierro)
+
+        ELSE IF (NAMrat(ira)(1:11).ne.'[var]_range') THEN 
+        
+C         ** All "regular" attributes :
+          Nlen = VARSIZE(NAMrat(ira))
+          IF (Nvals(ira).eq.1) THEN
+            Ierro=NF_PUT_ATT_REAL(FILEid,vsVID,NAMrat(ira)(1:Nlen),
+     &                           NF_FLOAT,   Nvals  , zero1      )
+            TTerr = TTerr + ABS(Ierro)
+          ELSE IF (Nvals(ira).eq.2) THEN
+            Ierro=NF_PUT_ATT_REAL(FILEid,vsVID,NAMrat(ira)(1:Nlen),
+     &                           NF_FLOAT, Nvals  , zero2        )
+            TTerr = TTerr + ABS(Ierro)
+c
+           END IF
+        END IF
+        END IF
+        END DO
+
+      END DO                     ! **END   LOOP on var. num.
+
+C     Set 'unit' attribute for the dimensions:
+C     ----------------------------------------
+
+      DO igd = 0,TND         !** BEGIN LOOP over all spatial dims
+
+C       ** getting NAMdim [char] size :
+        Nlen = VARSIZE(UNIdim(igd))
+
+        Ierro=NF_PUT_ATT_TEXT(FILEid , dimVID(igd),'units',
+     &                          Nlen   , UNIdim(igd)        )
+
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+        Nlen = VARSIZE(NAMdim(igd))
+
+        Ierro=NF_PUT_ATT_TEXT(FILEid , dimVID(igd),'long_name',
+     &                          Nlen   , NAMdim(igd)        )
+
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+        Ierro=NF_PUT_ATT_TEXT(FILEid , dimVID(igd),'standard_name',
+     &                          Nlen   , NAMdim(igd)        )
+
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+        TTerr = TTerr + ABS(Ierro)
+
+      ENDDO
+
+C     Global attribute(s).
+C     --------------------
+
+C     ** Title (some general file descriptor) :
+C     ** getting unit_vs [char] size :
+
+      Nlen = VARSIZE(title)
+
+      Ierro=NF_PUT_ATT_TEXT(FILEid ,NF_GLOBAL,'title',
+     &                      Nlen    ,title(1:Nlen)       )
+
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+
+      Nlen = VARSIZE(CF_institution)
+
+      Ierro=NF_PUT_ATT_TEXT(FILEid ,NF_GLOBAL,'institution',
+     &                      Nlen    ,CF_institution)
+
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+c     CALL HostNm(Host, Ierro)
+
+      tmpchar="libUN ("//CF_libUN_version//") - "//FDate()
+c    &        " - "//Host
+
+      Nlen = VARSIZE(tmpchar)
+
+      Ierro=NF_PUT_ATT_TEXT(FILEid ,NF_GLOBAL,'history',
+     &                      Nlen    ,tmpchar)     
+
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+
+      Nlen = VARSIZE(NF_INQ_LIBVERS())
+
+      Ierro=NF_PUT_ATT_TEXT(FILEid ,NF_GLOBAL,'netcdf',
+     &                      Nlen    ,NF_INQ_LIBVERS())
+
+
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+      TTerr = TTerr + ABS(Ierro)
+
+
+C     Leave define mode (!file remains open )
+C     ---------------------------------------
+      Ierro=NF_ENDDEF(FILEid)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+      TTerr = TTerr + ABS(Ierro)
+
+
+C     Writing of dimensions coordinates.
+C     ----------------------------------
+
+C     ** Time :
+C     - - - - -
+
+      start(1)= 1          !Vector of starting indexes values
+      count(1)= DFdim(0)   !Vector of total # indexes values
+        IF (icheck.ge.3)
+     &    WRITE (*,*) 'Write coords for ',NAMdim(0),count(1)
+
+C     ** Set 'imap' to write with NCVPTG; NCVPT could be enough ?
+C     ** (imap tells NetCDF about the memory locations of var,
+C     **  we choose NCVPTG because 
+C     **  only a portion of VALdim is written.)
+      imap(1) = 1
+      imap(2) = 0                 ! Not used : write only 1 coord.
+
+      Ierro=NF_PUT_VARM_REAL(FILEid ,dimVID(0), start        , count,
+     &                         stride , imap    , VALdim(1,0)         )
+C     **line 1 ^^^^^^^^^^^^^^^ ID file| id var. |read from...  |#data
+C     **line 2                 step   |re-arrang|variable(beg.)
+C     **                      (^^^^stride is not used)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+
+C     ** Space coordinates :
+C     - - - - - - - - - - - -
+
+      DO igd = 1,TND          !** BEGIN LOOP over all spatial dims
+
+        start(1)= 1
+        count(1)= DFdim(igd)
+        IF (icheck.ge.3)
+     &    WRITE (*,*) 'Write coords for ',NAMdim(igd),count(1)
+
+
+        Ierro=NF_PUT_VARM_REAL(FILEid ,dimVID(igd),start , count,
+     &                           stride , imap      ,VALdim(1,igd))
+C       **      ^^^^^^^^^^^^^^^^ see above
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNscreate', Ierro)
+
+        TTerr = TTerr + ABS(Ierro)
+ 
+      END DO                  !** END   LOOP over all spatial dims
+
+C     Stop if an error occured.
+C     -------------------------
+
+      IF (TTerr.ne.0) THEN 
+        STOP 'UNscreate : Sorry, an error occured.'
+      ENDIF
+
+C +
+      RETURN
+      END SUBROUTINE UNscreate
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNwrite :   +                                         +
+C**  +-------------------------+                                         +
+C**  +  * Writes a variable into a NetCDF file,                          +
+C**  +    (the NetCDF file must have been created (or re-opened) and     +
+C**  +     closed after all writing operations).                         +
+C**  +  * Automatically updates attribute 'actual_range' if available    +
+C**  +          "          "    special var. '[var]_range'    "          +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : input file identifier (from UNcreate OR NetCDF open) +
+C**  +    VARname : name given to the variable to write (must be in file)+
+C**  +    itime   : No of time step to write to                          +
+C**  +    Ni,Nj,Nlev: dimensions of 'var'                                +
+C**  +              ! Nlev= 1 for 2D and 1D input variables.             + 
+C**  +                Nj  = 1 for 1D input variables.                    +
+C**  +              NB: can not write 1 level of 3D var only (->UNlwrite)+
+C**  +                                                                   +
+C**  +    var     : The variable to be writen                            +
+C**  +                                                                   +
+C**  +  REMARK :                                                         +
+C**  +    Truncation of input data is permited:                          +
+C**  +    If the dim of "var" > dim in the NetCDF file,                  +
+C**  +    "var" is automatically truncted. However, this => WARNING      +
+C**  +    message, UNLESS a specific truncation was "announced"          +
+C**  +    in var:                                                        +
+C**  +       To truncate the first dim to Li, let var(Ni,1,1) = Li       +
+C**  +       To truncate the 2nd   dim to Lj, let var(1,Nj,1) = Lj       +
+C**  +       ... (this has no effect exept cancel the "WARNING" message) +
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNwrite (FILEid , VARname , itime,
+     &                    Ni,  Nj, Nlev, var)
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      INTEGER icheck
+
+      INTEGER Lvnam 
+      PARAMETER (Lvnam=20)
+
+C     ** input 
+      INTEGER        FILEid 
+      INTEGER        itime
+      INTEGER        Ni,  Nj, Nlev 
+      CHARACTER *(*) VARname 
+      REAL*4         var(Ni, Nj, Nlev)
+
+C     ** local :
+      INTEGER    MXlv
+      PARAMETER (MXlv=500) 
+C                ^^^^Maximal # levels for a special output
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      INTEGER NVRi,  NVRj, NVRlev
+      INTEGER Ierro, TTerr, Nvatts, vtype
+      INTEGER dimID(4), dimSIZ(4), count(4)    
+      INTEGER start(4),stride(4),imap(4)
+      CHARACTER*(Lvnam) dimNAM(4) 
+      CHARACTER*(Lvnam) recname
+      CHARACTER*(30) tmpchr
+      INTEGER varVID
+      INTEGER VNlen, NDIMvar, NSDIvar, tiDI, itmp
+      INTEGER iz, ii, jj, ll
+      INTEGER iUNLIMDIM
+      REAL*4 chkdim
+      REAL*4 Arange(2),sValRange(2)
+      REAL*4 Srange(MXlv,2)
+      LOGICAL OkRange
+      
+      icheck= 0     !** 'debugging' level
+      TTerr = 0     !** 'total number of errors
+ 
+      IF (icheck.ge.1) WRITE(*,*) 'UNwrite : Begin'
+
+C*    1. Get the variable field  and dims IDs
+C     ----------------------------------------
+
+      IF (icheck.ge.2) WRITE(*,*) 'FILEid  :', FILEid 
+
+C     ** getting VARname  size :
+      VNlen = VARSIZE (VARname)
+      IF (icheck.ge.3) WRITE(*,*) 'VNlen  :', VNlen
+      IF (icheck.ge.2) WRITE(*,*) 'VARname   :', VARname (1:VNlen)
+
+C     ** variable field ID :
+      Ierro=NF_INQ_VARID (FILEid, VARname (1:VNlen), varVID)
+
+C     ** Cancel writing if an error occured : variable undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNwrite  Info  : Variable ',VARname(1:VNlen)
+     &            ,' not found -> not written.' 
+      END IF
+      IF (Ierro.ne.0) GOTO 9999 !** UNwrite_end
+
+
+C     ** Inquire about the number of dimensions in var :
+C     **
+      Ierro=NF_INQ_VAR(FILEid , varVID, recname, vtype,
+     &                   NDIMvar,  dimID,  Nvatts)
+C     **  line1          id/file  id/var  var name var type
+C     **  line2          # dims   id/dims #attributes
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro1. ', Ierro
+
+
+C*    2. Dimensions : inquire about file + compare with input data.
+C     -------------------------------------------------------------
+
+C     2.1 Inquire dimensions names and sizes :
+C +   - - - - - - - - - - - - - - - - - - - - -
+      DO iz = 1,4
+        dimSIZ(iz)=0
+        dimNAM(iz)='       '
+C       ** Set any unused dimension to "0" size / no name
+      END DO 
+      DO iz = 1,NDIMvar
+        Ierro=NF_INQ_DIM(FILEid , dimID(iz), dimNAM(iz), dimSIZ(iz))
+C       **                 id/file  id/dim     dimname      dimsize    
+C       **                                     !output      output
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+      END DO
+      IF (icheck.ge.3) WRITE(*,*) 'NDIMvar  ',NDIMvar
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro 2.0',Ierro  
+
+C     2.2 Set writing region according to field dimension : 2D or 3D
+C +   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+C     ** Set horizontal dimensions (default, for most data) :
+      count(1) = Ni
+      count(2) = Nj
+C +   ** Other default values:
+      count(3) = 0
+      count(4) = 0
+      start(1) = 1
+      start(2) = 1
+      start(3) = 1
+      start(4) = 1
+
+C +- ------3D+time variable in file-----------
+      IF (NDIMvar.eq.4) THEN
+C       ** 3D space + time: 
+        NSDIvar = 3     ! # space dims
+        tiDI    = 4     ! No. of the time dim
+C       ** write 3D space:
+        start(3) = 1    ! Start of index 3 in var (here = vert. levs)
+        count(3) = Nlev ! # values of index 3 in var 
+C       ** write one time step:
+        start(4) = itime
+        count(4) = 1
+C +- ------3D *OR* 2D+time var in file--------
+      ELSE IF (NDIMvar.eq.3) THEN
+        IF (Nlev.EQ.1) THEN
+C         ** 2D space + time (standard use of UNlib):
+          NSDIvar = 2
+          tiDI    = 3
+C         ** ...write one time step:
+          start(3) = itime
+          count(3) = 1     
+        ELSE
+C         ** 3D (no time slice):
+          NSDIvar = 3
+          tiDI    = 0
+C         ** ...write 3rd dimension:
+          start(3) = 1    
+          count(3) = Nlev
+        ENDIF
+C +- ------2D *OR* 1D+time var in file--------
+      ELSE IF (NDIMvar.eq.2) THEN
+        IF (Nj.EQ.1 .AND. dimNAM(2)(1:4).EQ.'time') THEN
+C         ** Write a 1D vector at time= itime:
+          NSDIvar = 1
+          tiDI    = 2
+          start(2) = itime
+          count(2) = 1
+        ELSE
+C         ** Usual MAR 2D space (no time):
+          NSDIvar = 2
+          tiDI    = 0
+        END IF
+C +- ------1D *OR* 0D+time var in file--------
+      ELSE IF (NDIMvar.eq.1) THEN
+C       ** 1D space or time
+        IF (Ni.eq.1) THEN
+C         ** Write a single element (at itime)
+          start(1) = itime
+          count(1) = 1
+          count(2) = 0
+          NSDIvar = 0
+          tiDI    = 1
+        ELSE
+C         ** Write a vector (use only "space" dim 1)
+          NSDIvar = 1
+          tiDI    = 0
+          count(2)= 0
+        END IF
+      ELSE
+         WRITE(*,*) 'UNwrite ERROR : data field dimension ?'
+         STOP
+      END IF
+
+C     2.3 Compare file dimensions to input data.
+C +   - - - - - - - - - - - - - - - - - - - - - -
+C     ** Save variable size for use as "valid" size (-> range):
+      NVRi   = Ni
+      NVRj   = Nj
+      NVRlev = Nlev
+C     ** Space dimensions :
+      IF (NSDIvar.GT.0) THEN
+      DO iz = 1,NSDIvar
+        IF      (dimSIZ(iz).gt.count(iz)) THEN
+          write(*,*) 'UNwrite - WARNING: '
+          write(*,*) ' Your field ',VARname,' has an empty part.'
+          write(*,*) ' (for the dimension:',dimNAM(iz),')'
+        ELSE IF (dimSIZ(iz).lt.count(iz)) THEN
+C         ** Do display "warning" only if truncation
+C            was not "correctly announced" (see header)
+C            (NVR... => stop here when updating the range attribute)
+          IF (iz.EQ.1) THEN 
+            chkdim = var(Ni,1,1) 
+            NVRi   = dimSIZ(1) 
+          ELSE IF (iz.EQ.2) THEN 
+            chkdim = var(1,Nj,1)
+            NVRj   = dimSIZ(2)
+          ELSE IF (iz.EQ.3) THEN 
+            chkdim = var(1,1,Nlev)
+            NVRlev = dimSIZ(3)
+          ELSE  
+            chkdim = 0.0
+          ENDIF
+          Ierro= NF_INQ_UNLIMDIM (FILEid, iUNLIMDIM) 
+          IF (dimID(iz).NE.iUNLIMDIM) THEN
+           IF (ABS(chkdim-dimSIZ(iz)).GT. 0.1 ) THEN
+            write(*,*) 'UNwrite - WARNING: '
+            write(*,*) ' Your field ',VARname,' will be truncated.'
+            write(*,*) ' (for the dimension:',dimNAM(iz),')'
+           ENDIF
+           count(iz) = dimSIZ(iz)
+          ENDIF
+        END IF
+      END DO
+      END IF
+
+C     ** Time dimension (when defined):
+      IF (tiDI.ne.0) THEN
+       IF (itime.gt.dimSIZ(tiDI)) THEN
+         IF (icheck.ge.1) WRITE(*,*) 'Time limit, ID', dimID(tiDI) 
+         Ierro= NF_INQ_UNLIMDIM (FILEid, iUNLIMDIM) 
+         IF (dimID(tiDI).NE.iUNLIMDIM) THEN
+            WRITE(*,*) 'UNwrite - ERROR:   '
+            WRITE(*,*) ' Time index out of range '                        
+            STOP
+         ENDIF
+        END IF
+      END IF
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro2. ', Ierro
+      IF (icheck.ge.2) WRITE(*,*) 'Dimension names :',dimNAM
+      IF (icheck.ge.2) WRITE(*,*) 'dimSIZ :',dimSIZ
+      IF (icheck.ge.2) WRITE(*,*) 'count  :',count
+      IF (icheck.ge.2) WRITE(*,*) 'start  :',start
+      IF (icheck.ge.2) WRITE(*,*) 'dimID  :',dimID 
+
+C*    3. Write variable.
+C     ------------------
+
+C     ** Set 'imap' and WRITE with NCVPTG:
+C     ** NOTE : since the arrays (grid_*) may be over-dimensionned,
+C     **        we use the 'generalised' writing routine NCVPTG
+C     ** (imap tells NetCDF about the memory locations of var)
+      imap(1) = 1
+      imap(2) = imap(1) * Ni      ! 1st dim of var = Ni 
+      imap(3) = imap(2) * Nj      ! 2nd dim of var = Nj 
+      imap(4) = 0                 ! (not used: 0 or 1 time step)   
+      DO iz=1,4
+        stride(iz)=1
+      END DO
+C     ** NOTE: stride is not used.
+
+      Ierro=NF_PUT_VARM_REAL(FILEid , varVID  , start      , count,
+     &                         stride , imap    , var(1,1,1) )
+C     **  line1:              id/file | id/var  |read from...|#data
+C     **  line2:              step    |re-arrang|variable(beg.)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro3.2', Ierro
+
+C*    4a. Update 'actual_range' attribute.               
+C     ------------------------------------
+
+C     If 'actual_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get the old min and max values:
+      Ierro=NF_GET_ATT_REAL(FILEid ,varVID ,'actual_range' ,
+     &                        Arange )
+c     **line1 ^^^^^^^^^^^^^^  FILEid |var.id | attr.name
+C     **line2                 value
+
+C     ** Cancel if an error occured : attribute undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNwrite  Info : attribute actual_range ' 
+     &             ,' not found -> not written.'
+      END IF
+      IF (Ierro.ne.0) GOTO 9990 !** Next section
+
+C     If 'valid_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get the min/max valid range (outside = missing val):
+      Ierro=NF_GET_ATT_REAL(FILEid ,varVID ,'valid_range' ,
+     &                        sValRange)
+      IF (Ierro.ne.0) THEN
+         sValRange(1)=ValRange(1)
+         sValRange(2)=ValRange(2)
+      END IF
+
+C     Update the min an max
+C     - - - - - - - - - - - 
+
+C     **If this is the first pass, initialise min and max:
+      IF (      Arange(1).EQ. NF_FILL_REAL 
+     .    .OR. (Arange(1).EQ. 0.0 .AND. Arange(2).EQ. 0.0) ) THEN
+        OkRange = .false. 
+      ELSE
+        OkRange = .true.
+      ENDIF
+
+      DO ll=1, NVRlev
+      DO jj=1, NVRj
+      DO ii=1, NVRi 
+        IF (  var(ii,jj,ll).GE.sValRange(1)
+     &  .AND. var(ii,jj,ll).LE.sValRange(2)) THEN
+           IF (OkRange) THEN
+              Arange(1) = MIN(Arange(1), var(ii,jj,ll))
+              Arange(2) = MAX(Arange(2), var(ii,jj,ll))
+           ELSE        
+              Arange(1) = var(ii,jj,ll)
+              Arange(2) = var(ii,jj,ll)
+              OkRange = .true.
+           ENDIF
+        ENDIF
+      ENDDO
+      ENDDO
+      ENDDO
+      IF (icheck.ge.2) WRITE(*,*) 'Arange',Arange
+
+C     Set attribute.
+C     - - - - - - - -
+
+      Ierro=NF_PUT_ATT_REAL(FILEid  ,varVID ,'actual_range' ,
+     &                        NF_FLOAT,2      ,Arange)
+c     **line1 ^^^^^^^^^^^^^^^ FILEid  |var.id | attr.name
+C     **line2                 type    |len    | attr.value
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+      TTerr = TTerr + ABS(Ierro)
+
+C     ** Next section:
+ 9990 CONTINUE
+
+C*    5. Update the optional '[var]_range' special variable.
+C     ------------------------------------------------------
+      IF (NDIMvar.eq.4.and.Nlev.lt.MXlv) THEN
+
+C     If '[var]_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get ID of variable [var]_range :
+      tmpchr = VARname(1:VNlen)//'_range'
+      itmp   = VNlen + 6
+      Ierro=NF_INQ_VARID(FILEid, tmpchr(1:itmp), varVID)
+
+C     ** Cancel if an error occured : undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNwrite  Info : [var]_range '
+     &            ,' not found -> not written.'
+      END IF
+      IF (Ierro.ne.0) GOTO 9999 !** UNwrite_end
+
+C     ** Get the old min and max values:
+C     ** NOTE :
+C     **        we use the 'generalised' reading routine NCVGTG
+C     ** (imap tells NetCDF about the memory locations of var)
+      imap(1) = 1
+      imap(2) = imap(1) * MXlv   
+      start(1)= 1
+      start(2)= 1
+      count(1)= Nlev
+      count(2)= 2
+
+C     ** (See UNread for explanations about NCVGTG)
+      Ierro=NF_GET_VARM_REAL(FILEid, varVID, start, count,   
+     &                         stride,  imap , Srange(1,1) )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+
+C     Update the min an max
+C     - - - - - - - - - - -
+C     **If this is the first pass, initialise min and max:
+C     **(Constant fields shall not be accounted for)
+      DO ll=1, Nlev
+        IF (Srange(ll,1).eq.Srange(ll,2)) THEN
+          Srange(ll,1) = var(1,1,ll)
+          Srange(ll,2) = var(1,1,ll) 
+        ENDIF
+      ENDDO
+
+      DO jj=1, NVRj
+      DO ii=1, NVRi
+       DO ll=1, NVRlev
+        Srange(ll,1) = MIN(Srange(ll,1), var(ii,jj,ll))
+        Srange(ll,2) = MAX(Srange(ll,2), var(ii,jj,ll))
+       ENDDO
+      ENDDO
+      ENDDO
+      IF (icheck.ge.4) WRITE(*,*) 'Srange',Srange
+
+
+C     Set special variable [var]_range
+C     - - - - - - - - - - - - - - - - -
+C     **(See UNread for explanations abtout NCVPTG)
+
+      Ierro=NF_PUT_VARM_REAL(FILEid , varVID , start, count,
+     &                         stride , imap   , Srange(1,1) )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwrite', Ierro)
+
+      ENDIF  ! End Section 5.
+
+C     UNwrite_end
+C     -----------
+      IF (icheck.ge.2) WRITE(*,*) 'Errors count:',TTerr
+      IF (icheck.ge.2) WRITE(*,*) 'UNwrite : End'
+ 9999 CONTINUE
+      RETURN
+      END
+C**
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNlwrite :  +                                         +
+C**  +-------------------------+                                         +
+C**  +  * Writes a 2D horizontal LEVEL into a 3D+time NetCDF variable    +  
+C**  +       OR  a 1D vector           into a 2D+time                    +
+C**  +             --            ----         --                         +
+C**  +    (SEE ALSO : UNwrite, for all dimensions - this a pecular case  +
+C**  +     Note: 1D vectors are writen in the 1st dim of 2D+time)        +
+C**  +                                                                   +
+C**  +  * Automatically updates attribute 'actual_range' if available    +
+C**  +          "          "    special var. '[var]_range'    "          +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : input file identifier (from UNcreate OR NetCDF open) +
+C**  +    VARname : name given to the variable to write (must be in file)+
+C**  +    itime   : No of time step to write to                          +
+C**  +    level   : No of level     to write to                          +
+C**  +    Ni,  Nj : dimensions of 'var'...                               +
+C**  +    var     : A 2D variable to be writen                           +
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNlwrite (FILEid , VARname , itime,
+     &                     ilev, Ni,  Nj, var)
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      INTEGER icheck
+
+      INTEGER Lvnam 
+      PARAMETER (Lvnam=20)
+
+C     ** input 
+      INTEGER FILEid 
+      INTEGER itime, ilev
+      INTEGER Ni,  Nj
+      CHARACTER *(*) VARname 
+      REAL*4 var(Ni, Nj)
+
+C     ** local :
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      INTEGER Ierro, TTerr, Nvatts, vtype
+      INTEGER dimID(4), dimSIZ(4), count(4)    
+      INTEGER start(4),stride(4),imap(4)
+      INTEGER iUNLIMDIM
+      CHARACTER*(Lvnam) dimNAM(4) 
+      CHARACTER*(Lvnam) recname
+      CHARACTER*(30) tmpchr
+      INTEGER varVID
+      INTEGER VNlen, NDIMvar, NSDIvar, tiDI, ilDI, itmp
+      INTEGER iz, ii, jj
+      LOGICAL OkRange
+      REAL*4 Arange(2), sValRange(2)
+      REAL*4 Srange(2)
+            
+      icheck= 0     !** 'debugging' level
+      TTerr = 0     !** 'total numbe of errors
+ 
+      IF (icheck.ge.1) WRITE(*,*) 'UNlwrite : Begin'
+
+C*    1. Get the variable field  and dims IDs
+C     ----------------------------------------
+
+      IF (icheck.ge.2) WRITE(*,*) 'FILEid  :', FILEid 
+
+C     ** getting VARname  size :
+      VNlen = VARSIZE (VARname)
+      IF (icheck.ge.3) WRITE(*,*) 'VNlen  :',VNlen
+      IF (icheck.ge.2) WRITE(*,*) 'VARname   :', VARname (1:VNlen)
+
+C     ** variable field ID :
+      Ierro=NF_INQ_VARID (FILEid, VARname (1:VNlen), varVID)
+
+C     ** Cancel writing if an error occured : variable undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNlwrite  Info  : Variable ',VARname(1:VNlen)
+     &            ,' not found -> not written.' 
+      END IF
+      IF (Ierro.ne.0) GOTO 9999 !** UNlwrite_end
+
+
+C     ** Inquire about the number of dimensions in var :
+C     **
+      Ierro=NF_INQ_VAR(FILEid , varVID, recname, vtype,
+     &                   NDIMvar,  dimID,  Nvatts)
+C     **  line1          id/file  id/var  var name var type
+C     **  line2          # dims   id/dims #attributes
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro1. ', Ierro
+
+
+C*    2. Dimensions : inquire about file + compare with input data.
+C     -------------------------------------------------------------
+
+C     2.1 Inquire dimensions names and sizes :
+C +   - - - - - - - - - - - - - - - - - - - - -
+      DO iz = 1,4
+        dimSIZ(iz)=0
+        dimNAM(iz)='       '
+C       ** Set any unused dimension to "0" size / no name
+      END DO
+
+      DO iz = 1,NDIMvar
+        Ierro=NF_INQ_DIM(FILEid , dimID(iz), dimNAM(iz), dimSIZ(iz))
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+C       **           id/file   id/dim    dimname     dimsize    error
+C       **                               !output     output
+      END DO
+      IF (icheck.ge.3) WRITE(*,*) 'NDIMvar  ',NDIMvar
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro 2.0',Ierro  
+
+C     2.2 Set writing region according to field dimension :  3D
+C +   - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+C     ** Set horizontal dimensions (all field dims):
+      count(1) = Ni
+      count(2) = Nj
+      start(1) = 1
+      start(2) = 1
+C +- ------ 3D+time var in file--------
+      IF (NDIMvar.eq.4) THEN
+        NSDIvar = 2     ! # input space dims (for a 2D level)
+        tiDI    = 4     ! No. of the time dim
+C       ** write one level (set the level No) :
+        start(3) = ilev ! Start of index 3 in var 
+        count(3) = 1    ! # values of index 3 in var 
+        ilDI     = 3
+C       ** write one time step:
+        start(4) = itime
+        count(4) = 1
+C +- ------ 2D+time var in file--------
+      ELSE IF (NDIMvar.eq.3) THEN
+        NSDIvar = 1     ! # input space dims (for a 1D vector)
+        tiDI    = 3     ! No. of the time dim
+C       ** write one "level" - here a 1D vector in the 1st dim.
+        start(2) = ilev ! Start of index 2 in var
+        count(2) = 1    ! # values of index 3 in var
+        ilDI     = 2
+C       ** write one time step:
+        start(3) = itime
+        count(3) = 1
+      ELSE
+         WRITE(*,*) 'UNlwrite ERROR : data field dimension ?'
+         WRITE(*,*) '  NB: UNlwrite = only for (2 or) 3D +time.'
+         STOP
+      END IF
+
+C     2.3 Compare file dimensions to input data.
+C +   - - - - - - - - - - - - - - - - - - - - - -
+C     ** Space dimensions :
+      DO iz = 1,NSDIvar
+        IF      (dimSIZ(iz).gt.count(iz)) THEN
+          write(*,*) 'UNlwrite - WARNING: '
+          write(*,*) ' Your field ',VARname,' has an empty part.'
+          write(*,*) ' (for the dimension:',dimNAM(iz),')'
+        ELSE IF (dimSIZ(iz).lt.count(iz)) THEN
+          write(*,*) 'UNlwrite - WARNING: '
+          write(*,*) ' Your field ',VARname,' will be truncated.'
+          write(*,*) ' (for the dimension:',dimNAM(iz),')'
+          count(iz) = dimSIZ(iz)
+        END IF
+      END DO
+
+C     ** Space dimensions - check if requested level exists:
+      IF (dimSIZ(ilDI).lt.ilev) THEN
+        write(*,*) 'UNlwrite - ERROR: '
+        write(*,*) ' The requested level =',ilev
+        write(*,*) ' does not exist in the field ',VARname
+        write(*,*) ' (for the dimension:',dimNAM(ilDI),')'
+        STOP
+      END IF
+
+C     ** Time dimension (when defined):
+      IF (tiDI.ne.0) THEN
+       IF (itime.gt.dimSIZ(tiDI)) THEN
+         IF (icheck.ge.1) WRITE(*,*) 'Time limit, ID', dimID(tiDI) 
+         Ierro= NF_INQ_UNLIMDIM (FILEid, iUNLIMDIM) 
+         IF (dimID(tiDI).NE.iUNLIMDIM) THEN
+            WRITE(*,*) 'UNlwrite - ERROR:  '
+            WRITE(*,*) ' Time index out of range '                        
+            STOP
+         ENDIF
+        END IF
+      END IF
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro2. ', Ierro
+      IF (icheck.ge.2) WRITE(*,*) 'Dimension names :',dimNAM
+      IF (icheck.ge.3) WRITE(*,*) 'dimSIZ :',dimSIZ
+      IF (icheck.ge.3) WRITE(*,*) 'count  :',count
+      IF (icheck.ge.3) WRITE(*,*) 'start  :',start
+      IF (icheck.ge.3) WRITE(*,*) 'dimID  :',dimID 
+
+C*    3. Write variable.
+C     ------------------
+
+C     ** Set 'imap' and WRITE with NCVPTG:
+C     ** NOTE : since the arrays (grid_*) may be over-dimensionned,
+C     **        we use the 'generalised' writing routine NCVPTG
+C     ** (imap tells NetCDF about the memory locations of var)
+      imap(1) = 1
+      imap(2) = imap(1) * Ni      ! 1st dim of var = Ni 
+      imap(3) = imap(2) * Nj      ! (not used: 1 level...)
+      imap(4) = 0                 ! (not used: 0 or 1 time step)   
+      DO iz=1,4
+        stride(iz)=1
+      END DO
+C     ** NOTE: stride is not used.
+
+      Ierro=NF_PUT_VARM_REAL (FILEid  , varVID  , start      , count,
+     &                          stride  , imap    , var(1,1)          )
+C     **  line1:                id/file | id/var  |read from...|#data
+C     **  line2:                step    |re-arrang|variable(beg.)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+
+      IF (icheck.ge.2) WRITE(*,*) 'Ierro3.2', Ierro
+
+C*    4a. Update 'actual_range' attribute.               
+C     ------------------------------------
+
+C     If 'actual_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get the old min and max values:
+      Ierro=NF_GET_ATT_REAL(FILEid ,varVID ,'actual_range' ,
+     &                        Arange )
+c     **line1 ^^^^^^^^^^^^^^^ FILEid |var.id | attr.name
+C     **line2                 value
+
+C     ** Cancel if an error occured : attribute undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNlwrite  Info : attribute actual_range ' 
+     &             ,' not found -> not written.'
+      END IF
+      IF (Ierro.ne.0) GOTO 9990 !** Next section
+
+C     If 'valid_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get the min/max valid range (outside = missing val):
+      Ierro=NF_GET_ATT_REAL(FILEid ,varVID ,'valid_range' ,
+     &                        sValRange)
+      IF (Ierro.ne.0) THEN
+         sValRange(1)=ValRange(1)
+         sValRange(1)=ValRange(2)
+      END IF
+
+C     Update the min an max
+C     - - - - - - - - - - - 
+
+C     **If this is the first pass, initialise min and max:
+      IF (      Arange(1).EQ. NF_FILL_REAL 
+     .    .OR. (Arange(1).EQ. 0.0 .AND. Arange(2).EQ. 0.0) ) THEN
+        OkRange = .false. 
+      ELSE
+        OkRange = .true.
+      ENDIF
+
+      DO jj=1, Nj
+      DO ii=1, Ni
+        IF (  var(ii,jj).GE.sValRange(1)
+     &  .AND. var(ii,jj).LE.sValRange(2)) THEN
+           IF (OkRange) THEN
+              Arange(1) = MIN(Arange(1), var(ii,jj))
+              Arange(2) = MAX(Arange(2), var(ii,jj))
+           ELSE        
+              Arange(1) = var(ii,jj)
+              Arange(2) = var(ii,jj)
+              OkRange = .true.
+           ENDIF
+        ENDIF
+      ENDDO
+      ENDDO
+      IF (icheck.ge.2) WRITE(*,*) 'Arange',Arange
+
+C     Set attribute.
+C     - - - - - - - -
+
+      Ierro=NF_PUT_ATT_REAL(FILEid  ,varVID ,'actual_range' ,
+     &                        NF_FLOAT,2      ,Arange )
+c     **line1 ^^^^^^^^^^^^^^^ FILEid  |var.id | attr.name
+C     **line2                 type    |len    | attr.value
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+      TTerr = TTerr + ABS(Ierro)
+
+C     ** Next section:
+ 9990 CONTINUE
+ 
+
+C*    5. Update the optional '[var]_range' special variable.
+C     ------------------------------------------------------
+      IF (NDIMvar.eq.4) THEN
+
+C     If '[var]_range' available, get its current value:
+C     - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+C     ** Get ID of variable [var]_range :
+      tmpchr = VARname(1:VNlen)//'_range'
+      itmp   = VNlen + 6
+      Ierro=NF_INQ_VARID (FILEid, tmpchr(1:itmp), varVID)
+
+C     ** Cancel if an error occured : undefined ?
+      IF (Ierro.ne.0.and.icheck.ge.1) THEN
+         WRITE(*,*) 'UNlwrite  Info : [var]_range '
+     &             ,' not found -> not written.'
+      END IF
+      IF (Ierro.ne.0) GOTO 9999 !** UNlwrite_end
+
+C     ** Get the old min and max values:
+C     ** NOTE :
+C     **        we use the 'generalised' reading routine NCVGTG
+C     ** (imap tells NetCDF about the memory locations of var)
+      imap(1) = 1
+      imap(2) = 0                ! Not used (write only 1 lev)
+      start(1)= ilev
+      count(1)= 1   
+      start(2)= 1
+      count(2)= 2
+
+C     ** (See UNread for explanations abtout NCVGTG)
+      Ierro=NF_GET_VARM_REAL(FILEid, varVID, start      ,count,   
+     &                         stride,  imap , Srange(1) )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+
+C     Update the min an max
+C     - - - - - - - - - - -
+C     **If this is the first pass, initialise min and max:
+C     **(Constant fields shall not be accounted for)
+      IF (Srange(1).eq.Srange(2)) THEN
+          Srange(1) = var(1,1)
+          Srange(2) = var(1,1) 
+      ENDIF
+
+      DO jj=1, Nj
+      DO ii=1, Ni
+        Srange(1) = MIN(Srange(1), var(ii,jj))
+        Srange(2) = MAX(Srange(2), var(ii,jj))
+      ENDDO
+      ENDDO
+      IF (icheck.ge.4) WRITE(*,*) 'Srange',Srange
+
+
+C     Set special variable [var]_range
+C     - - - - - - - - - - - - - - - - -
+C     **(See UNread for explanations abtout NCVPTG)
+
+      Ierro=NF_PUT_VARM_REAL(FILEid , varVID , start        , count,
+     &                         stride , imap   , Srange(1)  )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNlwrite', Ierro)
+
+      ENDIF  ! End Section 5.
+
+C     UNlwrite_end
+C     -----------
+      IF (icheck.ge.2) WRITE(*,*) 'Errors count:',TTerr
+      IF (icheck.ge.2) WRITE(*,*) 'UNlwrite : End'
+ 9999 CONTINUE
+      RETURN
+      END
+C**
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNread :    +                                         +
+C**  +-------------------------+                                         +
+C**  +  * Reads a model variable from a NetCDF file,                     +
+C**  +    and reads the coordinates of the grid upon wich it is defined. +
+C**  +    (the NetCDF file must have been opened and must be closed      +
+C**  +     after all reading operations). May read an x-y subregion.     +
+C**  +                                                                   +
+C**  +  INPUT :                                                          + 
+C**  +    FILEid  : input file identifier (from NetCDF open)             +
+C**  +    VARname  : name of the requested variable.                     +
+C**  +    time : [integer*4] is the time index of the data field to read +
+C**  +    level: [integer*4] (usefull for 3D-space fields only) :        +
+C**  +                       if not=0 --> = no of the level              +
+C**  +                                      -> output is 2D (l_dim = 1)  +
+C**  +                       if  =0   --> read ALL levels                +
+C**  +                                      -> output is 3D              +
+C**  +    i_dbeg, j_dbeg      : horizontal indexes of requested region   +
+C**  +                          in input data file                       + 
+C**  +    i_dim, j_dim, l_dim : ...the dimensions of 'var',              + 
+C**  +                       = the dimensions of the sub-region to read  + 
+C**  +                       ! l_dim = 1 if level not=0                  + 
+C**  +                       ! j_dim = 1 if var is 1D                    + 
+C**  +  OUTPUT :                                                         + 
+C**  +    varax1[i_dim] (real  )                                         + 
+C**  +    varax2[j_dim]: Horizontal coordinates in the file (lat/lon,...)+ 
+C**  +    varlev[l_dim]: vertical coordinate of the levels               + 
+C**  +                   (! when level not=0, only varlev(1) is defined) + 
+C**  +    var_units                 : physical units of var.             + 
+C**  +    var[i_dim,j_dim,l_dim]    :                                    + 
+C**  +                            data field values                      + 
+C**  +                            (var must be defined, and is REAL  )   + 
+C**  +                                                                   + 
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNread
+     &      (FILEid , VARname , time, level, i_dbeg, j_dbeg,
+     &       i_dim   , j_dim   , l_dim    ,
+     &       varax1  , varax2  , varlev,      
+     &       var_units, var)
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      INTEGER icheck
+
+      INTEGER Lvnam 
+      PARAMETER (Lvnam=20)
+
+C     ** input 
+      INTEGER FILEid 
+      INTEGER time, level, i_dbeg, j_dbeg
+      INTEGER i_dim, j_dim, l_dim
+      CHARACTER *(*) VARname 
+
+C     ** output
+      REAL*4    varax1(i_dim), varax2(j_dim), varlev(l_dim)
+      CHARACTER *(*) var_units
+      REAL*4    var (i_dim, j_dim, l_dim)
+
+C     ** local :
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      REAL*4  varmin,varmax
+      INTEGER Ierro, Nvatts, vtype
+      INTEGER dimID(4), dimSIZ(4), dimREG(4)    
+      INTEGER start(4),begREG(4),count(4),stride(4),imap(4)
+      CHARACTER*(Lvnam) dimNAM(4) 
+      CHARACTER*(Lvnam) dNAMver, dNAMtim
+      CHARACTER*(Lvnam) recname
+      CHARACTER*(10) Routine
+      INTEGER ax1VID, ax2VID, verVID, timVID, varVID
+      INTEGER VNlen, varNUMDIM
+      INTEGER ii,jj,ll,z
+      
+      icheck= 0
+C*    0. Initialisations
+C     ------------------
+      Routine= 'UNread'
+      IF (icheck.ge.1) WRITE(*,*) 'UNread : Begin'
+
+      DO ii = 1,4 
+        stride(ii) = 1
+        begREG(ii) = 1
+        start (ii) = 1
+      ENDDO
+ 
+C*    1. Get the variable field  and dims IDs
+C     ----------------------------------------
+
+      IF (icheck.ge.3) WRITE(*,*) 'FILEid  :', FILEid 
+
+C     ** getting VARname  size :
+      VNlen = VARSIZE(VARname)
+      IF (icheck.ge.3) WRITE(*,*) 'VNlen  :',VNlen
+      IF (icheck.ge.2) WRITE(*,*) 'VARname   :', VARname (1:VNlen)
+
+C     ** variable field ID :
+      Ierro=NF_INQ_VARID (FILEid, VARname (1:VNlen), varVID)
+
+C*    1b. Handle non-existing variables
+C     ---------------------------------
+      IF (Ierro.NE.NF_NOERR) THEN 
+         IF (Ierro.EQ.NF_ENOTVAR .AND. iVarWarn.LE.1) THEN
+            IF (iVarWarn.EQ.1) THEN
+              write(*,*) 'WARNING (UNsread): variable not found:'
+              write(*,*) '     ',varName
+            ENDIF
+            DO ll=1,l_dim
+            DO jj=1,j_dim
+            DO ii=1,i_dim
+              var (ii,jj,ll)=VarRepl
+            ENDDO
+            ENDDO
+            ENDDO
+            RETURN  ! EXIT SUBROUTINE, read nothing
+         ENDIF
+         WRITE(*,*) 'Error reading variable: ', VARname(1:VNlen)
+         CALL HANDLE_ERR('UNsread',Ierro)
+      ENDIF
+
+C     1c. Inquire about the number of dimensions in var
+C     -------------------------------------------------
+
+      Ierro=NF_INQ_VAR(FILEid   , varVID, recname, vtype,
+     &                   varNUMDIM, dimID, Nvatts )
+C     **  line1          id/file    id/var  var name  var type
+C     **  line2          # dims    id/dims #attributes
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNsread', Ierro)
+
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro1. ', Ierro
+
+C*    2. Dimensions : in the reading region and in the file.
+C     ------------------------------------------------------
+
+C     ** inquire dimensions names and sizes :
+      DO z = 1,varNUMDIM
+        Ierro=NF_INQ_DIM(FILEid , dimID(z), dimNAM(z), dimSIZ(z))
+C       **                 id/file  id/dim    dimname    dimsize
+C       **                                    !output    output
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR(Routine, Ierro)
+      END DO
+
+C     ** In this version, we read only a xy subregion of the file :
+      dimREG(1) = i_dim
+      dimREG(2) = j_dim
+      begREG(1) = i_dbeg
+      begREG(2) = j_dbeg
+      IF (begREG(1).lt.1)  begREG(1) = 1
+      IF (begREG(2).lt.1)  begREG(2) = 1
+      
+C     ** Set reading region according to field dimension : 2D or 3D
+      IF (varNUMDIM.eq.4) THEN
+C       ** for 3D fields :
+        IF (level.gt.0) THEN
+C       ** one level is read :
+          dimREG(3) = 1 
+          begREG(3) = level
+          dNAMver   = dimNAM(3)
+        ELSE
+C       ** all levels are read :
+          dimREG(3) = l_dim
+          begREG(3) = 1    
+          dNAMver   = dimNAM(3)
+        END IF
+C       ** one time step is read:
+        dimREG(4) = 1 
+        begREG(4)  = time 
+        dNAMtim   = dimNAM(4)
+      ELSE IF (varNUMDIM.eq.3) THEN
+C       ** for 2D space fields + time:
+C       ** one time step is read:
+        dimREG(3) = 1      
+        begREG(3) = time
+        dNAMtim   = dimNAM(3)
+        dimREG(4) = 0
+        begREG(4) = 0
+        dimNAM(4) = 'none'
+      ELSE IF (varNUMDIM.eq.2) THEN
+C       ** for 2D fields :
+C       ** no time step is read:
+        dimREG(3) = 0     
+        begREG(3) = 0   
+        dNAMtim   = 'none'   
+        dimNAM(3) = 'none'
+        dimREG(4) = 0
+        begREG(4) = 0
+        dimNAM(4) = 'none'
+      ELSE IF (varNUMDIM.eq.1) THEN
+C       ** for 1D variable :
+C       ** not assumed to be on a XYZ grid,       
+C       ** just read a vector  
+        dimREG(1) = 1    ! this was added by Martin Vancop for 1d vectors
+        begREG(1) = time ! this was added by Martin Vancop for 1d vectors
+        dimREG(2) = 0
+        begREG(2) = 0
+        dimNAM(2) = 'none'
+        dimREG(3) = 0
+        begREG(3) = 0
+        dimNAM(3) = 'none'
+        dNAMtim   = 'none'
+        dimREG(4) = 0
+        begREG(4) = 0
+        dimNAM(4) = 'none'
+      ELSE
+        WRITE(*,*) 'UNread ERROR : data field dimension ?'
+        STOP
+      END IF
+
+      DO z = 1,varNUMDIM
+        IF (begREG(z).gt.dimSIZ(z)) THEN
+          write(*,*) 'UNread - ERROR   : requested area out      '
+          write(*,*) '                   of file area.          '
+          write(*,*) '  (for the dimension:' , dimNAM(z) , ')'
+          STOP
+        END IF
+        IF (dimSIZ(z).lt.(dimREG(z)+begREG(z)- 1) ) THEN
+          write(*,*) 'UNread - WARNING : empty portion in field, '
+          write(*,*) '  requested region > file contents       '
+          write(*,*) '  (for the dimension:' , dimNAM(z) , ')'
+          dimREG(z) = dimSIZ(z) - begREG(z) + 1
+        END IF
+      END DO
+
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro2. ', Ierro
+      IF (icheck.ge.2) WRITE(*,*) 'Dimension names :',dimNAM
+      IF (icheck.ge.2) WRITE(*,*) 'dimSIZ :',dimSIZ
+      IF (icheck.ge.2) WRITE(*,*) 'dimREG :',dimREG
+      IF (icheck.ge.2) WRITE(*,*) 'begREG :',begREG
+      IF (icheck.ge.3) WRITE(*,*) 'dimID  :',dimID 
+
+C*    3. Get the variables IDs for the grid points locations. 
+C     -------------------------------------------------------
+
+      IF (varNUMDIM.ge.2) THEN
+        Ierro=NF_INQ_VARID (FILEid, dimNAM(1), ax1VID)
+        IF (Ierro.NE.NF_NOERR) THEN
+          IF (Ierro.EQ.NF_ENOTVAR) THEN
+            WRITE(*,*) 'Coordinate values not found:',dimNAM(1)
+          ENDIF
+          CALL HANDLE_ERR(Routine, Ierro)
+        ENDIF
+        Ierro=NF_INQ_VARID (FILEid, dimNAM(2), ax2VID)
+        IF (Ierro.NE.NF_NOERR) THEN
+          IF (Ierro.EQ.NF_ENOTVAR) THEN
+            WRITE(*,*) 'Coordinate values not found:',dimNAM(2)
+          ENDIF
+          CALL HANDLE_ERR(Routine, Ierro)
+        ENDIF
+      ENDIF
+      IF (varNUMDIM.ge.3) THEN
+        Ierro=NF_INQ_VARID (FILEid, dNAMtim, timVID)
+        IF (Ierro.NE.NF_NOERR) THEN
+          IF (Ierro.EQ.NF_ENOTVAR) THEN
+            WRITE(*,*) 'Coordinate values not found:',dNAMtim
+          ENDIF
+          CALL HANDLE_ERR(Routine, Ierro)
+        ENDIF
+      END IF
+      IF (varNUMDIM.eq.4) THEN
+        Ierro=NF_INQ_VARID (FILEid, dNAMver, verVID)
+        IF (Ierro.NE.NF_NOERR) THEN
+          IF (Ierro.EQ.NF_ENOTVAR) THEN
+            WRITE(*,*) 'Coordinate values not found:',dNAMver
+          ENDIF
+          CALL HANDLE_ERR(Routine, Ierro)
+        ENDIF
+      END IF
+C     **                      id/file  name    id/var
+
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro3. ', Ierro
+
+C*    4. Get attributes.         
+C     ------------------
+
+      IF (varNUMDIM.ge.2) THEN   !Not for 1D vectors (special case)
+C       ** units attribute 
+        Ierro=NF_GET_ATT_TEXT (FILEid , varVID, 'units', 
+     &                           var_units) 
+        IF (Ierro.NE.NF_NOERR) THEN 
+          IF (Ierro.EQ.NF_ENOTATT) THEN
+            write(*,*) 'Note (UNread): units not found for'
+            write(*,*) '     ',varName
+            var_units=' '
+          ELSE
+            CALL HANDLE_ERR('UNread',Ierro)
+          ENDIF
+        ENDIF
+
+        IF (icheck.ge.2) WRITE(*,*) 'var_units :', var_units
+      ENDIF
+
+C*    5. Get values.
+C     --------------
+C*    5.1 ...for the grid points locations.
+C     -------------------------------------
+      
+C     ** Horizontal : always read, except for 1D vectors
+      IF (varNUMDIM.ge.2) THEN  
+        count(1)=dimREG(1)
+        start(1)=begREG(1)
+        Ierro=NF_GET_VARA_REAL(FILEid ,ax1VID,start,count,varax1)
+C       **                       id/file id/var from  #data data
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR(Routine, Ierro)
+        count(1)=dimREG(2)
+        start(1)=begREG(2)
+        Ierro=NF_GET_VARA_REAL(FILEid ,ax2VID,start,count,varax2)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR(Routine, Ierro)
+      ENDIF
+
+C     ** vertical :  only for 3D fields.
+      IF (varNUMDIM.eq.4) THEN
+        start(1) =begREG(3)
+        count(1) =dimREG(3)
+        Ierro =  NF_GET_VARA_REAL(FILEid ,verVID,start,count,varlev)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR(Routine, Ierro)
+      END IF
+
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro5.1', Ierro
+
+C*    5.2 ...for the the variable.
+C     ----------------------------
+
+C     ** Set 'imap' and READ with NCVGTG:
+C     ** NOTE :                                                  
+C     **        we use the 'generalised' reading routine NCVGTG 
+C     ** (imap tells NetCDF about the memory locations of var) 
+      imap(1) = 1
+      imap(2) = imap(1) * i_dim  ! 1st dim of var = i_dim
+      imap(3) = imap(2) * j_dim  ! 2nd dim of var = j_dim 
+      imap(4) = 0                !  Should NEVER be used        
+      Ierro=NF_GET_VARM_REAL(FILEid   ,  varVID ,begREG      , dimREG,
+     &                         stride   ,   imap  ,var(1,1,1)          )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR(Routine, Ierro)
+
+      IF (icheck.ge.3) WRITE(*,*) 'Ierro5.2', Ierro
+      
+C*    6. Check data
+C     -------------
+      IF (ireadchk.GE.1) THEN
+       varmax = var (1,1,1)
+       varmin = var (1,1,1)
+       DO ll=1,l_dim
+       DO jj=1,j_dim
+       DO ii=1,i_dim
+          var(ii,jj,ll)=var(ii,jj,ll)+0.0E0
+C           This fixes underflow values but must compile with -fpe1
+          varmax = MAX(var (ii,jj,ll),varmax)
+          varmin = MIN(var (ii,jj,ll),varmin)
+       ENDDO
+       ENDDO
+       ENDDO
+       IF (varmin.LT.vReadMin .OR. varmax.GT.vReadMax) THEN
+          write(*,*) 'WARNING (UNread): variable ', VARname
+          write(*,*) '  is out of specified bounds;'
+          write(*,*) '  min is:', varmin
+          write(*,*) '  max is:', varmax
+       ENDIF
+      ENDIF
+      
+      IF (icheck.ge.2) WRITE(*,*) 'UNread : End' 
+
+      END SUBROUTINE UNread
+
+C**
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNsread :   +                                         +
+C**  +-------------------------+                                         +
+C**  +  * Reads a model variable from a NetCDF file,                     +
+C**  +    SIMPLIFIED VERSION of  UNread  : does NOT read coordinates.    +
+C**  +                                                                   +
+C**  +                                                                   +
+C**  +  INPUT :                                                          + 
+C**  +    FILEid  : input file identifier (from NetCDF open)             +
+C**  +    VARname  : name of the requested variable.                     +
+C**  +    time : [integer*4] is the time index of the data field to read +
+C**  +    level: [integer*4] (usefull for 3D-space fields only) :        +
+C**  +                       if not=0 --> = no of the level              +
+C**  +                                      -> output is 2D (l_dim = 1)  +
+C**  +                       if  =0   --> read ALL levels                +
+C**  +                                      -> output is 3D              +
+C**  +    i_dbeg, j_dbeg      : horizontal indexes of requested region   +
+C**  +                          in input data file                       + 
+C**  +    i_dim, j_dim, l_dim : ...the dimensions of 'var',              + 
+C**  +                       = the dimensions of the sub-region to read  + 
+C**  +                       ! l_dim = 1 if level not=0                  + 
+C**  +                       ! j_dim = 1 if var is 1D                    + 
+C**  +  OUTPUT :                                                         + 
+C**  +    var_units                 : physical units of var.             + 
+C**  +    var[i_dim,j_dim,l_dim]    :                                    + 
+C**  +                            data field values                      + 
+C**  +                            (var must be defined, and is REAL  )   + 
+C**  +                                                                   + 
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNsread
+     &      (FILEid, VARname, time, level, i_dbeg, j_dbeg,
+     &                                     i_dim , j_dim , l_dim,
+     &       var_units, var)
+
+
+
+      IMPLICIT NONE
+
+C     ** input 
+      INTEGER        FILEid 
+      INTEGER        time, level, i_dbeg, j_dbeg
+      INTEGER        i_dim, j_dim, l_dim
+      CHARACTER *(*) VARname 
+
+C     ** output
+      CHARACTER *(*) var_units
+      REAL*4         var (i_dim, j_dim, l_dim)
+      REAL*4         varax1(i_dim), varax2(j_dim), varlev(l_dim)
+
+      call UNread (FILEid , VARname , time, level, i_dbeg, j_dbeg,
+     &       i_dim   , j_dim   , l_dim    ,
+     &       varax1  , varax2  , varlev,      
+     &       var_units, var)
+
+
+      END SUBROUTINE UNsread
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNwcatt :   +                                         +
+C**  +-------------------------+                                         +
+C**  +  *Character Attributes creation and (over)writing                 +
+C**  +    (the NetCDF file must be open, in data mode)                   +
+C**  +  *WARNING: this routine (may?) use a temporary disk space         +
+C**  +            equal to the file length (duplicate the file)          +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : input file identifier (from UNcreate OR NetCDF open) +
+C**  +    varnam  : name of variable to which attribute shall be attached+
+C**  +              or 'GLOBAL_ATT'                                      +
+C**  +    attnam  : name of writen attribute.                            +
+C**  +    attval  : string to be assigned to attribute.                  +
+C**  +              (never inclulde more than 3 consecutive blanks !)    +
+c**  +                                                                   +
+C**  +  Note : all arguments except FILEid  are strings of any length    +
+C**  +-------------------------------------------------------------------+
+
+      SUBROUTINE UNwcatt (FILEid , varnam, attnam, attval)
+
+      INCLUDE 'libUN.inc'
+
+C     **Input:
+
+      INTEGER FILEid 
+      CHARACTER*(*) varnam
+      CHARACTER*(*) attnam
+      CHARACTER*(*) attval
+
+C     **Local:
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      INTEGER Nlen, Ierro, varVID, Vlen, TTerr
+      INTEGER icheck
+      icheck= 0     !** 'debugging' level
+
+      IF (icheck.ge.1) WRITE(*,*) 'UNwcatt : Begin'
+
+C*    Get the variable ID
+C     -------------------
+
+      IF (icheck.ge.2) WRITE(*,*) 'FILEid  :', FILEid 
+
+C     ** getting varnam size :
+      Nlen = VARSIZE(varnam)
+
+C     ** Case of global attributes:
+      IF (varnam(1:Nlen).EQ.'GLOBAL_ATT') THEN 
+        varVID=NF_GLOBAL 
+
+      ELSE
+
+C     ** Get variable ID to which att is attached to:
+        Ierro=NF_INQ_VARID (FILEid , varnam(1:Nlen), varVID)
+        TTerr = ABS(Ierro)
+
+C       ** Cancel writing if an error occured : variable undefined ?
+        IF (Ierro.ne.0) THEN
+           WRITE(*,*) 'UNwcatt -ERROR : Variable ',varnam(1:Nlen)
+     &               ,' not found -> not written.'
+        END IF
+        IF (Ierro.ne.0) RETURN !** UNwcatt_end
+
+      ENDIF
+
+C     Switch to Define Mode, 
+C       because attribute may be created or change size.
+C     --------------------------------------------------
+      Ierro=NF_REDEF (FILEid)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwcatt', Ierro)
+
+C     Set attribute.
+C     --------------
+
+C     ** getting attnam [char] size :
+      Nlen = VARSIZE(attnam)
+C     ** getting attval [char] size :
+      Vlen = VARSIZE(attval)
+
+      Ierro=NF_PUT_ATT_TEXT(FILEid ,varVID ,attnam(1:Nlen),
+     &                       Vlen  ,attval(1:Vlen)      )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwcatt', Ierro)
+c     **line1^^^^ FILEid |var.id | attr.name
+C     **line2     type   | len   | attr.value | flag
+      TTerr = TTerr + ABS(Ierro)
+
+
+C     Leave define mode (!file remains open )
+C     ---------------------------------------
+      Ierro=NF_ENDDEF(FILEid )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwcatt', Ierro)
+
+      RETURN
+      END 
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNwratt :   +                                         +
+C**  +-------------------------+                                         +
+C**  +  *Real   attributes writing  - ! Can not create new attrib !      +
+C**  +    (the NetCDF file must be open)                                 +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : input file identifier (from UNcreate OR NetCDF open) +
+C**  +    varnam  : name given to the variable to write (must be in file)+
+C**  +    attnam  : name of treated attribute.                           +
+c**  +    Nvals   : Number of values of that attribute                   +
+C**  +    atvalsi(Nvals) : Real   vector of values for attribute.        +
+c**  +                                                                   +
+C**  +-------------------------------------------------------------------+
+
+C                    WARNING: this routine uses a temporary disk space
+C                             equal to the file length (duplicate the file)
+C                             (its use is NOT recommended)
+
+      SUBROUTINE UNwratt (FILEid , varnam, attnam, Nvals, atvals)
+
+      INCLUDE 'libUN.inc'
+
+C     **Input:
+
+      INTEGER FILEid , Nvals
+      CHARACTER*(*) varnam
+      CHARACTER*(*) attnam
+      REAL*4        atvals(Nvals)
+
+C     **Local:
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      INTEGER Nlen, Ierro, varVID
+      INTEGER icheck, TTerr
+      icheck= 0     !** 'debugging' level
+      TTerr = 0
+
+      IF (icheck.ge.1) WRITE(*,*) 'UNwratt : Begin'
+
+C*    Get the variable ID
+C     -------------------
+      IF (icheck.ge.2) WRITE(*,*) 'FILEid  :', FILEid 
+
+C     ** getting varnam size :
+      Nlen = VARSIZE(varnam)
+
+C     ** variable ID :
+      Ierro=NF_INQ_VARID(FILEid , varnam(1:Nlen), varVID)
+      TTerr = TTerr + ABS(Ierro)
+
+C     ** Cancel writing if an error occured : variable undefined ?
+      IF (Ierro.ne.0) THEN
+         WRITE(*,*) 'UNwratt -ERROR : Variable ',varnam(1:Nlen)
+     &            ,' not found -> not written.'
+      END IF
+      IF (Ierro.ne.0) GOTO 9999 !** UNwratt_end
+
+
+C     Set attribute.
+C     --------------
+
+C     ** getting attnam [char] size :
+      Nlen = VARSIZE(attnam)
+
+      Ierro=NF_PUT_ATT_REAL(FILEid ,varVID ,attnam(1:Nlen),
+     &           NF_FLOAT,nvals  ,atvals  )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNwratt', Ierro)
+c     **line1^^^^FILEid |var.id | attr.name
+C     **line2    type   | attr.value | flag
+      TTerr = TTerr + ABS(Ierro)
+
+
+ 9999 continue
+      RETURN
+      END
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNwopen :   +                            libUN (0896) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  * Open a NetCDF file for writing.                                +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEnam : file name                                            +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +    FILEid  : NetCDF file identifier ('logical unit')              +
+C**  +---------------------------------------------------------------7++++
+ 
+      SUBROUTINE UNwopen (FILEnam, FILEid )
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+C     ** input
+      CHARACTER*(*) FILEnam
+
+C     ** output
+      INTEGER FILEid
+
+C     ** local :
+      INTEGER Ierro
+      INTEGER icheck
+
+      icheck=0
+      
+C +   Routines which opens a file must reset libUN internals:
+      CALL UNparam('RESET_PARAMS_',0.0)
+      
+C     ** Open NetCDF file, for read-only:
+C     -----------------------------------
+      Ierro=NF_OPEN(FILEnam,NF_WRITE,FILEid)
+      IF (Ierro.NE.NF_NOERR) THEN
+         WRITE(*,*) 'Error opening file: ', FILEnam            
+         CALL HANDLE_ERR('UNwopen', Ierro)
+      ENDIF
+
+
+9999  continue
+      RETURN
+      END
+
+
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNropen :   +                            libUN (0896) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  * Open a NetCDF file for reading,                                +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEnam : file name                                            +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +    FILEid  : NetCDF file identifier ('logical unit')              +
+C**  +    FILEtit : title of the NetCDF file                             +
+C**  +              ! [CHAR], must be defined (length > length(title) !) +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNropen (FILEnam, FILEid , FILEtit)
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+C     ** input
+      CHARACTER*(*) FILEnam
+
+C     ** output
+      INTEGER FILEid      
+      CHARACTER*(*) FILEtit
+
+C     ** local :
+      INTEGER Ierro
+      INTEGER icheck
+
+      icheck=0
+      
+      IF (icheck.ge.2) WRITE(*,*) 'UNropen: Begin'
+      IF (icheck.ge.2) WRITE(*,*) 'FILEnam: ', FILEnam
+
+C +   Routines which opens a file must reset libUN internals:
+      CALL UNparam('RESET_PARAMS_',0.0)
+
+C     ** Open NetCDF file, for read-only:
+C     -----------------------------------
+      Ierro=NF_OPEN(FILEnam,NF_NOWRITE,FILEid)
+      IF (Ierro.NE.NF_NOERR) THEN
+         WRITE(*,*) 'Error opening file: ', FILEnam
+         CALL HANDLE_ERR('UNropen', Ierro)
+      ENDIF
+
+
+C     ** Read title attribute, 
+C     ------------------------
+
+C     ** Read attribute:
+      Ierro=NF_GET_ATT_TEXT(FILEid, NF_GLOBAL, 'title', 
+     &             FILEtit)
+
+C     ** Display message if an error occured : 
+C     **  no title or title too long ? 
+      IF (Ierro.ne.0) THEN
+         WRITE(*,*) 'UNropen WARNING: no title or title too long' 
+      END IF
+      IF (icheck.ge.2) WRITE(*,*) 'UNropen: End'
+
+9999  continue
+      RETURN
+      END
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNgtime :   +                            libUN (0896) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  * From a given value of desired 'time' coordinate,               +
+C**  +    gets the coordinate index ('iteration no') + found time value  +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : NetCDF file identifier (from UNropen)                +
+C**  +    RQtime  : ReQuested time                                       +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +    RDtime  : The last time for wich RDtime .le. RQtime            +
+C**  +    Ftime   : The next time value Following RDtime                 +
+C**  +              (-1 if it would be after end-of-file)                +
+C**  +    it      : The time index : RDtime = time(it)                   +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNgtime (FILEid, RQtime, RDtime, Ftime, it) 
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      INTEGER Lvnam
+      PARAMETER (Lvnam=20)
+
+C     ** input
+      INTEGER FILEid 
+      REAL*4  RQtime
+
+C     ** output
+      REAL*4  RDtime, Ftime
+      INTEGER it
+
+C     ** local :
+      INTEGER Ierro, timVID
+      INTEGER timDID
+      REAL*4  gtim
+      INTEGER K, KHI, KLO, Kmax
+      INTEGER Mindex(1)
+      INTEGER icheck
+      CHARACTER*(Lvnam) dimNAM(1)
+
+      icheck= 0
+
+C     ** Kmax= nb pas de temps dans le fichier, = dim(time):
+C     ** - - - - - - - - - - - - - - - - - - - - - - - - - -
+C     
+      Ierro=NF_INQ_DIMID(FILEid, 'time', timDID)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+C     **^^ Dimension'time' NetCDF index
+
+      Ierro=NF_INQ_DIM(FILEid, timDID , dimNAM, Kmax  )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+C     **         id/file  id/dim   dimname dimsize  error
+C     **                           !output output
+
+C     ** Read/Search the requested time step.
+C     ** - - - - - - - - - - - - - - - - - - -
+
+      Ierro=NF_INQ_VARID(FILEid, 'time',timVID)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+C                                         **^^ Variable 'time' NetCDF index
+
+      KLO=1
+      KHI=Kmax
+
+ 1    IF (KHI-KLO.GT.1) THEN
+        K=(KHI+KLO)/2
+
+C       ** Set the position of the needed time step:
+        Mindex(1)= K
+C       ** Get 1 time value (gtim = time(K)):
+        Ierro=NF_GET_VAR1_REAL(FILEid, timVID, Mindex, gtim)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+
+        IF(gtim.GT.RQtime)THEN
+          KHI=K
+        ELSE
+          KLO=K
+        ENDIF
+      GOTO 1
+      ENDIF
+      it= KLO
+C     ** read RDtime= time(KLO)
+      Mindex(1)= KLO
+      Ierro=NF_GET_VAR1_REAL(FILEid, timVID, Mindex, RDtime)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+C     ** read Ftime= time(KHI)
+      Mindex(1)= KHI
+      Ierro=NF_GET_VAR1_REAL(FILEid, timVID, Mindex, Ftime)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgtime', Ierro)
+ 
+C     ** IF the last available time step is before
+C     **     the requested time, then KHI and KLO are the
+C     **     two last available time step. Correct this :
+      IF (RQtime.ge.Ftime) THEN
+        RDtime= Ftime                   
+        it = KHI
+        Ftime= -1.0
+      ENDIF
+
+      RETURN
+      END
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNgindx :   +                            libUN (0199) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  * From a given value of a desired coordinate,                    +
+C**  +    gets the coordinate index + found the coresp. coordinate value +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : NetCDF file identifier (from UNropen)                +
+C**  +    Cname   : The name of the coordinate                           +
+C**  +    RQval   : The requested value for that coordinate              +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +    RDval   : The last value for wich RDval .le. RQval             +
+C**  +    Fval    : The next val value Following RDval                   +
+C**  +              (-1 if it would be after end-of-file)                +
+C**  +    indx    : The val index : RDval = value_of_Cname(it)           +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNgindx (FILEid, Cname, RQval, RDval, Fval, indx)
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      INTEGER Lvnam
+      PARAMETER (Lvnam=20)
+
+C     ** input
+      INTEGER FILEid
+      CHARACTER *(*) Cname
+      REAL*4  RQval
+
+C     ** output
+      REAL*4  RDval, Fval
+      INTEGER indx 
+
+C     ** local :
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      REAL*4  gval
+      INTEGER Ierro
+      INTEGER varDID, VNlen, varVID, varNUMDIM
+      INTEGER Nvatts, vtype
+      INTEGER K, KHI, KLO, Kmax
+      INTEGER Mindex(1), dimID(4)
+      INTEGER icheck
+      CHARACTER*(Lvnam) dimNAM(4)
+      CHARACTER*13 recname
+
+      icheck= 0
+
+C     ** Kmax= nb pas de temps dans le fichier, = dim(val):
+C     ** - - - - - - - - - - - - - - - - - - - - - - - - - -
+C     ** get Cname string size :
+      VNlen = VARSIZE (Cname)
+C
+C     ** get variable ID :
+      Ierro=NF_INQ_VARID(FILEid , Cname (1:VNlen), varVID)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+C
+C     ** Inquire about the id of the dimension:
+C     **
+      Ierro=NF_INQ_VAR(FILEid , varVID, recname, vtype,
+     &          varNUMDIM, dimID , Nvatts)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+C     **  line1  id/file   id/var  var name  var type
+C     **  line2   # dims   id/dims #attributes
+      varDID = dimID(1) 
+C     ^^^At last, the id of the relevant dimension.
+
+      Ierro=NF_INQ_DIM(FILEid, varDID , dimNAM, Kmax  )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+C     **         id/file  id/dim   dimname dimsize  error
+C     **                           !output output
+C     ** (Kmax is what we needed: size of the dimension)
+
+C     ** Read/Search the requested val step.
+C     ** - - - - - - - - - - - - - - - - - - -
+
+      KLO=1
+      KHI=Kmax
+
+ 1    IF (KHI-KLO.GT.1) THEN
+        K=(KHI+KLO)/2
+
+C       ** Set the position of the needed val step:
+        Mindex(1)= K
+C       ** Get 1 val value (gval = val(K)):
+        Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, gval)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+
+        IF(gval.GT.RQval)THEN
+          KHI=K
+        ELSE
+          KLO=K
+        ENDIF
+      GOTO 1
+      ENDIF
+      indx= KLO
+C     ** read RDval= val(KLO)
+      Mindex(1)= KLO
+      Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, RDval)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+C     ** read Fval= val(KHI)
+      Mindex(1)= KHI
+      Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, Fval)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNgindex', Ierro)
+
+C     ** IF the last available val step is before
+C     **     the requested val, then KHI and KLO are the
+C     **     two last available val step. Correct this :
+      IF (RQval.ge.Fval) THEN
+        RDval= Fval
+        indx = KHI
+        Fval= -1.0
+      ENDIF
+
+      RETURN
+      END
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNfindx :   +                            (libUN  2003)+
+C**  +-------------------------+-----------------------------------------+
+C**  +  * Intended to replace UNgindx or UNgtime                         +
+C**  +    From a given value of a desired coordinate,                    +
+C**  +    gets the coordinate index + the coresp. coordinate value       +
+C**  +    This version solves the issue of Dates at year change          +
+C**  +    occuring because 1 jan is < 31 dec.  Not optimised.            +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : NetCDF file identifier (from UNropen)                +
+C**  +    Cname   : The name of the coordinate                           +
+C**  +    RQval   : The requested value for that coordinate              +
+C**  +                                                                   +
+C**  +  OUTPUT :                                                         +
+C**  +    RDval   : The file value closest to RQval                      +
+C**  +    Fval    : The next value in the file                           +
+C**  +              (-1 if after file end)                               +
+C**  +              (This is mainly for compatibility with older version)+
+C**  +    indx    : The val index : RDval = value_of_Cname(it)           +
+C**  +              (-1 may be returned if the value can't be found)     +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNfindx (FILEid, Cname, RQval, RDval, Fval, indx)
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      INTEGER Lvnam
+      PARAMETER (Lvnam=20)
+
+C     ** input
+      INTEGER FILEid
+      CHARACTER *(*) Cname
+      REAL*4  RQval
+
+C     ** output
+      REAL*4  RDval, Fval
+      INTEGER indx
+
+C     ** local :
+      INTEGER  VARSIZE
+      EXTERNAL VARSIZE
+      REAL*4  gval, bmatch, gdist
+      INTEGER Ierro
+      INTEGER varDID, VNlen, varVID, varNUMDIM
+      INTEGER Nvatts, vtype
+      INTEGER K, KHI, KLO, Kmax
+      INTEGER Mindex(1), dimID(4)
+      INTEGER icheck
+      CHARACTER*(Lvnam) dimNAM(4)
+      CHARACTER*13 recname
+
+      icheck= 0
+
+C     ** Kmax= nb pas de temps dans le fichier, = dim(val):
+C     ** - - - - - - - - - - - - - - - - - - - - - - - - - -
+C     ** get Cname string size :
+      VNlen = VARSIZE (Cname)
+C
+C     ** get variable ID :
+      Ierro=NF_INQ_VARID(FILEid , Cname (1:VNlen), varVID)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+C
+C     ** Inquire about the id of the dimension:
+C     **
+      Ierro=NF_INQ_VAR(FILEid , varVID, recname, vtype,
+     &          varNUMDIM, dimID , Nvatts)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+C     **  line1  id/file   id/var  var name  var type
+C     **  line2   # dims   id/dims #attributes
+      varDID = dimID(1)
+C     ^^^At last, the id of the relevant dimension.
+
+      Ierro=NF_INQ_DIM(FILEid, varDID , dimNAM, Kmax  )
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+C     **         id/file  id/dim   dimname dimsize  error
+C     **                           !output output
+C     ** (Kmax is what we needed: size of the dimension)
+
+C     ** Read/Search the requested val step.
+C     ** - - - - - - - - - - - - - - - - - - -
+
+C     This is a workaround, not optimised as stated above.
+C     We simply look at all values sequencially.
+C
+      bmatch=1.E10
+      KLO=-1
+
+      DO K=1,KMAX
+
+C       ** Get 1 val value (gval = val(K)):
+        Mindex(1)= K
+        Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, gval)
+        IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+
+        gdist=ABS(gval-RQval)
+        IF (gdist.LT.bmatch) THEN
+
+         bmatch=gdist
+         KLO=K
+
+        ENDIF
+
+      ENDDO
+
+      indx= KLO
+
+      KHI = min((KLO+1),KMAX)
+
+C     ** read values...
+
+      Mindex(1)= KLO
+      Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, RDval)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+C     ** read Fval= val(KHI)
+      Mindex(1)= KHI
+      Ierro=NF_GET_VAR1_REAL(FILEid, varVID, Mindex, Fval)
+      IF (Ierro.NE.NF_NOERR) CALL HANDLE_ERR('UNfindex', Ierro)
+
+      IF (KHI.EQ.KLO) THEN
+        Fval= -1.0
+      ENDIF
+
+      IF (bmatch.GT.1.E9) THEN
+        Fval= -1.0
+        indx= -1
+      ENDIF
+
+      RETURN
+      END
+
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNclose :   +                            libUN (0300) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  * Close the desired file                                         +
+C**  +    Created to suppress the need the directly call a netcdf        +
+C**  +    routine from a program                                         +
+C**  +                                                                   +
+C**  +  INPUT :                                                          +
+C**  +    FILEid  : NetCDF file identifier (from UNropen)                +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNCLOSE(FILEid)
+
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      integer Ierro, FILEid
+
+      Ierro=NF_CLOSE(FILEid)
+      IF (Ierro.NE.NF_NOERR) THEN
+         CALL HANDLE_ERR('UNclose', Ierro)
+      ENDIF
+
+      END
+      
+C**  +-------------------------+-----------------------------------------+
+C**  +  Subroutine UNparam :   +                            libUN (0202) +
+C**  +-------------------------+-----------------------------------------+
+C**  +  Changes some global libUN parameters                             +
+C**  +  NB: default values are set at first libUN call                   +
+C**  +                                                                   +
+C**  +                                                                   +
+C**  +  INPUT : pname   name of the parameters to set                    +
+C**  +          pvalue  the requested new value                          +
+C**  +                                                                   +
+C**  +---------------------------------------------------------------7++++
+
+      SUBROUTINE UNparam(pname,pvalue)
+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+ 
+      CHARACTER*(*) pname
+      REAL*4  pvalue
+      
+      LOGICAL Lstart
+      SAVE    Lstart
+      DATA    Lstart /.true./
+
+      IF      (pname.EQ.'RESET_PARAMS_') THEN
+         IF (Lstart.OR.pvalue.GT.0.5) THEN
+           vMissVal= 1.0E21   ! for missing values
+           VarRepl = vMissVal ! for missing VARIABLES
+           ValRange(1)= -vMissVal/10.
+           ValRange(2)=  vMissVal/10.
+           iVarWarn= 2
+           vReadMin  = 0.0
+           vReadMax  = 0.0
+           ireadchk = 0
+           Lstart   = .false.
+          ENDIF
+          
+      ELSE IF (pname.EQ.'NOVAR_REPLACE') THEN
+         VarRepl = pvalue  
+         
+      ELSE IF (pname.EQ.'NOVAR_WARNING') THEN
+         iVarWarn= NINT(pvalue)
+         
+      ELSE IF (pname.EQ.'VALID_RANGE_MIN') THEN
+         ValRange(1) = pvalue  
+
+      ELSE IF (pname.EQ.'VALID_RANGE_MAX') THEN
+         ValRange(2) = pvalue  
+      
+      ELSE IF (pname.EQ.'READOVER_WARN') THEN
+         vReadMin  = - pvalue
+         vReadMax  =   pvalue
+         ireadchk = 1
+      
+      ELSE IF (pname.EQ.'READ_MIN_WARN') THEN
+         vReadMin  =   pvalue
+         ireadchk = 1
+         
+      ELSE IF (pname.EQ.'READ_MAX_WARN') THEN
+         vReadMax  =   pvalue
+         ireadchk = 1   
+         
+      ELSE 
+         write(*,*) 'UNparam (libUN) Error: '       
+         write(*,*) '  parameter undefined:', pname       
+
+      ENDIF
+
+      END
+      
+C**  +-------------------------+-----------------------------------------+
+      SUBROUTINE UNversion(UNver,NCDFver)
+C**  +-------------------------+-----------------------------------------+
+      
+      IMPLICIT NONE
+      INCLUDE 'libUN.inc'
+
+      CHARACTER*80 UNver,NCDFver
+
+      UNver  = '2005.03.31'
+      NCDFver= NF_INQ_LIBVERS()
+
+      END
+
+C**  +-------------------------------------------------------------------+
+      FUNCTION VARSIZE(CHAvar)
+C**  +-------------------------------------------------------------------+
+      IMPLICIT NONE
+      integer maxcha,iz,VARSIZE
+      parameter (maxcha=512)
+      character*(*)      CHAvar
+      character*(maxcha) CHAtmp
+
+      WRITE(CHAtmp,'(A)') CHAvar
+      iz = 0
+      do while ((CHAtmp(iz+1:iz+3).ne.'   ').and.(iz+3.le.maxcha))
+        iz = iz + 1
+      end do
+      VARSIZE =  iz
+
+      RETURN
+      END
+
+
+C**  +-------------------------------------------------------------------+
+      SUBROUTINE HANDLE_ERR(LOCATION, STATUS)
+C**  +-------------------------------------------------------------------+
+      IMPLICIT NONE
+
+      INCLUDE 'libUN.inc'
+
+      character*(*) LOCATION
+      integer STATUS
+      IF (STATUS.NE.NF_NOERR) THEN
+        WRITE(*,*) 'IN ROUTINE ', LOCATION
+        WRITE(*,*) NF_STRERROR(STATUS)
+        STOP 'Stopped'
+      ENDIF
+      END
+
+C UN library: history of fixed bugs and updates.
+C ----------------------------------------------
+C
+C                        961206 - UNgtime, trouble at end-of-file
+C                        961218 - - all -, display 'artificial' errors
+C                        970318 -   again, display 'artificial' errors
+C                        971028 - (3 sub),'syntax'error on Cray computer
+C                        971105 - Allowed variable "imap(1)", =8 for Cray
+C                        980705 - "single element" extension to UNwrite.
+C                        980709 - bug fixes (start) in UNwrite & UNlwrite
+C                                 ("DATA" statement incorrectly used).
+C                        980825 - Changed default "stride" to 1 for v3.x
+C                        981222 - bug fix: allow UNwrite for unlim dims.
+C                                 note that this should be tested.
+C                        990110 - Added "UNgindx" = general. of UNgtime
+C                               - Removed all "DATA" and all "//" in write
+C                                 (the later should improve compatibility)
+C                        990128 - UNwrite: added a "no warning" option.
+C                        990323 - UNwrite: added 1D+time capability.
+C                        990807 - UNwrite: added 3D-notime capability.
+C  -----------------------------------------------------------------------
+C                        000404 - Major upgrade: compatibility with
+C                                 NetCDF v3.4
+C                               - NOTE: Types other than REAL may be
+C                                 accepted in UNread, but not tested
+C  -----------------------------------------------------------------------
+C                        000614 - Bug fixes: uninitialised error count
+C                                 in UNwcatt, bug in UNclose. 
+C                        000620 - Bug fix: UNropen (args. of get title fn)
+C                        000713 - Bug fix: UNgtime (missing arg in a call)
+C                                 (last tree caused by 000404 upgrade)
+C  -----------------------------------------------------------------------
+C                        000928 - UNlwrite: added 2D+time capability.
+C                        001008 - All: CHARACTER*(*) declaration for units
+C                                 and longer strings for intern. variables
+C                        010417 - UNread: added var not found info
+C                                 UNropen: added file not found info
+C                        010715 - UNwrite + UNlwrite: 
+C                                   fixed bug / unlimited time dim
+C                        0107xx - UNwrite:  
+C                                   missing values -> not in "range"
+C                        020130 - All:    
+C                                  .removed obsolete warnings about 
+C                                   double precision in files.      
+C                                  .added a version (libUN_dbl) with
+C                                   REAL*8 as arguments - but still
+C                                   creates REAL*4 in files.
+C                        020526 - Added UNparam function,
+C                                 which provide optional features such
+C                                 as missing variable behavior control
+C                        020808 - Very simple fix for underflows while 
+C                                 reading some files; must use -fpe1
+C                                 Fixed a bug -> out of range msg
+C                        030121 - Enabled some non-standard NetCDF files
+C                                 (missing units...) -> new warnings
+C                                 rather then program stop.
+C                        030215 - Added UNfindx for non-monotonic data
+C                        030215 - Removed warning related to UNLIM dims
+C                        030311 - Added VALID_RANGE attribute (option)
+C                                 (if set, the range is accounted for
+C                                 in the min/max set while writing vars)
+C                        040902 - Improvements to "valid_range" attribute
+C                               - Added attribute "positive=down"
+C                                 if units are sigma or sigma_level
+C                        050331 - Added "user friendly" interfaces
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.inc
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.inc	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/libUN.inc	(revision 6)
@@ -0,0 +1,58 @@
+C     =========
+C     libUN.inc
+C     =========
+
+      INCLUDE 'netcdf.inc'
+ 
+      CHARACTER*50   CF_institution 
+      PARAMETER     (CF_institution="UCL-ASTR (Martin Vancoppenolle)") 
+
+      CHARACTER*10   CF_libUN_version 
+      PARAMETER     (CF_libUN_version="2005.04.08") 
+
+      INTEGER        CF_dimmaxlen
+      PARAMETER     (CF_dimmaxlen=99999) ! Maximum dim/axes length
+
+      INTEGER        CF_dimmaxnbr
+      PARAMETER     (CF_dimmaxnbr=20)    ! Nbr Maximum of dim/axes                  
+
+
+      INTEGER        CF_varmaxnbr       
+      PARAMETER     (CF_varmaxnbr=300)   ! Nbr maximum of variables
+
+      INTEGER        CF_attnbr       
+      PARAMETER     (CF_attnbr   =1)     ! nbr of attibutes
+
+      INTEGER        CF_dim(0:CF_dimmaxnbr),CF_attnum(CF_attnbr)
+      INTEGER        CF_varnbrtot,CF_dimnbrtot,CF_fileidopened
+
+      REAL           CF_dimval(CF_dimmaxlen,0:CF_dimmaxnbr)
+
+      CHARACTER*13   CF_dimnam(0:CF_dimmaxnbr)
+      CHARACTER*13   CF_varnam(CF_varmaxnbr)
+      CHARACTER*13   CF_varnamdim(4,CF_varmaxnbr)
+      CHARACTER*13   CF_attnam(CF_attnbr)
+      CHARACTER*31   CF_dimnamuni(0:CF_dimmaxnbr)
+      CHARACTER*31   CF_varnamuni(CF_varmaxnbr)
+      CHARACTER*50   CF_vardes(CF_varmaxnbr)
+      CHARACTER*200  CF_filenam,CF_filetit,CF_filenamopened
+
+      COMMON/CF_FILE_CREATi/CF_dim,CF_attnum,CF_fileidopened, 
+     .                      CF_varnbrtot,CF_dimnbrtot
+                     
+      COMMON/CF_FILE_CREATr/CF_dimval
+
+      COMMON/CF_FILE_CREATc/CF_dimnam,CF_varnam,CF_varnamdim,
+     .                      CF_attnam,CF_dimnamuni,CF_varnamuni,
+     .                      CF_vardes,CF_filenam,CF_filetit,
+     .                      CF_filenamopened
+
+C     =================================================================
+
+      INTEGER         iVarWarn,ireadchk
+      REAL            VarRepl,vReadMin,vReadMax,
+     .                vMissVal,ValRange(2)
+
+      COMMON/UNparams/VarRepl,iVarWarn,ireadchk,vReadMin,vReadMax,
+     .                vMissVal,ValRange
+
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.f	(revision 6)
@@ -0,0 +1,31 @@
+      MODULE lib_fortran
+      !!======================================================================
+      !!                       ***  MODULE  lib_fortran  ***
+      !! Fortran utilities:  includes some low levels fortran functionality
+      IMPLICIT NONE
+      PRIVATE
+
+      PUBLIC SIGN
+
+      INTERFACE SIGN
+      MODULE PROCEDURE SIGN_1D
+      END INTERFACE
+
+      CONTAINS
+
+      FUNCTION SIGN_1D(pa,pb)
+      !!-----------------------------------------------------------------------
+      !!                  ***  FUNCTION SIGN_SCALAR  ***
+      !!
+      !! ** Purpose : overwrite f95 behaviour of intrinsinc sign function
+      !!-----------------------------------------------------------------------
+      REAL(8) :: pa,pb          ! input
+      REAL(8) :: SIGN_1D        ! result
+      !!-----------------------------------------------------------------------
+      IF ( pb >= 0.e0) THEN   ;   SIGN_1D = ABS(pa)
+      ELSE                    ;   SIGN_1D =-ABS(pa)
+      ENDIF
+
+      END FUNCTION SIGN_1D
+
+      END MODULE lib_fortran
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.mod
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.mod	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/lib_fortran.mod	(revision 6)
@@ -0,0 +1,26 @@
+GFORTRAN module version '9' created from /Users/ioulianikolskaia/Boulot/CODES/LIM1D_BIO/SOURCES/source_3.01/lib_fortran.f
+MD5:3da1ff0b41ee6c844deeca18ea3cef5b -- If you edit this, you'll get what you deserve.
+
+(() () () () () () () () () () () () () () () () () () () () () () () ()
+() () ())
+
+()
+
+(('sign' 'lib_fortran' 2))
+
+()
+
+()
+
+()
+
+(2 'sign_1d' 'lib_fortran' '' 1 ((PROCEDURE UNKNOWN-INTENT MODULE-PROC
+DECL UNKNOWN 0 0 FUNCTION) (REAL 8 0 0 0 REAL ()) 3 0 (4 5) () 2 () () ()
+0 0)
+4 'pa' '' '' 3 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN UNKNOWN 0
+0 DUMMY) (REAL 8 0 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
+5 'pb' '' '' 3 ((VARIABLE UNKNOWN-INTENT UNKNOWN-PROC UNKNOWN UNKNOWN 0
+0 DUMMY) (REAL 8 0 0 0 REAL ()) 0 0 () () 0 () () () 0 0)
+)
+
+()
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/netcdf.inc
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/netcdf.inc	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/netcdf.inc	(revision 6)
@@ -0,0 +1,1369 @@
+!
+! netcdf version 3 fortran interface:
+!
+
+!
+! external netcdf data types:
+!
+      integer nf_byte
+      integer nf_int1
+      integer nf_char
+      integer nf_short
+      integer nf_int2
+      integer nf_int
+      integer nf_float
+      integer nf_real
+      integer nf_double
+      integer nf_ubyte
+      integer nf_ushort
+      integer nf_uint
+      integer nf_int64
+      integer nf_uint64
+      integer nf_string
+
+!
+! the user doesn't use these classes of user defined type, but they
+! are returned by nc_inq_user_type.
+!
+      integer nf_vlen
+      integer nf_opaque
+      integer nf_enum
+      integer nf_compound
+
+      parameter (nf_byte = 1)
+      parameter (nf_int1 = nf_byte)
+      parameter (nf_char = 2)
+      parameter (nf_short = 3)
+      parameter (nf_int2 = nf_short)
+      parameter (nf_int = 4)
+      parameter (nf_float = 5)
+      parameter (nf_real = nf_float)
+      parameter (nf_double = 6)
+      parameter (nf_ubyte = 7)
+      parameter (nf_ushort = 8)
+      parameter (nf_uint = 9)
+      parameter (nf_int64 = 10)
+      parameter (nf_uint64 = 11)
+      parameter (nf_string = 12)
+      parameter (nf_vlen = 13)
+      parameter (nf_opaque = 14)
+      parameter (nf_enum = 15)
+      parameter (nf_compound = 16)
+
+!
+! default fill values:
+!
+      integer           nf_fill_byte
+      integer           nf_fill_int1
+      integer           nf_fill_char
+      integer           nf_fill_short
+      integer           nf_fill_int2
+      integer           nf_fill_int
+      real              nf_fill_float
+      real              nf_fill_real
+      doubleprecision   nf_fill_double
+      integer           nf_fill_ubyte
+      integer           nf_fill_ushort
+!      real              nf_fill_uint
+!      real              nf_fill_int64
+!      real              nf_fill_uint64
+
+      parameter (nf_fill_byte = -127)
+      parameter (nf_fill_int1 = nf_fill_byte)
+      parameter (nf_fill_char = 0)
+      parameter (nf_fill_short = -32767)
+      parameter (nf_fill_int2 = nf_fill_short)
+      parameter (nf_fill_int = -2147483647)
+      parameter (nf_fill_float = 9.9692099683868690e+36)
+      parameter (nf_fill_real = nf_fill_float)
+      parameter (nf_fill_double = 9.9692099683868690e+36)
+      parameter (nf_fill_ubyte = 255)
+      parameter (nf_fill_ushort = 65535)
+
+!
+! mode flags for opening and creating a netcdf dataset:
+!
+      integer nf_nowrite
+      integer nf_write
+      integer nf_clobber
+      integer nf_noclobber
+      integer nf_fill
+      integer nf_nofill
+      integer nf_lock
+      integer nf_share
+      integer nf_64bit_offset
+      integer nf_sizehint_default
+      integer nf_align_chunk
+      integer nf_format_classic
+      integer nf_format_64bit
+      integer nf_format_netcdf4
+      integer nf_format_netcdf4_classic
+
+      parameter (nf_nowrite = 0)
+      parameter (nf_write = 1)
+      parameter (nf_clobber = 0)
+      parameter (nf_noclobber = 4)
+      parameter (nf_fill = 0)
+      parameter (nf_nofill = 256)
+      parameter (nf_lock = 1024)
+      parameter (nf_share = 2048)
+      parameter (nf_64bit_offset = 512)
+      parameter (nf_sizehint_default = 0)
+      parameter (nf_align_chunk = -1)
+      parameter (nf_format_classic = 1)
+      parameter (nf_format_64bit = 2)
+      parameter (nf_format_netcdf4 = 3)
+      parameter (nf_format_netcdf4_classic = 4)
+
+!
+! size argument for defining an unlimited dimension:
+!
+      integer nf_unlimited
+      parameter (nf_unlimited = 0)
+
+!
+! global attribute id:
+!
+      integer nf_global
+      parameter (nf_global = 0)
+
+!
+! implementation limits:
+!
+      integer nf_max_dims
+      integer nf_max_attrs
+      integer nf_max_vars
+      integer nf_max_name
+      integer nf_max_var_dims
+
+      parameter (nf_max_dims = 1024)
+      parameter (nf_max_attrs = 8192)
+      parameter (nf_max_vars = 8192)
+      parameter (nf_max_name = 256)
+      parameter (nf_max_var_dims = nf_max_dims)
+
+!
+! error codes:
+!
+      integer nf_noerr
+      integer nf_ebadid
+      integer nf_eexist
+      integer nf_einval
+      integer nf_eperm
+      integer nf_enotindefine
+      integer nf_eindefine
+      integer nf_einvalcoords
+      integer nf_emaxdims
+      integer nf_enameinuse
+      integer nf_enotatt
+      integer nf_emaxatts
+      integer nf_ebadtype
+      integer nf_ebaddim
+      integer nf_eunlimpos
+      integer nf_emaxvars
+      integer nf_enotvar
+      integer nf_eglobal
+      integer nf_enotnc
+      integer nf_ests
+      integer nf_emaxname
+      integer nf_eunlimit
+      integer nf_enorecvars
+      integer nf_echar
+      integer nf_eedge
+      integer nf_estride
+      integer nf_ebadname
+      integer nf_erange
+      integer nf_enomem
+      integer nf_evarsize
+      integer nf_edimsize
+      integer nf_etrunc
+
+      parameter (nf_noerr = 0)
+      parameter (nf_ebadid = -33)
+      parameter (nf_eexist = -35)
+      parameter (nf_einval = -36)
+      parameter (nf_eperm = -37)
+      parameter (nf_enotindefine = -38)
+      parameter (nf_eindefine = -39)
+      parameter (nf_einvalcoords = -40)
+      parameter (nf_emaxdims = -41)
+      parameter (nf_enameinuse = -42)
+      parameter (nf_enotatt = -43)
+      parameter (nf_emaxatts = -44)
+      parameter (nf_ebadtype = -45)
+      parameter (nf_ebaddim = -46)
+      parameter (nf_eunlimpos = -47)
+      parameter (nf_emaxvars = -48)
+      parameter (nf_enotvar = -49)
+      parameter (nf_eglobal = -50)
+      parameter (nf_enotnc = -51)
+      parameter (nf_ests = -52)
+      parameter (nf_emaxname = -53)
+      parameter (nf_eunlimit = -54)
+      parameter (nf_enorecvars = -55)
+      parameter (nf_echar = -56)
+      parameter (nf_eedge = -57)
+      parameter (nf_estride = -58)
+      parameter (nf_ebadname = -59)
+      parameter (nf_erange = -60)
+      parameter (nf_enomem = -61)
+      parameter (nf_evarsize = -62)
+      parameter (nf_edimsize = -63)
+      parameter (nf_etrunc = -64)
+!
+! error handling modes:
+!
+      integer  nf_fatal
+      integer nf_verbose
+
+      parameter (nf_fatal = 1)
+      parameter (nf_verbose = 2)
+
+!
+! miscellaneous routines:
+!
+      character*80   nf_inq_libvers
+      external       nf_inq_libvers
+
+      character*80   nf_strerror
+!                         (integer             ncerr)
+      external       nf_strerror
+
+      logical        nf_issyserr
+!                         (integer             ncerr)
+      external       nf_issyserr
+
+!
+! control routines:
+!
+      integer         nf_inq_base_pe
+!                         (integer             ncid,
+!                          integer             pe)
+      external        nf_inq_base_pe
+
+      integer         nf_set_base_pe
+!                         (integer             ncid,
+!                          integer             pe)
+      external        nf_set_base_pe
+
+      integer         nf_create
+!                         (character*(*)       path,
+!                          integer             cmode,
+!                          integer             ncid)
+      external        nf_create
+
+      integer         nf__create
+!                         (character*(*)       path,
+!                          integer             cmode,
+!                          integer             initialsz,
+!                          integer             chunksizehint,
+!                          integer             ncid)
+      external        nf__create
+
+      integer         nf__create_mp
+!                         (character*(*)       path,
+!                          integer             cmode,
+!                          integer             initialsz,
+!                          integer             basepe,
+!                          integer             chunksizehint,
+!                          integer             ncid)
+      external        nf__create_mp
+
+      integer         nf_open
+!                         (character*(*)       path,
+!                          integer             mode,
+!                          integer             ncid)
+      external        nf_open
+
+      integer         nf__open
+!                         (character*(*)       path,
+!                          integer             mode,
+!                          integer             chunksizehint,
+!                          integer             ncid)
+      external        nf__open
+
+      integer         nf__open_mp
+!                         (character*(*)       path,
+!                          integer             mode,
+!                          integer             basepe,
+!                          integer             chunksizehint,
+!                          integer             ncid)
+      external        nf__open_mp
+
+      integer         nf_set_fill
+!                         (integer             ncid,
+!                          integer             fillmode,
+!                          integer             old_mode)
+      external        nf_set_fill
+
+      integer         nf_set_default_format
+!                          (integer             format,
+!                          integer             old_format)
+      external        nf_set_default_format
+
+      integer         nf_redef
+!                         (integer             ncid)
+      external        nf_redef
+
+      integer         nf_enddef
+!                         (integer             ncid)
+      external        nf_enddef
+
+      integer         nf__enddef
+!                         (integer             ncid,
+!                          integer             h_minfree,
+!                          integer             v_align,
+!                          integer             v_minfree,
+!                          integer             r_align)
+      external        nf__enddef
+
+      integer         nf_sync
+!                         (integer             ncid)
+      external        nf_sync
+
+      integer         nf_abort
+!                         (integer             ncid)
+      external        nf_abort
+
+      integer         nf_close
+!                         (integer             ncid)
+      external        nf_close
+
+      integer         nf_delete
+!                         (character*(*)       ncid)
+      external        nf_delete
+
+!
+! general inquiry routines:
+!
+
+      integer         nf_inq
+!                         (integer             ncid,
+!                          integer             ndims,
+!                          integer             nvars,
+!                          integer             ngatts,
+!                          integer             unlimdimid)
+      external        nf_inq
+
+      integer         nf_inq_ndims
+!                         (integer             ncid,
+!                          integer             ndims)
+      external        nf_inq_ndims
+
+      integer         nf_inq_nvars
+!                         (integer             ncid,
+!                          integer             nvars)
+      external        nf_inq_nvars
+
+      integer         nf_inq_natts
+!                         (integer             ncid,
+!                          integer             ngatts)
+      external        nf_inq_natts
+
+      integer         nf_inq_unlimdim
+!                         (integer             ncid,
+!                          integer             unlimdimid)
+      external        nf_inq_unlimdim
+
+      integer         nf_inq_format
+!                         (integer             ncid,
+!                          integer             format)
+      external        nf_inq_format
+
+!
+! dimension routines:
+!
+
+      integer         nf_def_dim
+!                         (integer             ncid,
+!                          character(*)        name,
+!                          integer             len,
+!                          integer             dimid)
+      external        nf_def_dim
+
+      integer         nf_inq_dimid
+!                         (integer             ncid,
+!                          character(*)        name,
+!                          integer             dimid)
+      external        nf_inq_dimid
+
+      integer         nf_inq_dim
+!                         (integer             ncid,
+!                          integer             dimid,
+!                          character(*)        name,
+!                          integer             len)
+      external        nf_inq_dim
+
+      integer         nf_inq_dimname
+!                         (integer             ncid,
+!                          integer             dimid,
+!                          character(*)        name)
+      external        nf_inq_dimname
+
+      integer         nf_inq_dimlen
+!                         (integer             ncid,
+!                          integer             dimid,
+!                          integer             len)
+      external        nf_inq_dimlen
+
+      integer         nf_rename_dim
+!                         (integer             ncid,
+!                          integer             dimid,
+!                          character(*)        name)
+      external        nf_rename_dim
+
+!
+! general attribute routines:
+!
+
+      integer         nf_inq_att
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len)
+      external        nf_inq_att
+
+      integer         nf_inq_attid
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             attnum)
+      external        nf_inq_attid
+
+      integer         nf_inq_atttype
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype)
+      external        nf_inq_atttype
+
+      integer         nf_inq_attlen
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             len)
+      external        nf_inq_attlen
+
+      integer         nf_inq_attname
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             attnum,
+!                          character(*)        name)
+      external        nf_inq_attname
+
+      integer         nf_copy_att
+!                         (integer             ncid_in,
+!                          integer             varid_in,
+!                          character(*)        name,
+!                          integer             ncid_out,
+!                          integer             varid_out)
+      external        nf_copy_att
+
+      integer         nf_rename_att
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        curname,
+!                          character(*)        newname)
+      external        nf_rename_att
+
+      integer         nf_del_att
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name)
+      external        nf_del_att
+
+!
+! attribute put/get routines:
+!
+
+      integer         nf_put_att_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             len,
+!                          character(*)        text)
+      external        nf_put_att_text
+
+      integer         nf_get_att_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          character(*)        text)
+      external        nf_get_att_text
+
+      integer         nf_put_att_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len,
+!                          nf_int1_t           i1vals(1))
+      external        nf_put_att_int1
+
+      integer         nf_get_att_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          nf_int1_t           i1vals(1))
+      external        nf_get_att_int1
+
+      integer         nf_put_att_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len,
+!                          nf_int2_t           i2vals(1))
+      external        nf_put_att_int2
+
+      integer         nf_get_att_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          nf_int2_t           i2vals(1))
+      external        nf_get_att_int2
+
+      integer         nf_put_att_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len,
+!                          integer             ivals(1))
+      external        nf_put_att_int
+
+      integer         nf_get_att_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             ivals(1))
+      external        nf_get_att_int
+
+      integer         nf_put_att_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len,
+!                          real                rvals(1))
+      external        nf_put_att_real
+
+      integer         nf_get_att_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          real                rvals(1))
+      external        nf_get_att_real
+
+      integer         nf_put_att_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             xtype,
+!                          integer             len,
+!                          double              dvals(1))
+      external        nf_put_att_double
+
+      integer         nf_get_att_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          double              dvals(1))
+      external        nf_get_att_double
+
+!
+! general variable routines:
+!
+
+      integer         nf_def_var
+!                         (integer             ncid,
+!                          character(*)        name,
+!                          integer             datatype,
+!                          integer             ndims,
+!                          integer             dimids(1),
+!                          integer             varid)
+      external        nf_def_var
+
+      integer         nf_inq_var
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name,
+!                          integer             datatype,
+!                          integer             ndims,
+!                          integer             dimids(1),
+!                          integer             natts)
+      external        nf_inq_var
+
+      integer         nf_inq_varid
+!                         (integer             ncid,
+!                          character(*)        name,
+!                          integer             varid)
+      external        nf_inq_varid
+
+      integer         nf_inq_varname
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name)
+      external        nf_inq_varname
+
+      integer         nf_inq_vartype
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             xtype)
+      external        nf_inq_vartype
+
+      integer         nf_inq_varndims
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             ndims)
+      external        nf_inq_varndims
+
+      integer         nf_inq_vardimid
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             dimids(1))
+      external        nf_inq_vardimid
+
+      integer         nf_inq_varnatts
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             natts)
+      external        nf_inq_varnatts
+
+      integer         nf_rename_var
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        name)
+      external        nf_rename_var
+
+      integer         nf_copy_var
+!                         (integer             ncid_in,
+!                          integer             varid,
+!                          integer             ncid_out)
+      external        nf_copy_var
+
+!
+! entire variable put/get routines:
+!
+
+      integer         nf_put_var_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        text)
+      external        nf_put_var_text
+
+      integer         nf_get_var_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          character(*)        text)
+      external        nf_get_var_text
+
+      integer         nf_put_var_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          nf_int1_t           i1vals(1))
+      external        nf_put_var_int1
+
+      integer         nf_get_var_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          nf_int1_t           i1vals(1))
+      external        nf_get_var_int1
+
+      integer         nf_put_var_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          nf_int2_t           i2vals(1))
+      external        nf_put_var_int2
+
+      integer         nf_get_var_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          nf_int2_t           i2vals(1))
+      external        nf_get_var_int2
+
+      integer         nf_put_var_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             ivals(1))
+      external        nf_put_var_int
+
+      integer         nf_get_var_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             ivals(1))
+      external        nf_get_var_int
+
+      integer         nf_put_var_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          real                rvals(1))
+      external        nf_put_var_real
+
+      integer         nf_get_var_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          real                rvals(1))
+      external        nf_get_var_real
+
+      integer         nf_put_var_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          doubleprecision     dvals(1))
+      external        nf_put_var_double
+
+      integer         nf_get_var_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          doubleprecision     dvals(1))
+      external        nf_get_var_double
+
+!
+! single variable put/get routines:
+!
+
+      integer         nf_put_var1_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          character*1         text)
+      external        nf_put_var1_text
+
+      integer         nf_get_var1_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          character*1         text)
+      external        nf_get_var1_text
+
+      integer         nf_put_var1_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          nf_int1_t           i1val)
+      external        nf_put_var1_int1
+
+      integer         nf_get_var1_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          nf_int1_t           i1val)
+      external        nf_get_var1_int1
+
+      integer         nf_put_var1_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          nf_int2_t           i2val)
+      external        nf_put_var1_int2
+
+      integer         nf_get_var1_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          nf_int2_t           i2val)
+      external        nf_get_var1_int2
+
+      integer         nf_put_var1_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          integer             ival)
+      external        nf_put_var1_int
+
+      integer         nf_get_var1_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          integer             ival)
+      external        nf_get_var1_int
+
+      integer         nf_put_var1_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          real                rval)
+      external        nf_put_var1_real
+
+      integer         nf_get_var1_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          real                rval)
+      external        nf_get_var1_real
+
+      integer         nf_put_var1_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          doubleprecision     dval)
+      external        nf_put_var1_double
+
+      integer         nf_get_var1_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             index(1),
+!                          doubleprecision     dval)
+      external        nf_get_var1_double
+
+!
+! variable array put/get routines:
+!
+
+      integer         nf_put_vara_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          character(*)        text)
+      external        nf_put_vara_text
+
+      integer         nf_get_vara_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          character(*)        text)
+      external        nf_get_vara_text
+
+      integer         nf_put_vara_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_put_vara_int1
+
+      integer         nf_get_vara_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_get_vara_int1
+
+      integer         nf_put_vara_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_put_vara_int2
+
+      integer         nf_get_vara_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_get_vara_int2
+
+      integer         nf_put_vara_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             ivals(1))
+      external        nf_put_vara_int
+
+      integer         nf_get_vara_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             ivals(1))
+      external        nf_get_vara_int
+
+      integer         nf_put_vara_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          real                rvals(1))
+      external        nf_put_vara_real
+
+      integer         nf_get_vara_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          real                rvals(1))
+      external        nf_get_vara_real
+
+      integer         nf_put_vara_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          doubleprecision     dvals(1))
+      external        nf_put_vara_double
+
+      integer         nf_get_vara_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          doubleprecision     dvals(1))
+      external        nf_get_vara_double
+
+!
+! strided variable put/get routines:
+!
+
+      integer         nf_put_vars_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          character(*)        text)
+      external        nf_put_vars_text
+
+      integer         nf_get_vars_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          character(*)        text)
+      external        nf_get_vars_text
+
+      integer         nf_put_vars_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_put_vars_int1
+
+      integer         nf_get_vars_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_get_vars_int1
+
+      integer         nf_put_vars_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_put_vars_int2
+
+      integer         nf_get_vars_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_get_vars_int2
+
+      integer         nf_put_vars_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             ivals(1))
+      external        nf_put_vars_int
+
+      integer         nf_get_vars_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             ivals(1))
+      external        nf_get_vars_int
+
+      integer         nf_put_vars_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          real                rvals(1))
+      external        nf_put_vars_real
+
+      integer         nf_get_vars_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          real                rvals(1))
+      external        nf_get_vars_real
+
+      integer         nf_put_vars_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          doubleprecision     dvals(1))
+      external        nf_put_vars_double
+
+      integer         nf_get_vars_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          doubleprecision     dvals(1))
+      external        nf_get_vars_double
+
+!
+! mapped variable put/get routines:
+!
+
+      integer         nf_put_varm_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          character(*)        text)
+      external        nf_put_varm_text
+
+      integer         nf_get_varm_text
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          character(*)        text)
+      external        nf_get_varm_text
+
+      integer         nf_put_varm_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_put_varm_int1
+
+      integer         nf_get_varm_int1
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          nf_int1_t           i1vals(1))
+      external        nf_get_varm_int1
+
+      integer         nf_put_varm_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_put_varm_int2
+
+      integer         nf_get_varm_int2
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          nf_int2_t           i2vals(1))
+      external        nf_get_varm_int2
+
+      integer         nf_put_varm_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          integer             ivals(1))
+      external        nf_put_varm_int
+
+      integer         nf_get_varm_int
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          integer             ivals(1))
+      external        nf_get_varm_int
+
+      integer         nf_put_varm_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          real                rvals(1))
+      external        nf_put_varm_real
+
+      integer         nf_get_varm_real
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          real                rvals(1))
+      external        nf_get_varm_real
+
+      integer         nf_put_varm_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          doubleprecision     dvals(1))
+      external        nf_put_varm_double
+
+      integer         nf_get_varm_double
+!                         (integer             ncid,
+!                          integer             varid,
+!                          integer             start(1),
+!                          integer             count(1),
+!                          integer             stride(1),
+!                          integer             imap(1),
+!                          doubleprecision     dvals(1))
+      external        nf_get_varm_double
+
+!ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
+! begin netcdf 2.4 backward compatibility:
+!
+
+!      
+! functions in the fortran interface
+!
+      integer nccre
+      integer ncopn
+      integer ncddef
+      integer ncdid
+      integer ncvdef
+      integer ncvid
+      integer nctlen
+      integer ncsfil
+
+      external nccre
+      external ncopn
+      external ncddef
+      external ncdid
+      external ncvdef
+      external ncvid
+      external nctlen
+      external ncsfil
+
+
+      integer ncrdwr
+      integer nccreat
+      integer ncexcl
+      integer ncindef
+      integer ncnsync
+      integer nchsync
+      integer ncndirty
+      integer nchdirty
+      integer nclink
+      integer ncnowrit
+      integer ncwrite
+      integer ncclob
+      integer ncnoclob
+      integer ncglobal
+      integer ncfill
+      integer ncnofill
+      integer maxncop
+      integer maxncdim
+      integer maxncatt
+      integer maxncvar
+      integer maxncnam
+      integer maxvdims
+      integer ncnoerr
+      integer ncebadid
+      integer ncenfile
+      integer nceexist
+      integer nceinval
+      integer nceperm
+      integer ncenotin
+      integer nceindef
+      integer ncecoord
+      integer ncemaxds
+      integer ncename
+      integer ncenoatt
+      integer ncemaxat
+      integer ncebadty
+      integer ncebadd
+      integer ncests
+      integer nceunlim
+      integer ncemaxvs
+      integer ncenotvr
+      integer nceglob
+      integer ncenotnc
+      integer ncfoobar
+      integer ncsyserr
+      integer ncfatal
+      integer ncverbos
+      integer ncentool
+
+
+!
+! netcdf data types:
+!
+      integer ncbyte
+      integer ncchar
+      integer ncshort
+      integer nclong
+      integer ncfloat
+      integer ncdouble
+
+      parameter(ncbyte = 1)
+      parameter(ncchar = 2)
+      parameter(ncshort = 3)
+      parameter(nclong = 4)
+      parameter(ncfloat = 5)
+      parameter(ncdouble = 6)
+
+!     
+!     masks for the struct nc flag field; passed in as 'mode' arg to
+!     nccreate and ncopen.
+!     
+
+!     read/write, 0 => readonly 
+      parameter(ncrdwr = 1)
+!     in create phase, cleared by ncendef 
+      parameter(nccreat = 2)
+!     on create destroy existing file 
+      parameter(ncexcl = 4)
+!     in define mode, cleared by ncendef 
+      parameter(ncindef = 8)
+!     synchronise numrecs on change (x'10')
+      parameter(ncnsync = 16)
+!     synchronise whole header on change (x'20')
+      parameter(nchsync = 32)
+!     numrecs has changed (x'40')
+      parameter(ncndirty = 64)  
+!     header info has changed (x'80')
+      parameter(nchdirty = 128)
+!     prefill vars on endef and increase of record, the default behavior
+      parameter(ncfill = 0)
+!     do not fill vars on endef and increase of record (x'100')
+      parameter(ncnofill = 256)
+!     isa link (x'8000')
+      parameter(nclink = 32768)
+
+!     
+!     'mode' arguments for nccreate and ncopen
+!     
+      parameter(ncnowrit = 0)
+      parameter(ncwrite = ncrdwr)
+      parameter(ncclob = nf_clobber)
+      parameter(ncnoclob = nf_noclobber)
+
+!     
+!     'size' argument to ncdimdef for an unlimited dimension
+!     
+      integer ncunlim
+      parameter(ncunlim = 0)
+
+!     
+!     attribute id to put/get a global attribute
+!     
+      parameter(ncglobal  = 0)
+
+!     
+!     advisory maximums:
+!     
+      parameter(maxncop = 64)
+      parameter(maxncdim = 1024)
+      parameter(maxncatt = 8192)
+      parameter(maxncvar = 8192)
+!     not enforced 
+      parameter(maxncnam = 256)
+      parameter(maxvdims = maxncdim)
+
+!     
+!     global netcdf error status variable
+!     initialized in error.c
+!     
+
+!     no error 
+      parameter(ncnoerr = nf_noerr)
+!     not a netcdf id 
+      parameter(ncebadid = nf_ebadid)
+!     too many netcdfs open 
+      parameter(ncenfile = -31)   ! nc_syserr
+!     netcdf file exists && ncnoclob
+      parameter(nceexist = nf_eexist)
+!     invalid argument 
+      parameter(nceinval = nf_einval)
+!     write to read only 
+      parameter(nceperm = nf_eperm)
+!     operation not allowed in data mode 
+      parameter(ncenotin = nf_enotindefine )   
+!     operation not allowed in define mode 
+      parameter(nceindef = nf_eindefine)   
+!     coordinates out of domain 
+      parameter(ncecoord = nf_einvalcoords)
+!     maxncdims exceeded 
+      parameter(ncemaxds = nf_emaxdims)
+!     string match to name in use 
+      parameter(ncename = nf_enameinuse)   
+!     attribute not found 
+      parameter(ncenoatt = nf_enotatt)
+!     maxncattrs exceeded 
+      parameter(ncemaxat = nf_emaxatts)
+!     not a netcdf data type 
+      parameter(ncebadty = nf_ebadtype)
+!     invalid dimension id 
+      parameter(ncebadd = nf_ebaddim)
+!     ncunlimited in the wrong index 
+      parameter(nceunlim = nf_eunlimpos)
+!     maxncvars exceeded 
+      parameter(ncemaxvs = nf_emaxvars)
+!     variable not found 
+      parameter(ncenotvr = nf_enotvar)
+!     action prohibited on ncglobal varid 
+      parameter(nceglob = nf_eglobal)
+!     not a netcdf file 
+      parameter(ncenotnc = nf_enotnc)
+      parameter(ncests = nf_ests)
+      parameter (ncentool = nf_emaxname) 
+      parameter(ncfoobar = 32)
+      parameter(ncsyserr = -31)
+
+!     
+!     global options variable. used to determine behavior of error handler.
+!     initialized in lerror.c
+!     
+      parameter(ncfatal = 1)
+      parameter(ncverbos = 2)
+
+!
+!     default fill values.  these must be the same as in the c interface.
+!
+      integer filbyte
+      integer filchar
+      integer filshort
+      integer fillong
+      real filfloat
+      doubleprecision fildoub
+
+      parameter (filbyte = -127)
+      parameter (filchar = 0)
+      parameter (filshort = -32767)
+      parameter (fillong = -2147483647)
+      parameter (filfloat = 9.9692099683868690e+36)
+      parameter (fildoub = 9.9692099683868690e+36)
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/para.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/para.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/para.com	(revision 6)
@@ -0,0 +1,20 @@
+!-------------------------------------------------------------------------------
+!
+! para.com - basic model parameters
+!
+ 
+! size of the domain (from CLIO model, obsolete)
+      PARAMETER ( imax = 1 , jmax = 1 , kmax = 130 )
+      PARAMETER ( nbpt=imax*jmax )
+ 
+
+      PARAMETER ( maxnlay  = 35 )        ! maximum number of vertical levels
+      PARAMETER ( nlay_bio = 10 )        ! number of levels in the bio-grid
+      PARAMETER ( ntra_bio_max = 28  )   ! maximum number of tracers
+      PARAMETER ( n_forc = 11 )          ! number of forcing fields
+      PARAMETER ( numout   = 84 )        ! reference number of the output file
+
+      PARAMETER ( jpl = 1 )              ! number of ice categories (should be removed)
+ 
+!-- end of the file
+!-------------------------------------------------------------------------------
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/pdecli.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/pdecli.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/pdecli.f	(revision 6)
@@ -0,0 +1,46 @@
+c
+c     ********************
+      function pdecli(i,j)
+c     ********************
+c
+c		THIS FUNCTION COMPUTES THE SOLAR DECLINATION FOR THE DAY
+c		j (IN DECIMAL DEGREES).
+c		j = DAY OF THE YEAR (j=1 ON JANUARY 1)
+c		i = -1, 0, 1 FOR ODD, NORMAL AND LEAP YEARS,
+c		    RESPECTIVELY
+c
+c---
+c Ccpl [Ccp0] => ligne specifique a la version avec [sans] couplage .
+c---
+      include 'type.com'
+      include 'const.com'
+      xj     = j
+      a0     = 0.39507671
+      a1     = 22.85684301
+      a2     = -0.38637317
+      a3     = 0.15096535
+      a4     = -0.00961411
+      b1     = -4.29692073
+      b2     = 0.05702074
+      b3     = -0.09028607
+      b4     = 0.00592797
+      pi     = 3.1415927
+      if (i) 1,2,3
+ 1    xj     = xj-0.5
+      goto 4
+ 3    xj     = xj-1.
+      goto 4
+ 2    xj     = j
+ 4    p      = pi*(2.0*xj-367.0)
+      p      = p/yeaday
+      p2     = p*2.0
+      p3     = p*3.0
+      p4     = p*4.0
+      dcl1   = a1*cos(p)+a2*cos(p2)+a3*cos(p3)+a4*cos(p4)
+      dcl2   = b1*sin(p)+b2*sin(p2)+b3*sin(p3)+b4*sin(p4)
+      pdecli = a0+dcl1+dcl2
+c
+      return
+c---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
+c- Fin de la routine pdecli -
+      end
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/shine.f
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/shine.f	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/shine.f	(revision 6)
@@ -0,0 +1,109 @@
+      SUBROUTINE shine(tfsn, tfsg, ts, tsn, hgbq, hnbq, alb_c, alb_o)
+!-----------------------------------------------------------------------------!
+!
+!  Computes albedo of snow-sea ice following SHINE &
+!  HENDERSSON-SELLERS [1985].
+!  Simplified by Martouf for use in LIM1D
+!  fucking scientists!!!
+!
+      INCLUDE 'type.com'
+ 
+!  OUTPUTS :
+!  alb_c : Albedo for clear sky.
+!  alb_o :  Albedo for overcast sky.
+!
+!-----------------------------------------------------------------------------!
+!  1) Computation of surface albedo.                                          !
+!-----------------------------------------------------------------------------!
+!
+      WRITE(84,*) ' '
+      WRITE(84,*) ' shine '
+      WRITE(84,*) ' ~~~~~~'
+
+      cgren  = 0.06 ! corr factor under cloudy skies (Grenfell Perovich 84)
+      alphd  = 0.80 ! fixed boundary values of albedo
+      alphdi = 0.72
+      alphs  = 0.65
+      albice = 0.53 ! albedo of melting ice
+!
+      if (hnbq.gt.0.0) then                                       
+      !------------------
+      ! Snow covered-ice
+      !------------------
+        if ( (ts.lt.tfsn) .AND. (tsn.lt.tfsn) ) THEN                    
+
+      ! Cold snow.
+      !------------
+          if (hnbq.gt.0.05) then                                 
+            alb_c = alphd                                        
+          else                                                      
+            if (hgbq.gt.1.5) then                                
+              alb_c = alphdi+(hnbq*(alphd-alphdi)/0.05)          
+            else if (hgbq.gt.1.0.and.hgbq.le.1.5) then         
+                   al = 0.472+2.0*(alphdi-0.472)*(hgbq-1.0)
+            else if (hgbq.gt.0.05.and.hgbq.le.1.0) then        
+                   al = 0.2467+(0.7049*hgbq)-(0.8608*(hgbq*hgbq))+
+     &                 (0.3812*(hgbq*hgbq*hgbq))                     
+            else                                                    
+     &        al = 0.1+3.6*hgbq                                  
+            endif                                                   
+            if (hgbq.le.1.5) alb_c=al+(hnbq*(alphd-al)/0.05)
+          endif                                                     
+        else                                                        
+      ! Melting snow.
+      !--------------
+          if (hnbq.ge.0.1) then                                  
+            alb_c = 0.65                                           
+            alb_c = alphs                                      
+          else                                                      
+            alb_c = albice+((alphs-albice)/0.1)*hnbq
+          endif                                                     
+        endif                                                       
+      else                                                          
+      !----------
+      ! Bare ice
+      !----------
+        if (ts.lt.tfsg) then                                      
+
+      ! Cold ice
+      !-----------
+          if (hgbq.gt.1.5) then                                  
+            alb_c = alphdi                                          
+          else if (hgbq.gt.1..and.hgbq.le.1.5) then           
+            alb_c = 0.472+2.*(alphdi-0.472)*(hgbq-1.)       
+          else if (hgbq.gt.0.05.and.hgbq.le.1.) then          
+                 alb_c = 0.2467+                                        
+     &                   (0.7049*hgbq)-(0.8608*(hgbq*hgbq))+
+     &                   (0.3812*(hgbq*hgbq*hgbq))                  
+          else                                                      
+            alb_c = 0.1+3.6*hgbq                                
+          endif                                                     
+        else                                                        
+      ! Melting ice.
+      !--------------
+          if (hgbq.gt.1.5) then                                  
+            alb_c = albice                                           
+          else if (hgbq.gt.1..and.hgbq.le.1.5)  then          
+                 alb_c = 0.472+(2.*(albice-0.472)*(hgbq-1.))     
+          else if (hgbq.gt.0.05.and.hgbq.le.1.) then          
+                 alb_c = 0.2467+0.7049*hgbq                          
+     &                  -(0.8608*(hgbq*hgbq))
+     &                  +(0.3812*(hgbq*hgbq*hgbq)) 
+          else                                                      
+            alb_c = 0.1+3.6*hgbq
+          endif                                                     
+        endif                                                       
+      endif                                                         
+     
+      !--------------------------
+      ! Correction due to clouds
+      !--------------------------
+      alb_o= alb_c + cgren                                           
+
+      WRITE(84,*) ' alb_o: ', alb_o
+      WRITE(84,*) ' alb_c: ', alb_c
+
+!------------------------------------------------------------------------------!
+!- Fin de la routine shine -
+      RETURN
+      END                                                               
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/thermo.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/thermo.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/thermo.com	(revision 6)
@@ -0,0 +1,120 @@
+!		
+!---5----|----5----|----5----|----5----|----5----|----5----|----5----|72--5----|
+!  Thermo.com is incorparated by an instruction include in ice_th.f , 
+!      fontbc.f and acrlbq.f. It comprises the commons associated to
+!      thermodynamic ice computation
+! CLEANING REQUIRED
+!
+! Correspondance between the variables
+! qlbqb   qlbq
+! qcmbqb  qcmbq
+! thcmb   thcm
+! fstbqb  fstrbq
+! fltbqb  ffltbq
+! fscbqb  fscmbq
+! fsolgb  fsolg
+! ratbqb  ratbqg
+! psbqb   psbq
+! tabqb   tabq
+! qabqb   qabq
+! vabqb   vabq
+! qfvbqb  qfvbq
+! tsb     ts
+! tfub    tfu
+! hnpbqb  zhnpbq
+! hnbqb   hnbq
+! hgbqb   hgbq
+! albqb   albq
+! qstbqb  qstobq
+! fbbqb   fbbq
+! tbqb    tbq
+! dmgbqb  dmgbq
+! dmnbqb  dmnbq
+! qlbbqb  qlbsbq
+! cldqb   cloud
+! dmgwib  dmgwi
+! npb     number of points where computations has to be done
+! npac    correspondance between the points
+! fratsb  firg
+! fcsb    fcsg
+! fleb    fleg
+! albgb   albg   06/08/2001
+! sal     salic  08/03/2002
+
+      COMMON/combq/qlbqb(nbpt),qcmbqb(nbpt),thcmb(nbpt),fstbqb(nbpt),
+     &             fltbqb(nbpt),fscbqb(nbpt),fsolgb(nbpt),fsolgb2(nbpt),
+     &             ratbqb(nbpt),psbqb(nbpt),tabqb(nbpt),
+     &             qabqb(nbpt),vabqb(nbpt),qfvbqb(nbpt),tsb(nbpt),
+     &             tfub(nbpt),hnpbqb(nbpt),hnbqb(nbpt),hgbqb(nbpt),
+     &             albqb(nbpt),qstbqb(nbpt),fbbqb(nbpt),
+     &             dmgbqb(nbpt),dmnbqb(nbpt),qlbbqb(nbpt),cldqb(nbpt),
+     &             dmgwib(nbpt),npb(nbpt),npac(nbpt),tfs(nbpt),
+     &             albgb(nbpt),focea(nbpt),fsup(nbpt), qsfcb(nbpt), 
+     &             tdewb(nbpt)
+
+! heat diffusion equation
+      common/diff/ht_s_b(nbpt),ht_i_b(nbpt),ht_w_b(nbpt),t_su_b(nbpt),
+     &            t_bo_b(nbpt),t_i_b(nbpt,maxnlay),t_s_b(nbpt,maxnlay),
+     &            s_i_b(nbpt,maxnlay),h_i(maxnlay),h_s(maxnlay),
+     &            sn_i_b(maxnlay),
+     &            ab(nbpt),s_i_mean, q_i_b(nbpt,0:maxnlay+2), 
+     &            q_sal_i(nbpt,0:maxnlay+2),
+     &            q_s_b(nbpt,0:maxnlay+2),
+     &            old_ht_i_b(nbpt), e_i_b(maxnlay)
+
+      common/snow/f_s_im(nbpt)
+
+! vertical grid
+      common/vgrid/z_i(0:maxnlay),z_s(0:maxnlay),
+     &             dh_s_subl(nbpt), dh_s_prec(nbpt), dh_s_font(nbpt),
+     &             dh_s_snic(nbpt),
+     &             dh_i_subl(nbpt), dh_i_font(nbpt), dh_i_bott(nbpt),
+     &             dh_i_snic(nbpt),dh_snowice(nbpt),
+     &             dh_s_melt(nbpt),dh_i_melt(nbpt),
+     &             dh_i_surf(nbpt),dh_s_tot(nbpt)
+!
+      common/comdbq/fratsb(nbpt),fcsb(nbpt),
+     &              fleb(nbpt),dvsbqb(nbpt),dvbbqb(nbpt),dvlbqb(nbpt),
+     &              dvnbqb(nbpt), fc_su(nbpt), fc_bo_i(nbpt), 
+     &              fatm(nbpt,jpl), fc_i(nbpt,0:maxnlay),
+     &              fc_s(nbpt,0:maxnlay)
+
+! for computation of temperatures after accr/abl 
+      common/ comtem /enthal(0:maxnlay),
+     &		      aaa,bbb,ccc,discrim,
+     &                enthalsi
+      common/ brintrsp /q_br(maxnlay), dq_i_brf(maxnlay)
+      common/ bitzlip /ftrice,tmelts,ftroce
+      common/ vgrid /himax,hsmax
+      common/ conserv /e_i_o,e_s_o,de_i,de_s,isnow,imelt,
+     &                 z_e_i(maxnlay),z_f_i(0:maxnlay),
+     &                 e_t_o,ti_old(maxnlay),si_old(maxnlay),
+     &                 s_i_mmean(maxnlay),h_i_mmean,
+     &                 dq_i(nbpt,jpl), sum_fluxq(nbpt,jpl),
+     &                 cons_error(nbpt,jpl), surf_error(nbpt,jpl),
+     &                 dq_i_layer(nbpt, maxnlay),
+     &                 qt_i_in(nbpt,jpl), qt_s_in(nbpt,jpl),
+     &                 q_i_layer_in(nbpt,maxnlay),
+     &                 qt_i_fin(nbpt,jpl), qt_s_fin(nbpt,jpl),
+     &                 q_i_layer_fin(nbpt,maxnlay), fprec, fsnic
+
+      common/ salt / beta_sal, s_i_new, s_i_snic, e_skel, q_summer,
+     &               diff_br(maxnlay), rayleigh(maxnlay), fsb, fsbp,
+     &               w_flood, w_flush
+
+      ! units is a flux, including radab
+      common/radiation/radab_phy_i(maxnlay),radab_s(maxnlay),
+     &                 radab_phy_s(maxnlay),radtr_i(0:maxnlay),
+     &                 radab_alg_i(maxnlay),radtr_s(0:maxnlay),
+     &                 radab_i(maxnlay)
+
+      ! par, energy available at the top of each layer
+      common/biology/chla_i(maxnlay), par(maxnlay)
+
+      ! Remapping
+      INTEGER snswi,icsuswi,icboswi,snicswi
+      INTEGER snind,icsuind,icboind,snicind,limsum
+
+
+!-- End of file 'thermo.com'
+!-----------------------------------------------------------------------------!
Index: /tags/LIM1D_v3.20/SOURCES/source_3.20/type.com
===================================================================
--- /tags/LIM1D_v3.20/SOURCES/source_3.20/type.com	(revision 6)
+++ /tags/LIM1D_v3.20/SOURCES/source_3.20/type.com	(revision 6)
@@ -0,0 +1,9 @@
+!
+!		type.F : TYPE DEFINITIONS
+!		==========================
+!
+!
+! implicit declarations should be removed soon
+ 
+      IMPLICIT DOUBLE PRECISION (a-h,o-z)
+ 
