source: TOOLS/WATER_BUDGET/ATM_waterbudget.py @ 6271

Last change on this file since 6271 was 6271, checked in by omamce, 20 months ago

O.M. : Water Bugget

Various improvments
OCE budget is OK
Use .ini file as input

  • Property svn:executable set to *
  • Property svn:keywords set to Date Revision HeadURL Author Id
File size: 38.9 KB
Line 
1#!/usr/bin/env python3
2###
3### Script to check water conservation in the IPSL coupled model
4###
5##  Warning, to install, configure, run, use any of included software or
6##  to read the associated documentation you'll need at least one (1)
7##  brain in a reasonably working order. Lack of this implement will
8##  void any warranties (either express or implied).  Authors assumes
9##  no responsability for errors, omissions, data loss, or any other
10##  consequences caused directly or indirectly by the usage of his
11##  software by incorrectly or partially configured personal
12##
13##
14## SVN information
15#  $Author$
16#  $Date$
17#  $Revision$
18#  $Id$
19#  $HeadURL$
20
21###
22## Import system modules
23import sys, os, shutil, subprocess
24import numpy as np
25import configparser, re
26
27## Creates parser
28config = configparser.ConfigParser()
29config.optionxform = str # To keep capitals
30
31config['Files']  = {}
32config['System'] = {}
33
34##-- Some physical constants
35#-- Earth Radius
36Ra = 6366197.7236758135
37#-- Gravity
38Grav = 9.81
39#-- Ice volumic mass (kg/m3) in LIM3
40ICE_rho_ice = 917.0
41#-- Snow volumic mass (kg/m3) in LIM3
42ICE_rho_sno = 330.0
43#-- Ocean water volumic mass (kg/m3) in NEMO
44OCE_rho_liq = 1026.
45#-- Water volumic mass in atmosphere
46ATM_rho = 1.0e3
47#-- Water volumic mass in surface reservoirs
48SRF_rho = 1.0e3
49#-- Water volumic mass of rivers
50RUN_rho = 1.0e3
51
52## Read experiment parameters
53ATM = None ; ORCA = None ; NEMO = None ; OCE_relax = False ; OCE_icb = False ; Coupled = False ; Routing = None
54
55# Arguments passed
56print ( "Name of Python script:", sys.argv[0] )
57IniFile =  sys.argv[1]
58print ("Input file : ", IniFile )
59config.read (IniFile)
60
61def setBool (chars) :
62    '''Convert specific char string in boolean if possible'''
63    setBool = chars
64    for key in configparser.ConfigParser.BOOLEAN_STATES.keys () :
65        if chars.lower() == key : setBool = configparser.ConfigParser.BOOLEAN_STATES[key]
66    return setBool
67
68def setNum (chars) :
69    '''Convert specific char string in integer or real if possible'''
70    if type (chars) == str :
71        realnum = re.compile ("^[-+]?[0-9]*\.?[0-9]+(e[-+]?[0-9]+)?$")
72        isReal = realnum.match(chars.strip()) != None
73        isInt  = chars.strip().isdigit()
74        if isReal :
75            if isInt : setNum = int   (chars)
76            else     : setNum = float (chars)
77        else : setNum = chars
78    else : setNum = chars
79    return setNum
80
81print ('[Experiment]')
82for VarName in config['Experiment'].keys() :
83    locals()[VarName] = config['Experiment'][VarName]
84    locals()[VarName] = setBool (locals()[VarName])
85    locals()[VarName] = setNum  (locals()[VarName])
86    print ( '{:25} set to : {:}'.format (VarName, locals()[VarName]) )
87
88# ###
89ICO  = ( 'ICO' in ATM )
90LMDZ = ( 'LMD' in ATM )
91   
92###
93## Import system modules
94import sys, os, shutil, subprocess
95import configparser, re
96
97config = configparser.ConfigParser()
98config['Files'] = {}
99
100# Where do we run ?
101SysName, NodeName, Release, Version, Machine = os.uname()
102TGCC  = ( 'irene'   in NodeName )
103IDRIS = ( 'jeanzay' in NodeName )
104
105## Set site specific libIGCM directories, and other specific stuff
106if TGCC :
107    CPU = subprocess.getoutput ( 'lscpu | grep "Model name"' )
108    if "Intel(R) Xeon(R) Platinum" in CPU : Machine = 'irene'
109    if "AMD"                       in CPU : Machine = 'irene-amd'
110       
111    ARCHIVE     = subprocess.getoutput ( f'ccc_home --cccstore   -d {Project} -u {User}' )
112    STORAGE     = subprocess.getoutput ( f'ccc_home --cccwork    -d {Project} -u {User}' )
113    SCRATCHDIR  = subprocess.getoutput ( f'ccc_home --cccscratch -d {Project} -u {User}' )
114    R_IN        = os.path.join ( subprocess.getoutput ( f'ccc_home --cccwork -d igcmg -u igcmg' ), 'IGCM')
115    rebuild     = os.path.join ( subprocess.getoutput ( f'ccc_home --ccchome -d igcmg -u igcmg' ), 'Tools', Machine, 'rebuild_nemo', 'bin', 'rebuild_nemo' )
116
117    ## Specific to run at TGCC.
118    # Needed before importing a NetCDF library (netCDF4, xarray, cmds, etc ...)
119    import mpi4py
120    mpi4py.rc.initialize = False
121       
122    ## Creates output directory
123    #TmpDir = os.path.join ( subprocess.getoutput ( 'ccc_home --cccscratch' ), f'WATER_{JobName}_{YearBegin}_{YearEnd}' )
124    TmpDir = os.path.join ( '/ccc/scratch/cont003/drf/p86mart', f'WATER_{JobName}_{YearBegin}_{YearEnd}' )
125
126if IDRIS :
127    raise Exception ("Pour IDRIS : repertoires et chemins a definir") 
128
129## Import specific module
130import nemo, lmdz
131## Now import needed scientific modules
132import xarray as xr
133
134config['Files'][TmpDir] = TmpDir
135
136# Output file
137FileOut = f'ATM_waterbudget_{JobName}_{YearBegin}_{YearEnd}.out'
138f_out = open ( FileOut, mode = 'w' )
139
140# Function to print to stdout *and* output file
141def echo (string, end='\n') :
142    print ( string, end=end  )
143    sys.stdout.flush ()
144    f_out.write ( string + end )
145    f_out.flush ()
146    return None
147   
148## Set libIGCM directories
149R_OUT       = os.path.join ( ARCHIVE   , 'IGCM_OUT')
150R_BUF       = os.path.join ( SCRATCHDIR, 'IGCM_OUT')
151
152L_EXP = os.path.join (TagName, SpaceName, ExperimentName, JobName)
153R_SAVE      = os.path.join ( R_OUT, L_EXP )
154R_BUFR      = os.path.join ( R_BUF, L_EXP )
155POST_DIR    = os.path.join ( R_BUF, L_EXP, 'Out' )
156REBUILD_DIR = os.path.join ( R_BUF, L_EXP, 'REBUILD' )
157R_BUF_KSH   = os.path.join ( R_BUFR, 'Out' )
158R_FIGR      = os.path.join ( STORAGE, 'IGCM_OUT', L_EXP )
159
160#if os.path.isdir (TmpDir) : shutil.rmtree ( TmpDir )
161if not os.path.isdir (TmpDir) : os.mkdir (TmpDir)
162TmpDirOCE = os.path.join (TmpDir, 'OCE')
163TmpDirICE = os.path.join (TmpDir, 'ICE')
164if not os.path.exists (TmpDirOCE) : os.mkdir (TmpDirOCE )
165if not os.path.exists (TmpDirICE) : os.mkdir (TmpDirICE )
166
167echo ( f'Working in TMPDIR : {TmpDir}' )
168
169echo ( f'\nDealing with {L_EXP}' )
170
171#-- Model output directories
172if Freq == "MO" : FreqDir = os.path.join ('Output' , 'MO' )
173if Freq == "SE" : FreqDir = os.path.join ('Analyse', 'SE' )
174dir_ATM_his = os.path.join ( R_SAVE, "ATM", FreqDir )
175dir_SRF_his = os.path.join ( R_SAVE, "SRF", FreqDir )
176
177echo ( f'The analysis relies on files from the following model output directories : ' )
178echo ( f'{dir_ATM_his}' )
179echo ( f'{dir_SRF_his}' )
180
181#-- Files Names
182if Freq == 'MO' : FileCommon = f'{JobName}_{YearBegin}0101_{YearEnd}1231_1M'
183if Freq == 'SE' : FileCommon = f'{JobName}_SE_{YearBegin}0101_{YearEnd}1231_1M'
184
185echo ('\nOpen history files' )
186file_ATM_his = os.path.join (  dir_ATM_his, f'{FileCommon}_histmth.nc' )
187file_SRF_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
188if Routing == 'ORCHIDEE'  :
189    file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
190if Routing == 'SIMPLE' :
191    file_RUN_his = os.path.join (  dir_SRF_his, f'{FileCommon}_sechiba_history.nc' )
192
193d_ATM_his = xr.open_dataset ( file_ATM_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
194d_SRF_his = xr.open_dataset ( file_SRF_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
195if Routing == 'ORCHIDEE' :
196    d_RUN_his = d_SRF_his
197if Routing == 'SIMPLE' : 
198    d_RUN_his = xr.open_dataset ( file_RUN_his, use_cftime=True, decode_times=True, decode_cf=True ).squeeze()
199
200echo ( file_ATM_his )
201echo ( file_SRF_his )
202echo ( file_RUN_his )
203
204
205config['Files']['file_ATM_his'] = file_ATM_his
206config['Files']['file_SRF_his'] = file_SRF_his
207config['Files']['file_RUN_his'] = file_SRF_his
208
209## Compute run length
210dtime = ( d_ATM_his.time_counter_bounds.max() - d_ATM_his.time_counter_bounds.min() )
211echo ('\nRun length : {:8.2f} days'.format ( (dtime/np.timedelta64(1, "D")).values ) )
212dtime_sec = (dtime/np.timedelta64(1, "s")).values.item() # Convert in seconds
213
214## Compute length of each period
215dtime_per = (d_ATM_his.time_counter_bounds[:,-1] -  d_ATM_his.time_counter_bounds[:,0] )
216echo ('\nPeriods lengths (days) : {:} days'.format ( (dtime_per/np.timedelta64(1, "D")).values ) )
217dtime_per_sec = (dtime_per/np.timedelta64(1, "s")).values # In seconds
218dtime_per_sec = xr.DataArray (dtime_per_sec, dims=["time_counter", ], coords=[d_ATM_his.time_counter,] )
219
220#-- Open restart files
221YearRes = YearBegin - 1              # Year of the restart of beginning of simulation
222YearPre = YearBegin - PackFrequency  # Year to find the tarfile of the restart of beginning of simulation
223
224echo (f'Restart dates - Start : {YearRes}-12-31  /  End : {YearEnd}-12-31 ')
225
226file_restart_beg = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearPre}0101_{YearRes}1231_restart.tar' )
227file_restart_end = os.path.join ( R_SAVE, 'RESTART', f'{JobName}_{YearBegin}0101_{YearEnd}1231_restart.tar' )
228
229echo ( f'{file_restart_beg}' )
230echo ( f'{file_restart_end}' )
231
232file_ATM_beg = f'ATM_{JobName}_{YearRes}1231_restartphy.nc'
233file_ATM_end = f'ATM_{JobName}_{YearEnd}1231_restartphy.nc'
234if LMDZ :
235    file_DYN_beg = f'ATM_{JobName}_{YearRes}1231_restart.nc'
236    file_DYN_end = f'ATM_{JobName}_{YearEnd}1231_restart.nc'
237if ICO :
238    file_DYN_beg = f'ICO_{JobName}_{YearRes}1231_restart.nc'
239    file_DYN_end = f'ICO_{JobName}_{YearEnd}1231_restart.nc'
240file_SRF_beg = f'SRF_{JobName}_{YearRes}1231_sechiba_rest.nc'
241file_SRF_end = f'SRF_{JobName}_{YearEnd}1231_sechiba_rest.nc'
242liste_beg = [file_ATM_beg, file_DYN_beg, file_SRF_beg, ]
243liste_end = [file_ATM_end, file_DYN_end, file_SRF_end, ]
244echo ( f'{file_ATM_beg}')
245echo ( f'{file_ATM_end}')
246echo ( f'{file_SRF_beg}')
247echo ( f'{file_SRF_end}')
248
249if Routing == 'SIMPLE' : 
250    file_RUN_beg = f'SRF_{JobName}_{YearRes}1231_routing_restart.nc'
251    file_RUN_end = f'SRF_{JobName}_{YearEnd}1231_routing_restart.nc'
252    liste_beg.append ( file_RUN_beg )
253    liste_end.append ( file_RUN_end )
254    echo ( f'{file_RUN_beg}')
255    echo ( f'{file_RUN_end}')
256
257echo ('\nExtract restart files from tar : ATM, ICO and SRF')
258for resFile in liste_beg :
259    if not os.path.exists ( os.path.join (TmpDir, resFile) ) :
260        command =  f'cd {TmpDir} ; tar xf {file_restart_beg} {resFile}'
261        echo ( command )
262        os.system ( command )
263       
264for resFile in liste_end :
265    if not os.path.exists ( os.path.join (TmpDir, resFile) ) :
266        command =  f'cd {TmpDir} ; tar xf {file_restart_end} {resFile}'
267        echo ( command )
268        os.system ( command )
269
270config['Files']['file_ATM_beg'] = file_ATM_beg
271config['Files']['file_ATM_end'] = file_ATM_end
272config['Files']['file_SRF_beg'] = file_SRF_beg
273config['Files']['file_SRF_end'] = file_SRF_end
274if Routing == 'SIMPLE' : 
275    config['Files']['file_RUN_beg'] = file_RUN_beg
276    config['Files']['file_RUN_end'] = file_RUN_end
277config['Files']['file_DYN_beg'] = file_DYN_beg
278config['Files']['file_DYN_end'] = file_DYN_end
279       
280echo ('\nOpening ATM SRF and ICO restart files')
281d_ATM_beg = xr.open_dataset ( os.path.join (TmpDir, file_ATM_beg), decode_times=False, decode_cf=True).squeeze()
282d_ATM_end = xr.open_dataset ( os.path.join (TmpDir, file_ATM_end), decode_times=False, decode_cf=True).squeeze()
283d_SRF_beg = xr.open_dataset ( os.path.join (TmpDir, file_SRF_beg), decode_times=False, decode_cf=True).squeeze()
284d_SRF_end = xr.open_dataset ( os.path.join (TmpDir, file_SRF_end), decode_times=False, decode_cf=True).squeeze()
285d_DYN_beg = xr.open_dataset ( os.path.join (TmpDir, file_DYN_beg), decode_times=False, decode_cf=True).squeeze()
286d_DYN_end = xr.open_dataset ( os.path.join (TmpDir, file_DYN_end), decode_times=False, decode_cf=True).squeeze()
287
288for var in d_SRF_beg.variables :
289    d_SRF_beg[var] = d_SRF_beg[var].where (  d_SRF_beg[var]<1.e20, 0.)
290    d_SRF_end[var] = d_SRF_end[var].where (  d_SRF_end[var]<1.e20, 0.)
291
292if ICO :
293    d_RUN_beg = xr.open_dataset ( os.path.join (TmpDir, file_RUN_beg), decode_times=False, decode_cf=True).squeeze()
294    d_RUN_end = xr.open_dataset ( os.path.join (TmpDir, file_RUN_end), decode_times=False, decode_cf=True).squeeze()
295   
296echo ( file_ATM_beg )
297echo ( file_ATM_end )
298echo ( file_DYN_beg )
299echo ( file_DYN_end )
300echo ( file_SRF_beg )
301echo ( file_SRF_end )
302if Routing == 'SIMPLE' :
303    echo ( file_RUN_beg )
304    echo ( file_RUN_end )
305
306def ATM_stock_int (stock) :
307    '''Integrate stock on atmosphere grid'''
308    ATM_stock_int  = np.sum (  np.sort ( (stock * DYN_aire).to_masked_array().ravel()) )
309    return ATM_stock_int
310
311def ATM_flux_int (flux) :
312    '''Integrate flux on atmosphere grid'''
313    ATM_stock_int  = np.sum (  np.sort ( (flux * dtime_per_sec * ATM_aire).to_masked_array().ravel()) )
314    return ATM_stock_int
315
316def ONE_stock_int (stock) :
317    '''Sum stock '''
318    ONE_stock_int  = np.sum (  np.sort ( (stock).to_masked_array().ravel()) )
319    return ONE_stock_int
320
321def ONE_flux_int (flux) :
322    '''Sum flux '''
323    ONE_flux_int  = np.sum (  np.sort ( (flux * dtime_per_sec ).to_masked_array().ravel()) )
324    return ONE_flux_int
325   
326# ATM grid with cell surfaces
327if ICO :
328    jpja, jpia = d_ATM_his['aire'][0].shape   
329    file_ATM_aire = os.path.join ( R_IN, 'ATM', 'GRID', f'aire_{ATM}_to_{jpia}x{jpja}.nc' )
330    config['Files']['file_ATM_aire'] = file_ATM_aire
331    echo ('Aire sur grille reguliere :', file_ATM_aire)
332    d_ATM_aire = xr.open_dataset ( file_ATM_aire, decode_times=False ).squeeze()
333    ATM_aire = lmdz.geo2point ( d_ATM_aire ['aire'].squeeze(), cumulPoles=True )
334    ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] )
335    ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] + d_ATM_his ['fract_lic'][0] )
336    SRF_aire = lmdz.geo2point ( d_SRF_his ['Areas'] * d_SRF_his ['Contfrac'] )
337   
338if LMDZ :
339    ATM_aire = lmdz.geo2point ( d_ATM_his ['aire'][0], cumulPoles=True )
340    ATM_fsea = lmdz.geo2point ( d_ATM_his ['fract_oce'][0] + d_ATM_his ['fract_sic'][0] )
341    ATM_flnd = lmdz.geo2point ( d_ATM_his ['fract_ter'][0] )
342    SRF_aire = lmdz.geo2point ( d_SRF_his['Areas'] * d_SRF_his['Contfrac'] )
343
344SRF_aire = SRF_aire.where ( SRF_aire < 1E15, 0.)
345
346if ICO :
347    # Area on icosahedron grid
348    file_DYN_aire = os.path.join ( R_IN, 'ATM', 'GRID', ATM+'_grid.nc' )
349    d_DYN_aire = xr.open_dataset ( file_DYN_aire, decode_times=False).squeeze()
350    d_DYN_aire = d_DYN_aire.rename ( {'cell':'cell_mesh'} )
351    DYN_aire   = d_DYN_aire['aire']
352
353    DYN_fsea = d_DYN_aire ['fract_oce'] + d_DYN_aire ['fract_sic']
354    DYN_flnd = 1.0 - DYN_fsea
355   
356if LMDZ :
357    DYN_aire = ATM_aire
358    DYN_fsea = ATM_fsea
359    DYN_flnd = ATM_flnd
360
361#if LMDZ :
362#    d_ATM_beg = d_ATM_beg.assign ( coords={'lon':d_ATM_beg.lon*180./np.pi} )
363
364ATM_aire_sea     = ATM_aire * ATM_fsea
365ATM_aire_sea_tot = ONE_stock_int ( ATM_aire_sea )
366
367ATM_aire_tot     = ONE_stock_int (ATM_aire)
368ATM_aire_sea_tot = ONE_stock_int (ATM_aire*ATM_fsea)
369
370
371echo ( 'Aire atmosphere/4pi R^2 : {:12.5f}'.format(ATM_aire_tot/(Ra*Ra*4*np.pi) ) )
372
373if (  np.abs (ATM_aire_tot/(Ra*Ra*4*np.pi) - 1.0) > 0.01 ) :
374    raise Exception ('Erreur surface interpolee sur grille reguliere')
375
376echo ( '\n------------------------------------------------------------------------------------' )
377echo ( '-- ATM changes in stores ' )
378
379#-- Change in precipitable water from the atmosphere daily and monthly files
380#-- Compute sum weighted by gridcell area (kg/m2) then convert to Sv
381
382# ATM vertical grid
383ATM_Ahyb = d_ATM_his['Ahyb'].squeeze()
384ATM_Bhyb = d_ATM_his['Bhyb'].squeeze()
385
386# Surface pressure
387if ICO : 
388    DYN_ps_beg = d_DYN_beg['ps']
389    DYN_ps_end = d_DYN_end['ps']
390   
391if LMDZ : 
392    DYN_ps_beg = lmdz.geo2point ( d_DYN_beg['ps'].isel(rlonv=slice(0,-1)) )
393    DYN_ps_end = lmdz.geo2point ( d_DYN_end['ps'].isel(rlonv=slice(0,-1)) )
394   
395# 3D Pressure
396DYN_p_beg = ATM_Ahyb + ATM_Bhyb * DYN_ps_beg
397DYN_p_end = ATM_Ahyb + ATM_Bhyb * DYN_ps_end
398
399if ICO  : klevp1, cell_mesh        = DYN_p_beg.shape
400if LMDZ : klevp1, points_physiques = DYN_p_beg.shape
401klev = klevp1 - 1
402
403# Layer thickness
404if ICO : 
405    DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh) ) )
406    DYN_dsigma_end = xr.DataArray ( np.empty( (klev, cell_mesh       )), dims=('sigs', 'cell_mesh'       ), coords=(np.arange(klev), np.arange(cell_mesh) ) )
407if LMDZ : 
408    DYN_dsigma_beg = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
409    DYN_dsigma_end = xr.DataArray ( np.empty( (klev, points_physiques)), dims=('sigs', 'points_physiques'), coords=(np.arange(klev), np.arange(points_physiques) ) )
410
411for k in np.arange (klevp1-1) :
412    DYN_dsigma_beg[k,:] = DYN_p_beg[k,:] - DYN_p_beg[k+1,:]
413    DYN_dsigma_end[k,:] = DYN_p_end[k,:] - DYN_p_end[k+1,:]
414
415##-- Vertical and horizontal integral, and sum of liquid, solid and vapor water phases
416if LMDZ :
417    try : 
418        DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2Ov']  + d_DYN_beg['H2Ol']  + d_DYN_beg['H2Oi'] ).isel(rlonv=slice(0,-1) ) )
419        DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2Ov']  + d_DYN_end['H2Ol']  + d_DYN_end['H2Oi'] ).isel(rlonv=slice(0,-1) ) )
420    except :
421        DYN_wat_beg = lmdz.geo3point ( (d_DYN_beg['H2O_g'] + d_DYN_beg['H2O_l'] + d_DYN_beg['H2O_s']).isel(rlonv=slice(0,-1) ) )
422        DYN_wat_end = lmdz.geo3point ( (d_DYN_end['H2O_g'] + d_DYN_end['H2O_l'] + d_DYN_end['H2O_s']).isel(rlonv=slice(0,-1) ) )
423if ICO :
424    try :
425        DYN_wat_beg = (d_DYN_beg['H2O_g'] + d_DYN_beg['H2O_l'] + d_DYN_beg['H2O_s']).rename ( {'lev':'sigs'} )
426        DYN_wat_end = (d_DYN_end['H2O_g'] + d_DYN_end['H2O_l'] + d_DYN_end['H2O_s']).rename ( {'lev':'sigs'} )
427    except : 
428        DYN_wat_beg = (d_DYN_beg['q'].isel(nq=0) + d_DYN_beg['q'].isel(nq=1) + d_DYN_beg['q'].isel(nq=2) ).rename ( {'lev':'sigs'} )
429        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'} )
430   
431# Integral
432DYN_mas_wat_beg = ATM_stock_int (DYN_dsigma_beg * DYN_wat_beg) / Grav
433DYN_mas_wat_end = ATM_stock_int (DYN_dsigma_end * DYN_wat_end) / Grav
434
435dDYN_mas_wat = DYN_mas_wat_end - DYN_mas_wat_beg
436
437echo ( '\nVariation du contenu en eau atmosphere (dynamique) ' )
438echo ( 'DYN_mas_beg = {:12.6e} kg | DYN_mas_end = {:12.6e} kg'.format (DYN_mas_wat_beg, DYN_mas_wat_end) )
439echo ( 'dMass (atm)   = {:12.3e} kg '.format (dDYN_mas_wat) )
440echo ( 'dMass (atm)   = {:12.3e} Sv '.format (dDYN_mas_wat/dtime_sec*1.e-6/ATM_rho) )
441echo ( 'dMass (atm)   = {:12.3e} m  '.format (dDYN_mas_wat/ATM_aire_sea_tot/ATM_rho) )
442
443ATM_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']
444ATM_sno_end = d_ATM_end['SNOW01']*d_ATM_end['FTER']+d_ATM_end['SNOW02']*d_ATM_end['FLIC']+d_ATM_end['SNOW03']*d_ATM_end['FOCE']+d_ATM_end['SNOW04']*d_ATM_end['FSIC']
445
446ATM_qs_beg  = d_ATM_beg['QS01']*d_ATM_beg['FTER']+d_ATM_beg['QS02']*d_ATM_beg['FLIC']+d_ATM_beg['QS03']*d_ATM_beg['FOCE']+d_ATM_beg['QS04']*d_ATM_beg['FSIC']
447ATM_qs_end  = d_ATM_end['QS01']*d_ATM_end['FTER']+d_ATM_end['QS02']*d_ATM_end['FLIC']+d_ATM_end['QS03']*d_ATM_end['FOCE']+d_ATM_end['QS04']*d_ATM_end['FSIC']
448
449ATM_qsol_beg = d_ATM_beg['QSOL']
450ATM_qsol_end = d_ATM_end['QSOL']
451
452ATM_qs01_beg  = d_ATM_beg['QS01'] * d_ATM_beg['FTER']
453ATM_qs01_end  = d_ATM_end['QS01'] * d_ATM_end['FTER']
454ATM_qs02_beg  = d_ATM_beg['QS02'] * d_ATM_beg['FLIC']
455ATM_qs02_end  = d_ATM_end['QS02'] * d_ATM_end['FLIC']
456ATM_qs03_beg  = d_ATM_beg['QS03'] * d_ATM_beg['FOCE']
457ATM_qs03_end  = d_ATM_end['QS03'] * d_ATM_end['FOCE']
458ATM_qs04_beg  = d_ATM_beg['QS04'] * d_ATM_beg['FSIC']
459ATM_qs04_end  = d_ATM_end['QS04'] * d_ATM_end['FSIC'] 
460
461if ICO :
462   ATM_sno_beg   = ATM_sno_beg .rename ( {'points_physiques':'cell_mesh'} )
463   ATM_sno_end   = ATM_sno_end .rename ( {'points_physiques':'cell_mesh'} )
464   ATM_qs_beg    = ATM_qs_beg  .rename ( {'points_physiques':'cell_mesh'} )
465   ATM_qs_end    = ATM_qs_end  .rename ( {'points_physiques':'cell_mesh'} )
466   ATM_qsol_beg  = ATM_qsol_beg.rename ( {'points_physiques':'cell_mesh'} )
467   ATM_qsol_end  = ATM_qsol_end.rename ( {'points_physiques':'cell_mesh'} )
468   ATM_qs01_beg  = ATM_qs01_beg.rename ( {'points_physiques':'cell_mesh'} )
469   ATM_qs01_end  = ATM_qs01_end.rename ( {'points_physiques':'cell_mesh'} )
470   ATM_qs02_beg  = ATM_qs02_beg.rename ( {'points_physiques':'cell_mesh'} )
471   ATM_qs02_end  = ATM_qs02_end.rename ( {'points_physiques':'cell_mesh'} )
472   ATM_qs03_beg  = ATM_qs03_beg.rename ( {'points_physiques':'cell_mesh'} )
473   ATM_qs03_end  = ATM_qs03_end.rename ( {'points_physiques':'cell_mesh'} )
474   ATM_qs04_beg  = ATM_qs04_beg.rename ( {'points_physiques':'cell_mesh'} )
475   ATM_qs04_end  = ATM_qs04_end.rename ( {'points_physiques':'cell_mesh'} ) 
476
477ATM_mas_sno_beg   = ATM_stock_int ( ATM_sno_beg  )
478ATM_mas_sno_end   = ATM_stock_int ( ATM_sno_end  )
479ATM_mas_qs_beg    = ATM_stock_int ( ATM_qs_beg   )
480ATM_mas_qs_end    = ATM_stock_int ( ATM_qs_end   )
481ATM_mas_qsol_beg  = ATM_stock_int ( ATM_qsol_beg )
482ATM_mas_qsol_end  = ATM_stock_int ( ATM_qsol_end )
483ATM_mas_qs01_beg  = ATM_stock_int ( ATM_qs01_beg )
484ATM_mas_qs01_end  = ATM_stock_int ( ATM_qs01_end )
485ATM_mas_qs02_beg  = ATM_stock_int ( ATM_qs02_beg )
486ATM_mas_qs02_end  = ATM_stock_int ( ATM_qs02_end )
487ATM_mas_qs03_beg  = ATM_stock_int ( ATM_qs03_beg )
488ATM_mas_qs03_end  = ATM_stock_int ( ATM_qs03_end )
489ATM_mas_qs04_beg  = ATM_stock_int ( ATM_qs04_beg )
490ATM_mas_qs04_end  = ATM_stock_int ( ATM_qs04_end )
491
492dATM_mas_sno  = ATM_mas_sno_end  - ATM_mas_sno_beg
493dATM_mas_qs   = ATM_mas_qs_end   - ATM_mas_qs_beg
494dATM_mas_qsol = ATM_mas_qsol_end - ATM_mas_qsol_beg
495
496dATM_mas_qs01 = ATM_mas_qs01_end - ATM_mas_qs01_beg
497dATM_mas_qs02 = ATM_mas_qs02_end - ATM_mas_qs02_beg
498dATM_mas_qs03 = ATM_mas_qs03_end - ATM_mas_qs03_beg
499dATM_mas_qs04 = ATM_mas_qs04_end - ATM_mas_qs04_beg
500
501echo ( '\nVariation du contenu en neige atmosphere (calottes)' )
502echo ( 'ATM_mas_sno_beg  = {:12.6e} kg | ATM_mas_sno_end  = {:12.6e} kg'.format (ATM_mas_sno_beg, ATM_mas_sno_end) )
503echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_sno ) )
504echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_sno/dtime_sec*1e-6/ICE_rho_ice) )
505echo ( 'dMass (neige atm) = {:12.3e} m  '.format (dATM_mas_sno/ATM_aire_sea_tot/ATM_rho) )
506
507echo ( '\nVariation du contenu humidite du sol' )
508echo ( 'ATM_mas_qs_beg  = {:12.6e} kg | ATM_mas_qs_end  = {:12.6e} kg'.format (ATM_mas_qs_beg, ATM_mas_qs_end) )
509echo ( 'dMass (neige atm) = {:12.3e} kg '.format (dATM_mas_qs ) )
510echo ( 'dMass (neige atm) = {:12.3e} Sv '.format (dATM_mas_qs/dtime_sec*1e-6/ATM_rho) )
511echo ( 'dMass (neige atm) = {:12.3e} m  '.format (dATM_mas_qs/ATM_aire_sea_tot/ATM_rho) )
512
513echo ( '\nVariation du contenu en eau+neige atmosphere ' )
514echo ( 'dMass (eau + neige atm) = {:12.3e} kg '.format (  dDYN_mas_wat + dATM_mas_sno) )
515echo ( 'dMass (eau + neige atm) = {:12.3e} Sv '.format ( (dDYN_mas_wat + dATM_mas_sno)/dtime_sec*1E-6/ATM_rho) )
516echo ( 'dMass (eau + neige atm) = {:12.3e} m  '.format ( (dDYN_mas_wat + dATM_mas_sno)/ATM_aire_sea_tot/ATM_rho) )
517
518echo ( '\n------------------------------------------------------------------------------------' )
519echo ( '-- SRF changes ' )
520
521# 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}`
522# dInterce_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelIntercept_daily*Contfrac' ${file} -gridarea ${file}`
523# dSWE_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=DelSWE_daily*Contfrac' ${file} -gridarea ${file}`
524# dStream_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delstreamr_daily*Contfrac' ${file} -gridarea ${file}`
525# dFastR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfastr_daily*Contfrac' ${file} -gridarea ${file}`
526# dSlowR_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delslowr_daily*Contfrac' ${file} -gridarea ${file}`
527# dFlood_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delfloodr_daily*Contfrac' ${file} -gridarea ${file}`
528# dPond_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=delpondr_daily*Contfrac' ${file} -gridarea ${file}`
529# dLake_in_Sv=`cdo outputf,%12.8g,8 -divc,1.e9 -divc,${day2sec} -fldsum -mul -timavg -expr,'toto=dellakevol_daily*Contfrac' ${file} -gridarea ${file}`
530#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}
531#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"`
532#echo 'dSTOCK (Sv) total='${dSRF_tot} >> ${fileout}
533
534
535if Routing == 'SIMPLE' :
536    RUN_mas_wat_beg = ONE_stock_int ( d_RUN_beg ['fast_reservoir'] +  d_RUN_beg ['slow_reservoir'] +  d_RUN_beg ['stream_reservoir'] )
537    RUN_mas_wat_end = ONE_stock_int ( d_RUN_end ['fast_reservoir'] +  d_RUN_end ['slow_reservoir'] +  d_RUN_end ['stream_reservoir'] )
538
539if Routing == 'ORCHIDEE' : 
540    RUN_mas_wat_beg = ONE_stock_int ( d_SRF_beg['fastres']  + d_SRF_beg['slowres'] + d_SRF_beg['streamres'] \
541                                    + d_SRF_beg['floodres'] + d_SRF_beg['lakeres'] + d_SRF_beg['pondres']  )
542    RUN_mas_wat_end = ONE_stock_int ( d_SRF_end['fastres']  + d_SRF_end['slowres'] + d_SRF_end['streamres'] \
543                                    + d_SRF_end['floodres'] + d_SRF_end['lakeres'] + d_SRF_end['pondres']  )
544
545dRUN_mas_wat = RUN_mas_wat_end - RUN_mas_wat_beg
546   
547echo ( '\nWater content in routing ' )
548echo ( 'RUN_mas_wat_beg = {:12.6e} kg | RUN_mas_wat_end = {:12.6e} kg '.format (RUN_mas_wat_end, RUN_mas_wat_end) )
549echo ( 'dMass (routing)  = {:12.3e} kg '.format(dRUN_mas_wat) )
550echo ( 'dMass (routing)  = {:12.3e} Sv '.format(dRUN_mas_wat/dtime_sec*1E-9) )
551echo ( 'dMass (routing)  = {:12.3e} m  '.format(dRUN_mas_wat/ATM_aire_sea_tot*1E-3) )
552
553print ('Reading SRF restart')
554tot_watveg_beg  = d_SRF_beg['tot_watveg_beg']  ; tot_watveg_beg  = tot_watveg_beg .where (tot_watveg_beg < 1E10, 0.)
555tot_watsoil_beg = d_SRF_beg['tot_watsoil_beg'] ; tot_watsoil_beg = tot_watsoil_beg.where (tot_watsoil_beg< 1E10, 0.)
556snow_beg        = d_SRF_beg['snow_beg']        ; snow_beg        = snow_beg       .where (snow_beg       < 1E10, 0.)
557
558tot_watveg_end  = d_SRF_end['tot_watveg_beg']  ; tot_watveg_end  = tot_watveg_end .where (tot_watveg_end < 1E10, 0.)
559tot_watsoil_end = d_SRF_end['tot_watsoil_beg'] ; tot_watsoil_end = tot_watsoil_end.where (tot_watsoil_end< 1E10, 0.)
560snow_end        = d_SRF_end['snow_beg']        ; snow_end        = snow_end       .where (snow_end       < 1E10, 0.)
561
562if LMDZ :
563    tot_watveg_beg  = lmdz.geo2point (tot_watveg_beg)
564    tot_watsoil_beg = lmdz.geo2point (tot_watsoil_beg)
565    snow_beg        = lmdz.geo2point (snow_beg)
566    tot_watveg_end  = lmdz.geo2point (tot_watveg_end)
567    tot_watsoil_end = lmdz.geo2point (tot_watsoil_end)
568    snow_end        = lmdz.geo2point (snow_end)
569
570# Stock dSoilHum dInterce dSWE dStream dFastR dSlowR dLake dPond dFlood
571
572SRF_wat_beg = tot_watveg_beg + tot_watsoil_beg + snow_beg
573SRF_wat_end = tot_watveg_end + tot_watsoil_end + snow_end
574   
575if ICO :
576    tot_watveg_beg  = tot_watveg_beg .rename ( {'y':'cell_mesh'} )
577    tot_watsoil_beg = tot_watsoil_beg.rename ( {'y':'cell_mesh'} )
578    snow_beg        = snow_beg       .rename ( {'y':'cell_mesh'} )
579    tot_watveg_end  = tot_watveg_end .rename ( {'y':'cell_mesh'} )
580    tot_watsoil_end = tot_watsoil_end.rename ( {'y':'cell_mesh'} )
581    snow_end        = snow_end       .rename ( {'y':'cell_mesh'} )
582    SRF_wat_beg     = SRF_wat_beg    .rename ( {'y':'cell_mesh'} )
583    SRF_wat_end     = SRF_wat_end    .rename ( {'y':'cell_mesh'} )
584
585print ('Computing integrals')
586
587print ( ' 1/6', end='' ) ; sys.stdout.flush ()
588SRF_mas_watveg_beg   = ATM_stock_int ( tot_watveg_beg  )
589print ( ' 2/6', end='' ) ; sys.stdout.flush ()
590SRF_mas_watsoil_beg  = ATM_stock_int ( tot_watsoil_beg )
591print ( ' 3/6', end='' ) ; sys.stdout.flush ()
592SRF_mas_snow_beg     = ATM_stock_int ( snow_beg        )
593print ( ' 4/6', end='' ) ; sys.stdout.flush ()
594SRF_mas_watveg_end   = ATM_stock_int ( tot_watveg_end  )
595print ( ' 5/6', end='' ) ; sys.stdout.flush ()
596SRF_mas_watsoil_end  = ATM_stock_int ( tot_watsoil_end )
597print ( ' 6/6', end='' ) ; sys.stdout.flush ()
598SRF_mas_snow_end     = ATM_stock_int ( snow_end        )
599print (' -- ') ; sys.stdout.flush ()
600
601dSRF_mas_watveg   = SRF_mas_watveg_end   - SRF_mas_watveg_beg
602dSRF_mas_watsoil  = SRF_mas_watsoil_end  - SRF_mas_watsoil_beg
603dSRF_mas_snow     = SRF_mas_snow_end     - SRF_mas_snow_beg
604
605echo ('\nLes differents reservoirs')
606echo ( 'SRF_mas_watveg_beg   = {:12.6e} kg | SRF_mas_watveg_end   = {:12.6e} kg '.format (SRF_mas_watveg_beg  , SRF_mas_watveg_end   ) )
607echo ( 'SRF_mas_watsoil_beg  = {:12.6e} kg | SRF_mas_watsoil_end  = {:12.6e} kg '.format (SRF_mas_watsoil_beg , SRF_mas_watsoil_end  ) )
608echo ( 'SRF_mas_snow_beg     = {:12.6e} kg | SRF_mas_snow_end     = {:12.6e} kg '.format (SRF_mas_snow_beg    , SRF_mas_snow_end     ) )
609
610echo ( '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) )
611echo ( '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) )
612echo ( '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) )
613
614SRF_mas_wat_beg = SRF_mas_watveg_beg + SRF_mas_watsoil_beg + SRF_mas_snow_beg
615SRF_mas_wat_end = SRF_mas_watveg_end + SRF_mas_watsoil_end + SRF_mas_snow_end
616dSRF_mas_wat = SRF_mas_wat_end - SRF_mas_wat_beg
617
618echo ( '\nWater content in surface ' )
619echo ( 'SRF_mas_wat_beg  = {:12.6e} kg | SRF_mas_wat_end  = {:12.6e} kg '.format (SRF_mas_wat_beg, SRF_mas_wat_end) )
620echo ( 'dMass (water srf) = {:12.3e} kg '.format (dSRF_mas_wat) )
621echo ( 'dMass (water srf) = {:12.3e} Sv '.format (dSRF_mas_wat/dtime_sec*1E-6/ATM_rho) )
622echo ( 'dMass (water srf) = {:12.3e} m  '.format (dSRF_mas_wat/ATM_aire_sea_tot/ATM_rho) )
623
624echo ( '\nWater content in  ATM + SRF + RUN ' )
625echo ( 'mas_wat_beg = {:12.6e} kg | mas_wat_end = {:12.6e} kg '.
626           format (DYN_mas_wat_beg + ATM_mas_sno_beg + RUN_mas_wat_beg + SRF_mas_wat_beg,
627                   DYN_mas_wat_end + ATM_mas_sno_end + RUN_mas_wat_end + SRF_mas_wat_end) )
628echo ( 'dMass (water atm+srf+run) = {:12.6e} kg '.format ( dDYN_mas_wat + dATM_mas_sno + dRUN_mas_wat + dSRF_mas_wat) )
629echo ( '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) )
630echo ( '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) )
631
632echo ( '\n------------------------------------------------------------------------------------' )
633echo ( '-- ATM Fluxes ' )
634
635ATM_wbilo_oce   = lmdz.geo2point ( d_ATM_his ['wbilo_oce']   )
636ATM_wbilo_sic   = lmdz.geo2point ( d_ATM_his ['wbilo_sic']   )
637ATM_wbilo_ter   = lmdz.geo2point ( d_ATM_his ['wbilo_ter']   )
638ATM_wbilo_lic   = lmdz.geo2point ( d_ATM_his ['wbilo_lic']   )
639ATM_runofflic   = lmdz.geo2point ( d_ATM_his ['runofflic']   )
640ATM_fqcalving   = lmdz.geo2point ( d_ATM_his ['fqcalving']   )
641ATM_fqfonte     = lmdz.geo2point ( d_ATM_his ['fqfonte']     )
642ATM_precip      = lmdz.geo2point ( d_ATM_his ['precip']      )
643ATM_snowf       = lmdz.geo2point ( d_ATM_his ['snow']        )
644ATM_evap        = lmdz.geo2point ( d_ATM_his ['evap']        )
645ATM_bilo = ATM_wbilo_oce + ATM_wbilo_ter + ATM_wbilo_lic + ATM_wbilo_sic
646
647RUN_coastalflow = lmdz.geo2point ( d_RUN_his ['coastalflow'] ) 
648RUN_riverflow   = lmdz.geo2point ( d_RUN_his ['riverflow']   )
649RUN_runoff      = lmdz.geo2point ( d_RUN_his ['runoff']      )
650RUN_drainage    = lmdz.geo2point ( d_RUN_his ['drainage']    )
651RUN_riversret   = lmdz.geo2point ( d_RUN_his ['riversret']   )
652
653SRF_evap     = lmdz.geo2point ( d_SRF_his ['evap'] )
654SRF_snowf    = lmdz.geo2point ( d_SRF_his ['snowf'] )
655SRF_TWS      = lmdz.geo2point ( d_SRF_his ['TWS'] )
656SRF_subli    = lmdz.geo2point ( d_SRF_his ['subli'] )
657SRF_transpir = lmdz.geo2point ( np.sum(d_SRF_his ['transpir'], axis=1) ) ; SRF_transpir.attrs['units'] = d_SRF_his ['transpir'].attrs['units']
658
659def mmd2SI ( Var) :
660    '''Change unit from mm/d or m^3/s to kg/s if needed'''
661    if 'units' in VarT.attrs : 
662        if VarT.attrs['units'] in ['m^3/s', 'm3/s', 'm3.s-3'] :
663            VarT.values = VarT.values  * ATM_rho                 ;  VarT.attrs['units'] = 'kg/s'
664        if VarT.attrs['units'] == 'mm/d' :
665            VarT.values = VarT.values  * ATM_rho * (1e-3/86400.) ;  VarT.attrs['units'] = 'kg/s'
666
667for var in ['runoff', 'drainage', 'riversret', 'coastalflow', 'riverflow'] :
668    VarT = locals()['RUN_' + var]
669    mmd2SI (VarT)
670
671for var in ['evap', 'snowf', 'TWS', 'subli', 'transpir'] :
672    VarT = locals()['SRF_' + var]
673    mmd2SI (VarT)
674
675RUN_input  = RUN_runoff      + RUN_drainage
676RUN_output = RUN_coastalflow + RUN_riverflow
677
678ATM_wbilo_sea = ATM_wbilo_oce + ATM_wbilo_sic
679
680ATM_flx_oce       = ATM_flux_int ( ATM_wbilo_oce  )
681ATM_flx_sic       = ATM_flux_int ( ATM_wbilo_sic  )
682ATM_flx_sea       = ATM_flux_int ( ATM_wbilo_sea  )
683ATM_flx_ter       = ATM_flux_int ( ATM_wbilo_ter  )
684ATM_flx_lic       = ATM_flux_int ( ATM_wbilo_lic  )
685ATM_flx_calving   = ATM_flux_int ( ATM_fqcalving  )
686ATM_flx_qfonte    = ATM_flux_int ( ATM_fqfonte    )
687ATM_flx_precip    = ATM_flux_int ( ATM_precip     )
688ATM_flx_snowf     = ATM_flux_int ( ATM_snowf      )
689ATM_flx_evap      = ATM_flux_int ( ATM_evap       )
690ATM_flx_runlic    = ATM_flux_int ( ATM_runofflic  )
691
692RUN_flx_coastal   = ONE_flux_int ( RUN_coastalflow)
693RUN_flx_river     = ONE_flux_int ( RUN_riverflow  )
694RUN_flx_drainage  = ATM_flux_int ( RUN_drainage   )
695RUN_flx_riversret = ATM_flux_int ( RUN_riversret  )
696RUN_flx_runoff    = ATM_flux_int ( RUN_runoff     )
697RUN_flx_input     = ATM_flux_int ( RUN_input      )
698RUN_flx_output    = ONE_flux_int ( RUN_output     )
699
700ATM_flx_emp   = ATM_flx_evap - ATM_flx_precip
701ATM_flx_bilo  = ATM_flx_oce + ATM_flx_sic + ATM_flx_ter + ATM_flx_lic
702RUN_flx_bil   = RUN_flx_input - RUN_flx_output
703
704RUN_flx_rivcoa = RUN_flx_coastal + RUN_flx_river
705
706ATM_flx_bilo2 = ATM_flux_int (ATM_bilo)
707
708
709echo ('  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 ))
710echo ('  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 ))
711echo ('  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 ))
712echo ('  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 ))
713echo ('  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 ))
714echo ('  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 ))
715echo ('  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 ))
716echo ('  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 ))
717echo ('  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 ))
718echo ('  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 ))
719echo ('  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 ))
720echo ('  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 ))
721echo ('  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 ))
722echo ('  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 ))
723echo ('  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 ))
724echo ('  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 ))
725echo ('  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 ))
726echo ('  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 ))
727echo ('  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 ))
728echo ('  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 ))
729echo ('  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 ))
730echo ('  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 ))
731
732ATM_flx_budget = -ATM_flx_sea + ATM_flx_calving + ATM_flx_runlic #+ ATM_flx_qfonte + RUN_flx_river
733echo ('\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 ))
734
735#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 ))
736
737
738echo ( '------------------------------------------------------------------------------------' )
739echo ( '-- SECHIBA fluxes' )
740
741
742SRF_flx_evap     = ATM_flux_int ( SRF_evap     )
743SRF_flx_snowf    = ATM_flux_int ( SRF_snowf    )
744SRF_flx_subli    = ATM_flux_int ( SRF_subli    )
745SRF_flx_transpir = ATM_flux_int ( SRF_transpir )
746
747echo ('  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 ))
748echo ('  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 ))
749echo ('  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 ))
750echo ('  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 ))
Note: See TracBrowser for help on using the repository browser.