source: trunk/LMDZ.COMMON/libf/evolution/pem.F90 @ 4170

Last change on this file since 4170 was 4170, checked in by jbclement, 8 days ago

PEM:

  • Deletion of 'flux_ssice' ('zqdsdif_tot') from the "startfi.nc" as it is not needed.
  • Using the yearly average flux for the sublimating subsurface ice instead of the value at last timestep.
  • Keeping a clear separation between the subsurface ice flux and the surface ice tendency.
  • Making sure that subsurface ice depth is well given to the PCM at the end of the PEM (ice table VS layering).

JBC

File size: 21.7 KB
Line 
1PROGRAM pem
2!-----------------------------------------------------------------------
3! NAME
4!     pem
5!
6! DESCRIPTION
7!     Main entry point for the Planetary Evolution Model (PEM).
8!
9! AUTHORS & DATE
10!     R. Vandemeulebrouck, 22/07/2022 with r2778 & r2779
11!     L. Lange, 22/07/2022
12!     JB Clement, 2023-2025
13!
14! NOTES
15!     Ownership criterion for declarations:
16!       - Declare in module "planet" variables that are persistent climate
17!         state or persistent references used across multiple time steps.
18!       - Declare in program "pem.F90" transient workflow/control varaibles,
19!         one-shot initialization buffers and per-iteration working buffers.
20!-----------------------------------------------------------------------
21
22! DEPENDENCIES
23! ------------
24! Common modules
25use job_mod,        only: timelimit, antetime, timewall
26use parse_args_mod, only: parse_args
27! PEM modules
28use allocation,         only: ini_allocation, end_allocation
29use atmosphere,         only: ps_PCM, evolve_pressure, CO2cond_ps_PCM
30use backup,             only: save_clim_state, backup_rate
31use clim_state_init,    only: read_start, read_startfi, read_startevo
32use config,             only: read_rundef, read_display_config
33use display,            only: print_ini, print_end, print_msg, LVL_NFO, LVL_WRN
34use evolution,          only: n_yr_run, n_yr_sim, ntot_yr_sim, nmax_yr_run, dt, idt, r_plnt2earth_yr, pem_ini_date
35use geometry,           only: ngrid, nslope, nday, nsoil_PCM, nsoil, cell_area, total_surface
36use glaciers,           only: h2oice_flow, co2ice_flow, flow_co2glaciers, flow_h2oglaciers
37use ice_table,          only: icetable_equilibrium, icetable_dynamic, evolve_ice_table
38use layered_deposits,   only: do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering, print_layering
39use maths,              only: pi
40use numerics,           only: dp, qp, di, li, k4, minieps, minieps_qp
41use orbit,              only: evo_orbit, read_orbitpm, compute_maxyr_orbit, update_orbit
42use output,             only: write_diagevo, dim_ngrid, dim_nsoil
43use planet
44use physics,            only: g
45use slopes,             only: subslope_dist, def_slope_mean
46use soil,               only: do_soil, set_soil, TI
47use soil_temp,          only: tsoil_PCM, shift_tsoil2surf, evolve_soil_temp
48use soil_therm_inertia, only: update_soil_TI
49use sorption,           only: do_sorption, compute_totmass_adsorbed, evolve_regolith_adsorption
50use stopping_crit,      only: stopFlags, stopping_crit_pressure, stopping_crit_h2o, stopping_crit_h2oice, stopping_crit_co2ice
51use surface,            only: emissivity_PCM
52use surf_ice,           only: evolve_co2ice, evolve_h2oice, balance_h2oice_reservoirs
53use surf_temp,          only: tsurf_PCM, adapt_tsurf2disappearedice
54use tendencies,         only: compute_tendice, evolve_tend_co2ice, evolve_flux_ssice
55use tracers,            only: adapt_tracers2pressure
56use utility,            only: real2str
57use workflow_status,    only: i_pem_run, read_workflow_status, update_workflow_status
58use xios_data,          only: load_xios_data
59
60! DECLARATION
61! -----------
62implicit none
63
64! LOCAL VARIABLES
65! ---------------
66! Utility-related:
67integer(li)  :: cr     ! Number of clock ticks per second (count rate)
68integer(li)  :: c1, c2 ! Counts of processor clock
69character(8) :: num    ! Slope suffix to ouput variables
70integer(di)  :: i, islope
71! Ice-related:
72logical(k4), dimension(:,:),   allocatable :: is_co2ice_flow   ! Flag for location of CO2 glacier flow
73logical(k4), dimension(:,:),   allocatable :: is_h2oice_flow   ! Flag for location of H2O glacier flow
74real(dp),    dimension(:,:,:), allocatable :: minPCM_h2operice ! Minimum of H2O perennial ice over the last PCM year [kg/m2]
75real(dp),    dimension(:,:,:), allocatable :: minPCM_co2perice ! Minimum of CO2 perennial ice over the last PCM year [kg/m2]
76real(dp),    dimension(:,:,:), allocatable :: minPCM_h2ofrost  ! Minimum of H2O frost over the last PCM year [kg/m2]
77real(dp),    dimension(:,:,:), allocatable :: minPCM_co2frost  ! Minimum of CO2 frost over the last PCM year [kg/m2]
78! Surface-related:
79real(dp), dimension(:,:), allocatable :: tsurf_avg_yr1 ! Average surface temperature of the second to last PCM run [K]
80real(dp), dimension(:,:), allocatable :: zshift_surf   ! Elevation shift for the surface [m]
81real(dp), dimension(:,:), allocatable :: zlag          ! Newly built lag thickness [m]
82! Tendency-related:
83real(dp), dimension(:,:), allocatable :: d_h2oice_new ! Adjusted tendency of perennial H2O ice to keep balance between donor and recipient [kg/m2/y]
84! Layering-related:
85type(ptrarray), dimension(:,:), allocatable :: current          ! Current active stratum in the layering
86real(dp),       dimension(:,:), allocatable :: h2oice_depth     ! Depth of subsurface ice layer
87real(dp),       dimension(:,:), allocatable :: h2oice_depth_old ! Old depth of subsurface ice layer
88logical(k4),    dimension(:,:), allocatable :: new_str, new_lag ! Flags for the layering algorithm
89! Evolution-related:
90real(dp)        :: nmax_yr_runorb ! Maximum number of years for the run due to orbital parameters
91type(stopFlags) :: stopcrit       ! Stopping criteria
92! Balance-related
93real(qp) :: totmass_co2ice, totmass_atmco2, totmass_adsco2             ! Current total CO2 masses (surface ice|atmospheric|adsorbed)
94real(qp) :: totmass_co2ice_ini, totmass_atmco2_ini, totmass_adsco2_ini ! Initial total CO2 masses (surface ice|atmospheric|adsorbed)
95real(qp) :: totmass_ini                                                ! Initial total CO2 mass [kg]
96real(qp) :: totmass_adsh2o                                             ! Current total adsorbed H2O mass [kg]
97real(qp) :: S_atm_2_h2o, S_h2o_2_atm, S_atm_2_h2oice, S_h2oice_2_atm   ! Variables to balance H2O ice reservoirs
98
99! CODE
100! ----
101! Pre-processing step
102!~~~~~~~~~~~~~~~~~~~~
103! Elapsed time with system clock
104call system_clock(count_rate = cr)
105call system_clock(c1)
106
107! Parse command-line options
108call parse_args()
109
110! Initialization
111! ~~~~~~~~~~~~~~
112! Header
113call read_display_config()
114call print_ini()
115
116! Allocate module arrays
117call ini_allocation()
118
119! Read the duration information of the workflow
120call read_workflow_status()
121
122! Read the PEM parameters
123call read_rundef()
124
125! Read the orbital parameters
126call read_orbitpm(n_yr_sim)
127
128! Read the "start.nc"
129call read_start()
130
131! Read the "startfi.nc"
132call read_startfi()
133
134! Read the PCM data given by XIOS
135call allocate_xios_state()
136allocate(tsurf_avg_yr1(ngrid,nslope))
137allocate(minPCM_h2operice(ngrid,nslope,2))
138allocate(minPCM_co2perice(ngrid,nslope,2))
139allocate(minPCM_h2ofrost(ngrid,nslope,2))
140allocate(minPCM_co2frost(ngrid,nslope,2))
141
142call load_xios_data(ps_avg,ps_ts,tsurf_avg,tsurf_avg_yr1,tsoil_avg,tsoil_ts,h2o_surfdensity_avg,h2o_soildensity_avg, &
143                    q_h2o_ts,q_co2_ts,minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost,flux_ssice_avg)
144
145! Initiate soil settings and TI
146if (do_soil) call set_soil(TI)
147
148! Compute the deviation from the average
149call allocate_deviation_state()
150ps_dev(:) = ps_PCM(:) - ps_avg(:)
151tsurf_dev(:,:) = tsurf_PCM(:,:) - tsurf_avg(:,:)
152tsoil_dev(:,:,:) = tsoil_PCM(:,:,:) - tsoil_avg(:,1:nsoil_PCM,:)
153
154! Compute global surface pressure
155ps_avg_glob = sum(cell_area*ps_avg)/total_surface
156
157! Compute the accepted maximum number of years due to orbital parameters (if needed)
158call compute_maxyr_orbit(n_yr_sim,nmax_yr_runorb)
159
160! Read the "startevo.nc"
161call allocate_startevo_state()
162call read_startevo(tsurf_avg_yr1,tsurf_avg,ps_avg_glob_ini,ps_ts,q_co2_ts,q_h2o_ts,h2o_surfdensity_avg,h2o_ice,co2_ice, &
163                   tsoil_avg,h2o_soildensity_avg,icetable_depth,icetable_thickness,ice_porefilling,layerings_map,       &
164                   h2o_ads_reg,co2_ads_reg,delta_h2o_ads,delta_co2_ads)
165deallocate(tsurf_avg_yr1)
166
167! Compute ice tendencies from yearly minima
168call allocate_tendencies()
169call print_msg('> Computing surface ice tendencies',LVL_NFO)
170call compute_tendice(minPCM_h2operice,minPCM_h2ofrost,h2o_ice,d_h2oice)
171call print_msg('H2O ice tendencies [kg/m2/y] (min|max): '//real2str(minval(d_h2oice))//' | '//real2str(maxval(d_h2oice)),LVL_NFO)
172call compute_tendice(minPCM_co2perice,minPCM_co2frost,co2_ice,d_co2ice)
173call print_msg('CO2 ice tendencies [kg/m2/y] (min|max): '//real2str(minval(d_co2ice))//' | '//real2str(maxval(d_co2ice)),LVL_NFO)
174deallocate(minPCM_h2operice,minPCM_co2perice,minPCM_h2ofrost,minPCM_co2frost)
175
176! Save initial set-up useful for the next computations
177call print_msg('> Saving some initial climate state variables',LVL_NFO)
178call allocate_initial_snapshots()
179ps_avg_glob_ini = ps_avg_glob
180d_co2ice_ini(:,:) = d_co2ice(:,:)
181q_co2_ts_ini(:,:) = q_co2_ts(:,:)
182h2oice_sublim_coverage_ini = 0._dp
183co2ice_sublim_coverage_ini = 0._dp
184totmass_co2ice_ini = 0._qp
185totmass_atmco2_ini = 0._qp
186totmass_adsco2_ini = 0._qp
187totmass_adsh2o = 0._qp
188do i = 1,ngrid
189    totmass_atmco2_ini = totmass_atmco2_ini + cell_area(i)*ps_avg(i)/g
190    do islope = 1,nslope
191        totmass_co2ice_ini = totmass_co2ice_ini + co2_ice(i,islope)*cell_area(i)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180._dp)
192        if (co2_ice(i,islope) > 0._dp) then
193            is_co2ice_ini(i,islope) = .true.
194            if (d_co2ice(i,islope) < 0._dp) co2ice_sublim_coverage_ini = co2ice_sublim_coverage_ini + cell_area(i)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180._dp)
195        end if
196        if (h2o_ice(i,islope) > 0._dp) then
197            is_h2oice_ini(i,islope) = .true.
198            if (d_h2oice(i,islope) < 0._dp) h2oice_sublim_coverage_ini = h2oice_sublim_coverage_ini + cell_area(i)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180._dp)
199        end if
200    end do
201end do
202call print_msg("Initial global average pressure [Pa] = "//real2str(ps_avg_glob_ini),LVL_NFO)
203call print_msg("Initial surface area of sublimating CO2 ice [m2] = "//real2str(co2ice_sublim_coverage_ini),LVL_NFO)
204call print_msg("Initial surface area of sublimating H2O ice [m2] = "//real2str(h2oice_sublim_coverage_ini),LVL_NFO)
205if (do_sorption) call compute_totmass_adsorbed(h2o_ads_reg,co2_ads_reg,totmass_adsco2_ini,totmass_adsh2o)
206
207! Main evolution loop
208! ~~~~~~~~~~~~~~~~~~~
209call print_msg('',LVL_NFO)
210call print_msg('********* Evolution *********',LVL_NFO)
211if (do_layering) then
212    allocate(h2oice_depth(ngrid,nslope),h2oice_depth_old(ngrid,nslope),new_str(ngrid,nslope),new_lag(ngrid,nslope),current(ngrid,nslope))
213    new_str = .true.
214    new_lag = .true.
215    do islope = 1,nslope
216        do i = 1,ngrid
217            current(i,islope)%p => layerings_map(i,islope)%top
218        end do
219    end do
220    ! Conversion to surface ice
221    call layering2surfice(layerings_map,h2o_ice,co2_ice,h2oice_depth)
222end if
223call allocate_loop_state()
224n_yr_run = 0
225idt = 0
226do while (n_yr_run < min(nmax_yr_runorb,nmax_yr_run) .and. n_yr_sim < ntot_yr_sim)
227    call print_msg('**** Iteration of the PEM run [plnt y]: '//real2str(n_yr_run + dt),LVL_NFO)
228    ! Evolve global surface pressure
229    call evolve_pressure(d_co2ice,delta_co2_ads,do_sorption,ps_avg_glob_old,ps_avg_glob,ps_avg)
230
231    ! Adapt tracers according to global surface pressure
232    call adapt_tracers2pressure(ps_avg_glob_old,ps_avg_glob,ps_ts,q_h2o_ts,q_co2_ts)
233
234    ! Evolve surface ice
235    allocate(zshift_surf(ngrid,nslope),zlag(ngrid,nslope))
236    if (do_layering) then
237        allocate(d_h2oice_new(ngrid,nslope))
238        h2oice_depth_old(:,:) = h2oice_depth(:,:)
239        ! The sublimating tendency coming from subsurface ice is given through the surface ice tendency
240        where (h2oice_depth(:,:) > 0. .and. flux_ssice_avg(:,:) < 0._dp) d_h2oice(:,:) = flux_ssice_avg(:,:)
241        do islope = 1,nslope
242            do i = 1,ngrid
243                call evolve_layering(layerings_map(i,islope),d_co2ice(i,islope),d_h2oice_new(i,islope),new_str(i,islope),zshift_surf(i,islope),new_lag(i,islope),zlag(i,islope),current(i,islope)%p)
244                call print_layering(layerings_map(i,islope))
245            end do
246        end do
247        ! Conversion to surface ice
248        call layering2surfice(layerings_map,h2o_ice,co2_ice,h2oice_depth)
249        ! Balance H2O ice reservoirs
250        call stopping_crit_h2o(delta_h2o_ads,delta_icetable,h2o_ice,d_h2oice,S_atm_2_h2o,S_h2o_2_atm,S_atm_2_h2oice,S_h2oice_2_atm,stopcrit)
251        call balance_h2oice_reservoirs(S_atm_2_h2o,S_h2o_2_atm,S_atm_2_h2oice,S_h2oice_2_atm,h2o_ice,d_h2oice,d_h2oice_new)
252        deallocate(d_h2oice_new)
253    else
254        zlag(:,:) = 0._dp
255        zshift_surf(:,:) = 0._dp
256        call evolve_h2oice(delta_h2o_ads,delta_icetable,h2o_ice,d_h2oice,zshift_surf,stopcrit)
257        call evolve_co2ice(co2_ice,d_co2ice,zshift_surf)
258    end if
259
260    ! Flow glaciers according to surface ice
261    if (co2ice_flow) then
262        allocate(is_co2ice_flow(ngrid,nslope))
263        call flow_co2glaciers(q_co2_ts,ps_ts,ps_avg_glob_old,ps_avg_glob,co2_ice,is_co2ice_flow)
264    end if
265    if (h2oice_flow) then
266        allocate(is_h2oice_flow(ngrid,nslope))
267        call flow_h2oglaciers(tsurf_avg,h2o_ice,is_h2oice_flow)
268    end if
269    if (do_layering) call surfice2layering(h2o_ice,co2_ice,layerings_map)
270
271    ! Adapt surface temperature if surface ice disappeared
272    call adapt_tsurf2disappearedice(co2_ice,is_co2ice_ini,is_co2ice_disappeared,tsurf_avg)
273    !call adapt_tsurf2disappearedice(h2o_ice,is_h2oice_ini,tsurf_avg)
274
275    if (do_soil) then
276        ! Shift soil temperature to surface
277        call shift_tsoil2surf(ngrid,nsoil,nslope,zshift_surf,zlag,tsurf_avg,tsoil_avg)
278
279        ! Evolve soil temperature
280        call evolve_soil_temp(tsoil_avg,tsurf_avg,tsoil_ts,tsoil_ts_old,h2o_soildensity_avg)
281
282        ! Evolve ice table
283        call evolve_ice_table(h2o_ice,h2o_surfdensity_avg,h2o_soildensity_avg,tsoil_avg,tsurf_avg,delta_icetable,q_h2o_ts, &
284                              ps_avg,icetable_depth,icetable_thickness,ice_porefilling,icetable_depth_old)
285
286        ! Update soil thermal properties according to ice table and soil temperature
287        call update_soil_TI(h2o_ice,ps_avg_glob,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI)
288
289        ! Evolve adsorbed species
290        if (do_sorption) then
291            call evolve_regolith_adsorption(h2o_ice,co2_ice,tsoil_avg,TI,ps_ts,q_h2o_ts,q_co2_ts,h2o_ads_reg,co2_ads_reg,delta_h2o_ads,delta_co2_ads)
292            call compute_totmass_adsorbed(h2o_ads_reg,co2_ads_reg,totmass_adsco2,totmass_adsh2o)
293        else
294            totmass_adsh2o = 0._dp
295            totmass_adsco2 = 0._dp
296        end if
297    end if ! do_soil
298    deallocate(zshift_surf,zlag)
299
300    ! Output the results
301    call print_msg('> Standard outputs',LVL_NFO)
302    call write_diagevo('ps_avg_glob','Global average pressure','Pa',ps_avg_glob)
303    do islope = 1,nslope
304        if (nslope == 1) then
305            num = ''
306        else
307            write(num,'("_slope",i2.2)') islope
308        end if
309        call write_diagevo('h2oice'//trim(num),'H2O ice','kg/m2',h2o_ice(:,islope),(/dim_ngrid/))
310        call write_diagevo('co2ice'//trim(num),'CO2 ice','kg/m2',co2_ice(:,islope),(/dim_ngrid/))
311        call write_diagevo('d_h2oice'//trim(num),'H2O ice tendency','kg/m2/y',d_h2oice(:,islope),(/dim_ngrid/))
312        call write_diagevo('d_co2ice'//trim(num),'CO2 ice tendency','kg/m2/y',d_co2ice(:,islope),(/dim_ngrid/))
313        if (co2ice_flow) then
314            call write_diagevo('Flow_co2ice'//trim(num),'CO2 ice flow location','T/F',merge(1._dp,0._dp,is_co2ice_flow(:,islope)),(/dim_ngrid/))
315        end if
316        if (h2oice_flow) then
317            call write_diagevo('Flow_h2oice'//trim(num),'H2O ice flow location','T/F',merge(1._dp,0._dp,is_h2oice_flow(:,islope)),(/dim_ngrid/))
318        end if
319        call write_diagevo('tsurf'//trim(num),'Surface temperature','K',tsurf_avg(:,islope),(/dim_ngrid/))
320        if (do_soil) then
321            if (icetable_equilibrium) then
322                call write_diagevo('icetable_depth'//trim(num),'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
323                call write_diagevo('icetable_thick'//trim(num),'Ice table thickness','m',icetable_thickness(:,islope),(/dim_ngrid/))
324            else if (icetable_dynamic) then
325                call write_diagevo('icetable_depth'//trim(num),'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
326                call write_diagevo('ice_porefilling'//trim(num),'Ice pore filling','-',ice_porefilling(:,:,islope),(/dim_ngrid,dim_nsoil/))
327            end if
328            call write_diagevo('tsoil_avg'//trim(num),'Soil temperature','K',tsoil_avg(:,:,islope),(/dim_ngrid,dim_nsoil/))
329            call write_diagevo('inertiesoil'//trim(num),'Thermal inertia','SI',TI(:,:,islope),(/dim_ngrid,dim_nsoil/))
330            if (do_sorption) then
331                call write_diagevo('co2_ads_reg'//trim(num),'CO2 adsorbed in regolith','kg/m2',co2_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
332                call write_diagevo('h2o_ads_reg'//trim(num),'H2O adsorbed in regolith','kg/m2',h2o_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
333            end if
334        end if
335    end do
336    if (co2ice_flow .and. allocated(is_co2ice_flow)) deallocate(is_co2ice_flow)
337    if (h2oice_flow .and. allocated(is_h2oice_flow)) deallocate(is_h2oice_flow)
338
339    ! Checking mass balance for CO2
340    if (abs(CO2cond_ps_PCM - 1._dp) < minieps) then
341        totmass_co2ice = 0._dp
342        totmass_atmco2 = 0._dp
343        do i = 1,ngrid
344            totmass_atmco2 = totmass_atmco2 + cell_area(i)*ps_avg(i)/g
345            do islope = 1,nslope
346                totmass_co2ice = totmass_co2ice + co2_ice(i,islope)*cell_area(i)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180.)
347            end do
348        end do
349        totmass_ini = max(totmass_atmco2_ini + totmass_co2ice_ini + totmass_adsco2_ini,minieps_qp) ! To avoid division by 0
350        call print_msg('> Relative total CO2 mass balance = '//real2str(100._qp*(totmass_atmco2 + totmass_co2ice + totmass_adsco2 - totmass_atmco2_ini - totmass_co2ice_ini - totmass_adsco2_ini)/totmass_ini)//' %',LVL_NFO)
351        if (abs((totmass_atmco2 + totmass_co2ice + totmass_adsco2 - totmass_atmco2_ini - totmass_co2ice_ini - totmass_adsco2_ini)/totmass_ini) > 0.01_qp) then
352            call print_msg('Mass balance is not conserved!',LVL_WRN)
353            totmass_ini = max(totmass_atmco2_ini,minieps_qp) ! To avoid division by 0
354            call print_msg('    Atmospheric CO2 mass balance = '//real2str(100._qp*(totmass_atmco2 - totmass_atmco2_ini)/totmass_ini)//' %',LVL_WRN)
355            totmass_ini = max(totmass_co2ice_ini,minieps_qp) ! To avoid division by 0
356            call print_msg('    CO2 ice mass balance         = '//real2str(100._qp*(totmass_co2ice - totmass_co2ice_ini)/totmass_ini)//' %',LVL_WRN)
357            totmass_ini = max(totmass_adsco2_ini,minieps_qp) ! To avoid division by 0
358            call print_msg('    Adsorbed CO2 mass balance    = '//real2str(100._qp*(totmass_adsco2 - totmass_adsco2_ini)/totmass_ini)//' %',LVL_WRN)
359        end if
360    end if
361
362    ! Evolve the tendencies
363    call evolve_tend_co2ice(d_co2ice_ini,co2_ice,emissivity_PCM,q_co2_ts_ini,q_co2_ts,ps_ts,ps_avg_glob_ini,ps_avg_glob,d_co2ice)
364    if (do_layering) then
365        call evolve_flux_ssice(h2oice_depth_old,h2oice_depth,tsurf_avg,tsoil_ts_old,tsoil_ts,flux_ssice_avg)
366    else if (icetable_equilibrium .or. icetable_dynamic) then
367        call evolve_flux_ssice(icetable_depth_old,icetable_depth,tsurf_avg,tsoil_ts_old,tsoil_ts,flux_ssice_avg)
368    end if
369
370    ! Increment time
371    n_yr_run = n_yr_run + dt
372    n_yr_sim = n_yr_sim + dt
373    idt = idt + 1
374
375    ! Save periodic backups of restart files
376    if (backup_rate > 0) then
377        if (mod(idt,backup_rate) == 0) call save_clim_state(h2o_ice,co2_ice,tsurf_avg,tsurf_dev,tsoil_avg,tsoil_dev,ps_avg,ps_dev,ps_avg_glob,ps_avg_glob_ini, &
378                                                            icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,flux_ssice_avg,h2o_ads_reg,co2_ads_reg,layerings_map,idt)
379    end if
380
381    ! Check the stopping criteria
382    call print_msg("> Checking the stopping criteria",LVL_NFO)
383    call stopping_crit_pressure(ps_avg_glob_ini,ps_avg_glob,stopcrit)
384    call stopping_crit_h2oice(h2oice_sublim_coverage_ini,h2o_ice,d_h2oice,stopcrit)
385    call stopping_crit_co2ice(co2ice_sublim_coverage_ini,co2_ice,d_co2ice,stopcrit)
386    call system_clock(c2)
387    if (stopcrit%stop_code() == 0 .and. n_yr_run >= nmax_yr_run) stopcrit%nmax_yr_run_reached = .true.
388    if (stopcrit%stop_code() == 0 .and. n_yr_run >= nmax_yr_runorb) stopcrit%nmax_yr_runorb_reached = .true.
389    if (stopcrit%stop_code() == 0 .and. n_yr_sim >= ntot_yr_sim) stopcrit%nmax_yr_sim_reached = .true.
390    if (stopcrit%stop_code() == 0 .and. timewall .and. real(c2 - c1,dp)/real(cr,dp) >= timelimit - antetime) stopcrit%time_limit_reached = .true.
391    if (stopcrit%is_any_set()) then
392        call print_msg(stopcrit%stop_message(),LVL_NFO)
393        exit
394    else
395        call print_msg('**** This run has achieved '//real2str(n_yr_run)//' Planetary years.',LVL_NFO)
396        call print_msg('**** The workflow has achieved '//real2str(n_yr_sim)//' Planetary years.',LVL_NFO)
397        call print_msg('**** This run is continuing!',LVL_NFO)
398        call print_msg('****',LVL_NFO)
399    end if
400end do ! End of the evolution loop
401
402! Finalization
403! ~~~~~~~~~~~~
404call print_msg('',LVL_NFO)
405call print_msg('********* Finalization *********',LVL_NFO)
406! Update orbital parameters
407if (evo_orbit) call update_orbit(n_yr_sim,n_yr_run)
408
409call save_clim_state(h2o_ice,co2_ice,tsurf_avg,tsurf_dev,tsoil_avg,tsoil_dev,ps_avg,ps_dev,ps_avg_glob,ps_avg_glob_ini, &
410                     icetable_depth,icetable_thickness,ice_porefilling,h2oice_depth,flux_ssice_avg,h2o_ads_reg,co2_ads_reg,layerings_map)
411
412! Update the duration information of the workflow
413call update_workflow_status(n_yr_run,stopcrit%stop_code(),n_yr_sim,ntot_yr_sim)
414
415! Deallocation
416if (do_layering) then
417    deallocate(h2oice_depth,h2oice_depth_old,new_str,new_lag,current)
418    do islope = 1,nslope
419        do i = 1,ngrid
420            call del_layering(layerings_map(i,islope))
421        end do
422    end do
423end if
424call end_allocation()
425
426! Footer
427call system_clock(c2)
428call print_end(i_pem_run,n_yr_run,n_yr_sim,real((c2 - c1),dp)/real(cr,dp),pem_ini_date,r_plnt2earth_yr)
429
430END PROGRAM pem
Note: See TracBrowser for help on using the repository browser.