Index: TOOLS/WATER_BUDGET/ATM_waterbudget.py
===================================================================
--- TOOLS/WATER_BUDGET/ATM_waterbudget.py	(revision 6271)
+++ TOOLS/WATER_BUDGET/ATM_waterbudget.py	(revision 6277)
@@ -21,5 +21,5 @@
 ###
 ## Import system modules
-import sys, os, shutil, subprocess
+import sys, os, shutil, subprocess, platform
 import numpy as np
 import configparser, re
@@ -29,33 +29,24 @@
 config.optionxform = str # To keep capitals
 
-config['Files']  = {}
-config['System'] = {}
-
-##-- Some physical constants
-#-- Earth Radius
-Ra = 6366197.7236758135
-#-- Gravity
-Grav = 9.81
-#-- Ice volumic mass (kg/m3) in LIM3
-ICE_rho_ice = 917.0
-#-- Snow volumic mass (kg/m3) in LIM3
-ICE_rho_sno = 330.0
-#-- Ocean water volumic mass (kg/m3) in NEMO
-OCE_rho_liq = 1026.
-#-- Water volumic mass in atmosphere
-ATM_rho = 1.0e3
-#-- Water volumic mass in surface reservoirs
-SRF_rho = 1.0e3
-#-- Water volumic mass of rivers
-RUN_rho = 1.0e3
-
 ## Read experiment parameters
-ATM = None ; ORCA = None ; NEMO = None ; OCE_relax = False ; OCE_icb = False ; Coupled = False ; Routing = None
+ATM=None ; ORCA=None ; NEMO=None ; OCE_relax=False ; OCE_icb=False ; Coupled=False ; Routing=None ;  TarRestartPeriod_beg=None ; TarRestartPeriod_end=None ; Comment=None ; Period=None ; Title=None
+
+##
+ARCHIVE =None ; STORAGE = None ; SCRATCHDIR=None ; R_IN=None ; rebuild=None
+TmpDir=None ; FileOut=None ; dir_ATM_his=None ; dir_SRF_his=None ; dir_OCE_his=None ; dir_ICE_his=None ; FileCommon=None
+file_ATM_his=None ; file_SRF_his=None ; file_RUN_his=None ; file_OCE_his=None ;  file_ICE_his=None ; file_OCE_sca=None
+file_restart_beg=None ; file_restart_end=None ; file_ATM_beg=None ; file_ATM_end=None ; file_DYN_beg=None ; file_DYN_end=None ; file_SRF_beg=None ; file_SRF_end=None
+file_RUN_beg=None ; file_RUN_end=None ; file_RUN_end=None ; file_OCE_beg=None ; file_ICE_beg=None ; file_OCE_beg=None ; file_OCE_end=None
+
+d_ATM_his=None ; d_SRF_his=None ; d_RUN_his=None ; d_OCE_his=None ;  d_ICE_his=None ; d_OCE_sca=None
+d_restart_beg=None ; d_restart_end=None ; d_ATM_beg=None ; d_ATM_end=None ; d_DYN_beg=None ; d_DYN_end=None ; d_SRF_beg=None ; d_SRF_end=None
+d_RUN_beg=None ; d_RUN_end=None ; d_RUN_end=None ; d_OCE_beg=None ; d_ICE_beg=None ; d_OCE_beg=None ; d_OCE_end=None
 
 # Arguments passed
 print ( "Name of Python script:", sys.argv[0] )
-IniFile =  sys.argv[1]
+IniFile = sys.argv[1]
 print ("Input file : ", IniFile )
 config.read (IniFile)
+FullIniFile = 'full_' + IniFile
 
 def setBool (chars) :
@@ -79,25 +70,59 @@
     return setNum
 
-print ('[Experiment]')
-for VarName in config['Experiment'].keys() :
-    locals()[VarName] = config['Experiment'][VarName]
-    locals()[VarName] = setBool (locals()[VarName])
-    locals()[VarName] = setNum  (locals()[VarName])
-    print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) )
-
-# ###
+def setNone (chars) :
+    '''Convert specific char string to None if possible'''
+    if type (chars) == str :
+        if chars in ['None', 'NONE', 'none'] : setNone = None
+        else : setNone = chars
+    else : setNone = chars
+    return setNone
+
+## Reading config
+for Section in ['Experiment', 'libIGCM', 'Files', 'Physics' ] :
+    if Section in config.keys() : 
+        print ( f'[{Section}]' )
+        for VarName in config[Section].keys() :
+            locals()[VarName] = config[Section][VarName]
+            locals()[VarName] = setBool (locals()[VarName])
+            locals()[VarName] = setNum  (locals()[VarName])
+            print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) )
+
+if not 'Files' in config.keys() : config['Files'] = {}
+
+def unDefined (char) :
+    if char in globals () :
+        if char == None : return True
+        else : return False
+    else : return True
+
+##-- Some physical constants
+#-- Earth Radius
+if not 'Ra'            in locals () : Ra = 6366197.7236758135
+#-- Gravity
+if not 'Grav'          in locals () : Grav = 9.81
+#-- Ice volumic mass (kg/m3) in LIM3
+if not 'ICE_rho_ice'   in locals () : ICE_rho_ice = 917.0
+#-- Snow volumic mass (kg/m3) in LIM3
+if not 'ICE_rho_sno'   in locals () : ICE_rho_sno = 330.0
+#-- Ocean water volumic mass (kg/m3) in NEMO
+if not 'OCE_rho_liq'   in locals () : OCE_rho_liq = 1026.
+#-- Water volumic mass in atmosphere
+if not 'ATM_rho'       in locals () : ATM_rho = 1000.
+#-- Water volumic mass in surface reservoirs
+if not 'SRF_rho'       in locals () : SRF_rho = 1000.
+#-- Water volumic mass of rivers
+if not 'RUN_rho'       in locals () : RUN_rho = 1000.
+#-- Year length
+if not 'YearLength'    in locals () : YearLength = 365.25 * 24. * 60. * 60.
+
+config['Physics'] = { 'Ra':Ra, 'Grav':Grav, 'ICE_rho_ice':ICE_rho_ice, 'ICE_rho_sno':ICE_rho_sno, 'OCE_rho_liq':OCE_rho_liq, 'ATM_rho':ATM_rho, 'SRF_rho':SRF_rho, 'RUN_rho':RUN_rho}
+
+## --
 ICO  = ( 'ICO' in ATM )
 LMDZ = ( 'LMD' in ATM )
     
-###
-## Import system modules
-import sys, os, shutil, subprocess
-import configparser, re
-
-config = configparser.ConfigParser()
-config['Files'] = {}
 
 # Where do we run ?
-SysName, NodeName, Release, Version, Machine = os.uname()
+SysName, NodeName, Release, Version, Machine = os.uname ()
 TGCC  = ( 'irene'   in NodeName )
 IDRIS = ( 'jeanzay' in NodeName )
@@ -108,10 +133,11 @@
     if "Intel(R) Xeon(R) Platinum" in CPU : Machine = 'irene'
     if "AMD"                       in CPU : Machine = 'irene-amd'
-        
-    ARCHIVE     = subprocess.getoutput ( f'ccc_home --cccstore   -d {Project} -u {User}' )
-    STORAGE     = subprocess.getoutput ( f'ccc_home --cccwork    -d {Project} -u {User}' )
-    SCRATCHDIR  = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' )
-    R_IN        = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM')
-    rebuild     = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' )
+
+    if libIGCM : 
+        if ARCHIVE    == None : ARCHIVE     = subprocess.getoutput ( f'ccc_home --cccstore   -d {Project} -u {User}' )
+        if STORAGE    == None : STORAGE     = subprocess.getoutput ( f'ccc_home --cccwork    -d {Project} -u {User}' )
+        if SCRATCHDIR == None : SCRATCHDIR  = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' )
+        if R_IN       == None : R_IN        = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM')
+        if rebuild    == None : rebuild     = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' )
 
     ## Specific to run at TGCC.
@@ -121,9 +147,24 @@
         
     ## Creates output directory
-    #TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' )
-    TmpDir = os.path.join ( '/ccc/scratch/cont003/drf/p86mart', f'WATER_{JobName}_{YearBegin}_{YearEnd}' )
-
+    if TmpDir == None :
+        TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' )
+        config['Files']['TmpDir'] = TmpDir
+        
 if IDRIS :
     raise Exception ("Pour IDRIS : repertoires et chemins a definir") 
+
+config['System'] = {'SysName':SysName, 'NodeName':NodeName, 'Release':Release, 'Version':Version,'Machine':Machine, 'TGCC':TGCC,'IDRIS':IDRIS, 'CPU':CPU,
+                    'Program'  : "Generated by : " + str(sys.argv), 
+                    'HOSTNAME' : platform.node (), 'LOGNAME'  : os.getlogin (),
+                    'Python'   : f'{platform.python_version ()}',
+                    'OS'       : f'{platform.system ()} release : {platform.release ()} hardware : {platform.machine ()}',
+                    'SVN_Author'   : "$Author$", 
+                    'SVN_Date'     : "$Date$",
+                    'SVN_Revision' : "$Revision$",
+                    'SVN_Id'       : "$Id$",
+                    'SVN_HeadURL'  : "$HeadURL$"}
+
+if libIGCM :
+    config['libIGCM'] = {'ARCHIVE':ARCHIVE, 'STORAGE':STORAGE, 'SCRATCHDIR':SCRATCHDIR, 'R_IN':R_IN, 'rebuild':rebuild }
 
 ## Import specific module
@@ -132,15 +173,16 @@
 import xarray as xr
 
-config['Files'][TmpDir] = TmpDir
-
 # Output file
-FileOut = f'ATM_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out'
+if FileOut == None : 
+    FileOut = f'ATM_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out'
+    config['Files']['FileOut'] = FileOut
+
 f_out = open ( FileOut, mode = 'w' )
 
 # Function to print to stdout *and* output file
 def echo (string, end='\n') :
-    print ( string, end=end  )
+    print ( str(string), end=end  )
     sys.stdout.flush ()
-    f_out.write ( string + end )
+    f_out.write ( str(string) + end )
     f_out.flush ()
     return None
@@ -165,4 +207,7 @@
 if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE )
 
+echo (' ')
+echo ( f'JobName : {JobName}' )
+echo (Comment)
 echo ( f'Working in TMPDIR : {TmpDir}' )
 
@@ -172,7 +217,11 @@
 if Freq == "MO" : FreqDir = os.path.join ('Output' , 'MO' )
 if Freq == "SE" : FreqDir = os.path.join ('Analyse', 'SE' )
-dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir )
-dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir )
-
+if dir_ATM_his == None :
+    dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir )
+    config['Files']['dir_ATM_his'] = dir_ATM_his
+if dir_SRF_his == None : 
+    dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir )
+    config['Files']['dir_SRF_his'] = dir_SRF_his
+    
 echo ( f'The analysis relies on files from the following model output directories : ' )
 echo ( f'{dir_ATM_his}' )
@@ -180,18 +229,33 @@
 
 #-- Files Names
-if Freq == 'MO' : FileCommon = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M'
-if Freq == 'SE' : FileCommon = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M'
-
+if Period == None :
+    if Freq == 'MO' : Period = f'{YearBegin}0101_{YearEnd}1231_1M'
+    if Freq == 'SE' : Period = f'SE_{YearBegin}0101_{YearEnd}1231_1M'
+    config['Files']['Period'] = Period
+if FileCommon == None :
+    FileCommon = f'{JobName}_{Period}'
+    config['Files']['FileCommon'] = FileCommon
+
+if Title == None :
+    Title = f'{JobName} : {Freq} : {YearBegin}-01-01 - {YearEnd}-12-31'
+    config['Files']['Title'] = Title
+     
 echo ('\nOpen history files' )
-file_ATM_his = os.path.join (  dir_ATM_his, f'{FileCommon}_histmth.nc' )
-file_SRF_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
-if Routing == 'ORCHIDEE'  :
-    file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
+if file_ATM_his == None : 
+    file_ATM_his = os.path.join (  dir_ATM_his, f'{FileCommon}_histmth.nc' )
+    config['Files']['file_ATM_his'] = file_ATM_his
+if file_SRF_his == None :
+    file_SRF_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
+    config['Files']['file_SRF_his'] = file_SRF_his
+#if Routing == 'SECHIBA'  :
+#     file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
 if Routing == 'SIMPLE' :
-    file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
+    if file_RUN_his == None : 
+        file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
+        config['Files']['file_RUN_his'] = file_RUN_his
 
 d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
 d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
-if Routing == 'ORCHIDEE' :
+if Routing == 'SECHIBA' :
     d_RUN_his = d_SRF_his
 if Routing == 'SIMPLE' : 
@@ -200,10 +264,6 @@
 echo ( file_ATM_his )
 echo ( file_SRF_his )
-echo ( file_RUN_his )
-
-
-config['Files']['file_ATM_his'] = file_ATM_his
-config['Files']['file_SRF_his'] = file_SRF_his
-config['Files']['file_RUN_his'] = file_SRF_his
+if Routing == 'SIMPLE' : 
+    echo ( file_RUN_his )
 
 ## Compute run length
@@ -218,36 +278,85 @@
 dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] )
 
+## Number of years
+NbYear = dtime_sec / YearLength
+
 #-- Open restart files
+
 YearRes = YearBegin - 1              # Year of the restart of beginning of simulation
 YearPre = YearBegin - PackFrequency  # Year to find the tarfile of the restart of beginning of simulation
 
-echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
-
-file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' )
-file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' )
-
+if TarRestartPeriod_beg == None : 
+    echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
+    TarRestartPeriod_beg = f'{YearPre}0101_{YearRes}1231'
+    config['Files']['TarRestartPeriod_beg'] = TarRestartPeriod_beg
+
+if TarRestartPeriod_end == None : 
+    YearPre = YearBegin - PackFrequency  # Year to find the tarfile of the restart of beginning of simulation
+    echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
+    TarRestartPeriod_end = f'{YearBegin}0101_{YearEnd}1231'
+    config['Files']['TarRestartPeriod_end'] = TarRestartPeriod_end
+
+if file_restart_beg == None :
+    file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{TarRestartPeriod_beg}_restart.tar' )
+    config['Files']['file_restart_beg'] = file_restart_beg
+if file_restart_end == None :
+    file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{TarRestartPeriod_end}_restart.tar' )
+    config['Files']['file_restart_end'] = file_restart_end
+    
 echo ( f'{file_restart_beg}' )
 echo ( f'{file_restart_end}' )
 
