Ignore:
Timestamp:
Mar 26, 2026, 4:29:10 PM (2 weeks ago)
Author:
jbclement
Message:

PEM:

  • Separate variables ownership between the module "planet" for persistent climate state and the program "pem" for transient workflow logic. It provides a meaningful structure.
  • Add lifecycle helpers for clear allocation/deallocation logic.
  • Simplify string suffix for slopes variables.

JBC

Location:
trunk/LMDZ.COMMON/libf/evolution
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/allocation.F90

    r4138 r4157  
    2828use orbit,      only: ini_orbit, end_orbit
    2929use output,     only: ini_output, end_output
     30use planet,     only: ini_planet, end_planet
    3031
    3132! DECLARATION
     
    6768
    6869! Initialize everything else
     70call ini_planet()
    6971call ini_atmosphere()
    7072call ini_tracers()
     
    115117call end_tracers()
    116118call end_atmosphere()
     119call end_planet()
    117120call end_geometry()
    118121
  • trunk/LMDZ.COMMON/libf/evolution/atmosphere.F90

    r4147 r4157  
    267267! DEPENDENCIES
    268268! ------------
    269 use geometry, only: dyngrd2vect, nlon, nlat, ngrid
     269use geometry, only: dyngrd2vect
    270270
    271271! DECLARATION
     
    302302! DEPENDENCIES
    303303! ------------
    304 use geometry, only: dyngrd2vect, nlon, nlat, ngrid, nlayer
     304use geometry, only: dyngrd2vect, nlayer
    305305
    306306! DECLARATION
     
    343343! DEPENDENCIES
    344344! ------------
    345 use geometry, only: dyngrd2vect, nlon, nlat, ngrid, nlayer
     345use geometry, only: dyngrd2vect, nlayer
    346346
    347347! DECLARATION
     
    384384! DEPENDENCIES
    385385! ------------
    386 use geometry, only: dyngrd2vect, nlon, nlat, ngrid, nlayer
     386use geometry, only: dyngrd2vect, nlayer
    387387
    388388! DECLARATION
  • trunk/LMDZ.COMMON/libf/evolution/backup.F90

    r4135 r4157  
    9595use atmosphere,       only: build4PCM_atmosphere
    9696use tracers,          only: build4PCM_tracers, nq
    97 use clim_state_rec,   only: write_restart, write_restartfi, write_restartpem
     97use clim_state_rec,   only: write_restart, write_restartfi, write_restartevo
    9898use layered_deposits, only: layering
    9999
     
    143143
    144144! Write restart files
    145 call write_restartpem(h2o_ice,co2_ice,tsoil_avg,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
     145call write_restartevo(h2o_ice,co2_ice,tsoil_avg,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
    146146call write_restartfi(is_h2o_perice,h2o_ice4PCM,co2_ice4PCM,tsurf4PCM,tsoil4PCM,inertiesoil4PCM,albedo4PCM,emissivity4PCM,flux_geo4PCM)
    147147call write_restart(ps4PCM,pa4PCM,preff4PCM,q4PCM,teta4PCM,air_mass4PCM)
     
    191191! CODE
    192192! ----
    193 suffix = '_ts'//int2str(backup_idt)
     193suffix = ''
     194suffix = suffix//'_ts'//int2str(backup_idt)
    194195
    195196call print_msg('> Backup of "restart" files at dt = '//int2str(backup_idt),LVL_NFO)
  • trunk/LMDZ.COMMON/libf/evolution/changelog.txt

    r4152 r4157  
    945945- Fix sign in computing exchanges due to adsorption/ice table and in balancing H2O flux from/into atmosphere.
    946946- Few cleanings.
     947
     948== 26/03/2026 == JBC
     949- Separate variables ownership between the module "planet" for persistent climate state and the program "pem" for transient workflow logic. It provides a meaningful structure.
     950- Add lifecycle helpers for clear allocation/deallocation logic.
     951- Simplify string suffix for slopes variables.
  • trunk/LMDZ.COMMON/libf/evolution/clim_state_init.F90

    r4152 r4157  
    296296
    297297!=======================================================================
    298 SUBROUTINE read_startpem(tsurf_avg_yr1,tsurf_avg_yr2,ps_avg_glob,ps_ts,q_co2_ts,q_h2o_ts,h2o_surfdensity_avg,h2o_ice,co2_ice, &
     298SUBROUTINE read_startevo(tsurf_avg_yr1,tsurf_avg_yr2,ps_avg_glob,ps_ts,q_co2_ts,q_h2o_ts,h2o_surfdensity_avg,h2o_ice,co2_ice, &
    299299                         tsoil_avg,h2o_soildensity_avg,icetable_depth,icetable_thickness,ice_porefilling,layerings_map,       &
    300300                         h2o_ads_reg,co2_ads_reg,delta_h2o_ads,delta_co2_ads)
    301301!-----------------------------------------------------------------------
    302302! NAME
    303 !     read_startpem
     303!     read_startevo
    304304!
    305305! DESCRIPTION
     
    359359! ---------------
    360360logical(k4)                               :: here
    361 integer(di)                               :: i, islope, k, nb_str_max, nsoil_startpem
     361integer(di)                               :: i, islope, k, nb_str_max, nsoil_startevo
    362362real(dp)                                  :: delta           ! Depth of the interface regolith/breccia, breccia/bedrock [m]
    363 real(dp), dimension(ngrid,nsoil,nslope)   :: TI_startpem     ! Soil thermal inertia saved in the startevo [SI]
    364 real(dp), dimension(ngrid,nsoil,nslope)   :: tsoil_startpem  ! Soil temperature saved in the startevo [K]
     363real(dp), dimension(ngrid,nsoil,nslope)   :: TI_startevo     ! Soil thermal inertia saved in the startevo [SI]
     364real(dp), dimension(ngrid,nsoil,nslope)   :: tsoil_startevo  ! Soil temperature saved in the startevo [K]
    365365real(dp), dimension(:,:,:,:), allocatable :: layerings_array ! Array for layerings
    366366
     
    521521if (do_soil) then
    522522    ! Check if the number of soil layers is compatible
    523     call get_dim_nc('subsurface_layers',nsoil_startpem)
    524     if (nsoil_startpem /= nsoil) then
    525         call print_msg('nsoil (PEM) = '//int2str(nsoil)//' | nsoil ("'//startevo_name//'") = '//int2str(nsoil_startpem),LVL_ERR)
     523    call get_dim_nc('subsurface_layers',nsoil_startevo)
     524    if (nsoil_startevo /= nsoil) then
     525        call print_msg('nsoil (PEM) = '//int2str(nsoil)//' | nsoil ("'//startevo_name//'") = '//int2str(nsoil_startevo),LVL_ERR)
    526526        call stop_clean(__FILE__,__LINE__,'nsoil defined in the PEM is different from the one read in "'//startevo_name//'"!',1)
    527527    end if
     
    529529    do islope = 1,nslope
    530530        ! Soil temperature
    531         call get_var_nc('tsoil',tsoil_startpem(:,:,islope))
    532         ! Predictor-corrector: due to changes of surface temperature in the PCM, the tsoil_startpem is adapted firstly
     531        call get_var_nc('tsoil',tsoil_startevo(:,:,islope))
     532        ! Predictor-corrector: due to changes of surface temperature in the PCM, the tsoil_startevo is adapted firstly
    533533        !                      for PCM year 1 and then for PCM year 2 in order to build the evolution of the profile at depth
    534         call compute_tsoil(ngrid,nsoil,.true.,TI(:,:,islope),dt,tsurf_avg_yr1(:,islope),tsoil_startpem(:,:,islope))
    535         call compute_tsoil(ngrid,nsoil,.false.,TI(:,:,islope),dt,tsurf_avg_yr1(:,islope),tsoil_startpem(:,:,islope))
    536         call compute_tsoil(ngrid,nsoil,.false.,TI(:,:,islope),dt,tsurf_avg_yr2(:,islope),tsoil_startpem(:,:,islope))
     534        call compute_tsoil(ngrid,nsoil,.true.,TI(:,:,islope),dt,tsurf_avg_yr1(:,islope),tsoil_startevo(:,:,islope))
     535        call compute_tsoil(ngrid,nsoil,.false.,TI(:,:,islope),dt,tsurf_avg_yr1(:,islope),tsoil_startevo(:,:,islope))
     536        call compute_tsoil(ngrid,nsoil,.false.,TI(:,:,islope),dt,tsurf_avg_yr2(:,islope),tsoil_startevo(:,:,islope))
    537537    end do
    538     tsoil_avg(:,nsoil_PCM + 1:nsoil,:) = tsoil_startpem(:,nsoil_PCM + 1:nsoil,:)
     538    tsoil_avg(:,nsoil_PCM + 1:nsoil,:) = tsoil_startevo(:,nsoil_PCM + 1:nsoil,:)
    539539    if (any(isnan(tsoil_avg(:,:,:)))) call stop_clean(__FILE__,__LINE__,"NaN detected in 'tsoil_avg'",1)
    540540
    541541    ! Thermal inertia
    542     call get_var_nc('TI',TI_startpem(:,:,:))
    543     TI(:,nsoil_PCM + 1:nsoil,:) = TI_startpem(:,nsoil_PCM + 1:nsoil,:) ! 1st layers can change because of the presence of ice at the surface, so we don't change it here
     542    call get_var_nc('TI',TI_startevo(:,:,:))
     543    TI(:,nsoil_PCM + 1:nsoil,:) = TI_startevo(:,nsoil_PCM + 1:nsoil,:) ! 1st layers can change because of the presence of ice at the surface, so we don't change it here
    544544    call get_var_nc('inertiedat',inertiedat(:,:))
    545545
     
    579579call close_nc(startevo_name)
    580580
    581 END SUBROUTINE read_startpem
     581END SUBROUTINE read_startevo
    582582!=======================================================================
    583583
  • trunk/LMDZ.COMMON/libf/evolution/clim_state_rec.F90

    r4147 r4157  
    2525! VARIABLES
    2626! ---------
    27 logical(k4), protected, private :: is_restartpem = .false. ! Flag to know if "restartevo.nc" exists
     27logical(k4), protected, private :: is_restartevo = .false. ! Flag to know if "restartevo.nc" exists
    2828
    2929contains
     
    271271
    272272!=======================================================================
    273 SUBROUTINE create_nc_pem(nb_str_max)
     273SUBROUTINE create_startevo(nb_str_max)
    274274!-----------------------------------------------------------------------
    275275! NAME
    276 !     create_nc_pem
     276!     create_startevo
    277277!
    278278! DESCRIPTION
     
    414414
    415415! File creation done
    416 is_restartpem = .true.
    417 
    418 END SUBROUTINE create_nc_pem
    419 !=======================================================================
    420 
    421 !=======================================================================
    422 SUBROUTINE write_restartpem(h2o_ice,co2_ice,tsoil,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
     416is_restartevo = .true.
     417
     418END SUBROUTINE create_startevo
     419!=======================================================================
     420
     421!=======================================================================
     422SUBROUTINE write_restartevo(h2o_ice,co2_ice,tsoil,TI,icetable_depth,icetable_thickness,ice_porefilling,h2o_ads_reg,co2_ads_reg,layerings_map)
    423423!-----------------------------------------------------------------------
    424424! NAME
    425 !    write_restartpem
     425!    write_restartevo
    426426!
    427427! DESCRIPTION
     
    466466! Create the file
    467467nb_str_max = get_nb_str_max(layerings_map)
    468 call create_nc_pem(nb_str_max)
     468call create_startevo(nb_str_max)
    469469
    470470call print_msg('> Writing "re'//startevo_name//'"',LVL_NFO)
    471 if (.not. is_restartpem) call stop_clean(__FILE__,__LINE__,'The file"'//startevo_name//'" has not been created',1)
     471if (.not. is_restartevo) call stop_clean(__FILE__,__LINE__,'The file"'//startevo_name//'" has not been created',1)
    472472
    473473! Writing time counter
     
    510510call close_nc('re'//startevo_name)
    511511
    512 END SUBROUTINE write_restartpem
     512END SUBROUTINE write_restartevo
    513513!=======================================================================
    514514
  • trunk/LMDZ.COMMON/libf/evolution/pem.F90

    r4152 r4157  
    88!
    99! AUTHORS & DATE
    10 !     R. Vandemeulebrouck, 22/07/2022
     10!     R. Vandemeulebrouck, 22/07/2022 with r2778 & r2779
    1111!     L. Lange, 22/07/2022
    1212!     JB Clement, 2023-2025
    1313!
    1414! NOTES
    15 !
     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.
    1620!-----------------------------------------------------------------------
    1721
     
    2529use atmosphere,         only: ps_PCM, evolve_pressure, CO2cond_ps_PCM
    2630use backup,             only: save_clim_state, backup_rate
    27 use clim_state_init,    only: read_start, read_startfi, read_startpem
     31use clim_state_init,    only: read_start, read_startfi, read_startevo
    2832use config,             only: read_rundef, read_display_config
    2933use display,            only: print_ini, print_end, print_msg, LVL_NFO, LVL_WRN
     
    3236use glaciers,           only: h2oice_flow, co2ice_flow, flow_co2glaciers, flow_h2oglaciers
    3337use ice_table,          only: icetable_equilibrium, icetable_dynamic, evolve_ice_table
    34 use layered_deposits,   only: layering, do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering, print_layering
     38use layered_deposits,   only: do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering, print_layering
    3539use maths,              only: pi
    3640use numerics,           only: dp, qp, di, li, k4, minieps, minieps_qp
    3741use orbit,              only: evo_orbit, read_orbitpm, compute_maxyr_orbit, update_orbit
    3842use output,             only: write_diagevo, dim_ngrid, dim_nsoil
     43use planet
    3944use physics,            only: g
    4045use slopes,             only: subslope_dist, def_slope_mean
     
    6065! ---------------
    6166! Utility-related:
    62 integer(li)               :: cr     ! Number of clock ticks per second (count rate)
    63 integer(li)               :: c1, c2 ! Counts of processor clock
    64 character(:), allocatable :: num    ! To write slope variables
    65 integer(di)               :: i, islope
    66 ! Pressure-related:
    67 real(dp), dimension(:),   allocatable :: ps_avg          ! Average surface pressure [Pa]
    68 real(dp), dimension(:),   allocatable :: ps_dev          ! Deviation of surface pressure [Pa]
    69 real(dp), dimension(:,:), allocatable :: ps_ts           ! Surface pressure timeseries [Pa]
    70 real(dp)                              :: ps_avg_glob_ini ! Global average pressure at initialization [Pa]
    71 real(dp)                              :: ps_avg_glob_old ! Global average pressure of previous time step [Pa]
    72 real(dp)                              :: ps_avg_glob     ! Global average pressure of current time step [Pa]
     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
    7371! Ice-related:
    74 real(dp),    dimension(:,:),   allocatable :: h2o_ice                    ! H2O ice [kg.m-2]
    75 real(dp),    dimension(:,:),   allocatable :: co2_ice                    ! CO2 ice [kg.m-2]
    76 real(dp)                                   :: h2oice_sublim_coverage_ini ! Initial surface area of sublimating H2O ice [m2]
    77 real(dp)                                   :: co2ice_sublim_coverage_ini ! Initial surface area of sublimating CO2 ice [m2]
    78 logical(k4), dimension(:,:),   allocatable :: is_h2oice_ini              ! Initial location of H2O ice
    79 logical(k4), dimension(:,:),   allocatable :: is_co2ice_ini              ! Initial location of CO2 ice
    80 logical(k4), dimension(:,:),   allocatable :: is_co2ice_flow             ! Flag for location of CO2 glacier flow
    81 logical(k4), dimension(:,:),   allocatable :: is_h2oice_flow             ! Flag for location of H2O glacier flow
    82 real(dp),    dimension(:,:,:), allocatable :: minPCM_h2operice              ! Minimum of H2O perennial ice over the last PCM year [kg.m-2]
    83 real(dp),    dimension(:,:,:), allocatable :: minPCM_co2perice              ! Minimum of CO2 perennial ice over the last PCM year [kg.m-2]
    84 real(dp),    dimension(:,:,:), allocatable :: minPCM_h2ofrost               ! Minimum of H2O frost over the last PCM year [kg.m-2]
    85 real(dp),    dimension(:,:,:), allocatable :: minPCM_co2frost               ! Minimum of CO2 frost over the last PCM year [kg.m-2]
    86 logical(k4), dimension(:,:),   allocatable :: is_co2ice_disappeared      ! Flag to check if CO2 ice disappeared at the previous timestep
     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.m-2]
     75real(dp),    dimension(:,:,:), allocatable :: minPCM_co2perice ! Minimum of CO2 perennial ice over the last PCM year [kg.m-2]
     76real(dp),    dimension(:,:,:), allocatable :: minPCM_h2ofrost  ! Minimum of H2O frost over the last PCM year [kg.m-2]
     77real(dp),    dimension(:,:,:), allocatable :: minPCM_co2frost  ! Minimum of CO2 frost over the last PCM year [kg.m-2]
    8778! Surface-related:
    88 real(dp), dimension(:,:), allocatable :: tsurf_avg           ! Average surface temperature [K]
    89 real(dp), dimension(:,:), allocatable :: tsurf_avg_yr1       ! Average surface temperature of the second to last PCM run [K]
    90 real(dp), dimension(:,:), allocatable :: tsurf_dev           ! Deviation of surface temperature [K]
    91 real(dp), dimension(:,:), allocatable :: h2o_surfdensity_avg ! Average water surface density [kg/m^3]
    92 real(dp), dimension(:,:), allocatable :: zshift_surf         ! Elevation shift for the surface [m]
    93 real(dp), dimension(:,:), allocatable :: zlag                ! Newly built lag thickness [m]
    94 ! Soil-related:
    95 real(dp), dimension(:,:,:),   allocatable :: tsoil_avg                ! Average soil temperature [K]
    96 real(dp), dimension(:,:,:),   allocatable :: tsoil_dev                ! Deviation pf soil temperature [K]
    97 real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts                 ! Soil temperature timeseries [K]
    98 real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts_old             ! Soil temperature timeseries at the previous time step [K]
    99 real(dp), dimension(:,:,:),   allocatable :: h2o_soildensity_avg      ! Average of soil water soil density [kg/m^3]
    100 real(dp), dimension(:),       allocatable :: delta_co2_ads            ! Quantity of CO2 exchanged due to adsorption/desorption [kg/m^2]
    101 real(dp), dimension(:),       allocatable :: delta_h2o_ads            ! Quantity of H2O exchanged due to adsorption/desorption [kg/m^2]
    102 real(qp)                                  :: totmass_adsh2o           ! Total mass of H2O exchanged because of adsorption/desorption [kg]
    103 real(dp), dimension(:,:,:),   allocatable :: h2o_ads_reg              ! H2O adsorbed in the regolith [kg/m^2]
    104 real(dp), dimension(:,:,:),   allocatable :: co2_ads_reg              ! CO2 adsorbed in the regolith [kg/m^2]
    105 real(dp), dimension(:,:),     allocatable :: icetable_depth           ! Depth of the ice table [m]
    106 real(dp), dimension(:,:),     allocatable :: icetable_thickness       ! Thickness of the ice table [m]
    107 real(dp), dimension(:,:,:),   allocatable :: ice_porefilling          ! Amount of porefilling [m^3/m^3]
    108 real(dp), dimension(:,:),     allocatable :: icetable_depth_old       ! Old depth of the ice table [m]
    109 real(dp), dimension(:),       allocatable :: delta_icetable ! Total mass of the H2O that has sublimated / condenses from the ice table [kg]
    110 ! Tracer-related:
    111 real(dp), dimension(:,:),   allocatable :: q_co2_ts     ! CO2 mass mixing ratio in the first layer [kg/kg]
    112 real(dp), dimension(:,:),   allocatable :: q_co2_ts_ini ! Initial CO2 mass mixing ratio in the first layer [kg/kg]
    113 real(dp), dimension(:,:),   allocatable :: q_h2o_ts     ! H2O mass mixing ratio in the first layer [kg/kg]
     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]
    11482! Tendency-related:
    115 real(dp), dimension(:,:), allocatable :: d_co2ice     ! Tendency of perennial CO2 ice [kg/m2/y]
    116 real(dp), dimension(:,:), allocatable :: d_co2ice_ini ! Tendency of perennial CO2 ice at the beginning [kg/m2/y]
    117 real(dp), dimension(:,:), allocatable :: d_h2oice     ! Tendency of perennial H2O ice [kg/m2/y]
    11883real(dp), dimension(:,:), allocatable :: d_h2oice_new ! Adjusted tendency of perennial H2O ice to keep balance between donor and recipient [kg/m2/y]
    11984! Layering-related:
    120 type(layering), dimension(:,:), allocatable :: layerings_map    ! Layering for each grid point and slope
    12185type(ptrarray), dimension(:,:), allocatable :: current          ! Current active stratum in the layering
    12286real(dp),       dimension(:,:), allocatable :: h2oice_depth     ! Depth of subsurface ice layer
     
    13094real(qp) :: totmass_co2ice_ini, totmass_atmco2_ini, totmass_adsco2_ini ! Initial total CO2 masses (surface ice|atmospheric|adsorbed)
    13195real(qp) :: totmass_ini                                                ! Initial total CO2 mass [kg]
     96real(qp) :: totmass_adsh2o                                             ! Current total adsorbed H2O mass [kg]
    13297real(qp) :: S_atm_2_h2o, S_h2o_2_atm, S_atm_2_h2oice, S_h2oice_2_atm   ! Variables to balance H2O ice reservoirs
    13398
     
    168133
    169134! Read the PCM data given by XIOS
    170 allocate(ps_avg(ngrid),ps_ts(ngrid,nday))
    171 allocate(tsurf_avg(ngrid,nslope),tsurf_avg_yr1(ngrid,nslope),h2o_surfdensity_avg(ngrid,nslope))
    172 allocate(tsoil_avg(ngrid,nsoil,nslope),tsoil_ts(ngrid,nsoil,nslope,nday),h2o_soildensity_avg(ngrid,nsoil,nslope))
    173 allocate(q_h2o_ts(ngrid,nday),q_co2_ts(ngrid,nday))
    174 allocate(minPCM_h2operice(ngrid,nslope,2),minPCM_co2perice(ngrid,nslope,2),minPCM_h2ofrost(ngrid,nslope,2),minPCM_co2frost(ngrid,nslope,2))
     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))
    175141
    176142call load_xios_data(ps_avg,ps_ts,tsurf_avg,tsurf_avg_yr1,tsoil_avg,tsoil_ts,h2o_surfdensity_avg,h2o_soildensity_avg, &
     
    181147
    182148! Compute the deviation from the average
    183 allocate(ps_dev(ngrid),tsurf_dev(ngrid,nslope),tsoil_dev(ngrid,nsoil_PCM,nslope))
     149call allocate_deviation_state()
    184150ps_dev(:) = ps_PCM(:) - ps_avg(:)
    185151tsurf_dev(:,:) = tsurf_PCM(:,:) - tsurf_avg(:,:)
     
    193159
    194160! Read the "startevo.nc"
    195 allocate(h2o_ice(ngrid,nslope),co2_ice(ngrid,nslope))
    196 allocate(icetable_depth(ngrid,nslope),icetable_thickness(ngrid,nslope),ice_porefilling(ngrid,nsoil,nslope))
    197 allocate(h2o_ads_reg(ngrid,nsoil,nslope),co2_ads_reg(ngrid,nsoil,nslope),delta_h2o_ads(ngrid),delta_co2_ads(ngrid))
    198 allocate(layerings_map(ngrid,nslope))
    199 icetable_depth(:,:) = 0._dp
    200 icetable_thickness(:,:) = 0._dp
    201 ice_porefilling(:,:,:) = 0._dp
    202 delta_h2o_ads(:) = 0._dp
    203 delta_co2_ads(:) = 0._dp
    204 call read_startpem(tsurf_avg_yr1,tsurf_avg,ps_avg_glob_ini,ps_ts,q_co2_ts,q_h2o_ts,h2o_surfdensity_avg,h2o_ice,co2_ice, &
     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, &
    205163                   tsoil_avg,h2o_soildensity_avg,icetable_depth,icetable_thickness,ice_porefilling,layerings_map,       &
    206164                   h2o_ads_reg,co2_ads_reg,delta_h2o_ads,delta_co2_ads)
     
    208166
    209167! Compute ice tendencies from yearly minima
    210 allocate(d_h2oice(ngrid,nslope),d_co2ice(ngrid,nslope))
     168call allocate_tendencies()
    211169call print_msg('> Computing surface ice tendencies',LVL_NFO)
    212170call compute_tendice(minPCM_h2operice,minPCM_h2ofrost,h2o_ice,d_h2oice)
     
    218176! Save initial set-up useful for the next computations
    219177call print_msg('> Saving some initial climate state variables',LVL_NFO)
    220 allocate(d_co2ice_ini(ngrid,nslope),q_co2_ts_ini(ngrid,nday))
    221 allocate(is_h2oice_ini(ngrid,nslope),is_co2ice_ini(ngrid,nslope))
     178call allocate_initial_snapshots()
    222179ps_avg_glob_ini = ps_avg_glob
    223180d_co2ice_ini(:,:) = d_co2ice(:,:)
     
    225182h2oice_sublim_coverage_ini = 0._dp
    226183co2ice_sublim_coverage_ini = 0._dp
    227 is_h2oice_ini(:,:) = .false.
    228 is_co2ice_ini(:,:) = .false.
    229184totmass_co2ice_ini = 0._qp
    230185totmass_atmco2_ini = 0._qp
     
    268223    !where (h2oice_depth > 0. .and. zdqsdif_ssi_tot < -minieps) d_h2oice = zdqsdif_ssi_tot
    269224end if
    270 if (nslope == 1) then ! No slope
    271     allocate(character(0) :: num)
    272 else ! Using slopes
    273     allocate(character(8) :: num)
    274 end if
    275 allocate(delta_icetable(ngrid),icetable_depth_old(ngrid,nslope),is_co2ice_disappeared(ngrid,nslope),tsoil_ts_old(ngrid,nsoil,nslope,nday))
    276 is_co2ice_disappeared(:,:) = .false.
    277 delta_icetable(:) = 0._dp
     225call allocate_loop_state()
    278226n_yr_run = 0
    279227idt = 0
     
    353301    call write_diagevo('ps_avg_glob','Global average pressure','Pa',ps_avg_glob)
    354302    do islope = 1,nslope
    355         if (nslope /= 1) then
    356             num = '  '
    357             write(num,'(i2.2)') islope
    358             num = '_slope'//num
    359         end if
    360         call write_diagevo('h2oice'//num,'H2O ice','kg.m-2',h2o_ice(:,islope),(/dim_ngrid/))
    361         call write_diagevo('co2ice'//num,'CO2 ice','kg.m-2',co2_ice(:,islope),(/dim_ngrid/))
    362         call write_diagevo('d_h2oice'//num,'H2O ice tendency','kg.m-2.yr-1',d_h2oice(:,islope),(/dim_ngrid/))
    363         call write_diagevo('d_co2ice'//num,'CO2 ice tendency','kg.m-2.yr-1',d_co2ice(:,islope),(/dim_ngrid/))
     303        if (nslope == 1) then
     304            num = ''
     305        else
     306            write(num,'("_slope",i2.2)') islope
     307        end if
     308        call write_diagevo('h2oice'//trim(num),'H2O ice','kg.m-2',h2o_ice(:,islope),(/dim_ngrid/))
     309        call write_diagevo('co2ice'//trim(num),'CO2 ice','kg.m-2',co2_ice(:,islope),(/dim_ngrid/))
     310        call write_diagevo('d_h2oice'//trim(num),'H2O ice tendency','kg.m-2.yr-1',d_h2oice(:,islope),(/dim_ngrid/))
     311        call write_diagevo('d_co2ice'//trim(num),'CO2 ice tendency','kg.m-2.yr-1',d_co2ice(:,islope),(/dim_ngrid/))
    364312        if (co2ice_flow) then
    365             call write_diagevo('Flow_co2ice'//num,'CO2 ice flow location','T/F',merge(1._dp,0._dp,is_co2ice_flow(:,islope)),(/dim_ngrid/))
    366             deallocate(is_co2ice_flow)
     313            call write_diagevo('Flow_co2ice'//trim(num),'CO2 ice flow location','T/F',merge(1._dp,0._dp,is_co2ice_flow(:,islope)),(/dim_ngrid/))
    367314        end if
    368315        if (h2oice_flow) then
    369             call write_diagevo('Flow_h2oice'//num,'H2O ice flow location','T/F',merge(1._dp,0._dp,is_h2oice_flow(:,islope)),(/dim_ngrid/))
    370             deallocate(is_h2oice_flow)
    371         end if
    372         call write_diagevo('tsurf'//num,'Surface temperature','K',tsurf_avg(:,islope),(/dim_ngrid/))
     316            call write_diagevo('Flow_h2oice'//trim(num),'H2O ice flow location','T/F',merge(1._dp,0._dp,is_h2oice_flow(:,islope)),(/dim_ngrid/))
     317        end if
     318        call write_diagevo('tsurf'//trim(num),'Surface temperature','K',tsurf_avg(:,islope),(/dim_ngrid/))
    373319        if (do_soil) then
    374320            if (icetable_equilibrium) then
    375                 call write_diagevo('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
    376                 call write_diagevo('icetable_thick'//num,'Ice table thickness','m',icetable_thickness(:,islope),(/dim_ngrid/))
     321                call write_diagevo('icetable_depth'//trim(num),'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
     322                call write_diagevo('icetable_thick'//trim(num),'Ice table thickness','m',icetable_thickness(:,islope),(/dim_ngrid/))
    377323            else if (icetable_dynamic) then
    378                 call write_diagevo('icetable_depth'//num,'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
    379                 call write_diagevo('ice_porefilling'//num,'Ice pore filling','-',ice_porefilling(:,:,islope),(/dim_ngrid,dim_nsoil/))
     324                call write_diagevo('icetable_depth'//trim(num),'Ice table depth','m',icetable_depth(:,islope),(/dim_ngrid/))
     325                call write_diagevo('ice_porefilling'//trim(num),'Ice pore filling','-',ice_porefilling(:,:,islope),(/dim_ngrid,dim_nsoil/))
    380326            end if
    381             call write_diagevo('tsoil_avg'//num,'Soil temperature','K',tsoil_avg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    382             call write_diagevo('inertiesoil'//num,'Thermal inertia','SI',TI(:,:,islope),(/dim_ngrid,dim_nsoil/))
     327            call write_diagevo('tsoil_avg'//trim(num),'Soil temperature','K',tsoil_avg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     328            call write_diagevo('inertiesoil'//trim(num),'Thermal inertia','SI',TI(:,:,islope),(/dim_ngrid,dim_nsoil/))
    383329            if (do_sorption) then
    384                 call write_diagevo('co2_ads_reg'//num,'CO2 adsorbed in regolith','kg.m-2',co2_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    385                 call write_diagevo('h2o_ads_reg'//num,'H2O adsorbed in regolith','kg.m-2',h2o_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     330                call write_diagevo('co2_ads_reg'//trim(num),'CO2 adsorbed in regolith','kg.m-2',co2_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
     331                call write_diagevo('h2o_ads_reg'//trim(num),'H2O adsorbed in regolith','kg.m-2',h2o_ads_reg(:,:,islope),(/dim_ngrid,dim_nsoil/))
    386332            end if
    387333        end if
    388334    end do
     335    if (co2ice_flow .and. allocated(is_co2ice_flow)) deallocate(is_co2ice_flow)
     336    if (h2oice_flow .and. allocated(is_h2oice_flow)) deallocate(is_h2oice_flow)
    389337
    390338    ! Checking mass balance for CO2
     
    458406    end if
    459407end do ! End of the evolution loop
    460 deallocate(is_co2ice_disappeared)
    461408
    462409! Finalization
     
    474421
    475422! Deallocation
    476 deallocate(num)
    477423if (do_layering) then
    478424    deallocate(h2oice_depth,h2oice_depth_old,new_str,new_lag,current)
     
    483429    end do
    484430end if
    485 deallocate(layerings_map)
    486 deallocate(h2o_ads_reg,co2_ads_reg)
    487 deallocate(h2o_ice,co2_ice,is_h2oice_ini,is_co2ice_ini)
    488 deallocate(ps_avg,ps_dev,ps_ts)
    489 deallocate(tsurf_avg,tsurf_dev,h2o_surfdensity_avg)
    490 deallocate(tsoil_avg,tsoil_dev,tsoil_ts,tsoil_ts_old,h2o_soildensity_avg)
    491 deallocate(q_h2o_ts,q_co2_ts,q_co2_ts_ini)
    492 deallocate(d_h2oice,d_co2ice,d_co2ice_ini)
    493 deallocate(delta_h2o_ads,delta_co2_ads,delta_icetable,icetable_depth_old)
    494 deallocate(icetable_depth,icetable_thickness,ice_porefilling)
    495431call end_allocation()
    496432
  • trunk/LMDZ.COMMON/libf/evolution/planet.F90

    r4135 r4157  
    55!
    66! DESCRIPTION
    7 !     Legacy compatibility module for planet-specific definitions.
    8 !
    9 ! AUTHORS & DATE
    10 !     R. Vandemeulebrouck
    11 !     JB Clement, 2023-2025
    12 !
    13 ! NOTES
    14 !     Only valid for the Mars planet.
    15 !-----------------------------------------------------------------------
    16 
    17 ! DECLARATION
    18 ! -----------
    19 implicit none
    20 
    21 ! NOTE
    22 ! ----
     7!     Centralized climate-state storage and lifecycle helpers for PEM.
     8!
     9! AUTHORS & DATE
     10!     JB Clement, 03/2026
     11!
     12! NOTES
     13!     Ownership criterion for declarations:
     14!       - Declare in module "planet" variables that are persistent climate
     15!         state or persistent references used across multiple time steps.
     16!       - Declare in program "pem.F90" transient workflow/control varaibles,
     17!         one-shot initialization buffers and per-iteration working buffers.
     18!-----------------------------------------------------------------------
     19
     20! DEPENDENCIES
     21! ------------
     22use numerics,         only: dp, qp, k4
     23use layered_deposits, only: layering
     24
     25! DECLARATION
     26! -----------
     27implicit none
     28
     29! PARAMETERS
     30! ----------
     31! Pressure-related:
     32real(dp), dimension(:),   allocatable :: ps_avg          ! Average surface pressure [Pa]
     33real(dp), dimension(:,:), allocatable :: ps_ts           ! Surface pressure timeseries [Pa]
     34real(dp), dimension(:),   allocatable :: ps_dev          ! Deviation of surface pressure [Pa]
     35real(dp)                              :: ps_avg_glob_ini ! Global average pressure at initialization [Pa]
     36real(dp)                              :: ps_avg_glob_old ! Global average pressure of previous time step [Pa]
     37real(dp)                              :: ps_avg_glob     ! Global average pressure of current time step [Pa]
     38
     39! Ice-related:
     40real(dp),    dimension(:,:), allocatable :: h2o_ice                    ! H2O ice [kg.m-2]
     41real(dp),    dimension(:,:), allocatable :: co2_ice                    ! CO2 ice [kg.m-2]
     42real(dp)                                 :: h2oice_sublim_coverage_ini ! Initial surface area of sublimating H2O ice [m2]
     43real(dp)                                 :: co2ice_sublim_coverage_ini ! Initial surface area of sublimating CO2 ice [m2]
     44logical(k4), dimension(:,:), allocatable :: is_h2oice_ini              ! Initial location of H2O ice
     45logical(k4), dimension(:,:), allocatable :: is_co2ice_ini              ! Initial location of CO2 ice
     46logical(k4), dimension(:,:), allocatable :: is_co2ice_disappeared      ! Flag to check if CO2 ice disappeared at the previous timestep
     47
     48! Surface-related:
     49real(dp), dimension(:,:), allocatable :: tsurf_avg           ! Average surface temperature [K]
     50real(dp), dimension(:,:), allocatable :: tsurf_dev           ! Deviation of surface temperature [K]
     51real(dp), dimension(:,:), allocatable :: h2o_surfdensity_avg ! Average water surface density [kg/m^3]
     52
     53! Soil-related:
     54real(dp), dimension(:,:,:),   allocatable :: tsoil_avg    ! Average soil temperature [K]
     55real(dp), dimension(:,:,:),   allocatable :: tsoil_dev    ! Deviation of soil temperature [K]
     56real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts     ! Soil temperature timeseries [K]
     57real(dp), dimension(:,:,:,:), allocatable :: tsoil_ts_old ! Soil temperature timeseries at the previous time step [K]
     58
     59! Layering-related:
     60type(layering), dimension(:,:), allocatable :: layerings_map ! Layering for each grid point and slope
     61
     62! Sorption-related:
     63real(dp), dimension(:,:,:), allocatable :: h2o_soildensity_avg ! Average of soil water soil density [kg/m^3]
     64real(dp), dimension(:),     allocatable :: delta_co2_ads       ! Quantity of CO2 exchanged due to adsorption/desorption [kg/m^2]
     65real(dp), dimension(:),     allocatable :: delta_h2o_ads       ! Quantity of H2O exchanged due to adsorption/desorption [kg/m^2]
     66real(dp), dimension(:,:,:), allocatable :: h2o_ads_reg         ! H2O adsorbed in the regolith [kg/m^2]
     67real(dp), dimension(:,:,:), allocatable :: co2_ads_reg         ! CO2 adsorbed in the regolith [kg/m^2]
     68
     69! Ice table-related:
     70real(dp), dimension(:,:),   allocatable :: icetable_depth     ! Depth of the ice table [m]
     71real(dp), dimension(:,:),   allocatable :: icetable_thickness ! Thickness of the ice table [m]
     72real(dp), dimension(:,:,:), allocatable :: ice_porefilling    ! Amount of porefilling [m^3/m^3]
     73real(dp), dimension(:,:),   allocatable :: icetable_depth_old ! Old depth of the ice table [m]
     74real(dp), dimension(:),     allocatable :: delta_icetable     ! Total mass of the H2O exchanged with the ice table [kg]
     75
     76! Tracer-related:
     77real(dp), dimension(:,:), allocatable :: q_co2_ts     ! CO2 mass mixing ratio in the first layer [kg/kg]
     78real(dp), dimension(:,:), allocatable :: q_co2_ts_ini ! Initial CO2 mass mixing ratio in the first layer [kg/kg]
     79real(dp), dimension(:,:), allocatable :: q_h2o_ts     ! H2O mass mixing ratio in the first layer [kg/kg]
     80
     81! Tendency-related:
     82real(dp), dimension(:,:), allocatable :: d_co2ice     ! Tendency of perennial CO2 ice [kg/m2/y]
     83real(dp), dimension(:,:), allocatable :: d_co2ice_ini ! Tendency of perennial CO2 ice at the beginning [kg/m2/y]
     84real(dp), dimension(:,:), allocatable :: d_h2oice     ! Tendency of perennial H2O ice [kg/m2/y]
    2385
    2486contains
    2587!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    2688
     89!=======================================================================
     90SUBROUTINE ini_planet()
     91!-----------------------------------------------------------------------
     92! NAME
     93!     ini_planet
     94!
     95! DESCRIPTION
     96!     Initialize scalar state values of module planet.
     97!
     98! AUTHORS & DATE
     99!     JB Clement, 03/2026
     100!
     101! NOTES
     102!
     103!-----------------------------------------------------------------------
     104
     105! DECLARATION
     106! -----------
     107implicit none
     108
     109! CODE
     110! ----
     111ps_avg_glob_ini = 0._dp
     112ps_avg_glob_old = 0._dp
     113ps_avg_glob = 0._dp
     114h2oice_sublim_coverage_ini = 0._dp
     115co2ice_sublim_coverage_ini = 0._dp
     116
     117END SUBROUTINE ini_planet
     118!=======================================================================
     119
     120!=======================================================================
     121SUBROUTINE allocate_xios_state()
     122!-----------------------------------------------------------------------
     123! NAME
     124!     allocate_xios_state
     125!
     126! DESCRIPTION
     127!     Allocate arrays needed before loading PCM/XIOS data.
     128!
     129! AUTHORS & DATE
     130!     JB Clement, 03/2026
     131!
     132! NOTES
     133!
     134!-----------------------------------------------------------------------
     135
     136! DEPENDENCIES
     137! ------------
     138use geometry, only: ngrid, nslope, nday, nsoil
     139
     140! DECLARATION
     141! -----------
     142implicit none
     143
     144! CODE
     145! ----
     146allocate(ps_avg(ngrid))
     147allocate(ps_ts(ngrid,nday))
     148allocate(tsurf_avg(ngrid,nslope))
     149allocate(h2o_surfdensity_avg(ngrid,nslope))
     150allocate(tsoil_avg(ngrid,nsoil,nslope))
     151allocate(tsoil_ts(ngrid,nsoil,nslope,nday))
     152allocate(h2o_soildensity_avg(ngrid,nsoil,nslope))
     153allocate(q_h2o_ts(ngrid,nday))
     154allocate(q_co2_ts(ngrid,nday))
     155
     156ps_avg(:) = 0._dp
     157ps_ts(:,:) = 0._dp
     158tsurf_avg(:,:) = 0._dp
     159h2o_surfdensity_avg(:,:) = 0._dp
     160tsoil_avg(:,:,:) = 0._dp
     161tsoil_ts(:,:,:,:) = 0._dp
     162h2o_soildensity_avg(:,:,:) = 0._dp
     163q_h2o_ts(:,:) = 0._dp
     164q_co2_ts(:,:) = 0._dp
     165
     166END SUBROUTINE allocate_xios_state
     167!=======================================================================
     168
     169!=======================================================================
     170SUBROUTINE allocate_deviation_state()
     171!-----------------------------------------------------------------------
     172! NAME
     173!     allocate_deviation_state
     174!
     175! DESCRIPTION
     176!     Allocate persistent deviation fields derived from PCM averages.
     177!
     178! AUTHORS & DATE
     179!     JB Clement, 03/2026
     180!
     181! NOTES
     182!
     183!-----------------------------------------------------------------------
     184
     185! DEPENDENCIES
     186! ------------
     187use geometry, only: ngrid, nslope, nsoil_PCM
     188
     189! DECLARATION
     190! -----------
     191implicit none
     192
     193! CODE
     194! ----
     195allocate(ps_dev(ngrid))
     196allocate(tsurf_dev(ngrid,nslope))
     197allocate(tsoil_dev(ngrid,nsoil_PCM,nslope))
     198
     199ps_dev(:) = 0._dp
     200tsurf_dev(:,:) = 0._dp
     201tsoil_dev(:,:,:) = 0._dp
     202
     203END SUBROUTINE allocate_deviation_state
     204!=======================================================================
     205
     206!=======================================================================
     207SUBROUTINE allocate_startevo_state()
     208!-----------------------------------------------------------------------
     209! NAME
     210!     allocate_startevo_state
     211!
     212! DESCRIPTION
     213!     Allocate arrays loaded from startevo or evolving afterward.
     214!
     215! AUTHORS & DATE
     216!     JB Clement, 03/2026
     217!
     218! NOTES
     219!
     220!-----------------------------------------------------------------------
     221
     222! DEPENDENCIES
     223! ------------
     224use geometry, only: ngrid, nslope, nsoil
     225
     226! DECLARATION
     227! -----------
     228implicit none
     229
     230! CODE
     231! ----
     232allocate(h2o_ice(ngrid,nslope))
     233allocate(co2_ice(ngrid,nslope))
     234allocate(icetable_depth(ngrid,nslope))
     235allocate(icetable_thickness(ngrid,nslope))
     236allocate(ice_porefilling(ngrid,nsoil,nslope))
     237allocate(h2o_ads_reg(ngrid,nsoil,nslope))
     238allocate(co2_ads_reg(ngrid,nsoil,nslope))
     239allocate(delta_h2o_ads(ngrid))
     240allocate(delta_co2_ads(ngrid))
     241allocate(layerings_map(ngrid,nslope))
     242
     243h2o_ice(:,:) = 0._dp
     244co2_ice(:,:) = 0._dp
     245icetable_depth(:,:) = 0._dp
     246icetable_thickness(:,:) = 0._dp
     247ice_porefilling(:,:,:) = 0._dp
     248h2o_ads_reg(:,:,:) = 0._dp
     249co2_ads_reg(:,:,:) = 0._dp
     250delta_h2o_ads(:) = 0._dp
     251delta_co2_ads(:) = 0._dp
     252
     253END SUBROUTINE allocate_startevo_state
     254!=======================================================================
     255
     256!=======================================================================
     257SUBROUTINE allocate_tendencies()
     258!-----------------------------------------------------------------------
     259! NAME
     260!     allocate_tendencies
     261!
     262! DESCRIPTION
     263!     Allocate perennial ice tendency arrays.
     264!
     265! AUTHORS & DATE
     266!     JB Clement, 03/2026
     267!
     268! NOTES
     269!
     270!-----------------------------------------------------------------------
     271
     272! DEPENDENCIES
     273! ------------
     274use geometry, only: ngrid, nslope
     275
     276! DECLARATION
     277! -----------
     278implicit none
     279
     280! CODE
     281! ----
     282allocate(d_h2oice(ngrid,nslope))
     283allocate(d_co2ice(ngrid,nslope))
     284
     285d_h2oice(:,:) = 0._dp
     286d_co2ice(:,:) = 0._dp
     287
     288END SUBROUTINE allocate_tendencies
     289!=======================================================================
     290
     291!=======================================================================
     292SUBROUTINE allocate_initial_snapshots()
     293!-----------------------------------------------------------------------
     294! NAME
     295!     allocate_initial_snapshots
     296!
     297! DESCRIPTION
     298!     Allocate arrays storing initial-state snapshots.
     299!
     300! AUTHORS & DATE
     301!     JB Clement, 03/2026
     302!
     303! NOTES
     304!
     305!-----------------------------------------------------------------------
     306
     307! DEPENDENCIES
     308! ------------
     309use geometry, only: ngrid, nslope, nday
     310
     311! DECLARATION
     312! -----------
     313implicit none
     314
     315! CODE
     316! ----
     317allocate(d_co2ice_ini(ngrid,nslope))
     318allocate(q_co2_ts_ini(ngrid,nday))
     319allocate(is_h2oice_ini(ngrid,nslope))
     320allocate(is_co2ice_ini(ngrid,nslope))
     321
     322d_co2ice_ini(:,:) = 0._dp
     323q_co2_ts_ini(:,:) = 0._dp
     324is_h2oice_ini(:,:) = .false.
     325is_co2ice_ini(:,:) = .false.
     326
     327END SUBROUTINE allocate_initial_snapshots
     328!=======================================================================
     329
     330!=======================================================================
     331SUBROUTINE allocate_loop_state()
     332!-----------------------------------------------------------------------
     333! NAME
     334!     allocate_loop_state
     335!
     336! DESCRIPTION
     337!     Allocate arrays that start being used during the main PEM loop.
     338!
     339! AUTHORS & DATE
     340!     JB Clement, 03/2026
     341!
     342! NOTES
     343!
     344!-----------------------------------------------------------------------
     345
     346! DEPENDENCIES
     347! ------------
     348use geometry, only: ngrid, nslope, nsoil, nday
     349
     350! DECLARATION
     351! -----------
     352implicit none
     353
     354! CODE
     355! ----
     356allocate(delta_icetable(ngrid))
     357allocate(icetable_depth_old(ngrid,nslope))
     358allocate(is_co2ice_disappeared(ngrid,nslope))
     359allocate(tsoil_ts_old(ngrid,nsoil,nslope,nday))
     360
     361delta_icetable(:) = 0._dp
     362icetable_depth_old(:,:) = 0._dp
     363is_co2ice_disappeared(:,:) = .false.
     364tsoil_ts_old(:,:,:,:) = 0._dp
     365
     366END SUBROUTINE allocate_loop_state
     367!=======================================================================
     368
     369!=======================================================================
     370SUBROUTINE end_planet()
     371!-----------------------------------------------------------------------
     372! NAME
     373!     end_planet
     374!
     375! DESCRIPTION
     376!     Finalize module planet.
     377!
     378! AUTHORS & DATE
     379!     JB Clement, 03/2026
     380!
     381! NOTES
     382!     Deallocate all allocatable state arrays of module planet.
     383!-----------------------------------------------------------------------
     384
     385! DECLARATION
     386! -----------
     387implicit none
     388
     389! CODE
     390! ----
     391if (allocated(ps_avg)) deallocate(ps_avg)
     392if (allocated(ps_ts)) deallocate(ps_ts)
     393if (allocated(ps_dev)) deallocate(ps_dev)
     394if (allocated(h2o_ice)) deallocate(h2o_ice)
     395if (allocated(co2_ice)) deallocate(co2_ice)
     396if (allocated(is_h2oice_ini)) deallocate(is_h2oice_ini)
     397if (allocated(is_co2ice_ini)) deallocate(is_co2ice_ini)
     398if (allocated(is_co2ice_disappeared)) deallocate(is_co2ice_disappeared)
     399if (allocated(tsurf_avg)) deallocate(tsurf_avg)
     400if (allocated(tsurf_dev)) deallocate(tsurf_dev)
     401if (allocated(h2o_surfdensity_avg)) deallocate(h2o_surfdensity_avg)
     402if (allocated(tsoil_avg)) deallocate(tsoil_avg)
     403if (allocated(tsoil_dev)) deallocate(tsoil_dev)
     404if (allocated(tsoil_ts)) deallocate(tsoil_ts)
     405if (allocated(tsoil_ts_old)) deallocate(tsoil_ts_old)
     406if (allocated(layerings_map)) deallocate(layerings_map)
     407if (allocated(h2o_soildensity_avg)) deallocate(h2o_soildensity_avg)
     408if (allocated(delta_co2_ads)) deallocate(delta_co2_ads)
     409if (allocated(delta_h2o_ads)) deallocate(delta_h2o_ads)
     410if (allocated(h2o_ads_reg)) deallocate(h2o_ads_reg)
     411if (allocated(co2_ads_reg)) deallocate(co2_ads_reg)
     412if (allocated(icetable_depth)) deallocate(icetable_depth)
     413if (allocated(icetable_thickness)) deallocate(icetable_thickness)
     414if (allocated(ice_porefilling)) deallocate(ice_porefilling)
     415if (allocated(icetable_depth_old)) deallocate(icetable_depth_old)
     416if (allocated(delta_icetable)) deallocate(delta_icetable)
     417if (allocated(q_co2_ts)) deallocate(q_co2_ts)
     418if (allocated(q_co2_ts_ini)) deallocate(q_co2_ts_ini)
     419if (allocated(q_h2o_ts)) deallocate(q_h2o_ts)
     420if (allocated(d_co2ice)) deallocate(d_co2ice)
     421if (allocated(d_co2ice_ini)) deallocate(d_co2ice_ini)
     422if (allocated(d_h2oice)) deallocate(d_h2oice)
     423if (allocated(layerings_map)) deallocate(layerings_map)
     424
     425END SUBROUTINE end_planet
     426!=======================================================================
     427
    27428END MODULE planet
  • trunk/LMDZ.COMMON/libf/evolution/tracers.F90

    r4147 r4157  
    152152! DEPENDENCIES
    153153! ------------
    154 use geometry, only: dyngrd2vect, nlon, nlat, ngrid
     154use geometry, only: dyngrd2vect
    155155
    156156! DECLARATION
  • trunk/LMDZ.COMMON/libf/evolution/workflow_status.F90

    r4117 r4157  
    152152    n_id_PCM = n_pcm_runs
    153153end if
    154 headline = 'cycle=PCM('//int2str(id_PCM_1)
     154headline = ''
     155headline = headline//'cycle=PCM('//int2str(id_PCM_1)
    155156do i = 1,n_id_PCM - 1
    156157    headline = headline//'+'//int2str(id_PCM_1 + i)
  • trunk/LMDZ.COMMON/libf/evolution/xios_data.F90

    r4147 r4157  
    7272real(dp), dimension(:,:,:),   allocatable    :: var_read_3d
    7373real(dp), dimension(:,:,:,:), allocatable    :: var_read_4d
    74 character(:),                 allocatable    :: num ! To read slope variables
     74character(8)                                 :: num ! Slope suffix to read variables
    7575
    7676! CODE
     
    8181minPCM_h2ofrost(:,:,:) = 0._dp
    8282minPCM_co2frost(:,:,:) = 0._dp
    83 if (nslope == 1) then ! No slope
    84     allocate(character(0) :: num)
    85 else ! Using slopes
    86     allocate(character(8) :: num)
    87 end if
     83num = ''
    8884
    8985!~~~~~~~~~~~~~~~~~~~~~~~~ Year 1 - Yearly data ~~~~~~~~~~~~~~~~~~~~~~~~~
     
    9894allocate(var_read_2d(nlon,nlat),var_read_3d(nlon,nlat,nsoil_PCM))
    9995do islope = 1,nslope
    100     if (nslope /= 1) then
    101         num = '  '
    102         write(num,'(i2.2)') islope
    103         num = '_slope'//num
     96    if (nslope == 1) then
     97        num = ''
     98    else
     99        write(num,'("_slope",i2.2)') islope
    104100    end if
    105     call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,1))
    106     call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,1))
    107     call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,1))
    108     call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,1))
    109     call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg_yr1(:,islope))
     101    call get_var_nc('co2ice'//trim(num),var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,1))
     102    call get_var_nc('h2o_ice_s'//trim(num),var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,1))
     103    call get_var_nc('watercap'//trim(num),var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,1))
     104    call get_var_nc('perennial_co2ice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,1))
     105    call get_var_nc('tsurf'//trim(num),var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg_yr1(:,islope))
    110106end do
    111107
     
    123119call get_var_nc('ps',var_read_2d); call lonlat2vect(var_read_2d,ps_avg)
    124120do islope = 1,nslope
    125     if (nslope /= 1) then
    126         num='  '
    127         write(num,'(i2.2)') islope
    128         num = '_slope'//num
     121    if (nslope == 1) then
     122        num = ''
     123    else
     124        write(num,'("_slope",i2.2)') islope
    129125    end if
    130     call get_var_nc('tsurf'//num,var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg(:,islope))
    131     call get_var_nc('co2ice'//num,var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,2))
    132     call get_var_nc('h2o_ice_s'//num,var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,2))
    133     call get_var_nc('watercap'//num,var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,2))
    134     call get_var_nc('perennial_co2ice'//num,var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,2))
     126    call get_var_nc('tsurf'//trim(num),var_read_2d)           ; call lonlat2vect(var_read_2d,tsurf_avg(:,islope))
     127    call get_var_nc('co2ice'//trim(num),var_read_2d)          ; call lonlat2vect(var_read_2d,minPCM_co2frost(:,islope,2))
     128    call get_var_nc('h2o_ice_s'//trim(num),var_read_2d)       ; call lonlat2vect(var_read_2d,minPCM_h2ofrost(:,islope,2))
     129    call get_var_nc('watercap'//trim(num),var_read_2d)        ; call lonlat2vect(var_read_2d,minPCM_h2operice(:,islope,2))
     130    call get_var_nc('perennial_co2ice'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,minPCM_co2perice(:,islope,2))
    135131    if (do_soil) then
    136         call get_var_nc('soiltemp'//num,var_read_3d)
     132        call get_var_nc('soiltemp'//trim(num),var_read_3d)
    137133        do isoil = 1,nsoil_PCM
    138134            call lonlat2vect(var_read_3d(:,:,isoil),tsoil_avg(:,isoil,islope))
     
    141137            tsoil_avg(:,isoil,islope) = tsoil_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
    142138        end do
    143         call get_var_nc('waterdensity_surface'//num,var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
     139        call get_var_nc('waterdensity_surface'//trim(num),var_read_2d); call lonlat2vect(var_read_2d,h2o_surfdensity_avg(:,islope))
    144140    end if
    145141end do
     
    173169    h2o_soildensity_avg(:,:,:) = 0._dp
    174170    do islope = 1,nslope
    175         if (nslope /= 1) then
    176             num='  '
    177             write(num,'(i2.2)') islope
    178             num = '_slope'//num
     171        if (nslope == 1) then
     172            num = ''
     173        else
     174            write(num,'("_slope",i2.2)') islope
    179175        end if
    180         call get_var_nc('soiltemp'//num,var_read_4d)
     176        call get_var_nc('soiltemp'//trim(num),var_read_4d)
    181177        do iday = 1,nday
    182178            do isoil = 1,nsoil_PCM
     
    187183            end do
    188184        end do
    189         call get_var_nc('waterdensity_soil'//num,var_read_4d)
     185        call get_var_nc('waterdensity_soil'//trim(num),var_read_4d)
    190186        do iday = 1,nday
    191187            do isoil = 1,nsoil_PCM
     
    200196    h2o_soildensity_avg(:,:,:) = h2o_soildensity_avg(:,:,:)/real(nday,dp)
    201197end if
    202 deallocate(var_read_1d,var_read_3d,var_read_4d,num)
     198deallocate(var_read_1d,var_read_3d,var_read_4d)
    203199
    204200! Close the NetCDF file of XIOS outputs
Note: See TracChangeset for help on using the changeset viewer.