-file_ATM_beg = f'ATM_{JobName}_{YearRes}1231_restartphy.nc'
-file_ATM_end = f'ATM_{JobName}_{YearEnd}1231_restartphy.nc'
-if LMDZ :
-    file_DYN_beg = f'ATM_{JobName}_{YearRes}1231_restart.nc'
-    file_DYN_end = f'ATM_{JobName}_{YearEnd}1231_restart.nc'
-if ICO :
-    file_DYN_beg = f'ICO_{JobName}_{YearRes}1231_restart.nc'
-    file_DYN_end = f'ICO_{JobName}_{YearEnd}1231_restart.nc'
-file_SRF_beg = f'SRF_{JobName}_{YearRes}1231_sechiba_rest.nc'
-file_SRF_end = f'SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc'
-liste_beg = [file_ATM_beg, file_DYN_beg, file_SRF_beg, ]
-liste_end = [file_ATM_end, file_DYN_end, file_SRF_end, ]
+if file_ATM_beg == None : 
+    file_ATM_beg = f'{TmpDir}/ATM_{JobName}_{YearRes}1231_restartphy.nc'
+    config['Files']['file_ATM_beg'] = file_ATM_beg
+if file_ATM_end == None :
+    file_ATM_end = f'{TmpDir}/ATM_{JobName}_{YearEnd}1231_restartphy.nc'
+    config['Files']['file_ATM_end'] = file_ATM_end
+
+liste_beg = [file_ATM_beg, ]
+liste_end = [file_ATM_end, ]
+    
+
+if file_DYN_beg == None :
+    if LMDZ :
+        file_DYN_beg = f'{TmpDir}/ATM_{JobName}_{YearRes}1231_restart.nc'
+    if ICO  :
+        file_DYN_beg = f'{TmpDir}/ICO_{JobName}_{YearRes}1231_restart.nc'
+    liste_beg.append (file_DYN_beg)
+    config['Files']['file_DYN_beg'] = file_DYN_beg
+    
+if file_DYN_end == None : 
+    if LMDZ :
+        file_DYN_end = f'{TmpDir}/ATM_{JobName}_{YearEnd}1231_restart.nc'
+    if ICO  :
+        file_DYN_end = f'{TmpDir}/ICO_{JobName}_{YearEnd}1231_restart.nc'
+    liste_end.append ( file_DYN_end )
+    config['Files']['file_DYN_end'] = file_DYN_end
+
+if file_SRF_beg == None : 
+    file_SRF_beg = f'{TmpDir}/SRF_{JobName}_{YearRes}1231_sechiba_rest.nc'
+    config['Files']['file_SRF_beg'] = file_SRF_beg
+if file_SRF_end == None : 
+    file_SRF_end = f'{TmpDir}/SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc'
+    config['Files']['file_SRF_end'] = file_SRF_end
+    
+liste_beg.append ( file_SRF_beg )
+liste_end.append ( file_SRF_end )
+
 echo ( f'{file_ATM_beg}')
 echo ( f'{file_ATM_end}')
+echo ( f'{file_DYN_beg}')
+echo ( f'{file_DYN_end}')
 echo ( f'{file_SRF_beg}')
 echo ( f'{file_SRF_end}')
 
-if Routing == 'SIMPLE' : 
-    file_RUN_beg = f'SRF_{JobName}_{YearRes}1231_routing_restart.nc'
-    file_RUN_end = f'SRF_{JobName}_{YearEnd}1231_routing_restart.nc'
+if Routing == 'SIMPLE' :
+    if file_RUN_beg == None : 
+        file_RUN_beg = f'{TmpDir}/SRF_{JobName}_{YearRes}1231_routing_restart.nc'
+        config['Files']['file_RUN_beg'] = file_RUN_beg
+    if file_RUN_end == None : 
+        file_RUN_end = f'{TmpDir}/SRF_{JobName}_{YearEnd}1231_routing_restart.nc'
+        config['Files']['file_RUN_end'] = file_RUN_end
+        
     liste_beg.append ( file_RUN_beg )
     liste_end.append ( file_RUN_end )
@@ -257,25 +366,21 @@
 echo ('\nExtract restart files from tar : ATM, ICO and SRF')
 for resFile in liste_beg :
-    if not os.path.exists ( os.path.join (TmpDir, resFile) ) :
-        command =  f'cd {TmpDir} ; tar xf {file_restart_beg} {resFile}'
+    if os.path.exists ( os.path.join (TmpDir, resFile) ) :
+        echo ( f'file found : {resFile}' )
+    else :
+        base_resFile = os.path.basename (resFile)
+        command =  f'cd {TmpDir} ; tar xf {file_restart_beg} {base_resFile}'
         echo ( command )
         os.system ( command )
         
 for resFile in liste_end :
-    if not os.path.exists ( os.path.join (TmpDir, resFile) ) :
-        command =  f'cd {TmpDir} ; tar xf {file_restart_end} {resFile}'
+    if os.path.exists ( os.path.join (TmpDir, resFile) ) :
+        echo ( f'file found : {resFile}' )
+    else :
+        base_resFile = os.path.basename (resFile)
+        command =  f'cd {TmpDir} ; tar xf {file_restart_end} {base_resFile}'
         echo ( command )
         os.system ( command )
-
-config['Files']['file_ATM_beg'] = file_ATM_beg
-config['Files']['file_ATM_end'] = file_ATM_end
-config['Files']['file_SRF_beg'] = file_SRF_beg
-config['Files']['file_SRF_end'] = file_SRF_end
-if Routing == 'SIMPLE' : 
-    config['Files']['file_RUN_beg'] = file_RUN_beg
-    config['Files']['file_RUN_end'] = file_RUN_end
-config['Files']['file_DYN_beg'] = file_DYN_beg
-config['Files']['file_DYN_end'] = file_DYN_end
-        
+       
 echo ('\nOpening ATM SRF and ICO restart files')
 d_ATM_beg = xr.open_dataset ( os.path.join (TmpDir, file_ATM_beg), decode_times=False, decode_cf=True).squeeze()
@@ -287,8 +392,8 @@
 
 for var in d_SRF_beg.variables :
-    d_SRF_beg[var] = d_SRF_beg[var].where (  d_SRF_beg[var]<1.e20, 0.)
-    d_SRF_end[var] = d_SRF_end[var].where (  d_SRF_end[var]<1.e20, 0.)
-
-if ICO :
+    d_SRF_beg[var] = d_SRF_beg[var].where ( d_SRF_beg[var]<1.e20, 0.)
+    d_SRF_end[var] = d_SRF_end[var].where ( d_SRF_end[var]<1.e20, 0.)
+
+if Routing == 'SIMPLE' :
     d_RUN_beg = xr.open_dataset ( os.path.join (TmpDir, file_RUN_beg), decode_times=False, decode_cf=True).squeeze()
     d_RUN_end = xr.open_dataset ( os.path.join (TmpDir, file_RUN_end), decode_times=False, decode_cf=True).squeeze()
@@ -304,23 +409,79 @@
     echo ( file_RUN_end )
 
+##
+config_out = open (FullIniFile, 'w')
+config.write (config_out )
+config_out.close ()
+
+def Ksum (tab) :
+    '''
+    Kahan summation algorithm, also known as compensated summation
+    https://en.wikipedia.org/wiki/Kahan_summation_algorithm
+    '''
+    Ksum = 0.0                   # Prepare the accumulator.
+    comp = 0.0                   # A running compensation for lost low-order bits.
+   
+    for xx in np.where ( np.isnan(tab), 0., tab ) : 
+        yy = xx - comp           # comp is zero the first time around.
+        tt = Ksum + yy           # Alas, sum is big, y small, so low-order digits of y are lost.
+        comp = (tt - Ksum) - yy  # (tt - Ksum) cancels the high-order part of y; subtracting y recovers negative (low part of yy)
+        Ksum = tt                # Algebraically, comp should always be zero. Beware overly-aggressive optimizing compilers!
+                                 # Next time around, the lost low part will be added to y in a fresh attempt.
+    return Ksum
+
+def Ssum (tab) :
+    '''
+    Precision summation by sorting by absolute value
+    '''
+    Ssum = np.sum ( tab[np.argsort(np.abs(tab))] )
+    return Ssum
+
+def KSsum (tab) :
+    '''
+    Precision summation by sorting by absolute value, and applying Kahan summation
+    '''
+    KSsum = Ksum ( tab[np.argsort(np.abs(tab))] )
+    return KSsum
+
+# Choosing algorithm
+Psum = KSsum
+
 def ATM_stock_int (stock) :
     '''Integrate stock on atmosphere grid'''
-    ATM_stock_int  = np.sum (  np.sort ( (stock * DYN_aire).to_masked_array().ravel()) )
+    ATM_stock_int  = Psum ( (stock * DYN_aire).to_masked_array().ravel() ) 
     return ATM_stock_int
 
 def ATM_flux_int (flux) :
     '''Integrate flux on atmosphere grid'''
-    ATM_stock_int  = np.sum (  np.sort ( (flux * dtime_per_sec * ATM_aire).to_masked_array().ravel()) )
+    ATM_flux_int  = Psum ( (flux * dtime_per_sec * ATM_aire).to_masked_array().ravel() )
+    return ATM_flux_int
+
+def SRF_stock_int (stock) :
+    '''Integrate stock on land grid'''
+    ATM_stock_int  = Ksum (  ( (stock * DYN_aire_fter).to_masked_array().ravel()) )
     return ATM_stock_int
+
+def SRF_flux_int (flux) :
+    '''Integrate flux on land grid'''
+    SRF_flux_int  = Psum (  (flux * dtime_per_sec * SRF_aire).to_masked_array().ravel() )
+    return SRF_flux_int
 
 def ONE_stock_int (stock) :
     '''Sum stock '''
-    ONE_stock_int  = np.sum (  np.sort ( (stock).to_masked_array().ravel()) )
+    ONE_stock_int  = Psum ( stock.to_masked_array().ravel() )
     return ONE_stock_int
 
 def ONE_flux_int (flux) :
     '''Sum flux '''
-    ONE_flux_int  = np.sum (  np.sort ( (flux * dtime_per_sec ).to_masked_array().ravel()) )
+    ONE_flux_int  = Psum ( (flux * dtime_per_sec ).to_masked_array().ravel() )
     return ONE_flux_int
+
+def kg2Sv  (val, rho=ATM_rho) :
+    '''From kg to Sverdrup'''
+    return val/dtime_sec*1.0e-6/rho
+
+def kg2myear (val, rho=ATM_rho) :
+    '''From kg to m/year'''
+    return val/ATM_aire_sea_tot/rho/NbYear
     
 # ATM grid with cell surfaces
@@ -329,10 +490,16 @@
     file_ATM_aire = os.path.join ( R_IN, 'ATM', 'GRID', f'aire_{ATM}_to_{jpia}x{jpja}.nc' )
     config['Files']['file_ATM_aire'] = file_ATM_aire
-    echo ('Aire sur grille reguliere :', file_ATM_aire)
+    echo ( f'Aire sur grille reguliere : {file_ATM_aire}' )
     d_ATM_aire = xr.open_dataset ( file_ATM_aire, decode_times=False ).squeeze()
     ATM_aire = lmdz.geo2point ( d_ATM_aire ['aire'].squeeze(), cumulPoles=True )
-    ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] )
-    ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] + d_ATM_his ['fract_lic'][0] )
+    ATM_fter = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] )
+    ATM_foce = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] )
+    ATM_fsic = lmdz.geo2point ( d_ATM_his ['fract_sic'][0] )
+    ATM_flic = lmdz.geo2point ( d_ATM_his ['fract_lic'][0] )
+    ATM_fsea = ATM_foce + ATM_fsic
+    ATM_flnd = ATM_fter + ATM_flic
     SRF_aire = lmdz.geo2point ( d_SRF_his ['Areas'] * d_SRF_his ['Contfrac'] )
+    #SRF_aire = ATM_aire * lmdz.geo2point (d_SRF_his ['Contfrac'] )
+    #SRF_aire = ATM_aire * ATM_fter
     
 if LMDZ :
@@ -340,5 +507,6 @@
     ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] )
     ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] )
-    SRF_aire = lmdz.geo2point ( d_SRF_his['Areas'] * d_SRF_his['Contfrac'] )
+    #SRF_aire = lmdz.geo2point ( d_SRF_his['Areas'] * d_SRF_his['Contfrac'] )
+    SRF_aire = ATM_aire * lmdz.geo2point ( d_SRF_his['Contfrac'] )
 
 SRF_aire = SRF_aire.where ( SRF_aire < 1E15, 0.)
@@ -353,4 +521,6 @@
     DYN_fsea = d_DYN_aire ['fract_oce'] + d_DYN_aire ['fract_sic']
     DYN_flnd = 1.0 - DYN_fsea
+    DYN_fter = d_ATM_beg['FTER'].rename({'points_physiques':'cell_mesh'})
+    DYN_flic = d_ATM_beg['FTER'].rename({'points_physiques':'cell_mesh'})
     
 if LMDZ :
@@ -358,4 +528,9 @@
     DYN_fsea = ATM_fsea
     DYN_flnd = ATM_flnd
+    DYN_fter = d_ATM_beg['FTER']
+    DYN_flic = d_ATM_beg['FTER']
+
+    
+DYN_aire_fter = DYN_aire * DYN_fter
 
 #if LMDZ :
@@ -374,6 +549,6 @@
     raise Exception ('Erreur surface interpolee sur grille reguliere')
 
-echo ( '\n------------------------------------------------------------------------------------' )
-echo ( '-- ATM changes in stores ' )
+echo ( '\n====================================================================================' )
+echo ( f'-- ATM changes in stores  -- {Title} ' )
 
 #-- Change in precipitable water from the atmosphere daily and monthly files
@@ -386,30 +561,30 @@
 # Surface pressure
 if ICO : 
-    DYN_ps_beg = d_DYN_beg['ps']
-    DYN_ps_end = d_DYN_end['ps']
-    
+    DYN_psol_beg = d_DYN_beg['ps']
+    DYN_psol_end = d_DYN_end['ps']
 if LMDZ : 
-    DYN_ps_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) )
-    DYN_ps_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) )
-    
-# 3D Pressure
-DYN_p_beg = ATM_Ahyb + ATM_Bhyb * DYN_ps_beg
-DYN_p_end = ATM_Ahyb + ATM_Bhyb * DYN_ps_end
-
-if ICO  : klevp1, cell_mesh        = DYN_p_beg.shape
-if LMDZ : klevp1, points_physiques = DYN_p_beg.shape
+    DYN_psol_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) )
+    DYN_psol_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) )
+    
+# 3D Pressure at the interface layers (not scalar points)
+DYN_pres_beg = ATM_Ahyb + ATM_Bhyb * DYN_psol_beg
+DYN_pres_end = ATM_Ahyb + ATM_Bhyb * DYN_psol_end
+
+klevp1 = ATM_Bhyb.shape[-1]
+if ICO  : cell_mesh        = DYN_psol_beg.shape[-1]
+if LMDZ : points_physiques = DYN_psol_beg.shape[-1]
 klev = klevp1 - 1
 
-# Layer thickness
+# Layer thickness (pressure)
 if ICO : 
-    DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh) ) )
-    DYN_dsigma_end = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh) ) )
+    DYN_dpres_beg = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh)        ) )
+    DYN_dpres_end = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh)        ) )
 if LMDZ : 
-    DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
-    DYN_dsigma_end = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
+    DYN_dpres_beg = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
+    DYN_dpres_end = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
 
 for k in np.arange (klevp1-1) :
-    DYN_dsigma_beg[k,:] = DYN_p_beg[k,:] - DYN_p_beg[k+1,:]
-    DYN_dsigma_end[k,:] = DYN_p_end[k,:] - DYN_p_end[k+1,:]
+    DYN_dpres_beg[k,:] = DYN_pres_beg[k,:] - DYN_pres_beg[k+1,:]
+    DYN_dpres_end[k,:] = DYN_pres_end[k,:] - DYN_pres_end[k+1,:]
 
 ##-- Vertical and horizontal integral, and sum of liquid, solid and vapor water phases
@@ -429,15 +604,32 @@
         DYN_wat_end = (d_DYN_end['q'].isel(nq=0) + d_DYN_end['q'].isel(nq=1) + d_DYN_end['q'].isel(nq=2) ).rename ( {'lev':'sigs'} )
     
-# Integral
-DYN_mas_wat_beg = ATM_stock_int (DYN_dsigma_beg * DYN_wat_beg) / Grav
-DYN_mas_wat_end = ATM_stock_int (DYN_dsigma_end * DYN_wat_end) / Grav
-
+# Compute water content : vertical and horizontal integral
+DYN_mas_wat_beg = ATM_stock_int (DYN_dpres_beg * DYN_wat_beg) / Grav
+DYN_mas_wat_end = ATM_stock_int (DYN_dpres_end * DYN_wat_end) / Grav
+
+# Variation of water content
 dDYN_mas_wat = DYN_mas_wat_end - DYN_mas_wat_beg
 
-echo ( '\nVariation du contenu en eau atmosphere (dynamique) ' )
+# \([a-z,A-Z,_]*\)/dtime_sec\*1e-9  kg2Sv(\1)
+# \([a-z,A-Z,_]*\)\/ATM_aire_sea_tot\/ATM_rho\/NbYear  kg2myear(\1)
+
+def var2prt (var, small=False) :
+    if small :  return var , kg2Sv(var)*1000., kg2myear(var)*1000.
+    else     :  return var , kg2Sv(var)      , kg2myear(var)
+
+def prtFlux (Desc, var, Form='F', small=False) :
+    if small :
+        if Form in ['f', 'F'] : ff=" {:12.4e} kg | {:12.4f} mSv | {:12.4f} mm/year "
+        if Form in ['e', 'E'] : ff=" {:12.4e} kg | {:12.4e} mSv | {:12.4e} mm/year "
+    else :
+        if Form in ['f', 'F'] : ff=" {:12.4e} kg | {:12.4f} Sv  | {:12.4f} m/year  "
+        if Form in ['e', 'E'] : ff=" {:12.4e} kg | {:12.4e} Sv  | {:12.4e} m/year  "
+    echo ( (' {:>15} = ' +ff).format (Desc, *var2prt(var, small) ) )
+    return None
+
+echo ( f'\nVariation du contenu en eau atmosphere (dynamique)  -- {Title} ' )
+echo ( '------------------------------------------------------------------------------------' )
 echo ( 'DYN_mas_beg = {:12.6e} kg | DYN_mas_end = {:12.6e} kg'.format (DYN_mas_wat_beg, DYN_mas_wat_end) )
-echo ( 'dMass (atm)   = {:12.3e} kg '.format (dDYN_mas_wat) )
-echo ( 'dMass (atm)   = {:12.3e} Sv '.format (dDYN_mas_wat/dtime_sec*1.e-6/ATM_rho) )
-echo ( 'dMass (atm)   = {:12.3e} m  '.format (dDYN_mas_wat/ATM_aire_sea_tot/ATM_rho) )
+prtFlux ( 'dMass (atm)  ', dDYN_mas_wat, 'e', True )
 
 ATM_sno_beg = d_ATM_beg['SNOW01']*d_ATM_beg['FTER']+d_ATM_beg['SNOW02']*d_ATM_beg['FLIC']+d_ATM_beg['SNOW03']*d_ATM_beg['FOCE']+d_ATM_beg['SNOW04']*d_ATM_beg['FSIC']
@@ -499,137 +691,188 @@
 dATM_mas_qs04 = ATM_mas_qs04_end - ATM_mas_qs04_beg
 
-echo ( '\nVariation du contenu en neige atmosphere (calottes)' )
+dATM_mas_sno_2 = ATM_stock_int ( ATM_sno_end - ATM_sno_beg )
+
+echo ( f'\nVariation du contenu en neige atmosphere (calottes)  -- {Title} ' )
+echo ( '------------------------------------------------------------------------------------' )
 echo ( 'ATM_mas_sno_beg  = {:12.6e} kg | ATM_mas_sno_end  = {:12.6e} kg'.format (ATM_mas_sno_beg, ATM_mas_sno_end) )
-echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_sno ) )
-echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_sno/dtime_sec*1e-6/ICE_rho_ice) )
-echo ( 'dMass (neige atm) = {:12.3e} m  '.format (dATM_mas_sno/ATM_aire_sea_tot/ATM_rho) )
-
-echo ( '\nVariation du contenu humidite du sol' )
+prtFlux ( 'dMass (neige atm) ', dATM_mas_sno  , 'e', True  )
+prtFlux ( 'dMass (neige atm) ', dATM_mas_sno_2, 'e', True  )
+
+echo ( f'\nVariation du contenu humidite du sol  -- {Title} ' )
+echo ( '------------------------------------------------------------------------------------' )
 echo ( 'ATM_mas_qs_beg  = {:12.6e} kg | ATM_mas_qs_end  = {:12.6e} kg'.format (ATM_mas_qs_beg, ATM_mas_qs_end) )
-echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_qs ) )
-echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_qs/dtime_sec*1e-6/ATM_rho) )
-echo ( 'dMass (neige atm) = {:12.3e} m  '.format (dATM_mas_qs/ATM_aire_sea_tot/ATM_rho) )
-
-echo ( '\nVariation du contenu en eau+neige atmosphere ' )
-echo ( 'dMass (eau + neige atm) = {:12.3e} kg '.format (  dDYN_mas_wat + dATM_mas_sno) )
-echo ( 'dMass (eau + neige atm) = {:12.3e} Sv '.format ( (dDYN_mas_wat + dATM_mas_sno)/dtime_sec*1E-6/ATM_rho) )
-echo ( 'dMass (eau + neige atm) = {:12.3e} m  '.format ( (dDYN_mas_wat + dATM_mas_sno)/ATM_aire_sea_tot/ATM_rho) )
-
-echo ( '\n------------------------------------------------------------------------------------' )
-echo ( '-- SRF changes ' )
-
-# dSoilHum_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=(maxvegetfrac*DelSoilMoist_daily)*Contfrac' ${file} -gridarea ${file}`
-# dInterce_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelIntercept_daily*Contfrac' ${file} -gridarea ${file}`
-# dSWE_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelSWE_daily*Contfrac' ${file} -gridarea ${file}`
-# dStream_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delstreamr_daily*Contfrac' ${file} -gridarea ${file}`
-# dFastR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfastr_daily*Contfrac' ${file} -gridarea ${file}`
-# dSlowR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delslowr_daily*Contfrac' ${file} -gridarea ${file}`
-# dFlood_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfloodr_daily*Contfrac' ${file} -gridarea ${file}`
-# dPond_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delpondr_daily*Contfrac' ${file} -gridarea ${file}`
-# dLake_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=dellakevol_daily*Contfrac' ${file} -gridarea ${file}`
-#echo 'dSTOCK (Sv) Soil Intercept SWE Stream FastR SlowR Lake Pond Flood=' $dSoilHum_in_Sv, $dInterce_in_Sv, $dSWE_in_Sv, $dStream_in_Sv, $dFastR_in_Sv, $dSlowR_in_Sv, $dLake_in_Sv, $dPond_in_Sv, $dFlood_in_Sv >> ${fileout}
-#dSRF_tot=`python -c "print $dSoilHum_in_Sv+$dInterce_in_Sv+$dSWE_in_Sv+$dStream_in_Sv+$dFastR_in_Sv+$dSlowR_in_Sv+$dLake_in_Sv+$dPond_in_Sv+$dFlood_in_Sv"`
-#echo 'dSTOCK (Sv) total='${dSRF_tot} >> ${fileout}
-
+prtFlux ( 'dMass (neige atm) ', dATM_mas_qs, 'e', True )
+
+echo ( f'\nVariation du contenu en eau+neige atmosphere  -- {Title}  ' )
+echo ( '------------------------------------------------------------------------------------' )
+prtFlux ( 'dMass (eau + neige atm) ', dDYN_mas_wat + dATM_mas_sno , 'e', True)
+
+echo ( '\n====================================================================================' )
+echo ( f'-- SRF changes  -- {Title} ' )
 
 if Routing == 'SIMPLE' :
-    RUN_mas_wat_beg = ONE_stock_int ( d_RUN_beg ['fast_reservoir'] +  d_RUN_beg ['slow_reservoir'] +  d_RUN_beg ['stream_reservoir'] )
-    RUN_mas_wat_end = ONE_stock_int ( d_RUN_end ['fast_reservoir'] +  d_RUN_end ['slow_reservoir'] +  d_RUN_end ['stream_reservoir'] )
-
-if Routing == 'ORCHIDEE' : 
-    RUN_mas_wat_beg = ONE_stock_int ( d_SRF_beg['fastres']  + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \
-                                    + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres']  )
-    RUN_mas_wat_end = ONE_stock_int ( d_SRF_end['fastres']  + d_SRF_end['slowres'] + d_SRF_end['streamres'] \
-                                    + d_SRF_end['floodres'] + d_SRF_end['lakeres'] + d_SRF_end['pondres']  )
-
-dRUN_mas_wat = RUN_mas_wat_end - RUN_mas_wat_beg
-    
-echo ( '\nWater content in routing ' )
+    RUN_mas_wat_fast_beg   = ONE_stock_int ( d_RUN_beg ['fast_reservoir']   )
+    RUN_mas_wat_slow_beg   = ONE_stock_int ( d_RUN_beg ['slow_reservoir']   )
+    RUN_mas_wat_stream_beg = ONE_stock_int ( d_RUN_beg ['stream_reservoir'] )
+    RUN_mas_wat_flood_beg  = 0.0
+    RUN_mas_wat_lake_beg   = 0.0
+    RUN_mas_wat_pond_beg   = 0.0
+    
+    RUN_mas_wat_fast_end   = ONE_stock_int ( d_RUN_end ['fast_reservoir']   )
+    RUN_mas_wat_slow_end   = ONE_stock_int ( d_RUN_end ['slow_reservoir']   )
+    RUN_mas_wat_stream_end = ONE_stock_int ( d_RUN_end ['stream_reservoir'] )
+    RUN_mas_wat_flood_end  = 0.0
+    RUN_mas_wat_lake_end   = 0.0
+    RUN_mas_wat_pond_end   = 0.0
+
+if Routing == 'SECHIBA' :
+    RUN_mas_wat_fast_beg   = ONE_stock_int ( d_SRF_beg ['fastres']   )
+    RUN_mas_wat_slow_beg   = ONE_stock_int ( d_SRF_beg ['slowres']   )
+    RUN_mas_wat_stream_beg = ONE_stock_int ( d_SRF_beg ['streamres'] )
+    RUN_mas_wat_flood_beg  = ONE_stock_int ( d_SRF_beg ['floodres']  )
+    RUN_mas_wat_lake_beg   = ONE_stock_int ( d_SRF_beg ['lakeres']   )
+    RUN_mas_wat_pond_beg   = ONE_stock_int ( d_SRF_beg ['pondres']   )
+
+    
+    RUN_mas_wat_fast_end   = ONE_stock_int ( d_SRF_end ['fastres']   )
+    RUN_mas_wat_slow_end   = ONE_stock_int ( d_SRF_end ['slowres']   )
+    RUN_mas_wat_stream_end = ONE_stock_int ( d_SRF_end ['streamres'] )
+    RUN_mas_wat_flood_end  = ONE_stock_int ( d_SRF_end ['floodres']  )
+    RUN_mas_wat_lake_end   = ONE_stock_int ( d_SRF_end ['lakeres']   )
+    RUN_mas_wat_pond_end   = ONE_stock_int ( d_SRF_end ['pondres']   )
+
+RUN_mas_wat_beg = RUN_mas_wat_fast_beg + RUN_mas_wat_slow_beg + RUN_mas_wat_stream_beg + RUN_mas_wat_flood_beg + RUN_mas_wat_lake_beg + RUN_mas_wat_pond_beg
+RUN_mas_wat_end = RUN_mas_wat_fast_end + RUN_mas_wat_slow_end + RUN_mas_wat_stream_end + RUN_mas_wat_flood_end + RUN_mas_wat_lake_end + RUN_mas_wat_pond_end
+
+dRUN_mas_wat_fast   = RUN_mas_wat_fast_end   - RUN_mas_wat_fast_beg
+dRUN_mas_wat_slow   = RUN_mas_wat_slow_end   - RUN_mas_wat_slow_beg
+dRUN_mas_wat_stream = RUN_mas_wat_stream_end - RUN_mas_wat_stream_beg
+dRUN_mas_wat_flood  = RUN_mas_wat_flood_end  - RUN_mas_wat_flood_beg
+dRUN_mas_wat_lake   = RUN_mas_wat_lake_end   - RUN_mas_wat_lake_beg
+dRUN_mas_wat_pond   = RUN_mas_wat_pond_end   - RUN_mas_wat_pond_beg
+
+dRUN_mas_wat        = RUN_mas_wat_end        - RUN_mas_wat_beg
+
+echo ( f'\nLes differents reservoirs  -- {Title} ')
+echo ( '------------------------------------------------------------------------------------' )
+echo ( 'RUN_mas_wat_fast_beg   = {:12.6e} kg | RUN_mas_wat_fast_end   = {:12.6e} kg '.format (RUN_mas_wat_fast_beg  , RUN_mas_wat_fast_end   ) )
+echo ( 'RUN_mas_wat_slow_beg   = {:12.6e} kg | RUN_mas_wat_slow_end   = {:12.6e} kg '.format (RUN_mas_wat_slow_beg  , RUN_mas_wat_slow_end   ) )
+echo ( 'RUN_mas_wat_stream_beg = {:12.6e} kg | RUN_mas_wat_stream_end = {:12.6e} kg '.format (RUN_mas_wat_stream_beg, RUN_mas_wat_stream_end ) )
+echo ( 'RUN_mas_wat_flood_beg  = {:12.6e} kg | RUN_mas_wat_flood_end  = {:12.6e} kg '.format (RUN_mas_wat_flood_beg , RUN_mas_wat_flood_end  ) )
+echo ( 'RUN_mas_wat_lake_beg   = {:12.6e} kg | RUN_mas_wat_lake_end   = {:12.6e} kg '.format (RUN_mas_wat_lake_beg  , RUN_mas_wat_lake_end   ) )
+echo ( 'RUN_mas_wat_pond_beg   = {:12.6e} kg | RUN_mas_wat_pond_end   = {:12.6e} kg '.format (RUN_mas_wat_pond_beg  , RUN_mas_wat_pond_end   ) )
+
+echo ( '------------------------------------------------------------------------------------' )
+
+prtFlux ( 'dMass (fast)   ', dRUN_mas_wat_fast  , 'e', True )
+prtFlux ( 'dMass (slow)   ', dRUN_mas_wat_slow  , 'e', True )
+prtFlux ( 'dMass (stream) ', dRUN_mas_wat_stream, 'e', True )
+prtFlux ( 'dMass (flood)  ', dRUN_mas_wat_flood , 'e', True )
+prtFlux ( 'dMass (lake)   ', dRUN_mas_wat_lake  , 'e', True )
+prtFlux ( 'dMass (pond)   ', dRUN_mas_wat_pond  , 'e', True )
+prtFlux ( 'dMass (all)    ', dRUN_mas_wat       , 'e', True )
+
+echo ( f'\nWater content in routing  -- {Title} ' )
+echo ( '------------------------------------------------------------------------------------' )
 echo ( 'RUN_mas_wat_beg = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_end, RUN_mas_wat_end) )
-echo ( 'dMass (routing)  = {:12.3e} kg '.format(dRUN_mas_wat) )
-echo ( 'dMass (routing)  = {:12.3e} Sv '.format(dRUN_mas_wat/dtime_sec*1E-9) )
-echo ( 'dMass (routing)  = {:12.3e} m  '.format(dRUN_mas_wat/ATM_aire_sea_tot*1E-3) )
-
-print ('Reading SRF restart')
-tot_watveg_beg  = d_SRF_beg['tot_watveg_beg']  ; tot_watveg_beg  = tot_watveg_beg .where (tot_watveg_beg < 1E10, 0.)
-tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; tot_watsoil_beg = tot_watsoil_beg.where (tot_watsoil_beg< 1E10, 0.)
-snow_beg        = d_SRF_beg['snow_beg']        ; snow_beg        = snow_beg       .where (snow_beg       < 1E10, 0.)
-
-tot_watveg_end  = d_SRF_end['tot_watveg_beg']  ; tot_watveg_end  = tot_watveg_end .where (tot_watveg_end < 1E10, 0.)
-tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; tot_watsoil_end = tot_watsoil_end.where (tot_watsoil_end< 1E10, 0.)
-snow_end        = d_SRF_end['snow_beg']        ; snow_end        = snow_end       .where (snow_end       < 1E10, 0.)
+prtFlux ( 'dMass (routing) ', dRUN_mas_wat       )
+
+echo ( '\n====================================================================================' )
+print (f'Reading SRF restart')
+SRF_tot_watveg_beg  = d_SRF_beg['tot_watveg_beg']  ; SRF_tot_watveg_beg  = SRF_tot_watveg_beg .where (SRF_tot_watveg_beg < 1E15, 0.)
+SRF_tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; SRF_tot_watsoil_beg = SRF_tot_watsoil_beg.where (SRF_tot_watsoil_beg< 1E15, 0.)
+SRF_snow_beg        = d_SRF_beg['snow_beg']        ; SRF_snow_beg        = SRF_snow_beg       .where (SRF_snow_beg       < 1E15, 0.)
+SRF_lakeres_beg     = d_SRF_beg['lakeres']         ; SRF_lakeres_beg     = SRF_lakeres_beg    .where (SRF_lakeres_beg    < 1E15, 0.)
+
+SRF_tot_watveg_end  = d_SRF_end['tot_watveg_beg']  ; SRF_tot_watveg_end  = SRF_tot_watveg_end .where (SRF_tot_watveg_end < 1E15, 0.)
+SRF_tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; SRF_tot_watsoil_end = SRF_tot_watsoil_end.where (SRF_tot_watsoil_end< 1E15, 0.)
+SRF_snow_end        = d_SRF_end['snow_beg']        ; SRF_snow_end        = SRF_snow_end       .where (SRF_snow_end       < 1E15, 0.)
+SRF_lakeres_end     = d_SRF_end['lakeres']         ; SRF_lakeres_end     = SRF_lakeres_end    .where (SRF_lakeres_end    < 1E15, 0.)
 
 if LMDZ :
-    tot_watveg_beg  = lmdz.geo2point (tot_watveg_beg)
-    tot_watsoil_beg = lmdz.geo2point (tot_watsoil_beg)
-    snow_beg        = lmdz.geo2point (snow_beg)
-    tot_watveg_end  = lmdz.geo2point (tot_watveg_end)
-    tot_watsoil_end = lmdz.geo2point (tot_watsoil_end)
-    snow_end        = lmdz.geo2point (snow_end)
+    SRF_tot_watveg_beg  = lmdz.geo2point (SRF_tot_watveg_beg )
+    SRF_tot_watsoil_beg = lmdz.geo2point (SRF_tot_watsoil_beg)
+    SRF_snow_beg        = lmdz.geo2point (SRF_snow_beg       )
+    SRF_lakeres_beg     = lmdz.geo2point (SRF_lakeres_beg    )
+    SRF_tot_watveg_end  = lmdz.geo2point (SRF_tot_watveg_end )
+    SRF_tot_watsoil_end = lmdz.geo2point (SRF_tot_watsoil_end)
+    SRF_snow_end        = lmdz.geo2point (SRF_snow_end       )
+    SRF_lakeres_end     = lmdz.geo2point (SRF_lakeres_end    )
+  
+if ICO :
+    SRF_tot_watveg_beg  = SRF_tot_watveg_beg .rename ( {'y':'cell_mesh'} )
+    SRF_tot_watsoil_beg = SRF_tot_watsoil_beg.rename ( {'y':'cell_mesh'} )
+    SRF_snow_beg        = SRF_snow_beg       .rename ( {'y':'cell_mesh'} )
+    SRF_lakeres_beg     = SRF_lakeres_beg    .rename ( {'y':'cell_mesh'} )
+    SRF_tot_watveg_end  = SRF_tot_watveg_end .rename ( {'y':'cell_mesh'} )
+    SRF_tot_watsoil_end = SRF_tot_watsoil_end.rename ( {'y':'cell_mesh'} )
+    SRF_snow_end        = SRF_snow_end       .rename ( {'y':'cell_mesh'} )
+    SRF_lakeres_end     = SRF_lakeres_end    .rename ( {'y':'cell_mesh'} )
 
 # Stock dSoilHum dInterce dSWE dStream dFastR dSlowR dLake dPond dFlood
 
-SRF_wat_beg = tot_watveg_beg + tot_watsoil_beg + snow_beg
-SRF_wat_end = tot_watveg_end + tot_watsoil_end + snow_end
-    
-if ICO :
-    tot_watveg_beg  = tot_watveg_beg .rename ( {'y':'cell_mesh'} )
-    tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'cell_mesh'} )
-    snow_beg        = snow_beg       .rename ( {'y':'cell_mesh'} )
-    tot_watveg_end  = tot_watveg_end .rename ( {'y':'cell_mesh'} )
-    tot_watsoil_end = tot_watsoil_end.rename ( {'y':'cell_mesh'} )
-    snow_end        = snow_end       .rename ( {'y':'cell_mesh'} )
-    SRF_wat_beg     = SRF_wat_beg    .rename ( {'y':'cell_mesh'} )
-    SRF_wat_end     = SRF_wat_end    .rename ( {'y':'cell_mesh'} )
-
+SRF_wat_beg = SRF_tot_watveg_beg + SRF_tot_watsoil_beg + SRF_snow_beg 
+SRF_wat_end = SRF_tot_watveg_end + SRF_tot_watsoil_end + SRF_snow_end
+
+echo ( '\n====================================================================================' )
 print ('Computing integrals')
 
-print ( ' 1/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_watveg_beg   = ATM_stock_int ( tot_watveg_beg  )
-print ( ' 2/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_watsoil_beg  = ATM_stock_int ( tot_watsoil_beg )
-print ( ' 3/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_snow_beg     = ATM_stock_int ( snow_beg        )
-print ( ' 4/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_watveg_end   = ATM_stock_int ( tot_watveg_end  )
-print ( ' 5/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_watsoil_end  = ATM_stock_int ( tot_watsoil_end )
-print ( ' 6/6', end='' ) ; sys.stdout.flush ()
-SRF_mas_snow_end     = ATM_stock_int ( snow_end        )
+print ( ' 1/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_watveg_beg   = SRF_stock_int ( SRF_tot_watveg_beg  )
+print ( ' 2/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_watsoil_beg  = SRF_stock_int ( SRF_tot_watsoil_beg )
+print ( ' 3/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_snow_beg     = SRF_stock_int ( SRF_snow_beg        )
+print ( ' 4/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_lake_beg     = ONE_stock_int ( SRF_lakeres_beg     )
+print ( ' 5/8', end='' ) ; sys.stdout.flush ()
+
+SRF_mas_watveg_end   = SRF_stock_int ( SRF_tot_watveg_end  )
+print ( ' 6/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_watsoil_end  = SRF_stock_int ( SRF_tot_watsoil_end )
+print ( ' 7/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_snow_end     = SRF_stock_int ( SRF_snow_end        )
+print ( ' 8/8', end='' ) ; sys.stdout.flush ()
+SRF_mas_lake_end     = ONE_stock_int ( SRF_lakeres_end     )
+
 print (' -- ') ; sys.stdout.flush ()
 
-dSRF_mas_watveg   = SRF_mas_watveg_end   - SRF_mas_watveg_beg
-dSRF_mas_watsoil  = SRF_mas_watsoil_end  - SRF_mas_watsoil_beg
-dSRF_mas_snow     = SRF_mas_snow_end     - SRF_mas_snow_beg
-
-echo ('\nLes differents reservoirs')
+dSRF_mas_watveg   = SRF_mas_watveg_end  - SRF_mas_watveg_beg
+dSRF_mas_watsoil  = SRF_mas_watsoil_end - SRF_mas_watsoil_beg
+dSRF_mas_snow     = SRF_mas_snow_end    - SRF_mas_snow_beg
+dSRF_mas_lake     = SRF_mas_lake_end    - SRF_mas_lake_beg
+
+
+
+echo ( '------------------------------------------------------------------------------------' )
+echo ( f'\nLes differents reservoirs  -- {Title} ')
 echo ( 'SRF_mas_watveg_beg   = {:12.6e} kg | SRF_mas_watveg_end   = {:12.6e} kg '.format (SRF_mas_watveg_beg  , SRF_mas_watveg_end   ) )
 echo ( 'SRF_mas_watsoil_beg  = {:12.6e} kg | SRF_mas_watsoil_end  = {:12.6e} kg '.format (SRF_mas_watsoil_beg , SRF_mas_watsoil_end  ) )
 echo ( 'SRF_mas_snow_beg     = {:12.6e} kg | SRF_mas_snow_end     = {:12.6e} kg '.format (SRF_mas_snow_beg    , SRF_mas_snow_end     ) )
-
-echo ( 'dMass (watveg)    = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_watveg  , dSRF_mas_watveg  /dtime_sec*1E-9, dSRF_mas_watveg  /ATM_aire_sea_tot*1E-3) )
-echo ( 'dMass (watsoil)   = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_watsoil , dSRF_mas_watsoil /dtime_sec*1E-9, dSRF_mas_watsoil /ATM_aire_sea_tot*1E-3) )
-echo ( 'dMass (sno)       = {:12.3e} kg | {:12.2e} Sv | {:12.2e} m '.format (dSRF_mas_snow    , dSRF_mas_snow    /dtime_sec*1E-9, dSRF_mas_snow    /ATM_aire_sea_tot*1E-3) )
+echo ( 'SRF_mas_lake_beg     = {:12.6e} kg | SRF_mas_lake_end     = {:12.6e} kg '.format (SRF_mas_lake_beg    , SRF_mas_lake_end     ) )
+
+prtFlux ('dMass (watveg) ', dSRF_mas_watveg , 'e' , True)
+prtFlux ('dMass (watsoil)', dSRF_mas_watsoil, 'e' , True)
+prtFlux ('dMass (snow)   ', dSRF_mas_snow   , 'e' , True)
+prtFlux ('dMass (lake)   ', dSRF_mas_lake   , 'e' , True)
 
 SRF_mas_wat_beg = SRF_mas_watveg_beg + SRF_mas_watsoil_beg + SRF_mas_snow_beg 
 SRF_mas_wat_end = SRF_mas_watveg_end + SRF_mas_watsoil_end + SRF_mas_snow_end 
-dSRF_mas_wat = SRF_mas_wat_end - SRF_mas_wat_beg
-
-echo ( '\nWater content in surface ' )
-echo ( 'SRF_mas_wat_beg  = {:12.6e} kg | SRF_mas_wat_end  = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) )
-echo ( 'dMass (water srf) = {:12.3e} kg '.format (dSRF_mas_wat) )
-echo ( 'dMass (water srf) = {:12.3e} Sv '.format (dSRF_mas_wat/dtime_sec*1E-6/ATM_rho) )
-echo ( 'dMass (water srf) = {:12.3e} m  '.format (dSRF_mas_wat/ATM_aire_sea_tot/ATM_rho) )
-
-echo ( '\nWater content in  ATM + SRF + RUN ' )
+dSRF_mas_wat    = SRF_mas_wat_end - SRF_mas_wat_beg
+
+echo ( '------------------------------------------------------------------------------------' )
+echo ( f'Water content in surface  -- {Title} ' )
+echo ( 'SRF_mas_wat_beg   = {:12.6e} kg | SRF_mas_wat_end  = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) )
+prtFlux ( 'dMass (water srf)', dSRF_mas_wat, 'e', True )
+
+echo ( '------------------------------------------------------------------------------------' )
+echo ( 'Water content in  ATM + SRF + RUN + LAKE' )
 echo ( 'mas_wat_beg = {:12.6e} kg | mas_wat_end = {:12.6e} kg '.
-           format (DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg,
-                   DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) )
-echo ( 'dMass (water atm+srf+run) = {:12.6e} kg '.format ( dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat) )
-echo ( 'dMass (water atm+srf+run) = {:12.3e} Sv '.format ((dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/dtime_sec*1E-6/ATM_rho) )
-echo ( 'dMass (water atm+srf+run) = {:12.3e} m  '.format ((dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat)/ATM_aire_sea_tot/ATM_rho) )
-
-echo ( '\n------------------------------------------------------------------------------------' )
-echo ( '-- ATM Fluxes ' )
+           format (DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg + SRF_mas_lake_beg ,
+                   DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end + SRF_mas_lake_end ) )
+prtFlux ( 'dMass (water atm+srf+run+lake)', dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat + dSRF_mas_lake, 'e', True)
+
+echo ( '\n====================================================================================' )
+echo ( f'-- ATM Fluxes  -- {Title} ' )
 
 ATM_wbilo_oce   = lmdz.geo2point ( d_ATM_his ['wbilo_oce']   )
@@ -643,5 +886,6 @@
 ATM_snowf       = lmdz.geo2point ( d_ATM_his ['snow']        )
 ATM_evap        = lmdz.geo2point ( d_ATM_his ['evap']        )
-ATM_bilo = ATM_wbilo_oce + ATM_wbilo_ter + ATM_wbilo_lic + ATM_wbilo_sic
+ATM_wbilo       = ATM_wbilo_oce + ATM_wbilo_sic + ATM_wbilo_ter + ATM_wbilo_lic
+ATM_emp         = ATM_evap - ATM_precip
 
 RUN_coastalflow = lmdz.geo2point ( d_RUN_his ['coastalflow'] ) 
@@ -651,11 +895,16 @@
 RUN_riversret   = lmdz.geo2point ( d_RUN_his ['riversret']   )
 
-SRF_evap     = lmdz.geo2point ( d_SRF_his ['evap'] )
+RUN_coastalflow_cpl = lmdz.geo2point ( d_RUN_his ['coastalflow_cpl'] ) 
+RUN_riverflow_cpl   = lmdz.geo2point ( d_RUN_his ['riverflow_cpl']   )
+
+SRF_rain     = lmdz.geo2point ( d_SRF_his ['rain']  )
+SRF_evap     = lmdz.geo2point ( d_SRF_his ['evap']  )
 SRF_snowf    = lmdz.geo2point ( d_SRF_his ['snowf'] )
-SRF_TWS      = lmdz.geo2point ( d_SRF_his ['TWS'] )
 SRF_subli    = lmdz.geo2point ( d_SRF_his ['subli'] )
 SRF_transpir = lmdz.geo2point ( np.sum(d_SRF_his ['transpir'], axis=1) ) ; SRF_transpir.attrs['units'] = d_SRF_his ['transpir'].attrs['units']
-
-def mmd2SI ( Var) :
+SRF_emp      = SRF_evap - SRF_rain - SRF_snowf ; SRF_emp.attrs['units'] = SRF_rain.attrs['units']
+
+## Correcting units of SECHIBA variables
+def mmd2SI ( Var ) :
     '''Change unit from mm/d or m^3/s to kg/s if needed'''
     if 'units' in VarT.attrs : 
@@ -665,12 +914,13 @@
             VarT.values = VarT.values  * ATM_rho * (1e-3/86400.) ;  VarT.attrs['units'] = 'kg/s'
 
-for var in ['runoff', 'drainage', 'riversret', 'coastalflow', 'riverflow'] :
+for var in [ 'runoff', 'drainage', 'riversret', 'coastalflow', 'riverflow', 'coastalflow_cpl', 'riverflow_cpl' ] :
     VarT = locals()['RUN_' + var]
     mmd2SI (VarT)
 
-for var in ['evap', 'snowf', 'TWS', 'subli', 'transpir'] :
+for var in ['evap', 'snowf', 'subli', 'transpir', 'rain', 'emp' ] :
     VarT = locals()['SRF_' + var]
     mmd2SI (VarT)
 
+
 RUN_input  = RUN_runoff      + RUN_drainage
 RUN_output = RUN_coastalflow + RUN_riverflow
@@ -678,73 +928,134 @@
 ATM_wbilo_sea = ATM_wbilo_oce + ATM_wbilo_sic
 
-ATM_flx_oce       = ATM_flux_int ( ATM_wbilo_oce  )
-ATM_flx_sic       = ATM_flux_int ( ATM_wbilo_sic  )
-ATM_flx_sea       = ATM_flux_int ( ATM_wbilo_sea  )
-ATM_flx_ter       = ATM_flux_int ( ATM_wbilo_ter  )
-ATM_flx_lic       = ATM_flux_int ( ATM_wbilo_lic  )
-ATM_flx_calving   = ATM_flux_int ( ATM_fqcalving  )
-ATM_flx_qfonte    = ATM_flux_int ( ATM_fqfonte    )
-ATM_flx_precip    = ATM_flux_int ( ATM_precip     )
-ATM_flx_snowf     = ATM_flux_int ( ATM_snowf      )
-ATM_flx_evap      = ATM_flux_int ( ATM_evap       )
-ATM_flx_runlic    = ATM_flux_int ( ATM_runofflic  )
-
-RUN_flx_coastal   = ONE_flux_int ( RUN_coastalflow)
-RUN_flx_river     = ONE_flux_int ( RUN_riverflow  )
-RUN_flx_drainage  = ATM_flux_int ( RUN_drainage   )
-RUN_flx_riversret = ATM_flux_int ( RUN_riversret  )
-RUN_flx_runoff    = ATM_flux_int ( RUN_runoff     )
-RUN_flx_input     = ATM_flux_int ( RUN_input      )
-RUN_flx_output    = ONE_flux_int ( RUN_output     )
-
-ATM_flx_emp   = ATM_flx_evap - ATM_flx_precip
-ATM_flx_bilo  = ATM_flx_oce + ATM_flx_sic + ATM_flx_ter + ATM_flx_lic
+ATM_flx_oce         = ATM_flux_int ( ATM_wbilo_oce  )
+ATM_flx_sic         = ATM_flux_int ( ATM_wbilo_sic  )
+ATM_flx_sea         = ATM_flux_int ( ATM_wbilo_sea  )
+ATM_flx_ter         = ATM_flux_int ( ATM_wbilo_ter  )
+ATM_flx_lic         = ATM_flux_int ( ATM_wbilo_lic  )
+ATM_flx_calving     = ATM_flux_int ( ATM_fqcalving  )
+ATM_flx_qfonte      = ATM_flux_int ( ATM_fqfonte    )
+ATM_flx_precip      = ATM_flux_int ( ATM_precip     )
+ATM_flx_snowf       = ATM_flux_int ( ATM_snowf      )
+ATM_flx_evap        = ATM_flux_int ( ATM_evap       )
+ATM_flx_runlic      = ATM_flux_int ( ATM_runofflic  )
+
+RUN_flx_coastal     = ONE_flux_int ( RUN_coastalflow)
+RUN_flx_river       = ONE_flux_int ( RUN_riverflow  )
+RUN_flx_coastal_cpl = ONE_flux_int ( RUN_coastalflow_cpl)
+RUN_flx_river_cpl   = ONE_flux_int ( RUN_riverflow_cpl  )
+RUN_flx_drainage    = SRF_flux_int ( RUN_drainage   )
+RUN_flx_riversret   = SRF_flux_int ( RUN_riversret  )
+RUN_flx_runoff      = SRF_flux_int ( RUN_runoff     )
+RUN_flx_input       = SRF_flux_int ( RUN_input      )
+RUN_flx_output      = ONE_flux_int ( RUN_output     )
+
+ATM_flx_emp   = ATM_flux_int (ATM_emp)
+ATM_flx_wbilo = ATM_flux_int (ATM_wbilo)
+
 RUN_flx_bil   = RUN_flx_input - RUN_flx_output
-
 RUN_flx_rivcoa = RUN_flx_coastal + RUN_flx_river
 
-ATM_flx_bilo2 = ATM_flux_int (ATM_bilo)
-
-
-echo ('  wbilo_oce     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_oce      , ATM_flx_oce      / dtime_sec*1E-6/ATM_rho, ATM_flx_oce      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  wbilo_sic     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_sic      , ATM_flx_sic      / dtime_sec*1E-6/ATM_rho, ATM_flx_sic      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  wbilo_sic+oce {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_sea      , ATM_flx_sea      / dtime_sec*1E-6/ATM_rho, ATM_flx_sea      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  wbilo_ter     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_ter      , ATM_flx_ter      / dtime_sec*1E-6/ATM_rho, ATM_flx_ter      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  wbilo_lic     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_lic      , ATM_flx_lic      / dtime_sec*1E-6/ATM_rho, ATM_flx_lic      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  Sum wbilo_*   {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_bilo     , ATM_flx_bilo     / dtime_sec*1E-6/ATM_rho, ATM_flx_bilo     /ATM_aire_sea_tot/ATM_rho ))
-echo ('  E-P           {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_emp      , ATM_flx_emp      / dtime_sec*1E-6/ATM_rho, ATM_flx_emp      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  calving       {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_calving  , ATM_flx_calving  / dtime_sec*1E-6/ATM_rho, ATM_flx_calving  /ATM_aire_sea_tot/ATM_rho ))
-echo ('  fqfonte       {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_qfonte   , ATM_flx_qfonte   / dtime_sec*1E-6/ATM_rho, ATM_flx_qfonte   /ATM_aire_sea_tot/ATM_rho ))
-echo ('  precip        {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_precip   , ATM_flx_precip   / dtime_sec*1E-6/ATM_rho, ATM_flx_precip   /ATM_aire_sea_tot/ATM_rho ))
-echo ('  snowf         {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_snowf    , ATM_flx_snowf    / dtime_sec*1E-6/ATM_rho, ATM_flx_snowf    /ATM_aire_sea_tot/ATM_rho ))
-echo ('  evap          {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_evap     , ATM_flx_evap     / dtime_sec*1E-6/ATM_rho, ATM_flx_evap     /ATM_aire_sea_tot/ATM_rho ))
-echo ('  coastalflow   {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_coastal  , RUN_flx_coastal  / dtime_sec*1E-6/ATM_rho, RUN_flx_coastal  /ATM_aire_sea_tot/ATM_rho ))
-echo ('  riverflow     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_river    , RUN_flx_river    / dtime_sec*1E-6/ATM_rho, RUN_flx_river    /ATM_aire_sea_tot/ATM_rho ))
-echo ('  river+coastal {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_rivcoa   , RUN_flx_rivcoa   / dtime_sec*1E-6/ATM_rho, RUN_flx_rivcoa   /ATM_aire_sea_tot/ATM_rho ))
-echo ('  drainage      {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_drainage , RUN_flx_drainage / dtime_sec*1E-6/ATM_rho, RUN_flx_drainage /ATM_aire_sea_tot/ATM_rho ))
-echo ('  riversret     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_riversret, RUN_flx_riversret/ dtime_sec*1E-6/ATM_rho, RUN_flx_riversret/ATM_aire_sea_tot/ATM_rho ))
-echo ('  runoff        {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_runoff   , RUN_flx_runoff   / dtime_sec*1E-6/ATM_rho, RUN_flx_runoff   /ATM_aire_sea_tot/ATM_rho ))
-echo ('  river in      {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_input    , RUN_flx_input    / dtime_sec*1E-6/ATM_rho, RUN_flx_input    /ATM_aire_sea_tot/ATM_rho ))
-echo ('  river out     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_output   , RUN_flx_output   / dtime_sec*1E-6/ATM_rho, RUN_flx_output   /ATM_aire_sea_tot/ATM_rho ))
-echo ('  river bil     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( RUN_flx_bil      , RUN_flx_bil      / dtime_sec*1E-6/ATM_rho, RUN_flx_bil      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  runoff lic    {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_runlic   , ATM_flx_runlic   / dtime_sec*1E-6/ATM_rho, ATM_flx_runlic   /ATM_aire_sea_tot/ATM_rho ))
-
-ATM_flx_budget = -ATM_flx_sea + ATM_flx_calving + ATM_flx_runlic #+ ATM_flx_qfonte + RUN_flx_river 
-echo ('\n  Global      {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( ATM_flx_budget , ATM_flx_budget / dtime_sec*1E-9, ATM_flx_budget /ATM_aire_sea_tot/ATM_rho ))
-
-#echo ('  E-P-R         {:12.3e} (kg) | {:12.4e} (Sv) | {:12.4f} m '.format ( ATM_flx_emp      , ATM_flx_emp      / dtime_sec*1E-6/ATM_rho, ATM_flx_emp      /ATM_aire_sea_tot/ATM_rho ))
-
-
-echo ( '------------------------------------------------------------------------------------' )
-echo ( '-- SECHIBA fluxes' )
-
-
-SRF_flx_evap     = ATM_flux_int ( SRF_evap     )
-SRF_flx_snowf    = ATM_flux_int ( SRF_snowf    )
-SRF_flx_subli    = ATM_flux_int ( SRF_subli    )
-SRF_flx_transpir = ATM_flux_int ( SRF_transpir )
-
-echo ('  evap     {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_evap      , SRF_flx_evap      / dtime_sec*1E-6/ATM_rho, SRF_flx_evap      /ATM_aire_sea_tot/ATM_rho ))
-echo ('  snowf    {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_snowf     , SRF_flx_snowf     / dtime_sec*1E-6/ATM_rho, SRF_flx_snowf     /ATM_aire_sea_tot/ATM_rho ))
-echo ('  subli    {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_subli     , SRF_flx_subli     / dtime_sec*1E-6/ATM_rho, SRF_flx_subli     /ATM_aire_sea_tot/ATM_rho ))
-echo ('  transpir {:12.3e} (kg) | {:12.4f} (Sv) | {:12.4f} m '.format ( SRF_flx_transpir  , SRF_flx_transpir  / dtime_sec*1E-6/ATM_rho, SRF_flx_transpir  /ATM_aire_sea_tot/ATM_rho ))
+prtFlux ('wbilo_oce     ', ATM_flx_oce, 'f' )
+prtFlux ('wbilo_oce     ', ATM_flx_oce, 'f' )          
+prtFlux ('wbilo_sic     ', ATM_flx_sic, 'f' )          
+prtFlux ('wbilo_sic+oce ', ATM_flx_sea, 'f' )          
+prtFlux ('wbilo_ter     ', ATM_flx_ter, 'f' )          
+prtFlux ('wbilo_lic     ', ATM_flx_lic, 'f' )          
+prtFlux ('Sum wbilo_*   ', ATM_flx_wbilo      , 'f', True)  
+prtFlux ('E-P           ', ATM_flx_emp        , 'f', True)  
+prtFlux ('calving       ', ATM_flx_calving    , 'f' ) 
+prtFlux ('fqfonte       ', ATM_flx_qfonte     , 'f' )       
+prtFlux ('precip        ', ATM_flx_precip     , 'f' )       
+prtFlux ('snowf         ', ATM_flx_snowf      , 'f' )        
+prtFlux ('evap          ', ATM_flx_evap       , 'f' )         
+prtFlux ('coastalflow   ', RUN_flx_coastal    , 'f' ) 
+prtFlux ('riverflow     ', RUN_flx_river      , 'f' )        
+prtFlux ('coastal_cpl   ', RUN_flx_coastal_cpl, 'f' )  
+prtFlux ('riverf_cpl    ', RUN_flx_river_cpl  , 'f' )    
+prtFlux ('river+coastal ', RUN_flx_rivcoa     , 'f' )   
+prtFlux ('drainage      ', RUN_flx_drainage   , 'f' )   
+prtFlux ('riversret     ', RUN_flx_riversret  , 'f' )   
+prtFlux ('runoff        ', RUN_flx_runoff     , 'f' )   
+prtFlux ('river in      ', RUN_flx_input      , 'f' )   
+prtFlux ('river out     ', RUN_flx_output     , 'f' )   
+prtFlux ('river bil     ', RUN_flx_bil        , 'f' )   
+prtFlux ('runoff lic    ', ATM_flx_runlic     , 'f' )   
+
+ATM_flx_budget = -ATM_flx_sea + ATM_flx_calving + ATM_flx_runlic #+ ATM_flx_qfonte + RUN_flx_river
+echo ('')
+echo ('  Global        {:12.3e} kg | {:12.4f} Sv | {:12.4f} m '.format ( ATM_flx_budget , ATM_flx_budget / dtime_sec*1E-9, ATM_flx_budget /ATM_aire_sea_tot/ATM_rho ))
+
+#echo ('  E-P-R         {:12.3e} kg | {:12.4e} Sv | {:12.4f} m '.format ( ATM_flx_emp      , ATM_flx_emp      / dtime_sec*1E-6/ATM_rho, ATM_flx_emp      /ATM_aire_sea_tot/ATM_rho ))
+
+echo (' ')
+echo ( '\n====================================================================================' )
+echo ( f'--  Atmosphere  -- {Title} ' )
+echo ( 'Mass begin = {:12.6e} kg | Mass end = {:12.6e} kg'.format (DYN_mas_wat_beg, DYN_mas_wat_end) )
+echo ( 'dmass (atm)  = {:12.3e} kg | {:12.4e} Sv | {:12.4f} mm/year '.format ( dDYN_mas_wat , kg2Sv(dDYN_mas_wat) , kg2myear(dDYN_mas_wat )*1000. ))
+echo ( 'Sum wbilo_*  = {:12.3e} kg | {:12.4e} Sv | {:12.4f} mm/year '.format ( ATM_flx_wbilo, kg2Sv(ATM_flx_wbilo), kg2myear(ATM_flx_wbilo )*1000. ))
+echo ( 'E-P          = {:12.3e} kg | {:12.4e} Sv | {:12.4f} mm/year '.format ( ATM_flx_emp  , kg2Sv(ATM_flx_emp ) , kg2myear(ATM_flx_emp  )*1000. ))
+echo ( ' ' )
+prtFlux ( 'Perte eau atm ', ATM_flx_wbilo - dDYN_mas_wat, 'e', True )
+echo ( 'Perte eau atm = {:12.3e} (rel)  '.format ( (ATM_flx_wbilo - dDYN_mas_wat)/dDYN_mas_wat  ) )
+
+echo (' ')
+prtFlux ( 'Perte eau atm', ATM_flx_emp  - dDYN_mas_wat , 'e', True )
+echo ( 'Perte eau atm = {:12.3e} (rel)  '.format ( (ATM_flx_emp-dDYN_mas_wat)/dDYN_mas_wat  ) )
+echo (' ')
+
+echo ( '\n====================================================================================' )
+echo ( f'-- SECHIBA fluxes  -- {Title} ' )
+
+SRF_flx_rain     = SRF_flux_int ( SRF_rain     )
+SRF_flx_evap     = SRF_flux_int ( SRF_evap     )
+SRF_flx_snowf    = SRF_flux_int ( SRF_snowf    )
+SRF_flx_subli    = SRF_flux_int ( SRF_subli    )
+SRF_flx_transpir = SRF_flux_int ( SRF_transpir )
+SRF_flx_emp      = SRF_flux_int ( SRF_emp      )
+
+RUN_flx_torouting  =  RUN_flx_runoff  + RUN_flx_drainage
+RUN_flx_fromrouting = RUN_flx_coastal + RUN_flx_river
+
+SRF_flx_all = SRF_flx_rain + SRF_flx_snowf - SRF_flx_evap - RUN_flx_runoff - RUN_flx_drainage
+
+prtFlux ('rain       ', SRF_flx_rain     , 'f' )
+prtFlux ('evap       ', SRF_flx_evap     , 'f' )
+prtFlux ('snowf      ', SRF_flx_snowf    , 'f' )
+prtFlux ('E-P        ', SRF_flx_emp      , 'f' )
+prtFlux ('subli      ', SRF_flx_subli    , 'f' )
+prtFlux ('transpir   ', SRF_flx_transpir , 'f' )
+prtFlux ('to routing ', RUN_flx_torouting, 'f' )
+prtFlux ('budget     ', SRF_flx_all      , 'f', True )
+
+echo ( '\n------------------------------------------------------------------------------------' )
+echo ( 'Water content in surface ' )
+echo ( 'SRF_mas_wat_beg  = {:12.6e} kg | SRF_mas_wat_end  = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) )
+prtFlux ( 'dMass (water srf)', dSRF_mas_wat, 'e', True)
+echo ( 'dMass (water srf) = {:12.4e} (rel)   '.format ( (SRF_flx_all-dSRF_mas_wat)/dSRF_mas_wat) )
+
+echo ('')
+echo ( '\n====================================================================================' )
+echo ( f'-- RUNOFF fluxes  -- {Title} ' )
+RUN_flx_all = RUN_flx_torouting - RUN_flx_river - RUN_flx_coastal
+prtFlux ('runoff    ', RUN_flx_runoff      , 'f' ) 
+prtFlux ('drainage  ', RUN_flx_drainage    , 'f' ) 
+prtFlux ('run+drain ', RUN_flx_torouting   , 'f' ) 
+prtFlux ('river     ', RUN_flx_river       , 'f' ) 
+prtFlux ('coastal   ', RUN_flx_coastal     , 'f' ) 
+prtFlux ('riv+coa   ', RUN_flx_fromrouting , 'f' ) 
+prtFlux ('budget    ', RUN_flx_all         , 'f' , True)
+
+echo ( '\n------------------------------------------------------------------------------------' )
+echo ( f'Water content in routing  -- {Title} ' )
+echo ( 'RUN_mas_wat_beg  = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_beg, RUN_mas_wat_end) )
+prtFlux ( 'dMass (routing)  ', dRUN_mas_wat+dSRF_mas_lake, 'f', True)
+
+echo ( '\n------------------------------------------------------------------------------------' )
+echo ( f'Water content in routing  -- {Title} ' )
+echo ( 'RUN_mas_wat_beg  = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_beg, RUN_mas_wat_end) )
+prtFlux ( 'dMass (routing)  ', dRUN_mas_wat, 'f', True  )
+
+print ( 'Routing error : {:12.3e} (rel)'.format ( (RUN_flx_all-dRUN_mas_wat)/dRUN_mas_wat ) )
+
+# PRINT *,"routing water Balance ;  before : ",Â water_balance_before," ; after : ",water_balance_after,  &a
+# 1150	            " ; delta : ",Â 100*(water_balance_after-water_balance_before)/(0.5*(water_balance_after+water_balance_before)),"%"
Index: TOOLS/WATER_BUDGET/CPL_waterbudget.py
===================================================================
--- TOOLS/WATER_BUDGET/CPL_waterbudget.py	(revision 6271)
+++ TOOLS/WATER_BUDGET/CPL_waterbudget.py	(revision 6277)
@@ -692,5 +692,5 @@
     RUN_mas_wat_end = ONE_stock_int ( d_RUN_end ['fast_reservoir'] +  d_RUN_end ['slow_reservoir'] +  d_RUN_end ['stream_reservoir'])
 
-if Routing == 'ORCHIDEE' : 
+if Routing == 'SECHIBA' : 
     RUN_mas_wat_beg = ONE_stock_int ( d_SRF_beg['fastres']  + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \
                                     + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres'] )
Index: TOOLS/WATER_BUDGET/OCE_waterbudget.py
===================================================================
--- TOOLS/WATER_BUDGET/OCE_waterbudget.py	(revision 6271)
+++ TOOLS/WATER_BUDGET/OCE_waterbudget.py	(revision 6277)
@@ -21,5 +21,5 @@
 ###
 ## Import system modules
-import sys, os, shutil, subprocess
+import sys, os, shutil, subprocess, platform
 import numpy as np
 import configparser, re
@@ -29,29 +29,21 @@
 config.optionxform = str # To keep capitals
 
-config['Files']  = {}
-config['System'] = {}
-
-##-- Some physical constants
-#-- Earth Radius
-Ra = 40.e6 / (2. * np.pi)
-#-- Gravity
-g = 9.81
-#-- Ice density (kg/m3) in LIM3
-ICE_rho_ice = 917.0
-#-- Snow density (kg/m3) in LIM3
-ICE_rho_sno = 330.0
-#-- Ocean water density (kg/m3) in NEMO
-OCE_rho_liq = 1026.
-#-- Water density in ice pounds in SI3
-ICE_rho_pnd = 1000.
-
 ## Read experiment parameters
-ATM = None ; ORCA = None ; NEMO = None ; OCE_relax = False ; OCE_icb = False ; Coupled = False ; Routing = None
+ATM=None ; ORCA=None ; NEMO=None ; OCE_relax=False ; OCE_icb=False ; Coupled=False ; Routing=None ;  TarRestartPeriod_beg=None ; TarRestartPeriod_end=None ; Comment=None ; Period=None ; Title=None
+
+##
+ARCHIVE=None ; STORAGE = None ; SCRATCHDIR=None ; R_IN=None ; rebuild=None
+TmpDir=None ; FileOut=None ; dir_ATM_his=None ; dir_SRF_his=None ; dir_OCE_his=None ; dir_ICE_his=None ; FileCommon=None
+file_ATM_his=None ; file_SRF_his=None ; file_RUN_his=None ; file_OCE_his=None ;  file_ICE_his=None ; file_OCE_sca=None 
+file_restart_beg=None ; file_restart_end=None ; file_ATM_beg=None ; file_ATM_end=None ; file_DYN_beg=None ; file_DYN_end=None ; file_SRF_beg=None ; file_SRF_end=None
+file_RUN_beg=None ; file_RUN_end=None ; file_OCE_beg=None ; file_ICE_beg=None ; file_OCE_end=None ; file_ICE_end=None
 
 # Arguments passed
 print ( "Name of Python script:", sys.argv[0] )
-IniFile =  sys.argv[1]
+IniFile = sys.argv[1]
 print ("Input file : ", IniFile )
 config.read (IniFile)
+if 'full' in IniFile : FullIniFile = IniFile
+else                 : FullIniFile = 'full_' + IniFile
 
 def setBool (chars) :
@@ -75,10 +67,56 @@
     return setNum
 
-print ('[Experiment]')
-for VarName in config['Experiment'].keys() :
-    locals()[VarName] = config['Experiment'][VarName]
-    locals()[VarName] = setBool (locals()[VarName])
-    locals()[VarName] = setNum  (locals()[VarName])
-    print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) )
+def setNone (chars) :
+    '''Convert specific char string to None if possible'''
+    if type (chars) == str :
+        if chars in ['None', 'NONE', 'none'] : setNone = None
+        else : setNone = chars
+    else : setNone = chars
+    return setNone
+
+## Reading config
+for Section in ['Experiment', 'libIGCM', 'Files', 'Physics' ] :
+    if Section in config.keys() : 
+        print ( f'[{Section}]' )
+        for VarName in config[Section].keys() :
+            locals()[VarName] = config[Section][VarName]
+            locals()[VarName] = setBool (locals()[VarName])
+            locals()[VarName] = setNum  (locals()[VarName])
+            print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) )
+
+if not 'Files' in config.keys() : config['Files'] = {}
+
+def unDefined (char) :
+    if char in globals () :
+        if char == None : return True
+        else : return False
+    else : return True
+
+##-- Some physical constants
+#-- Earth Radius
+if not 'Ra'            in locals () : Ra = 6366197.7236758135
+#-- Gravity
+if not 'Grav'          in locals () : Grav = 9.81
+#-- Ice volumic mass (kg/m3) in LIM3
+if not 'ICE_rho_ice'   in locals () : ICE_rho_ice = 917.0
+#-- Snow volumic mass (kg/m3) in LIM3
+if not 'ICE_rho_sno'   in locals () : ICE_rho_sno = 330.0
+    #-- Water density in ice pounds in SI3
+if not 'ICE_rho_pnd'   in locals () : ICE_rho_pnd = 1000.
+#-- Ocean water volumic mass (kg/m3) in NEMO
+if not 'OCE_rho_liq'   in locals () : OCE_rho_liq = 1026.
+#-- Water volumic mass in atmosphere
+if not 'ATM_rho'       in locals () : ATM_rho = 1000.
+#-- Water volumic mass in surface reservoirs
+if not 'SRF_rho'       in locals () : SRF_rho = 1000.
+#-- Water volumic mass of rivers
+if not 'RUN_rho'       in locals () : RUN_rho = 1000.
+#-- Year length
+if not 'YearLength'    in locals () : YearLength = 365.25 * 24. * 60. * 60.
+
+config['Physics'] = { 'Ra':Ra, 'Grav':Grav, 'ICE_rho_ice':ICE_rho_ice, 'ICE_rho_sno':ICE_rho_sno, 'OCE_rho_liq':OCE_rho_liq, 'ICE_rho_pnd':ICE_rho_pnd,
+                          'ATM_rho':ATM_rho, 'SRF_rho':SRF_rho, 'RUN_rho':RUN_rho}
+        
+
 
 # Where do we run ?
@@ -109,5 +147,18 @@
 if IDRIS :
     raise Exception ("Pour IDRIS : repertoires et chemins a definir") 
-    
+
+config['System'] = {'SysName':SysName, 'NodeName':NodeName, 'Release':Release, 'Version':Version,'Machine':Machine, 'TGCC':TGCC,'IDRIS':IDRIS, 'CPU':CPU,
+                    'Program'  : "Generated by : " + str(sys.argv), 
+                    'HOSTNAME' : platform.node (), 'LOGNAME'  : os.getlogin (),
+                    'Python'   : f'{platform.python_version ()}',
+                    'OS'       : f'{platform.system ()} release : {platform.release ()} hardware : {platform.machine ()}',
+                    'SVN_Author'   : "$Author$", 
+                    'SVN_Date'     : "$Date$",
+                    'SVN_Revision' : "$Revision$",
+                    'SVN_Id'       : "$Id$",
+                    'SVN_HeadURL'  : "$HeadURL$"}
+
+if libIGCM :
+    config['libIGCM'] = {'ARCHIVE':ARCHIVE, 'STORAGE':STORAGE, 'SCRATCHDIR':SCRATCHDIR, 'R_IN':R_IN, 'rebuild':rebuild }
 
 ## Import specific module
@@ -117,11 +168,15 @@
     
 # Output file
-FileOut = f'OCE_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out'
+if FileOut == None : 
+    FileOut = f'OCE_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out'
+    config['Files']['FileOut'] = FileOut
+
 f_out = open ( FileOut, mode = 'w' )
-
+    
 # Function to print to stdout *and* output file
-def echo (string) :
-    print ( string  )
-    f_out.write ( string + '\n' )
+def echo (string, end='\n') :
+    print ( str(string), end=end  )
+    sys.stdout.flush ()
+    f_out.write ( str(string) + end )
     f_out.flush ()
     return None
@@ -146,4 +201,7 @@
 if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE )
 
+echo (' ')
+echo ( f'JobName : {JobName}' )
+echo (Comment)
 echo ( f'Working in TMPDIR : {TmpDir}' )
 
@@ -153,7 +211,11 @@
 if Freq == "MO" : FreqDir =  os.path.join ('Output' , 'MO' )
 if Freq == "SE" : FreqDir =  os.path.join ('Analyse', 'SE' )
-dir_OCE_his = os.path.join ( R_SAVE, "OCE", FreqDir )
-dir_ICE_his = os.path.join ( R_SAVE, "ICE", FreqDir )
-
+if dir_OCE_his == None :
+    dir_OCE_his = os.path.join ( R_SAVE, "OCE", FreqDir )
+    config['Files']['dir_OCE_his'] = dir_OCE_his
+if dir_ICE_his == None :
+    dir_ICE_his = os.path.join ( R_SAVE, "ICE", FreqDir )
+    config['Files']['dir_OCE_his'] = dir_OCE_his
+ 
 echo ( f'The analysis relies on files from the following model output directories : ' )
 echo ( f'{dir_OCE_his}' )
@@ -161,11 +223,27 @@
 
 #-- Files Names
-if Freq == 'MO' : FileCommon = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M'
-if Freq == 'SE' : FileCommon = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M'
-
+if Period == None :
+    if Freq == 'MO' : Period = f'{YearBegin}0101_{YearEnd}1231_1M'
+    if Freq == 'SE' : Period = f'SE_{YearBegin}0101_{YearEnd}1231_1M'
+    config['Files']['Period'] = Period
+if FileCommon == None :
+    FileCommon = f'{JobName}_{Period}'
+    config['Files']['FileCommon'] = FileCommon
+
+if Title == None :
+    Title = f'{JobName} : {Freq} : {YearBegin}-01-01 - {YearEnd}-12-31'
+    config['Files']['Title'] = Title
+        
+        
 echo ('\nOpen history files' )
-file_OCE_his = os.path.join ( dir_OCE_his, f'{FileCommon}_grid_T.nc' )
-file_OCE_sca = os.path.join ( dir_OCE_his, f'{FileCommon}_scalar.nc' )
-file_ICE_his = os.path.join ( dir_ICE_his, f'{FileCommon}_icemod.nc' )
+if file_OCE_his == None :
+    file_OCE_his = os.path.join ( dir_OCE_his, f'{FileCommon}_grid_T.nc' )
+    file_OCE_his = file_OCE_his
+if file_OCE_sca == None :    
+    file_OCE_sca = os.path.join ( dir_OCE_his, f'{FileCommon}_scalar.nc' )
+    config['Files']['file_OCE_sca'] = file_OCE_sca
+if file_ICE_his == None : 
+    file_ICE_his = os.path.join ( dir_ICE_his, f'{FileCommon}_icemod.nc' )
+    config['Files']['file_ICE_his'] = file_ICE_his
 
 d_OCE_his = xr.open_dataset ( file_OCE_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
@@ -191,20 +269,45 @@
 dtime_per_sec.attrs['unit'] = 's'
 
+## Number of years
+NbYear = dtime_sec / YearLength
 #-- Open restart files
-YearRes = YearBegin - 1        # Year of the restart of beginning of simulation
+YearRes = YearBegin - 1              # Year of the restart of beginning of simulation
 YearPre = YearBegin - PackFrequency  # Year to find the tarfile of the restart of beginning of simulation
 
 echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
 
-file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' )
-file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' )
+if TarRestartPeriod_beg == None : 
+    echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
+    TarRestartPeriod_beg = f'{YearPre}0101_{YearRes}1231'
+    config['Files']['TarRestartPeriod_beg'] = TarRestartPeriod_beg
+
+if TarRestartPeriod_end == None : 
+    YearPre = YearBegin - PackFrequency  # Year to find the tarfile of the restart of beginning of simulation
+    echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
+    TarRestartPeriod_end = f'{YearBegin}0101_{YearEnd}1231'
+    config['Files']['TarRestartPeriod_end'] = TarRestartPeriod_end
+
+if file_restart_beg == None :
+    file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{TarRestartPeriod_beg}_restart.tar' )
+    config['Files']['file_restart_beg'] = file_restart_beg
+if file_restart_end == None :
+    file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{TarRestartPeriod_end}_restart.tar' )
+    config['Files']['file_restart_end'] = file_restart_end
 
 echo ( f'{file_restart_beg}' )
 echo ( f'{file_restart_end}' )
 
-file_OCE_beg = f'OCE_{JobName}_{YearRes}1231_restart.nc'
-file_OCE_end = f'OCE_{JobName}_{YearEnd}1231_restart.nc'
-file_ICE_beg = f'ICE_{JobName}_{YearRes}1231_restart_icemod.nc'
-file_ICE_end = f'ICE_{JobName}_{YearEnd}1231_restart_icemod.nc'
+if file_OCE_beg == None : 
+    file_OCE_beg = f'{TmpDir}/OCE_{JobName}_{YearRes}1231_restart.nc'
+    config['Files']['file_OCE_beg'] = file_OCE_beg
+if file_OCE_end == None :
+    file_OCE_end = f'{TmpDir}/OCE_{JobName}_{YearEnd}1231_restart.nc'
+    config['Files']['file_OCE_end'] = file_OCE_end
+if file_ICE_beg == None :
+    file_ICE_beg = f'{TmpDir}/ICE_{JobName}_{YearRes}1231_restart_icemod.nc'
+    config['Files']['file_ICE_beg'] = file_ICE_beg
+if file_ICE_end == None : 
+    file_ICE_end = f'{TmpDir}/ICE_{JobName}_{YearEnd}1231_restart_icemod.nc'
+    config['Files']['file_ICE_end'] = file_ICE_end
 
 echo ( f'{file_OCE_beg}' )
@@ -221,6 +324,7 @@
     return int (ndomain_opa)
 
-if not os.path.exists ( os.path.join (TmpDir, file_OCE_beg) ) :
-    echo ( 'Extracting '+ os.path.join (TmpDir, file_OCE_beg) )
+if not os.path.exists ( file_OCE_beg) :
+    echo ( f'Extracting {file_OCE_beg}' )
+    base_file_OCE_beg = os.path.basename (file_OCE_beg)
     if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart_0000.nc') ) :
         command =  f'cd {TmpDirOCE} ; tar xf {file_restart_beg}  OCE_{JobName}_{YearRes}1231_restart_*.nc'
@@ -229,10 +333,12 @@
     echo ('extract ndomain' )
     ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearRes}1231_restart') )
-    command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearRes}1231_restart {ndomain_opa} ; mv {file_OCE_beg} {TmpDir}'
+    command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearRes}1231_restart {ndomain_opa} ; mv {base_file_OCE_beg} {TmpDir}'
     echo ( command )
     os.system ( command )
     echo ( f'Rebuild done : {file_OCE_beg}')
     
-if not os.path.exists ( os.path.join (TmpDir, file_OCE_end) ) :
+if not os.path.exists ( file_OCE_end) :
+    echo ( f'Extracting {file_OCE_end}' )
+    base_file_OCE_end = os.path.basename (file_OCE_end)
     if not os.path.exists ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart_0000.nc') ):
         command =  f'cd {TmpDirOCE} ; tar xf {file_restart_end}  OCE_{JobName}_{YearEnd}1231_restart_*.nc'
@@ -241,10 +347,12 @@
     echo ('extract ndomain' )
     ndomain_opa = get_ndomain ( os.path.join (TmpDirOCE, f'OCE_{JobName}_{YearEnd}1231_restart') )
-    command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearEnd}1231_restart {ndomain_opa} ; mv {file_OCE_end} {TmpDir}'
+    command = f'cd {TmpDirOCE} ; {rebuild} OCE_{JobName}_{YearEnd}1231_restart {ndomain_opa} ; mv {base_file_OCE_end} {TmpDir}'
     echo ( command )
     os.system ( command )
     echo ( f'Rebuild done : {file_OCE_end}')
 
-if not os.path.exists ( os.path.join (TmpDir, file_ICE_beg) ) :
+if not os.path.exists ( file_ICE_beg) :
+    echo ( f'Extracting {file_ICE_beg}' )
+    base_file_ICE_beg = os.path.basename (file_ICE_beg)
     if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod_0000.nc') ):
         command =  f'cd {TmpDirICE} ; tar xf {file_restart_beg}  ICE_{JobName}_{YearRes}1231_restart_icemod_*.nc'
@@ -253,10 +361,12 @@
     echo ('extract ndomain' )
     ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') )
-    command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearRes}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_beg} {TmpDir} '
+    command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearRes}1231_restart_icemod {ndomain_opa} ; mv {base_file_ICE_beg} {TmpDir} '
     echo ( command )
     os.system ( command )
     echo ( f'Rebuild done : {file_OCE_beg}')
     
-if not os.path.exists ( os.path.join (TmpDir, file_ICE_end) ) :
+if not os.path.exists ( file_ICE_end ) :
+    echo ( f'Extracting {file_ICE_end}' )
+    base_file_ICE_end = os.path.basename (file_ICE_end)
     if not os.path.exists ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearEnd}1231_restart_icemod_0000.nc') ):
         command =  f'cd {TmpDirICE} ; tar xf {file_restart_end} ICE_{JobName}_{YearEnd}1231_restart_icemod_*.nc'
@@ -265,5 +375,5 @@
     echo ('extract ndomain' )
     ndomain_opa = get_ndomain ( os.path.join (TmpDirICE, f'ICE_{JobName}_{YearRes}1231_restart_icemod') )
-    command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearEnd}1231_restart_icemod {ndomain_opa} ; mv {file_ICE_end} {TmpDir}'
+    command = f'cd {TmpDirICE} ; {rebuild} ICE_{JobName}_{YearEnd}1231_restart_icemod {ndomain_opa} ; mv {base_file_ICE_end} {TmpDir}'
     echo ( command )
     os.system ( command )
@@ -282,4 +392,32 @@
     d_ICE_end = xr.open_dataset ( os.path.join (TmpDir, file_ICE_end), decode_times=False, decode_cf=True, drop_variables=['y', 'x']).squeeze()
 
+##
+config_out = open (FullIniFile, 'w')
+config.write (config_out )
+config_out.close ()
+
+    
+def kg2Sv  (val, rho=OCE_rho_liq) :
+    '''From kg to Sverdrup'''
+    return val/dtime_sec*1.0e-6/rho
+
+def kg2myear (val, rho=OCE_rho_liq) :
+    '''From kg to m/year'''
+    return val/OCE_aire_tot/rho/NbYear
+
+def var2prt (var, small=False) :
+    if small :  return var , kg2Sv(var)*1000., kg2myear(var)*1000.
+    else     :  return var , kg2Sv(var)      , kg2myear(var)
+
+def prtFlux (Desc, var, Form='F', small=False) :
+    if small :
+        if Form in ['f', 'F'] : ff=" {:12.4e} kg | {:12.4f} mSv | {:12.4f} mm/year "
+        if Form in ['e', 'E'] : ff=" {:12.4e} kg | {:12.4e} mSv | {:12.4e} mm/year "
+    else :
+        if Form in ['f', 'F'] : ff=" {:12.4e} kg | {:12.4f} Sv  | {:12.4f} m/year  "
+        if Form in ['e', 'E'] : ff=" {:12.4e} kg | {:12.4e} Sv  | {:12.4e} m/year  "
+    echo ( (' {:>15} = ' +ff).format (Desc, *var2prt(var, small) ) )
+    return None
+
 # Get mask and surfaces
 sos = d_OCE_his ['sos'][0].squeeze()
@@ -300,5 +438,5 @@
 def ONE_stock_int (stock) :
     '''Sum stock'''
-    ONE_stock_int = np.sum (  np.sort ( (stock * OCE_aire).to_masked_array().ravel()) )
+    ONE_stock_int = np.sum (  np.sort ( (stock ).to_masked_array().ravel()) )
     return ONE_stock_int
 
@@ -306,4 +444,9 @@
     '''Integrate flux on oce grid'''
     OCE_flux_int = np.sum (  np.sort ( (flux * OCE_aire * dtime_per_sec).to_masked_array().ravel()) )
+    return OCE_flux_int
+
+def ONE_flux_int (flux) :
+    '''Integrate flux on oce grid'''
+    OCE_flux_int = np.sum (  np.sort ( (flux * dtime_per_sec).to_masked_array().ravel()) )
     return OCE_flux_int
 
@@ -343,13 +486,12 @@
 echo ( 'dOCE vol    = {:12.3e} m^3'.format ( dOCE_vol_wat) )
 echo ( 'dOCE ssh    = {:12.3e} m  '.format ( dOCE_vol_wat/OCE_aire_tot) )
-echo ( 'dOCE mass   = {:12.3e} kg '.format ( dOCE_mas_wat) )
-echo ( 'dOCE mass   = {:12.3e} Sv '.format ( dOCE_mas_wat/dtime_sec*1E-9) )
+prtFlux ( 'dOCE mass ', dOCE_mas_wat, 'e' )
 
 if NEMO == 3.6 :
     echo ( 'dOCE e3tn   vol    = {:12.3e} m^3'.format ( dOCE_e3tn_vol) )
-    echo ( 'dOCE e3tn   mass   = {:12.3e} kg '.format ( dOCE_e3tn_mas) )
+    prtFlux ( 'dOCE e3tn   mass', dOCE_e3tn_mas, 'e' )
 
 ## Glace et neige
-if NEMO == 3.6 :
+if NEMO == 3.6 :        
     ICE_ice_beg = d_ICE_beg['v_i_htc1']+d_ICE_beg['v_i_htc2']+d_ICE_beg['v_i_htc3']+d_ICE_beg['v_i_htc4']+d_ICE_beg['v_i_htc5']
     ICE_ice_end = d_ICE_end['v_i_htc1']+d_ICE_end['v_i_htc2']+d_ICE_end['v_i_htc3']+d_ICE_end['v_i_htc4']+d_ICE_end['v_i_htc5']
@@ -358,9 +500,5 @@
     ICE_sno_end = d_ICE_end['v_s_htc1']+d_ICE_end['v_s_htc2']+d_ICE_end['v_s_htc3']+d_ICE_end['v_s_htc4']+d_ICE_end['v_s_htc5']
     
-    ICE_pnd_beg = 0.0
-    ICE_pnd_end = 0.0
-    
-    ICE_fzl_beg = 0.0
-    ICE_fzl_end = 0.0
+    ICE_pnd_beg = 0.0 ; ICE_pnd_end = 0.0 ; ICE_fzl_beg = 0.0 ; ICE_fzl_end = 0.0
 
     ICE_mas_wat_beg = ICE_ice_beg*ICE_rho_ice + ICE_sno_beg*ICE_rho_sno
@@ -424,7 +562,5 @@
 echo ( '\n------------------------------------------------------------')
 echo ( 'Variation du contenu en eau ocean + glace ' )
-echo ( 'dMass (ocean)   = {:12.6e} kg '.format(dSEA_mas_wat) )
-echo ( 'dVol  (ocean)   = {:12.3e} Sv '.format(dSEA_mas_wat/dtime_sec*1E-9) )
-echo ( 'dVol  (ocean)   = {:12.3e} m  '.format(dSEA_mas_wat*1E-3/OCE_aire_tot) )
+prtFlux ( 'dMass (ocean)', dSEA_mas_wat, 'e', True )
 
 
@@ -504,32 +640,32 @@
 
 echo ('\n-- Fields:' ) 
-echo ('OCE+ICE budget {:12.3e} (kg) {:12.3e} (Sv) '.format ( OCE_mas_all       , OCE_mas_all        / dtime_sec*1E-9 ))
-echo ('  EMPMR        {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_empmr     , OCE_mas_empmr      / dtime_sec*1E-9 ))
-echo ('  WFOB         {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_wfob      , OCE_mas_wfob       / dtime_sec*1E-9 ))
-echo ('  EMP_OCE      {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_emp_oce   , OCE_mas_emp_oce    / dtime_sec*1E-9 ))
-echo ('  EMP_ICE      {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_emp_ice   , OCE_mas_emp_ice    / dtime_sec*1E-9 ))
-echo ('  EMP          {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_emp       , OCE_mas_emp        / dtime_sec*1E-9 ))
-echo ('  ICEBERG      {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_iceberg   , OCE_mas_iceberg    / dtime_sec*1E-9 ))
-echo ('  ICESHELF     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_iceshelf  , OCE_mas_iceshelf   / dtime_sec*1E-9 ))
-echo ('  CALVING      {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_calving   , OCE_mas_calving    / dtime_sec*1E-9 ))
-echo ('  FRIVER       {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_friver    , OCE_mas_friver     / dtime_sec*1E-9 ))  
-echo ('  RUNOFFS      {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_runoffs   , OCE_mas_runoffs    / dtime_sec*1E-9 ))
-echo ('  WFXICE       {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_wfxice    , OCE_mas_wfxice     / dtime_sec*1E-9 ))
-echo ('  WFXSNW       {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_wfxsnw    , OCE_mas_wfxsnw     / dtime_sec*1E-9 ))
-echo ('  WFXSUB       {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_wfxsub    , OCE_mas_wfxsub     / dtime_sec*1E-9 ))
-echo ('  WFXPND       {:12.3e} (kg) {:12.3f} (Sv) '.format ( ICE_mas_wfxpnd    , ICE_mas_wfxpnd     / dtime_sec*1E-9 ))
-echo ('  WFXSNW_SUB   {:12.3e} (kg) {:12.3f} (Sv) '.format ( ICE_mas_wfxsnw_sub, ICE_mas_wfxsnw_sub / dtime_sec*1E-9 ))
-echo ('  WFXSNW_PRE   {:12.3e} (kg) {:12.3f} (Sv) '.format ( ICE_mas_wfxsnw_pre, ICE_mas_wfxsnw_pre / dtime_sec*1E-9 ))
-echo ('  WFXSUB_ERR   {:12.3e} (kg) {:12.3e} (Sv) '.format ( ICE_mas_wfxsub_err, ICE_mas_wfxsub_err / dtime_sec*1E-9 ))
-echo ('  EVAP_OCE     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_evap_oce  , OCE_mas_evap_oce   / dtime_sec*1E-9 ))
-echo ('  EVAP_ICE     {:12.3e} (kg) {:12.3f} (Sv) '.format ( ICE_mas_evap_ice  , ICE_mas_evap_ice   / dtime_sec*1E-9 ))
-echo ('  SNOW_OCE     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_snow_oce  , OCE_mas_snow_oce   / dtime_sec*1E-9 ))
-echo ('  SNOW_ICE     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_snow_ice  , OCE_mas_snow_ice   / dtime_sec*1E-9 ))
-echo ('  RAIN         {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_rain      , OCE_mas_rain       / dtime_sec*1E-9 ))
-echo ('  FWB          {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_fwb       , OCE_mas_fwb        / dtime_sec*1E-9 ))
-echo ('  SSR          {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_ssr       , OCE_mas_ssr        / dtime_sec*1E-9 ))
-echo ('  WFCORR       {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_wfcorr    , OCE_mas_wfcorr     / dtime_sec*1E-9 ))
-echo ('  BERG_ICB     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_berg_icb  , OCE_mas_berg_icb   / dtime_sec*1E-9 ))
-echo ('  CALV_ICB     {:12.3e} (kg) {:12.3f} (Sv) '.format ( OCE_mas_calv_icb  , OCE_mas_calv_icb   / dtime_sec*1E-9 ))
+prtFlux ('OCE+ICE budget ', OCE_mas_all       , 'e', True)
+prtFlux ('  EMPMR        ', OCE_mas_empmr     , 'e', True)
+prtFlux ('  WFOB         ', OCE_mas_wfob      , 'e', True)
+prtFlux ('  EMP_OCE      ', OCE_mas_emp_oce   , 'e', True)
+prtFlux ('  EMP_ICE      ', OCE_mas_emp_ice   , 'e', True)
+prtFlux ('  EMP          ', OCE_mas_emp       , 'e', True)
+prtFlux ('  ICEBERG      ', OCE_mas_iceberg   , 'e', True)
+prtFlux ('  ICESHELF     ', OCE_mas_iceshelf  , 'e', True)
+prtFlux ('  CALVING      ', OCE_mas_calving   , 'e', True)
+prtFlux ('  FRIVER       ', OCE_mas_friver    , 'e', True)  
+prtFlux ('  RUNOFFS      ', OCE_mas_runoffs   , 'e', True)
+prtFlux ('  WFXICE       ', OCE_mas_wfxice    , 'e', True)
+prtFlux ('  WFXSNW       ', OCE_mas_wfxsnw    , 'e', True)
+prtFlux ('  WFXSUB       ', OCE_mas_wfxsub    , 'e', True)
+prtFlux ('  WFXPND       ', ICE_mas_wfxpnd    , 'e', True)
+prtFlux ('  WFXSNW_SUB   ', ICE_mas_wfxsnw_sub, 'e', True)
+prtFlux ('  WFXSNW_PRE   ', ICE_mas_wfxsnw_pre, 'e', True)
+prtFlux ('  WFXSUB_ERR   ', ICE_mas_wfxsub_err, 'e', True)
+prtFlux ('  EVAP_OCE     ', OCE_mas_evap_oce  , 'e' )
+prtFlux ('  EVAP_ICE     ', ICE_mas_evap_ice  , 'e', True)
+prtFlux ('  SNOW_OCE     ', OCE_mas_snow_oce  , 'e', True)
+prtFlux ('  SNOW_ICE     ', OCE_mas_snow_ice  , 'e', True)
+prtFlux ('  RAIN         ', OCE_mas_rain      , 'e' )
+prtFlux ('  FWB          ', OCE_mas_fwb       , 'e', True)
+prtFlux ('  SSR          ', OCE_mas_ssr       , 'e', True)
+prtFlux ('  WFCORR       ', OCE_mas_wfcorr    , 'e', True)
+prtFlux ('  BERG_ICB     ', OCE_mas_berg_icb  , 'e', True)
+prtFlux ('  CALV_ICB     ', OCE_mas_calv_icb  , 'e', True)
 
 echo     ('\n===>  Comparing ===>' ) 
