Changeset 3571 for trunk/LMDZ.COMMON


Ignore:
Timestamp:
Jan 10, 2025, 5:45:03 PM (10 days ago)
Author:
jbclement
Message:

PEM:

  • New way to manage the pressure: now the PEM manages only the average pressure and keeps the pressure deviation with the instantaneous pressure from the start to reconstruct the pressure at the end ('ps_avg = ps_start + ps_dev'). As a consequence, everything related to pressure in the PEM is modified accordingly.
  • Surface temperatures management is now simpler. It follows the strategy for the pressure (and soil temperature) described above.
  • Soil temperatures are now adapted to match the surface temperature changes occured during the PEM by modifying the soil temperature deviation at the end.
  • Few simplifications/optimizations: notably, the two PCM years are now read in one go in 'read_data_PCM_mod.F90' and only the needed variables are extracted.
  • Deletion of unused variables and unnecessary intermediate variables (memory saving and loop deletion in some cases).
  • Renaming of variables and subroutines to make everything clearer. In particular, the suffixes: '_avg' = average, '_start' = PCM start file, '_dev' = deviation, '_ini' or '0' = initial, '_dyn' = dynamical grid, '_timeseries' = daily average of last PCM year.
  • Cosmetic cleanings for readability.

JBC

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

Legend:

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

    r3554 r3571  
    33implicit none
    44
    5 logical                                   :: adsorption_pem     ! True by default, to compute adsorption/desorption. Read in pem.def
    6 real, save, allocatable, dimension(:,:,:) :: co2_adsorbed_phys ! co2 that is in the regolith [kg/m^2]
    7 real, save, allocatable, dimension(:,:,:) :: h2o_adsorbed_phys ! h2o that is in the regolith [kg/m^2]
     5logical                             :: adsorption_pem     ! True by default, to compute adsorption/desorption. Read in pem.def
     6real, allocatable, dimension(:,:,:) :: co2_adsorbed_phys ! co2 that is in the regolith [kg/m^2]
     7real, allocatable, dimension(:,:,:) :: h2o_adsorbed_phys ! h2o that is in the regolith [kg/m^2]
    88
    99!=======================================================================
  • trunk/LMDZ.COMMON/libf/evolution/changelog.txt

    r3563 r3571  
    528528== 17/12/2024 == JBC
    529529Correction of Norbert Schorghofer's code due to missing initialization and bad shape array as subroutine argument + some cleanings.
     530
     531== 10/01/2025 == JBC
     532- New way to manage the pressure: now the PEM manages only the average pressure and keeps the pressure deviation with the instantaneous pressure from the start to reconstruct the pressure at the end ('ps_avg = ps_start + ps_dev'). As a consequence, everything related to pressure in the PEM is modified accordingly.
     533- Surface temperatures management is now simpler. It follows the strategy for the pressure (and soil temperature) described above.
     534- Soil temperatures are now adapted to match the surface temperature changes occured during the PEM by modifying the soil temperature deviation at the end.
     535- Few simplifications/optimizations: notably, the two PCM years are now read in one go in 'read_data_PCM_mod.F90' and only the needed variables are extracted.
     536- Deletion of unused variables and unnecessary intermediate variables (memory saving and loop deletion in some cases).
     537- Renaming of variables and subroutines to make everything clearer. In particular, the suffixes: '_avg' = average, '_start' = PCM start file, '_dev' = deviation, '_ini' or '0' = initial, '_dyn' = dynamical grid, '_timeseries' = daily average of last PCM year.
     538- Cosmetic cleanings for readability.
  • trunk/LMDZ.COMMON/libf/evolution/evol_ice_mod.F90

    r3556 r3571  
    7777
    7878! OUTPUT
    79 real, dimension(ngrid,nslope), intent(inout) :: h2o_ice     ! Previous and actual density of h2o ice (kg/m^2)
    80 real, dimension(ngrid,nslope), intent(inout) :: d_h2oice    ! Evolution of perennial ice over one year (kg/m^2/year)
    81 integer,                       intent(inout) :: stopPEM     ! Stopping criterion code
     79real, dimension(ngrid,nslope), intent(inout) :: h2o_ice  ! Previous and actual density of h2o ice (kg/m^2)
     80real, dimension(ngrid,nslope), intent(inout) :: d_h2oice ! Evolution of perennial ice over one year (kg/m^2/year)
     81integer,                       intent(inout) :: stopPEM  ! Stopping criterion code
    8282real, dimension(ngrid,nslope), intent(out) :: zshift_surf ! Elevation shift for the surface [m]
    8383
  • trunk/LMDZ.COMMON/libf/evolution/get_timelen_PCM_mod.F90

    r3570 r3571  
    1 MODULE nb_time_step_PCM_mod
     1MODULE get_timelen_PCM_mod
    22
    33use netcdf, only: nf90_open, NF90_NOWRITE, nf90_noerr, nf90_strerror, &
     
    1313!=======================================================================
    1414
    15 SUBROUTINE nb_time_step_PCM(fichnom,timelen)
     15SUBROUTINE get_timelen_PCM(fichnom,timelen)
    1616
    1717implicit none
     
    3030character(len = *), intent(in) :: fichnom !--- FILE NAME
    3131!=======================================================================
    32 !   Local Variables
     32!   Local variables
    3333integer        :: fID, vID, ierr
    3434integer        :: timelen ! number of times stored in the file
    3535!-----------------------------------------------------------------------
    36 modname = "nb_time_step_PCM"
     36modname = "get_timelen_PCM"
    3737
    3838!  Open initial state NetCDF file
     
    5252            write(*,*)"read_data_PCM: Le champ <Time> est absent"
    5353            write(*,*)trim(nf90_strerror(ierr))
    54             call abort_gcm("nb_time_step_PCM", "", 1)
     54            call abort_gcm("get_timelen_PCM", "", 1)
    5555        endif
    5656        ! Get the length of the "Time" dimension
     
    7272write(*,*) "The number of timestep of the PCM run data=", timelen
    7373
    74 END SUBROUTINE nb_time_step_PCM
     74END SUBROUTINE get_timelen_PCM
    7575
    7676!=======================================================================
     
    9898END SUBROUTINE error_msg
    9999
    100 END MODULE nb_time_step_PCM_mod
     100END MODULE get_timelen_PCM_mod
  • trunk/LMDZ.COMMON/libf/evolution/glaciers_mod.F90

    r3553 r3571  
    2121!=======================================================================
    2222
    23 SUBROUTINE flow_co2glaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,vmr_co2_PEM,ps_PCM,global_avg_ps_PCM,global_avg_ps_PEM,co2ice,flag_co2flow,flag_co2flow_mesh)
     23SUBROUTINE flow_co2glaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,vmr_co2_PEM,ps_PCM,ps_avg_global_ini,ps_avg_global,co2ice,flag_co2flow,flag_co2flow_mesh)
    2424
    2525!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
    3838!--------
    3939integer,                           intent(in) :: timelen, ngrid, nslope, iflat ! number of time sample, physical points, subslopes, index of the flat subslope
    40 real,    dimension(ngrid,nslope),  intent(in) :: subslope_dist                 ! Physical points x Slopes: Distribution of the subgrid slopes
    41 real,    dimension(ngrid),         intent(in) :: def_slope_mean                ! Physical points: values of the sub grid slope angles
    42 real,    dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM                   ! Physical x Time field : VMR of co2 in the first layer [mol/mol]
    43 real,    dimension(ngrid,timelen), intent(in) :: ps_PCM                        ! Physical x Time field: surface pressure given by the PCM [Pa]
    44 real,                              intent(in) :: global_avg_ps_PCM             ! Global averaged surface pressure from the PCM [Pa]
    45 real,                              intent(in) :: global_avg_ps_PEM             ! global averaged surface pressure during the PEM iteration [Pa]
     40real,    dimension(ngrid,nslope),  intent(in) :: subslope_dist                 ! Grid points x Slopes: Distribution of the subgrid slopes
     41real,    dimension(ngrid),         intent(in) :: def_slope_mean                ! Grid points: values of the sub grid slope angles
     42real,    dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM                   ! Grid points x Time field : VMR of co2 in the first layer [mol/mol]
     43real,    dimension(ngrid,timelen), intent(in) :: ps_PCM                        ! Grid points x Time field: surface pressure given by the PCM [Pa]
     44real,                              intent(in) :: ps_avg_global_ini             ! Global averaged surface pressure at the beginning [Pa]
     45real,                              intent(in) :: ps_avg_global                 ! Global averaged surface pressure during the PEM iteration [Pa]
    4646
    4747! Ouputs:
    4848!--------
    49 real, dimension(ngrid,nslope), intent(inout) :: co2ice            ! Physical x Slope field: co2 ice on the subgrid slopes [kg/m^2]
     49real, dimension(ngrid,nslope), intent(inout) :: co2ice            ! Grid points x Slope field: co2 ice on the subgrid slopes [kg/m^2]
    5050real, dimension(ngrid,nslope), intent(inout) :: flag_co2flow      ! flag to see if there is flow on the subgrid slopes
    5151real, dimension(ngrid),        intent(inout) :: flag_co2flow_mesh ! same but within the mesh
     
    5353!------
    5454real, dimension(ngrid,nslope) :: Tcond ! Physical field: CO2 condensation temperature [K]
    55 real, dimension(ngrid,nslope) :: hmax  ! Physical x Slope field: maximum thickness for co2  glacier before flow
     55real, dimension(ngrid,nslope) :: hmax  ! Grid points x Slope field: maximum thickness for co2  glacier before flow
    5656
    5757write(*,*) "Flow of CO2 glaciers"
    58 call computeTcondCO2(timelen,ngrid,nslope,vmr_co2_PEM,ps_PCM,global_avg_ps_PCM,global_avg_ps_PEM,Tcond)
     58call computeTcondCO2(timelen,ngrid,nslope,vmr_co2_PEM,ps_PCM,ps_avg_global_ini,ps_avg_global,Tcond)
    5959call compute_hmaxglaciers(ngrid,nslope,iflat,def_slope_mean,Tcond,"co2",hmax)
    60 call transfer_ice_duringflow(ngrid,nslope,iflat, subslope_dist,def_slope_mean,hmax,Tcond,"co2",co2ice,flag_co2flow,flag_co2flow_mesh)
     60call transfer_ice_duringflow(ngrid,nslope,iflat,subslope_dist,def_slope_mean,hmax,Tcond,co2ice,flag_co2flow,flag_co2flow_mesh)
    6161
    6262END SUBROUTINE flow_co2glaciers
     
    6464!=======================================================================
    6565
    66 SUBROUTINE flow_h2oglaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,Tice,h2oice,flag_h2oflow,flag_h2oflow_mesh)
     66SUBROUTINE flow_h2oglaciers(ngrid,nslope,iflat,subslope_dist,def_slope_mean,Tice,h2oice,flag_h2oflow,flag_h2oflow_mesh)
    6767
    6868!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
    8282
    8383! Inputs:
    84 integer,                       intent(in) :: timelen, ngrid, nslope, iflat ! number of time sample, physical points, subslopes, index of the flat subslope
    85 real, dimension(ngrid,nslope), intent(in) :: subslope_dist  ! Physical points x Slopes : Distribution of the subgrid slopes
     84integer,                       intent(in) :: ngrid, nslope, iflat ! number of time sample, physical points, subslopes, index of the flat subslope
     85real, dimension(ngrid,nslope), intent(in) :: subslope_dist  ! Grid points x Slopes : Distribution of the subgrid slopes
    8686real, dimension(ngrid),        intent(in) :: def_slope_mean ! Slopes: values of the sub grid slope angles
    8787real, dimension(ngrid,nslope), intent(in) :: Tice           ! Ice Temperature [K]
    8888! Ouputs:
    89 real, dimension(ngrid,nslope), intent(inout) :: h2oice            ! Physical x Slope field: co2 ice on the subgrid slopes [kg/m^2]
     89real, dimension(ngrid,nslope), intent(inout) :: h2oice            ! Grid points x Slope field: co2 ice on the subgrid slopes [kg/m^2]
    9090real, dimension(ngrid,nslope), intent(inout) :: flag_h2oflow      ! flag to see if there is flow on the subgrid slopes
    9191real, dimension(ngrid),        intent(inout) :: flag_h2oflow_mesh ! same but within the mesh
    9292! Local
    93 real, dimension(ngrid,nslope) :: hmax ! Physical x Slope field: maximum thickness for co2  glacier before flow
     93real, dimension(ngrid,nslope) :: hmax ! Grid points x Slope field: maximum thickness for co2  glacier before flow
    9494
    9595write(*,*) "Flow of H2O glaciers"
    9696call compute_hmaxglaciers(ngrid,nslope,iflat,def_slope_mean,Tice,"h2o",hmax)
    97 call transfer_ice_duringflow(ngrid,nslope,iflat, subslope_dist,def_slope_mean,hmax,Tice,"h2o",h2oice,flag_h2oflow,flag_h2oflow_mesh)
     97call transfer_ice_duringflow(ngrid,nslope,iflat,subslope_dist,def_slope_mean,hmax,Tice,h2oice,flag_h2oflow,flag_h2oflow_mesh)
    9898
    9999END SUBROUTINE flow_h2oglaciers
     
    161161!=======================================================================
    162162
    163 SUBROUTINE transfer_ice_duringflow(ngrid,nslope,iflat,subslope_dist,def_slope_mean,hmax,Tice,name_ice,qice,flag_flow,flag_flowmesh)
     163SUBROUTINE transfer_ice_duringflow(ngrid,nslope,iflat,subslope_dist,def_slope_mean,hmax,Tice,qice,flag_flow,flag_flowmesh)
    164164!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    165165!!!
     
    188188real, dimension(ngrid,nslope), intent(in) :: hmax           ! maximum height of the  glaciers before initiating flow [m]
    189189real, dimension(ngrid,nslope), intent(in) :: Tice           ! Ice temperature[K]
    190 character(3),                  intent(in) :: name_ice       ! Nature of the ice
    191190! Outputs
    192191!--------
     
    232231!=======================================================================
    233232
    234 SUBROUTINE computeTcondCO2(timelen,ngrid,nslope,vmr_co2_PEM,ps_PCM,global_avg_ps_PCM,global_avg_ps_PEM,Tcond)
     233SUBROUTINE computeTcondCO2(timelen,ngrid,nslope,vmr_co2_PEM,ps_PCM,ps_avg_global_ini,ps_avg_global,Tcond)
    235234!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    236235!!!
     
    241240!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    242241
    243 use constants_marspem_mod, only: alpha_clap_co2,beta_clap_co2
     242use constants_marspem_mod, only: alpha_clap_co2, beta_clap_co2
    244243
    245244implicit none
     
    250249! INPUT
    251250integer,                        intent(in) :: timelen, ngrid, nslope ! # of timesample, physical points, subslopes
    252 real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM            ! Physical points x times field: VMR of CO2 in the first layer [mol/mol]
    253 real, dimension(ngrid,timelen), intent(in) :: ps_PCM                 ! Physical points x times field: surface pressure in the PCM [Pa]
    254 real,                           intent(in) :: global_avg_ps_PCM      ! Global averaged surfacepressure in the PCM [Pa]
    255 real,                           intent(in) :: global_avg_ps_PEM      ! Global averaged surface pressure computed during the PEM iteration
     251real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM            ! Grid points x times field: VMR of CO2 in the first layer [mol/mol]
     252real, dimension(ngrid,timelen), intent(in) :: ps_PCM                 ! Grid points x times field: surface pressure in the PCM [Pa]
     253real,                           intent(in) :: ps_avg_global_ini      ! Global averaged surfacepressure in the PCM [Pa]
     254real,                           intent(in) :: ps_avg_global          ! Global averaged surface pressure computed during the PEM iteration
    256255
    257256! OUTPUT
    258 real, dimension(ngrid,nslope), intent(out) :: Tcond ! Physical points: condensation temperature of CO2, yearly averaged
     257real, dimension(ngrid,nslope), intent(out) :: Tcond ! Grid points: condensation temperature of CO2, yearly averaged
    259258
    260259! LOCAL
    261260integer :: ig, it ! For loop
    262 real    :: ave    ! Intermediate to compute average
    263261
    264262do ig = 1,ngrid
    265     ave = 0
     263    Tcond(ig,:) = 0
    266264    do it = 1,timelen
    267         ave = ave + beta_clap_co2/(alpha_clap_co2 - log(vmr_co2_PEM(ig,it)*ps_PCM(ig,it)*global_avg_ps_PCM/global_avg_ps_PEM/100))
     265        Tcond(ig,:) = Tcond(ig,:) + beta_clap_co2/(alpha_clap_co2 - log(vmr_co2_PEM(ig,it)*ps_PCM(ig,it)*ps_avg_global_ini/ps_avg_global/100))
    268266    enddo
    269     Tcond(ig,:) = ave/timelen
     267    Tcond(ig,:) = Tcond(ig,:)/timelen
    270268enddo
    271269
  • trunk/LMDZ.COMMON/libf/evolution/ice_table_mod.F90

    r3532 r3571  
    383383!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    384384
    385 use comsoil_h_PEM, only: layer_PEM, mlayer_PEM
     385use comsoil_h_PEM, only: mlayer_PEM
    386386use abort_pem_mod, only: abort_pem
    387387
  • trunk/LMDZ.COMMON/libf/evolution/lask_param_mod.F90

    r3149 r3571  
    1111implicit none
    1212
    13 real, dimension(:), allocatable, save :: yearlask   ! year before present from Laskar et al. Tab
    14 real, dimension(:), allocatable, save :: obllask    ! obliquity    [deg]
    15 real, dimension(:), allocatable, save :: ecclask    ! eccentricity [deg]
    16 real, dimension(:), allocatable, save :: lsplask    ! ls perihelie [deg]
    17 integer,                         save :: last_ilask ! Index of the line in the file year_obl_lask.asc corresponding to the closest lower year to the current year
     13real, dimension(:), allocatable :: yearlask   ! year before present from Laskar et al. Tab
     14real, dimension(:), allocatable :: obllask    ! obliquity    [deg]
     15real, dimension(:), allocatable :: ecclask    ! eccentricity [deg]
     16real, dimension(:), allocatable :: lsplask    ! ls perihelie [deg]
     17integer                        :: last_ilask ! Index of the line in the file year_obl_lask.asc corresponding to the closest lower year to the current year
    1818
    1919!=======================================================================
  • trunk/LMDZ.COMMON/libf/evolution/pem.F90

    r3554 r3571  
    77!    I_e Initialization of the PEM variable and soil
    88!    I_f Compute tendencies
    9 !    I_g Save the initial situation
     9!    I_g Compute global surface pressure
    1010!    I_h Read the "startpem.nc"
    1111!    I_i Compute orbit criterion
     
    4040use pemredem,                   only: pemdem0, pemdem1
    4141use glaciers_mod,               only: flow_co2glaciers, flow_h2oglaciers, co2ice_flow, h2oice_flow, inf_h2oice_threshold, &
    42                                       metam_h2oice_threshold, metam_co2ice_threshold, metam_h2oice, metam_co2ice
     42                                      metam_h2oice_threshold, metam_co2ice_threshold, metam_h2oice, metam_co2ice, computeTcondCO2
    4343use stopping_crit_mod,          only: stopping_crit_h2o_ice, stopping_crit_co2
    4444use constants_marspem_mod,      only: alpha_clap_co2, beta_clap_co2, alpha_clap_h2o, beta_clap_h2o, m_co2, m_noco2
    4545use evol_ice_mod,               only: evol_co2_ice, evol_h2o_ice
    46 use comsoil_h_PEM,              only: soil_pem, ini_comsoil_h_PEM, end_comsoil_h_PEM, nsoilmx_PEM, mlayer_PEM, &
    47                                       TI_PEM,               & ! soil thermal inertia
     46use comsoil_h_PEM,              only: soil_pem, ini_comsoil_h_PEM, end_comsoil_h_PEM, nsoilmx_PEM, &
     47                                      TI_PEM,               & ! Soil thermal inertia
    4848                                      tsoil_PEM, layer_PEM, & ! Soil temp, number of subsurface layers, soil mid layer depths
    4949                                      fluxgeo                 ! Geothermal flux for the PEM and PCM
    5050use adsorption_mod,             only: regolith_adsorption, adsorption_pem,        & ! Bool to check if adsorption, main subroutine
    5151                                      ini_adsorption_h_PEM, end_adsorption_h_PEM, & ! Allocate arrays
    52                                       co2_adsorbed_phys, h2o_adsorbed_phys        ! Mass of co2 and h2O adsorbed
     52                                      co2_adsorbed_phys, h2o_adsorbed_phys          ! Mass of co2 and h2O adsorbed
    5353use time_evol_mod,              only: dt, evol_orbit_pem, Max_iter_pem, convert_years, year_bp_ini
    5454use orbit_param_criterion_mod,  only: orbit_param_criterion
     
    6262use compute_tend_mod,           only: compute_tend
    6363use info_PEM_mod,               only: info_PEM
    64 use nb_time_step_PCM_mod,       only: nb_time_step_PCM
     64use get_timelen_PCM_mod,        only: get_timelen_PCM
    6565use pemetat0_mod,               only: pemetat0
    6666use read_data_PCM_mod,          only: read_data_PCM
    67 use recomp_tend_co2_slope_mod,  only: recomp_tend_co2
     67use recomp_tend_co2_mod,        only: recomp_tend_co2
    6868use compute_soiltemp_mod,       only: compute_tsoil_pem, shift_tsoil2surf
    6969use writediagpem_mod,           only: writediagpem, writediagsoilpem
     
    7777                                  albedodat, zmea, zstd, zsig, zgam, zthe,     &
    7878                                  albedo_h2o_frost,frost_albedo_threshold,     &
    79                                   emissiv, watercaptag, perennial_co2ice, emisice, albedice
     79                                  emissiv, watercaptag, perennial_co2ice
    8080    use dimradmars_mod,     only: totcloudfrac, albedo
    8181    use dust_param_mod,     only: tauscaling
     
    128128real               :: time_phys    ! Same as in PCM
    129129real               :: ptimestep    ! Same as in PCM
    130 real               :: ztime_fin     ! Same as in PCM
    131 
    132 ! Variables to read start.nc
     130real               :: ztime_fin    ! Same as in PCM
     131
     132! Variables to read "start.nc"
    133133character(*), parameter :: start_name = "start.nc" ! Name of the file used to initialize the PEM
    134134
     
    136136real, dimension(ip1jm,llm)          :: vcov          ! vents covariants
    137137real, dimension(ip1jmp1,llm)        :: ucov          ! vents covariants
    138 real, dimension(ip1jmp1,llm)        :: teta          ! temperature potentielle
     138real, dimension(ip1jmp1,llm)        :: teta          ! Potential temperature
    139139real, dimension(:,:,:), allocatable :: q             ! champs advectes
    140 real, dimension(ip1jmp1)            :: ps            ! pression au sol
    141 real, dimension(ip1jmp1)            :: ps0           ! pression au sol initiale
    142 real, dimension(:),     allocatable :: ps_start_PCM  ! (ngrid) surface pressure
    143 real, dimension(:,:),   allocatable :: ps_timeseries ! (ngrid x timelen) instantaneous surface pressure
    144 real, dimension(ip1jmp1,llm)        :: masse         ! masse d'air
     140real, dimension(ip1jmp1)            :: ps_start_dyn  ! surface pressure in the start file (dynamic grid)
     141real, dimension(:),     allocatable :: ps_start      ! surface pressure in the start file
     142real, dimension(:),     allocatable :: ps_start0     ! surface pressure in the start file at the beginning
     143real, dimension(:),     allocatable :: ps_avg        ! (ngrid) Averaged surface pressure
     144real, dimension(:),     allocatable :: ps_dev        ! (ngrid x timelen) Surface pressure deviation
     145real, dimension(:,:),   allocatable :: ps_timeseries ! (ngrid x timelen) Instantaneous surface pressure
     146real, dimension(ip1jmp1,llm)        :: masse         ! Air mass
    145147real, dimension(ip1jmp1)            :: phis          ! geopotentiel au sol
    146148real                                :: time_0
     
    157159real, dimension(:), allocatable :: latitude      ! Latitude read in startfi_name and written in restartfi
    158160real, dimension(:), allocatable :: cell_area     ! Cell_area read in startfi_name and written in restartfi
    159 real                            :: Total_surface ! Total surface of the planet
     161real                            :: total_surface ! Total surface of the planet
    160162
    161163! Variables for h2o_ice evolution
    162164real, dimension(:,:),    allocatable  :: h2o_ice              ! h2o ice in the PEM
     165real, dimension(:,:),    allocatable  :: d_h2oice             ! physical point x slope field: Tendency of evolution of perennial h2o ice
    163166real, dimension(:,:,:),  allocatable  :: min_h2o_ice          ! Minima of h2o ice at each point for the PCM years [kg/m^2]
    164167real                                  :: h2oice_ini_surf      ! Initial surface of sublimating h2o ice
    165 logical, dimension(:,:), allocatable  :: ini_h2oice_sublim    ! Logical array to know if h2o ice is sublimating
    166 real                                  :: global_avg_press_PCM ! constant: global average pressure retrieved in the PCM [Pa]
    167 real                                  :: global_avg_press_old ! constant: Global average pressure of initial/previous time step
    168 real                                  :: global_avg_press_new ! constant: Global average pressure of current time step
    169 real,   dimension(:,:),   allocatable :: zplev_new            ! Physical x Atmospheric field: mass of the atmospheric layers in the pem at current time step [kg/m^2]
    170 real,   dimension(:,:),   allocatable :: zplev_PCM            ! same but retrieved from the PCM [kg/m^2]
    171 real,   dimension(:,:,:), allocatable :: zplev_new_timeseries ! Physical x Atmospheric x Time: same as zplev_new, but in times series [kg/m ^2]
    172 real,   dimension(:,:,:), allocatable :: zplev_old_timeseries ! same but with the time series, for oldest time step
     168logical, dimension(:,:), allocatable  :: is_h2oice_sublim_ini ! Logical array to know if h2o ice is sublimating
     169real                                  :: ps_avg_global_ini    ! constant: Global average pressure at initialization [Pa]
     170real                                  :: ps_avg_global_old    ! constant: Global average pressure of previous time step
     171real                                  :: ps_avg_global_new    ! constant: Global average pressure of current time step
     172real,   dimension(:,:),   allocatable :: zplev_new            ! Grid points x Atmospheric field: mass of the atmospheric layers in the pem at current time step [kg/m^2]
     173real,   dimension(:,:),   allocatable :: zplev_start0         ! Grid points x Atmospheric field: mass of the atmospheric layers in the start [kg/m^2]
     174real,   dimension(:,:,:), allocatable :: zplev_timeseries_new ! Grid points x Atmospheric x Time: same as zplev_new, but in times series [kg/m ^2]
     175real,   dimension(:,:,:), allocatable :: zplev_timeseries_old ! same but with the time series, for previous time step
    173176integer                               :: stopPEM              ! which criterion is reached? 0 = no stopping; 1 = h2o ice surf; 2 = no h2o ice; 3 = co2 ice surf; 4 = ps; 5 = orb param; 6 = end of simu
    174 real, save                            :: A, B, mmean          ! Molar mass: intermediate A, B for computations of the  mean molar mass of the layer [mol/kg]
    175 real,   dimension(:,:),   allocatable :: q_h2o_PEM_phys       ! Physics x Times: h2o mass mixing ratio computed in the PEM, first value comes from PCM [kg/kg]
     177real                                  :: A, B, mmean          ! Molar mass: intermediate A, B for computations of the  mean molar mass of the layer [mol/kg]
     178real,   dimension(:,:),   allocatable :: q_h2o_PEM_phys       ! Grid points x Times: h2o mass mixing ratio computed in the PEM, first value comes from PCM [kg/kg]
    176179integer                               :: timelen              ! # time samples
    177 real                                  :: ave                  ! intermediate varibale to compute average
    178 real,   dimension(:,:),   allocatable :: p                    ! Physics x Atmosphere: pressure to recompute and write in restart (ngrid,llmp1)
     180real,   dimension(:,:),   allocatable :: p                    ! Grid points x Atmosphere: pressure to recompute and write in restart (ngrid,llmp1)
    179181real                                  :: extra_mass           ! Intermediate variables Extra mass of a tracer if it is greater than 1
    180182
    181183! Variables for co2_ice evolution
    182 real,    dimension(:,:), allocatable :: co2_ice           ! co2 ice in the PEM
    183 logical, dimension(:,:), allocatable :: is_co2ice_ini     ! Was there co2 ice initially in the PEM?
    184 real,  dimension(:,:,:), allocatable :: min_co2_ice       ! Minimum of co2 ice at each point for the first year [kg/m^2]
    185 real                                 :: co2ice_ini_surf   ! Initial surface of sublimating co2 ice
    186 logical, dimension(:,:), allocatable :: ini_co2ice_sublim ! Logical array to know if co2 ice is sublimating
    187 real,    dimension(:,:), allocatable :: vmr_co2_PCM       ! Physics x Times co2 volume mixing ratio retrieve from the PCM [m^3/m^3]
    188 real,    dimension(:,:), allocatable :: vmr_co2_PEM_phys  ! Physics x Times co2 volume mixing ratio used in the PEM
    189 real,    dimension(:,:), allocatable :: q_co2_PEM_phys    ! Physics x Times co2 mass mixing ratio in the first layer computed in the PEM, first value comes from PCM [kg/kg]
     184real,    dimension(:,:), allocatable :: co2_ice                ! co2 ice in the PEM
     185real,    dimension(:,:), allocatable :: d_co2ice               ! physical point x slope field: Tendency of evolution of perennial co2 ice over a year
     186real,    dimension(:,:), allocatable :: d_co2ice_ini           ! physical point x slope field: Tendency of evolution of perennial co2 ice over a year in the PCM
     187logical, dimension(:,:), allocatable :: is_co2ice_ini          ! Was there co2 ice initially in the PEM?
     188real,  dimension(:,:,:), allocatable :: min_co2_ice            ! Minimum of co2 ice at each point for the first year [kg/m^2]
     189real                                 :: co2ice_sublim_surf_ini ! Initial surface of sublimating co2 ice
     190logical, dimension(:,:), allocatable :: is_co2ice_sublim_ini   ! Logical array to know if co2 ice is sublimating
     191real,    dimension(:,:), allocatable :: vmr_co2_PCM            ! Grid points x Times co2 volume mixing ratio retrieve from the PCM [m^3/m^3]
     192real,    dimension(:,:), allocatable :: vmr_co2_PEM_phys       ! Grid points x Times co2 volume mixing ratio used in the PEM
     193real,    dimension(:,:), allocatable :: q_co2_PEM_phys         ! Grid points x Times co2 mass mixing ratio in the first layer computed in the PEM, first value comes from PCM [kg/kg]
    190194
    191195! Variables for stratification (layering) evolution
     
    195199
    196200! Variables for slopes
    197 real, dimension(:,:),   allocatable :: d_co2ice          ! physical point x slope field: Tendency of evolution of perennial co2 ice over a year
    198 real, dimension(:,:),   allocatable :: d_co2ice_ini      ! physical point x slope field: Tendency of evolution of perennial co2 ice over a year in the PCM
    199 real, dimension(:,:),   allocatable :: d_h2oice          ! physical point x slope field: Tendency of evolution of perennial h2o ice
    200201real, dimension(:,:),   allocatable :: flag_co2flow      ! (ngrid,nslope): Flag where there is a CO2 glacier flow
    201202real, dimension(:),     allocatable :: flag_co2flow_mesh ! (ngrid)       : Flag where there is a CO2 glacier flow
     
    204205
    205206! Variables for surface and soil
    206 real, dimension(:,:),     allocatable :: tsurf_avg                        ! Physic x SLOPE field: Averaged Surface Temperature [K]
    207 real, dimension(:,:,:),   allocatable :: tsoil_avg                        ! Physic x SOIL x SLOPE field: Averaged Soil Temperature [K]
    208 real, dimension(:,:,:),   allocatable :: tsurf_PCM_timeseries             ! ngrid x SLOPE x TIMES field: Surface Temperature in timeseries [K]
    209 real, dimension(:,:,:,:), allocatable :: tsoil_phys_PEM_timeseries        ! IG x SOIL x SLOPE x TIMES field: Non averaged Soil Temperature [K]
    210 real, dimension(:,:,:,:), allocatable :: tsoil_anom                       ! IG x SOIL x SLOPE x TIMES field: Amplitude between instataneous and yearly average soil temperature at the beginning [K]
    211 real, dimension(:,:),     allocatable :: tsurf_avg_yr1                    ! Physic x SLOPE field: Averaged Surface Temperature of first call of the PCM [K]
    212 real, dimension(:,:),     allocatable :: Tsoil_locslope                   ! Physic x Soil: Intermediate when computing Tsoil [K]
    213 real, dimension(:),       allocatable :: Tsurf_locslope                   ! Physic x Soil: Intermediate surface temperature to compute Tsoil [K]
    214 real, dimension(:,:,:,:), allocatable :: watersoil_density_timeseries     ! Physic x Soil x Slope x Times water soil density, time series [kg /m^3]
    215 real, dimension(:,:),     allocatable :: watersurf_density_avg            ! Physic x Slope, water surface density, yearly averaged [kg/m^3]
    216 real, dimension(:,:,:,:), allocatable :: watersoil_density_PEM_timeseries ! Physic x Soil x Slope x Times, water soil density, time series [kg/m^3]
    217 real, dimension(:,:,:),   allocatable :: watersoil_density_PEM_avg        ! Physic x Soil x Slopes, water soil density, yearly averaged [kg/m^3]
    218 real, dimension(:,:),     allocatable :: Tsurfavg_before_saved            ! Surface temperature saved from previous time step [K]
     207real, dimension(:,:),     allocatable :: tsurf_avg                        ! Grid points x Slope field: Averaged surface temperature [K]
     208real, dimension(:,:),     allocatable :: tsurf_dev                        ! ngrid x Slope x Times field: Surface temperature deviation [K]
     209real, dimension(:,:),     allocatable :: tsurf_avg_yr1                    ! Grid points x Slope field: Averaged surface temperature of first call of the PCM [K]
     210real, dimension(:,:,:),   allocatable :: tsoil_avg                        ! Grid points x Soil x Slope field: Averaged Soil Temperature [K]
     211real, dimension(:,:),     allocatable :: tsoil_avg_old                    ! Grid points x Soil field: Averaged Soil Temperature at the previous time step [K]
     212real, dimension(:,:,:),   allocatable :: tsoil_dev                        ! Grid points x Soil x Slope field: Soil temperature deviation [K]
     213real, dimension(:,:,:,:), allocatable :: tsoil_timeseries                 ! Grid points x Soil x Slope x Times field: Soil temperature timeseries [K]
     214real, dimension(:,:,:,:), allocatable :: tsoil_PEM_timeseries             ! Grid points x Soil x Slope x Times field: Soil temperature timeseries for PEM [K]
     215real, dimension(:,:,:,:), allocatable :: watersoil_density_timeseries     ! Grid points x Soil x Slope x Times Water soil density timeseries [kg /m^3]
     216real, dimension(:,:),     allocatable :: watersurf_density_avg            ! Grid points x Slope: Averaged  water surface density [kg/m^3]
     217real, dimension(:,:,:,:), allocatable :: watersoil_density_PEM_timeseries ! Grid points x Soil x Slope x Times: Water soil density timeseries for PEM [kg/m^3]
     218real, dimension(:,:,:),   allocatable :: watersoil_density_PEM_avg        ! Grid points x Soil x Slopes: Averaged water soil density [kg/m^3]
     219real, dimension(:,:),     allocatable :: tsurf_avg_old                    ! Surface temperature saved from previous time step [K]
    219220real, dimension(:),       allocatable :: delta_co2_adsorbed               ! Physics: quantity of CO2 that is exchanged because of adsorption / desorption [kg/m^2]
    220221real, dimension(:),       allocatable :: delta_h2o_adsorbed               ! Physics: quantity of H2O that is exchanged because of adsorption / desorption [kg/m^2]
    221222real                                  :: totmassco2_adsorbed              ! Total mass of CO2 that is exchanged because of adsorption / desoprtion over the planets [kg]
    222223real                                  :: totmassh2o_adsorbed              ! Total mass of H2O that is exchanged because of adsorption / desoprtion over the planets [kg]
    223 logical                               :: bool_sublim                      ! logical to check if there is sublimation or not
    224224logical, dimension(:,:),  allocatable :: co2ice_disappeared               ! logical to check if a co2 ice reservoir already disappeared at a previous timestep
    225225real, dimension(:,:),     allocatable :: icetable_thickness_old           ! ngrid x nslope: Thickness of the ice table at the previous iteration [m]
     
    233233! Some variables for the PEM run
    234234real, parameter :: year_step = 1   ! Timestep for the pem
    235 real            :: i_myear_leg       ! Number of iteration
     235real            :: i_myear_leg     ! Number of iteration
    236236real            :: n_myear_leg     ! Maximum number of iterations before stopping
    237237real            :: i_myear         ! Global number of Martian years of the chained simulations
     
    249249
    250250#ifdef CPP_STD
    251     real                                :: frost_albedo_threshold = 0.05 ! frost albedo threeshold to convert fresh frost to old ice
    252     real                                :: albedo_h2o_frost              ! albedo of h2o frost
     251    real                                :: frost_albedo_threshold = 0.05 ! Frost albedo threeshold to convert fresh frost to old ice
     252    real                                :: albedo_h2o_frost              ! Albedo of h2o frost
    253253    real, dimension(:),     allocatable :: tsurf_read_generic            ! Temporary variable to do the subslope transfert dimension when reading form generic
    254254    real, dimension(:,:),   allocatable :: qsurf_read_generic            ! Temporary variable to do the subslope transfert dimension when reading form generic
     
    286286
    287287! Loop variables
    288 integer :: i, l, ig, nnq, t, islope, ig_loop, islope_loop, isoil, icap
     288integer :: i, l, ig, nnq, t, islope, ig_loop, islope_loop, isoil
    289289
    290290! Elapsed time with system clock
     
    379379    endif
    380380
    381     call init_testphys1d('start1D.txt','startfi.nc',therestart1D,therestartfi,ngrid,nlayer,610.,nq,q,        &
    382                          time_0,ps(1),ucov,vcov,teta,ndt,ptif,pks,dtphys,zqsat,dq,dqdyn,day0,day,gru,grv,w,  &
     381    call init_testphys1d('start1D.txt','startfi.nc',therestart1D,therestartfi,ngrid,nlayer,610.,nq,q,            &
     382                         time_0,ps_start_dyn(1),ucov,vcov,teta,ndt,ptif,pks,dtphys,zqsat,dq,dqdyn,day0,day,gru,grv,w,  &
    383383                         play,plev,latitude,longitude,cell_area,atm_wat_profile,atm_wat_tau)
    384     ps(2) = ps(1)
     384    ps_start_dyn(2) = ps_start_dyn(1)
    385385    nsplit_phys = 1
    386386    day_step = steps_per_sol
     
    391391!------------------------
    392392! I   Initialization
    393 !    I_b Read of the "start.nc" and starfi_evol.nc
     393!    I_b Read of the "start.nc" and "starfi.nc"
    394394!------------------------
    395395! I_b.1 Read "start.nc"
    396 allocate(ps_start_PCM(ngrid))
     396allocate(ps_start(ngrid),ps_start0(ngrid))
    397397#ifndef CPP_1D
    398     call dynetat0(start_name,vcov,ucov,teta,q,masse,ps,phis,time_0)
    399 
    400     call gr_dyn_fi(1,iip1,jjp1,ngridmx,ps,ps_start_PCM)
     398    call dynetat0(start_name,vcov,ucov,teta,q,masse,ps_start_dyn,phis,time_0)
     399
     400    call gr_dyn_fi(1,iip1,jjp1,ngridmx,ps_start_dyn,ps_start)
    401401
    402402    call iniconst !new
     
    412412    status = nf90_close(ncid)
    413413
    414     call iniphysiq(iim,jjm,llm,(jjm-1)*iim+2,comm_lmdz,daysec,day_ini,dtphys/nsplit_phys,rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,iflag_phys)
     414    call iniphysiq(iim,jjm,llm,(jjm - 1)*iim + 2,comm_lmdz,daysec,day_ini,dtphys/nsplit_phys,rlatu,rlatv,rlonu,rlonv,aire,cu,cv,rad,g,r,cpp,iflag_phys)
    415415#else
    416     ps_start_PCM(1) = ps(1)
     416    ps_start(1) = ps_start_dyn(1)
    417417#endif
    418418
    419419! Save initial surface pressure
    420 ps0 = ps
     420ps_start0 = ps_start
    421421
    422422! In the PCM, these values are given to the physic by the dynamic.
    423423! Here we simply read them in the "startfi.nc" file
    424 status = nf90_open(startfi_name, NF90_NOWRITE, ncid)
     424status = nf90_open(startfi_name,NF90_NOWRITE,ncid)
    425425
    426426status = nf90_inq_varid(ncid,"longitude",lonvarid)
     
    537537!------------------------
    538538! First we read the evolution of water and co2 ice (and the mass mixing ratio) over the first year of the PCM run, saving only the minimum value
    539 call nb_time_step_PCM("data_PCM_Y1.nc",timelen)
    540 
    541 allocate(tsoil_avg(ngrid,nsoilmx,nslope))
     539call get_timelen_PCM("data_PCM_Y1.nc",timelen)
     540
    542541allocate(watersoil_density_PEM_avg(ngrid,nsoilmx_PEM,nslope))
    543542allocate(vmr_co2_PCM(ngrid,timelen))
    544 allocate(ps_timeseries(ngrid,timelen))
     543allocate(ps_timeseries(ngrid,timelen),ps_avg(ngrid),ps_dev(ngrid))
    545544allocate(min_co2_ice(ngrid,nslope,2),min_h2o_ice(ngrid,nslope,2))
    546 allocate(tsurf_avg_yr1(ngrid,nslope))
    547 allocate(tsurf_avg(ngrid,nslope))
    548 allocate(tsurf_PCM_timeseries(ngrid,nslope,timelen))
    549 allocate(tsoil_anom(ngrid,nsoilmx,nslope,timelen))
     545allocate(tsurf_avg_yr1(ngrid,nslope),tsurf_avg(ngrid,nslope),tsurf_avg_old(ngrid,nslope),tsurf_dev(ngrid,nslope))
     546allocate(tsoil_avg(ngrid,nsoilmx,nslope),tsoil_dev(ngrid,nsoilmx,nslope))
     547allocate(tsoil_timeseries(ngrid,nsoilmx,nslope,timelen),tsoil_PEM_timeseries(ngrid,nsoilmx_PEM,nslope,timelen))
    550548allocate(zshift_surf(ngrid,nslope),zlag(ngrid,nslope))
    551549allocate(q_co2_PEM_phys(ngrid,timelen),q_h2o_PEM_phys(ngrid,timelen))
    552550allocate(watersurf_density_avg(ngrid,nslope))
    553 allocate(watersoil_density_timeseries(ngrid,nsoilmx,nslope,timelen))
    554 allocate(Tsurfavg_before_saved(ngrid,nslope))
    555 allocate(tsoil_phys_PEM_timeseries(ngrid,nsoilmx_PEM,nslope,timelen))
    556 allocate(watersoil_density_PEM_timeseries(ngrid,nsoilmx_PEM,nslope,timelen))
     551allocate(watersoil_density_timeseries(ngrid,nsoilmx,nslope,timelen),watersoil_density_PEM_timeseries(ngrid,nsoilmx_PEM,nslope,timelen))
    557552allocate(delta_co2_adsorbed(ngrid))
    558553allocate(co2ice_disappeared(ngrid,nslope))
     
    561556allocate(vmr_co2_PEM_phys(ngrid,timelen))
    562557
    563 write(*,*) "Downloading data Y1..."
    564 call read_data_PCM("data_PCM_Y1.nc",timelen,iim,jjm_value,ngrid,nslope,vmr_co2_PCM,ps_timeseries,min_co2_ice(:,:,1),min_h2o_ice(:,:,1), &
    565                    tsurf_avg_yr1,tsoil_avg,tsurf_PCM_timeseries,tsoil_anom,q_co2_PEM_phys,q_h2o_PEM_phys,                     &
    566                    watersurf_density_avg,watersoil_density_timeseries)
    567 write(*,*) "Downloading data Y1 done!"
    568 
    569 ! Then we read the evolution of water and co2 ice (and the mass mixing ratio) over the second year of the PCM run, saving only the minimum value
    570 write(*,*) "Downloading data Y2..."
    571 call read_data_PCM("data_PCM_Y2.nc",timelen,iim,jjm_value,ngrid,nslope,vmr_co2_PCM,ps_timeseries,min_co2_ice(:,:,2),min_h2o_ice(:,:,2), &
    572                    tsurf_avg,tsoil_avg,tsurf_PCM_timeseries,tsoil_anom,q_co2_PEM_phys,q_h2o_PEM_phys,                         &
    573                    watersurf_density_avg,watersoil_density_timeseries)
    574 write(*,*) "Downloading data Y2 done!"
     558call read_data_PCM("data_PCM_Y1.nc","data_PCM_Y2.nc",timelen,iim,jjm_value,ngrid,nslope,vmr_co2_PCM,ps_timeseries,ps_avg,tsurf_avg_yr1,tsurf_avg, &
     559                   tsoil_avg,tsoil_timeseries,min_co2_ice,min_h2o_ice,q_co2_PEM_phys,q_h2o_PEM_phys,watersurf_density_avg,watersoil_density_timeseries)
     560
     561! Compute the deviation from the average
     562ps_dev = ps_start - ps_avg
     563tsurf_dev = tsurf - tsurf_avg
     564tsoil_dev = tsoil - tsoil_avg(:,1:nsoilmx,:)
    575565
    576566!------------------------
     
    586576
    587577if (soil_pem) then
    588     do t = 1,timelen
    589         tsoil_anom(:,:,:,t) = tsoil_anom(:,:,:,t) - tsoil_avg ! compute anomaly between Tsoil(t) in the startfi - <Tsoil> to recompute properly tsoil in the restart
    590     enddo
    591578    call soil_settings_PEM(ngrid,nslope,nsoilmx_PEM,nsoilmx,inertiesoil,TI_PEM)
    592579    tsoil_PEM(:,1:nsoilmx,:) = tsoil_avg
    593     tsoil_phys_PEM_timeseries(:,1:nsoilmx,:,:) = tsoil_anom
    594580    watersoil_density_PEM_timeseries(:,1:nsoilmx,:,:) = watersoil_density_timeseries
     581    tsoil_PEM_timeseries(:,1:nsoilmx,:,:) = tsoil_timeseries
    595582    do l = nsoilmx + 1,nsoilmx_PEM
    596583        tsoil_PEM(:,l,:) = tsoil_avg(:,nsoilmx,:)
    597584        watersoil_density_PEM_timeseries(:,l,:,:) = watersoil_density_timeseries(:,nsoilmx,:,:)
     585        tsoil_PEM_timeseries(:,l,:,:) = tsoil_timeseries(:,nsoilmx,:,:)
    598586    enddo
    599587    watersoil_density_PEM_avg = sum(watersoil_density_PEM_timeseries,4)/timelen
    600588endif !soil_pem
    601 deallocate(tsoil_avg)
     589deallocate(tsoil_avg,watersoil_density_timeseries,tsoil_timeseries)
    602590
    603591!------------------------
     
    616604!------------------------
    617605! I   Initialization
    618 !    I_g Save the initial situation
    619 !------------------------
    620 allocate(zplev_PCM(ngrid,nlayer + 1))
    621 Total_surface = 0.
    622 do ig = 1,ngrid
    623     Total_surface = Total_surface + cell_area(ig)
    624     zplev_PCM(ig,:) = ap + bp*ps_start_PCM(ig)
    625 enddo
    626 global_avg_press_old = sum(cell_area*ps_start_PCM)/Total_surface
    627 global_avg_press_PCM = global_avg_press_old
    628 global_avg_press_new = global_avg_press_old
    629 write(*,*) "Total surface of the planet =", Total_surface
    630 write(*,*) "Initial global average pressure =", global_avg_press_PCM
     606!    I_g Compute global surface pressure
     607!------------------------
     608total_surface = sum(cell_area)
     609ps_avg_global_ini = sum(cell_area*ps_avg)/total_surface
     610ps_avg_global_new = ps_avg_global_ini
     611write(*,*) "Total surface of the planet =", total_surface
     612write(*,*) "Initial global averaged pressure =", ps_avg_global_ini
    631613
    632614!------------------------
     
    635617!------------------------
    636618allocate(co2_ice(ngrid,nslope),h2o_ice(ngrid,nslope))
    637 
    638619allocate(stratif(ngrid,nslope))
    639620if (layering_algo) then
     
    647628call pemetat0("startpem.nc",ngrid,nsoilmx,nsoilmx_PEM,nslope,timelen,timestep,TI_PEM,tsoil_PEM,icetable_depth, &
    648629              icetable_thickness,ice_porefilling,tsurf_avg_yr1,tsurf_avg,q_co2_PEM_phys,q_h2o_PEM_phys,        &
    649               ps_timeseries,tsoil_phys_PEM_timeseries,d_h2oice,d_co2ice,co2_ice,h2o_ice,                       &
    650               global_avg_press_PCM,watersurf_density_avg,watersoil_density_PEM_avg,co2_adsorbed_phys,         &
    651               delta_co2_adsorbed,h2o_adsorbed_phys,delta_h2o_adsorbed,stratif)
     630              ps_timeseries,ps_avg_global_ini,d_h2oice,d_co2ice,co2_ice,h2o_ice,watersurf_density_avg,         &
     631              watersoil_density_PEM_avg,co2_adsorbed_phys,delta_co2_adsorbed,h2o_adsorbed_phys,delta_h2o_adsorbed,stratif)
     632deallocate(tsurf_avg_yr1)
    652633
    653634! We save the places where h2o ice is sublimating
    654635! We compute the surface of h2o ice sublimating
    655 allocate(ini_co2ice_sublim(ngrid,nslope),ini_h2oice_sublim(ngrid,nslope),is_co2ice_ini(ngrid,nslope))
    656 co2ice_ini_surf = 0.
     636allocate(is_co2ice_sublim_ini(ngrid,nslope),is_h2oice_sublim_ini(ngrid,nslope),is_co2ice_ini(ngrid,nslope))
     637co2ice_sublim_surf_ini = 0.
    657638h2oice_ini_surf = 0.
    658 ini_co2ice_sublim = .false.
    659 ini_h2oice_sublim = .false.
     639is_co2ice_sublim_ini = .false.
     640is_h2oice_sublim_ini = .false.
    660641is_co2ice_ini = .false.
    661642co2ice_disappeared = .false.
     
    664645        if (co2_ice(i,islope) > 0.) is_co2ice_ini(i,islope) = .true.
    665646        if (d_co2ice(i,islope) < 0. .and. co2_ice(i,islope) > 0.) then
    666             ini_co2ice_sublim(i,islope) = .true.
    667             co2ice_ini_surf = co2ice_ini_surf + cell_area(i)*subslope_dist(i,islope)
     647            is_co2ice_sublim_ini(i,islope) = .true.
     648            co2ice_sublim_surf_ini = co2ice_sublim_surf_ini + cell_area(i)*subslope_dist(i,islope)
    668649        endif
    669650        if (d_h2oice(i,islope) < 0. .and. h2o_ice(i,islope) > 0.) then
    670             ini_h2oice_sublim(i,islope) = .true.
     651            is_h2oice_sublim_ini(i,islope) = .true.
    671652            h2oice_ini_surf = h2oice_ini_surf + cell_area(i)*subslope_dist(i,islope)
    672653        endif
    673654    enddo
    674655enddo
    675 write(*,*) "Total initial surface of co2 ice sublimating (slope) =", co2ice_ini_surf
     656write(*,*) "Total initial surface of co2 ice sublimating (slope) =", co2ice_sublim_surf_ini
    676657write(*,*) "Total initial surface of h2o ice sublimating (slope) =", h2oice_ini_surf
    677658
     
    684665        do islope = 1,nslope
    685666            do l = 1,nsoilmx_PEM - 1
    686                 if (l==1) then
     667                if (l == 1) then
    687668                   totmassco2_adsorbed = totmassco2_adsorbed + co2_adsorbed_phys(ig,l,islope)*(layer_PEM(l))* &
    688669                                       subslope_dist(ig,islope)/cos(pi*def_slope_mean(islope)/180.)*cell_area(ig)
     
    701682    write(*,*) "Tot mass of H2O in the regolith =", totmassh2o_adsorbed
    702683endif ! adsorption
    703 deallocate(tsurf_avg_yr1)
    704684
    705685!------------------------
     
    741721! II.a.1. Compute updated global pressure
    742722    write(*,*) "Recomputing the new pressure..."
     723    ps_avg_global_old = ps_avg_global_new
    743724    do i = 1,ngrid
    744725        do islope = 1,nslope
    745             global_avg_press_new = global_avg_press_new - CO2cond_ps*g*cell_area(i)*d_co2ice(i,islope)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180.)/Total_surface
     726            ps_avg_global_new = ps_avg_global_old - CO2cond_ps*g*cell_area(i)*d_co2ice(i,islope)*subslope_dist(i,islope)/cos(pi*def_slope_mean(islope)/180.)/total_surface
    746727        enddo
    747728    enddo
     
    749730    if (adsorption_pem) then
    750731        do i = 1,ngrid
    751             global_avg_press_new = global_avg_press_new - g*cell_area(i)*delta_co2_adsorbed(i)/Total_surface
    752         enddo
    753     endif
    754     write(*,*) 'Global average pressure old time step',global_avg_press_old
    755     write(*,*) 'Global average pressure new time step',global_avg_press_new
    756 
    757 ! II.a.2. Old pressure levels for the timeseries, this value is deleted when unused and recreated each time (big memory consumption)
    758     allocate(zplev_old_timeseries(ngrid,nlayer + 1,timelen))
    759     write(*,*) "Recomputing the old pressure levels timeserie adapted to the old pressure..."
     732            ps_avg_global_new = ps_avg_global_old - g*cell_area(i)*delta_co2_adsorbed(i)/total_surface
     733        enddo
     734    endif
     735    write(*,*) 'Global average pressure old time step',ps_avg_global_old
     736    write(*,*) 'Global average pressure new time step',ps_avg_global_new
     737
     738! II.a.2. Pressure timeseries (the values are deleted when unused because of big memory consumption)
     739    allocate(zplev_timeseries_old(ngrid,nlayer + 1,timelen))
     740    write(*,*) "Recomputing the pressure levels timeseries adapted to the old pressure..."
    760741    do l = 1,nlayer + 1
    761742        do ig = 1,ngrid
    762             zplev_old_timeseries(ig,l,:) = ap(l) + bp(l)*ps_timeseries(ig,:)
    763         enddo
    764     enddo
    765 
    766 ! II.a.3. Surface pressure timeseries
    767     write(*,*) "Recomputing the surface pressure timeserie adapted to the new pressure..."
     743            zplev_timeseries_old(ig,l,:) = ap(l) + bp(l)*ps_timeseries(ig,:)
     744        enddo
     745    enddo
     746    write(*,*) "Recomputing the surface pressure timeseries adapted to the new pressure..."
    768747    do ig = 1,ngrid
    769         ps_timeseries(ig,:) = ps_timeseries(ig,:)*global_avg_press_new/global_avg_press_old
    770     enddo
    771 
    772 ! II.a.4. New pressure levels timeseries
    773     allocate(zplev_new_timeseries(ngrid,nlayer + 1,timelen))
    774     write(*,*) "Recomputing the new pressure levels timeserie adapted to the new pressure..."
     748        ps_timeseries(ig,:) = ps_timeseries(ig,:)*ps_avg_global_new/ps_avg_global_old
     749    enddo
     750    write(*,*) "Recomputing the pressure levels timeseries adapted to the new pressure..."
     751    allocate(zplev_timeseries_new(ngrid,nlayer + 1,timelen))
    775752    do l = 1,nlayer + 1
    776753        do ig = 1,ngrid
    777             zplev_new_timeseries(ig,l,:) = ap(l) + bp(l)*ps_timeseries(ig,:)
    778         enddo
    779     enddo
    780 
    781 ! II.a.5. Tracers timeseries
     754            zplev_timeseries_new(ig,l,:) = ap(l) + bp(l)*ps_timeseries(ig,:)
     755        enddo
     756    enddo
     757
     758! II.a.3. Tracers timeseries
    782759    write(*,*) "Recomputing of tracer VMR timeseries for the new pressure..."
    783 
    784760    l = 1
    785761    do ig = 1,ngrid
    786762        do t = 1,timelen
    787             q_h2o_PEM_phys(ig,t) = q_h2o_PEM_phys(ig,t)*(zplev_old_timeseries(ig,l,t) - zplev_old_timeseries(ig,l + 1,t))/ &
    788                                    (zplev_new_timeseries(ig,l,t) - zplev_new_timeseries(ig,l + 1,t))
     763            ! H2O
     764            q_h2o_PEM_phys(ig,t) = q_h2o_PEM_phys(ig,t)*(zplev_timeseries_old(ig,l,t) - zplev_timeseries_old(ig,l + 1,t))/ &
     765                                   (zplev_timeseries_new(ig,l,t) - zplev_timeseries_new(ig,l + 1,t))
    789766            if (q_h2o_PEM_phys(ig,t) < 0) then
    790767                q_h2o_PEM_phys(ig,t) = 1.e-30
     
    792769                q_h2o_PEM_phys(ig,t) = 1.
    793770            endif
    794         enddo
    795     enddo
    796 
    797     do ig = 1,ngrid
    798         do t = 1,timelen
    799             q_co2_PEM_phys(ig,t) = q_co2_PEM_phys(ig,t)*(zplev_old_timeseries(ig,l,t) - zplev_old_timeseries(ig,l + 1,t))/ &
    800                                    (zplev_new_timeseries(ig,l,t) - zplev_new_timeseries(ig,l + 1,t))                       &
    801                                 + ((zplev_new_timeseries(ig,l,t) - zplev_new_timeseries(ig,l + 1,t))                       &
    802                                 -  (zplev_old_timeseries(ig,l,t) - zplev_old_timeseries(ig,l + 1,t)))/                     &
    803                                    (zplev_new_timeseries(ig,l,t) - zplev_new_timeseries(ig,l + 1,t))
     771            ! CO2
     772            q_co2_PEM_phys(ig,t) = q_co2_PEM_phys(ig,t)*(zplev_timeseries_old(ig,l,t) - zplev_timeseries_old(ig,l + 1,t))/ &
     773                                   (zplev_timeseries_new(ig,l,t) - zplev_timeseries_new(ig,l + 1,t))                       &
     774                                + ((zplev_timeseries_new(ig,l,t) - zplev_timeseries_new(ig,l + 1,t))                       &
     775                                -  (zplev_timeseries_old(ig,l,t) - zplev_timeseries_old(ig,l + 1,t)))/                     &
     776                                   (zplev_timeseries_new(ig,l,t) - zplev_timeseries_new(ig,l + 1,t))
    804777            if (q_co2_PEM_phys(ig,t) < 0) then
    805778                q_co2_PEM_phys(ig,t) = 1.e-30
     
    807780                q_co2_PEM_phys(ig,t) = 1.
    808781            endif
    809             mmean=1/(A*q_co2_PEM_phys(ig,t) + B)
     782            mmean = 1./(A*q_co2_PEM_phys(ig,t) + B)
    810783            vmr_co2_PEM_phys(ig,t) = q_co2_PEM_phys(ig,t)*mmean/m_co2
    811784        enddo
    812785    enddo
    813 
    814     deallocate(zplev_new_timeseries,zplev_old_timeseries)
     786    deallocate(zplev_timeseries_new,zplev_timeseries_old)
    815787
    816788!------------------------
     
    834806!    II_c Flow of glaciers
    835807!------------------------
    836     if (co2ice_flow .and. nslope > 1) call flow_co2glaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,vmr_co2_PEM_phys,ps_timeseries, &
    837                                                             global_avg_press_PCM,global_avg_press_new,co2_ice,flag_co2flow,flag_co2flow_mesh)
    838     if (h2oice_flow .and. nslope > 1) call flow_h2oglaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,tsurf_avg,h2o_ice,flag_h2oflow,flag_h2oflow_mesh)
     808    if (co2ice_flow .and. nslope > 1) call flow_co2glaciers(timelen,ngrid,nslope,iflat,subslope_dist,def_slope_mean,vmr_co2_PEM_phys, &
     809                                                            ps_timeseries,ps_avg_global_old,ps_avg_global_new,co2_ice,flag_co2flow,flag_co2flow_mesh)
     810    if (h2oice_flow .and. nslope > 1) call flow_h2oglaciers(ngrid,nslope,iflat,subslope_dist,def_slope_mean,tsurf_avg,h2o_ice,flag_h2oflow,flag_h2oflow_mesh)
    839811
    840812!------------------------
     
    844816! II_d.1 Update Tsurf
    845817    write(*,*) "Updating the new Tsurf"
    846     bool_sublim = .false.
    847     Tsurfavg_before_saved = tsurf_avg
    848818    do ig = 1,ngrid
    849819        do islope = 1,nslope
    850             if (is_co2ice_ini(ig,islope) .and. co2_ice(ig,islope) < 1.e-10 .and. .not. co2ice_disappeared(ig,islope)) then ! co2 ice disappeared, look for closest point without co2ice
     820            ! CO2 ice disappeared so we look for the closest point without CO2 ice
     821            if (is_co2ice_ini(ig,islope) .and. co2_ice(ig,islope) < 1.e-10 .and. .not. co2ice_disappeared(ig,islope)) then
    851822                co2ice_disappeared(ig,islope) = .true.
    852823                if (latitude_deg(ig) > 0) then
    853                     do ig_loop = ig,ngrid
     824                    outer1: do ig_loop = ig,ngrid
    854825                        do islope_loop = islope,iflat,-1
    855826                            if (.not. is_co2ice_ini(ig_loop,islope_loop) .and. co2_ice(ig_loop,islope_loop) < 1.e-10) then
    856827                                tsurf_avg(ig,islope) = tsurf_avg(ig_loop,islope_loop)
    857                                 bool_sublim = .true.
    858                                 exit
     828                                exit outer1
    859829                            endif
    860830                        enddo
    861                         if (bool_sublim) exit
    862                     enddo
     831                    enddo outer1
    863832                else
    864                     do ig_loop = ig,1,-1
     833                    outer2: do ig_loop = ig,1,-1
    865834                        do islope_loop = islope,iflat
    866835                            if (.not. is_co2ice_ini(ig_loop,islope_loop) .and. co2_ice(ig_loop,islope_loop) < 1.e-10) then
    867836                                tsurf_avg(ig,islope) = tsurf_avg(ig_loop,islope_loop)
    868                                 bool_sublim = .true.
    869                                 exit
     837                                exit outer2
    870838                            endif
    871839                        enddo
    872                         if (bool_sublim) exit
    873                     enddo
     840                    enddo outer2
    874841                endif
    875                 if ((co2_ice(ig,islope) < 1.e-10) .and. (h2o_ice(ig,islope) > frost_albedo_threshold)) then
     842                if (h2o_ice(ig,islope) > frost_albedo_threshold) then
    876843                    albedo(ig,1,islope) = albedo_h2o_frost
    877844                    albedo(ig,2,islope) = albedo_h2o_frost
     
    881848                    emis(ig,islope) = emissiv
    882849                endif
    883             else if ((co2_ice(ig,islope) > 1.e-3) .and. (d_co2ice(ig,islope) > 1.e-10)) then ! Put tsurf as tcond co2
    884                 ave = 0.
    885                 do t = 1,timelen
    886                     ave = ave + beta_clap_co2/(alpha_clap_co2 - log(vmr_co2_PEM_phys(ig,t)*ps_timeseries(ig,t)/100.))
    887                 enddo
    888                 tsurf_avg(ig,islope) = ave/timelen
     850            else if (co2_ice(ig,islope) > 1.e-10 .and. d_co2ice(ig,islope) > 1.e-10) then ! Put tsurf as tcond CO2
     851                call computeTcondCO2(timelen,ngrid,nslope,vmr_co2_PEM_phys,ps_timeseries,ps_avg_global_ini,ps_avg_global_new,tsurf_avg)
    889852            endif
    890             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! SUBLIMATION??? !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    891         enddo
    892     enddo
    893 
    894     do t = 1,timelen
    895         tsurf_PCM_timeseries(:,:,t) = tsurf_PCM_timeseries(:,:,t) + tsurf_avg - Tsurfavg_before_saved
    896     enddo
    897     ! for the start
    898     do ig = 1,ngrid
    899         do islope = 1,nslope
    900             tsurf(ig,islope) =  tsurf(ig,islope) - (Tsurfavg_before_saved(ig,islope) - tsurf_avg(ig,islope))
    901853        enddo
    902854    enddo
     
    908860! II_d.3 Update soil temperature
    909861        write(*,*)"Updating soil temperature"
    910         allocate(Tsoil_locslope(ngrid,nsoilmx_PEM))
     862        allocate(tsoil_avg_old(ngrid,nsoilmx_PEM))
    911863        do islope = 1,nslope
     864            tsoil_avg_old = tsoil_PEM(:,:,islope)
    912865            call compute_tsoil_pem(ngrid,nsoilmx_PEM,.true.,TI_PEM(:,:,islope),timestep,tsurf_avg(:,islope),tsoil_PEM(:,:,islope))
    913866            call compute_tsoil_pem(ngrid,nsoilmx_PEM,.false.,TI_PEM(:,:,islope),timestep,tsurf_avg(:,islope),tsoil_PEM(:,:,islope))
    914867
    915868            do t = 1,timelen
    916                 Tsoil_locslope(:,1:nsoilmx) = tsoil_PEM(:,1:nsoilmx,islope) + tsoil_anom(:,:,islope,t)
    917                 Tsoil_locslope(:,nsoilmx + 1:) = tsoil_PEM(:,nsoilmx + 1:,islope)
    918869                do ig = 1,ngrid
    919870                    do isoil = 1,nsoilmx_PEM
    920                         watersoil_density_PEM_timeseries(ig,isoil,islope,t) = exp(beta_clap_h2o/Tsoil_locslope(ig,isoil) + alpha_clap_h2o)/Tsoil_locslope(ig,isoil)*mmol(igcm_h2o_vap)/(mugaz*r)
     871            ! Update of soil temperature timeseries which is needed to compute the water soil density timeseries
     872            tsoil_PEM_timeseries(ig,isoil,islope,t) = tsoil_PEM_timeseries(ig,isoil,islope,t)*tsoil_PEM(ig,isoil,islope)/tsoil_avg_old(ig,isoil)
     873            ! Update of watersoil density
     874                        watersoil_density_PEM_timeseries(ig,isoil,islope,t) = exp(beta_clap_h2o/tsoil_PEM_timeseries(ig,isoil,islope,t) + alpha_clap_h2o)/tsoil_PEM_timeseries(ig,isoil,islope,t)*mmol(igcm_h2o_vap)/(mugaz*r)
    921875                        if (isnan(tsoil_PEM(ig,isoil,islope))) call abort_pem("PEM - Update Tsoil","NaN detected in tsoil_PEM",1)
    922876                    enddo
     
    925879        enddo
    926880        watersoil_density_PEM_avg = sum(watersoil_density_PEM_timeseries,4)/timelen
    927 
     881        deallocate(tsoil_avg_old)
    928882        write(*,*) "Update of soil temperature done"
    929 
    930         deallocate(Tsoil_locslope)
    931883
    932884! II_d.4 Update the ice table
     
    942894            do ig = 1,ngrid
    943895                do islope = 1,nslope
    944                     call dyn_ss_ice_m(icetable_depth(ig,islope),tsurf_avg(ig,islope),tsoil_PEM(ig,:,islope),nsoilmx_PEM,TI_PEM(ig,1,nslope),ps(ig),(/sum(q_h2o_PEM_phys(ig,:))/size(q_h2o_PEM_phys,2)/),ice_porefilling(ig,:,islope),porefill,ssi_depth)
     896                    call dyn_ss_ice_m(icetable_depth(ig,islope),tsurf_avg(ig,islope),tsoil_PEM(ig,:,islope),nsoilmx_PEM,TI_PEM(ig,1,nslope),ps_avg(ig),(/sum(q_h2o_PEM_phys(ig,:))/size(q_h2o_PEM_phys,2)/),ice_porefilling(ig,:,islope),porefill,ssi_depth)
    945897                    icetable_depth(ig,islope) = ssi_depth
    946898                    ice_porefilling(ig,:,islope) = porefill
     
    952904
    953905! II_d.5 Update the soil thermal properties
    954         call update_soil_thermalproperties(ngrid,nslope,nsoilmx_PEM,d_h2oice,h2o_ice,global_avg_press_new,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
     906        call update_soil_thermalproperties(ngrid,nslope,nsoilmx_PEM,d_h2oice,h2o_ice,ps_avg_global_new,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
    955907
    956908! II_d.6 Update the mass of the regolith adsorbed
    957909        if (adsorption_pem) then
    958             call regolith_adsorption(ngrid,nslope,nsoilmx_PEM,timelen,d_h2oice,d_co2ice,                          &
    959                                      h2o_ice,co2_ice,tsoil_PEM,TI_PEM,ps_timeseries,q_co2_PEM_phys,q_h2o_PEM_phys, &
     910            call regolith_adsorption(ngrid,nslope,nsoilmx_PEM,timelen,d_h2oice,d_co2ice,h2o_ice,co2_ice, &
     911                                     tsoil_PEM,TI_PEM,ps_timeseries,q_co2_PEM_phys,q_h2o_PEM_phys,      &
    960912                                     h2o_adsorbed_phys,delta_h2o_adsorbed,co2_adsorbed_phys,delta_co2_adsorbed)
    961913
     
    988940!    II_e Outputs
    989941!------------------------
    990     call writediagpem(ngrid,'ps_avg','Global average pressure','Pa',0,(/global_avg_press_new/))
     942    call writediagpem(ngrid,'ps_avg','Global average pressure','Pa',0,(/ps_avg_global_new/))
    991943    do islope = 1,nslope
    992944        write(str2(1:2),'(i2.2)') islope
     
    996948        call writediagpem(ngrid,'d_co2ice_slope'//str2,'CO2 ice tend','kg.m-2.year-1',2,d_co2ice(:,islope))
    997949        call writediagpem(ngrid,'Flow_co2ice_slope'//str2,'CO2 ice flow','Boolean',2,flag_co2flow(:,islope))
    998         call writediagpem(ngrid,'tsurf_slope'//str2,'tsurf','K',2,tsurf(:,islope))
     950        call writediagpem(ngrid,'tsurf_slope'//str2,'tsurf','K',2,tsurf_avg(:,islope))
    999951        if (icetable_equilibrium) then
    1000952            call writediagpem(ngrid,'ssi_depth_slope'//str2,'ice table depth','m',2,icetable_depth(:,islope))
     
    1005957
    1006958        if (soil_pem) then
    1007             call writediagsoilpem(ngrid,'tsoil_PEM_slope'//str2,'tsoil_PEM','K',3,tsoil_PEM(:,:,islope))
    1008             call writediagsoilpem(ngrid,'inertiesoil_PEM_slope'//str2,'TI_PEM','K',3,TI_PEM(:,:,islope))
     959            call writediagsoilpem(ngrid,'tsoil_PEM_slope'//str2,'tsoil','K',3,tsoil_PEM(:,:,islope))
     960            call writediagsoilpem(ngrid,'inertiesoil_PEM_slope'//str2,'TI','K',3,TI_PEM(:,:,islope))
    1009961            if (icetable_dynamic) call writediagsoilpem(ngrid,'ice_porefilling'//str2,'ice pore filling','-',3,ice_porefilling(:,:,islope))
    1010962            if (adsorption_pem) then
     
    1019971!    II_f Update the tendencies
    1020972!------------------------
    1021     call recomp_tend_co2(ngrid,nslope,timelen,d_co2ice,d_co2ice_ini,co2_ice,emis,vmr_co2_PCM,vmr_co2_PEM_phys,ps_timeseries,global_avg_press_PCM,global_avg_press_new)
     973    call recomp_tend_co2(ngrid,nslope,timelen,d_co2ice,d_co2ice_ini,co2_ice,emis,vmr_co2_PCM,vmr_co2_PEM_phys,ps_timeseries,ps_avg_global_old,ps_avg_global_new)
    1022974
    1023975!------------------------
     
    1026978!------------------------
    1027979    write(*,*) "Checking the stopping criteria..."
    1028     call stopping_crit_h2o_ice(cell_area,h2oice_ini_surf,ini_h2oice_sublim,h2o_ice,stopPEM,ngrid)
    1029     call stopping_crit_co2(cell_area,co2ice_ini_surf,ini_co2ice_sublim,co2_ice,stopPEM,ngrid,global_avg_press_PCM,global_avg_press_new,nslope)
     980    call stopping_crit_h2o_ice(cell_area,h2oice_ini_surf,is_h2oice_sublim_ini,h2o_ice,stopPEM,ngrid)
     981    call stopping_crit_co2(cell_area,co2ice_sublim_surf_ini,is_co2ice_sublim_ini,co2_ice,stopPEM,ngrid,ps_avg_global_ini,ps_avg_global_new,nslope)
    1030982    i_myear_leg = i_myear_leg + dt
    1031983    i_myear = i_myear + dt
     
    10611013        write(*,*) "Number of simulated Martian years: i_myear =", i_myear
    10621014    endif
    1063 
    1064     global_avg_press_old = global_avg_press_new
    1065 
    10661015enddo ! big time iteration loop of the pem
    10671016!------------------------------ END RUN --------------------------------
     
    10721021!    III_a Update surface value for the PCM start files
    10731022!------------------------
    1074 ! III_a.1 Ice update (for startfi)
     1023! III_a.1 Ice update for start file
    10751024watercap = 0.
    10761025perennial_co2ice = co2_ice
     
    11001049enddo
    11011050
    1102 ! III_a.2 Tsoil update (for startfi)
     1051! III.a.2. Tsurf update for start file
     1052tsurf = tsurf_avg + tsurf_dev
     1053
     1054! III_a.3 Tsoil update for start file
    11031055if (soil_pem) then
    11041056    inertiesoil = TI_PEM(:,:nsoilmx,:)
    1105     tsoil = tsoil_PEM(:,1:nsoilmx,:) + tsoil_anom(:,:,:,timelen)
     1057    ! Tsurf has evolved and so the soil temperature profile needs to be adapted to match this new value
     1058    do isoil = 1,nsoilmx
     1059        tsoil_dev(:,isoil,:) = tsoil_dev(:,isoil,:)*(tsurf_avg(:,:) - tsoil_PEM(:,1,:))/tsoil_dev(:,1,:)
     1060    enddo
     1061    tsoil = tsoil_PEM(:,1:nsoilmx,:) + tsoil_dev
    11061062#ifndef CPP_STD
    11071063    flux_geo = fluxgeo
    11081064#endif
    11091065endif
    1110 deallocate(tsoil_anom)
    1111 
    1112 ! III_a.4 Pressure (for start)
    1113 ps = ps*global_avg_press_new/global_avg_press_PCM
    1114 ps_start_PCM = ps_start_PCM*global_avg_press_new/global_avg_press_PCM
    1115 
    1116 ! III_a.5 Tracer (for start)
    1117 allocate(zplev_new(ngrid,nlayer + 1))
    1118 
     1066
     1067! III_a.4 Pressure update for start file
     1068ps_start = ps_avg + ps_dev
     1069
     1070! III_a.5 Tracers update for start file
     1071allocate(zplev_start0(ngrid,nlayer + 1),zplev_new(ngrid,nlayer + 1))
    11191072do l = 1,nlayer + 1
    1120     zplev_new(:,l) = ap(l) + bp(l)*ps_start_PCM
     1073    zplev_start0(:,l) = ap(l) + bp(l)*ps_start0
     1074    zplev_new(:,l) = ap(l) + bp(l)*ps_start
    11211075enddo
    11221076
     
    11251079        do l = 1,llm - 1
    11261080            do ig = 1,ngrid
    1127                 q(ig,l,nnq) = q(ig,l,nnq)*(zplev_PCM(ig,l) - zplev_PCM(ig,l + 1))/(zplev_new(ig,l) - zplev_new(ig,l + 1))
     1081                q(ig,l,nnq) = q(ig,l,nnq)*(zplev_start0(ig,l) - zplev_start0(ig,l + 1))/(zplev_new(ig,l) - zplev_new(ig,l + 1))
    11281082            enddo
    11291083            q(:,llm,nnq) = q(:,llm - 1,nnq)
     
    11321086        do l = 1,llm - 1
    11331087            do ig = 1,ngrid
    1134                 q(ig,l,nnq) = q(ig,l,nnq)*(zplev_PCM(ig,l) - zplev_PCM(ig,l + 1))/(zplev_new(ig,l) - zplev_new(ig,l + 1)) &
    1135                               + ((zplev_new(ig,l) - zplev_new(ig,l + 1)) - (zplev_PCM(ig,l) - zplev_PCM(ig,l + 1)))/(zplev_new(ig,l) - zplev_new(ig,l + 1))
     1088                q(ig,l,nnq) = q(ig,l,nnq)*(zplev_start0(ig,l) - zplev_start0(ig,l + 1))/(zplev_new(ig,l) - zplev_new(ig,l + 1)) &
     1089                              + ((zplev_new(ig,l) - zplev_new(ig,l + 1)) - (zplev_start0(ig,l) - zplev_start0(ig,l + 1)))/(zplev_new(ig,l) - zplev_new(ig,l + 1))
    11361090            enddo
    11371091            q(:,llm,nnq) = q(:,llm - 1,nnq)
     
    11401094enddo
    11411095
    1142 ! Conserving the tracers mass for PCM start files
     1096! Conserving the tracers mass for start file
    11431097do nnq = 1,nqtot
    11441098    do ig = 1,ngrid
     
    11541108    enddo
    11551109enddo
     1110deallocate(zplev_start0,zplev_new)
    11561111
    11571112if (evol_orbit_pem) call recomp_orb_param(i_myear,i_myear_leg)
     
    11711126    do l = 1,nlayer
    11721127        do i = 1,ip1jmp1
    1173             teta(i,l)= teta(i,l)*(ps0(i)/ps(i))**kappa
     1128            teta(i,l)= teta(i,l)*(ps_start0(i)/ps_start(i))**kappa
    11741129        enddo
    11751130    enddo
    11761131    ! Correction on atmospheric pressure
    1177     call pression(ip1jmp1,ap,bp,ps,p)
     1132    call pression(ip1jmp1,ap,bp,ps_start,p)
    11781133    ! Correction on the mass of atmosphere
    11791134    call massdair(p,masse)
    11801135    call dynredem0("restart.nc",day_ini,phis)
    1181     call dynredem1("restart.nc",time_0,vcov,ucov,teta,q,masse,ps)
     1136    call dynredem1("restart.nc",time_0,vcov,ucov,teta,q,masse,ps_start)
    11821137    write(*,*) "restart.nc has been written"
    11831138#else
    1184     call writerestart1D('restart1D.txt',ps(1),tsurf(1,:),nlayer,size(tsurf,2),teta,ucov,vcov,nq,noms,qsurf(1,:,:),q)
     1139    call writerestart1D('restart1D.txt',ps_start(1),tsurf(1,:),nlayer,size(tsurf,2),teta,ucov,vcov,nq,noms,qsurf(1,:,:),q)
    11851140    write(*,*) "restart1D.txt has been written"
    11861141#endif
     
    12311186    deallocate(new_str,new_lag1,new_lag2,current1,current2)
    12321187endif
    1233 deallocate(vmr_co2_PCM,ps_timeseries,tsurf_PCM_timeseries,q_co2_PEM_phys,q_h2o_PEM_phys)
    1234 deallocate(watersurf_density_avg,watersoil_density_timeseries,Tsurfavg_before_saved)
    1235 deallocate(tsoil_phys_PEM_timeseries,watersoil_density_PEM_timeseries,watersoil_density_PEM_avg)
    1236 deallocate(delta_co2_adsorbed,delta_h2o_adsorbed,vmr_co2_PEM_phys,delta_h2o_icetablesublim)
     1188deallocate(ps_start,ps_start0,ps_timeseries,ps_avg,ps_dev)
     1189deallocate(tsurf_avg,tsurf_dev,tsurf_avg_old)
     1190deallocate(tsoil_PEM,tsoil_dev,tsoil_PEM_timeseries)
     1191deallocate(vmr_co2_PCM,vmr_co2_PEM_phys,q_co2_PEM_phys,q_h2o_PEM_phys)
     1192deallocate(watersurf_density_avg,watersoil_density_PEM_timeseries,watersoil_density_PEM_avg)
     1193deallocate(delta_co2_adsorbed,delta_h2o_adsorbed,delta_h2o_icetablesublim)
    12371194deallocate(icetable_thickness_old,ice_porefilling_old,zshift_surf,zlag)
    1238 deallocate(is_co2ice_ini,co2ice_disappeared,ini_co2ice_sublim,ini_h2oice_sublim,stratif)
     1195deallocate(is_co2ice_ini,co2ice_disappeared,is_co2ice_sublim_ini,is_h2oice_sublim_ini,stratif)
    12391196!----------------------------- END OUTPUT ------------------------------
    12401197
  • trunk/LMDZ.COMMON/libf/evolution/pemetat0.F90

    r3563 r3571  
    88
    99SUBROUTINE pemetat0(filename,ngrid,nsoil_PCM,nsoil_PEM,nslope,timelen,timestep,TI_PEM,tsoil_PEM,icetable_depth,icetable_thickness, &
    10                     ice_porefilling,tsurf_avg_yr1,tsurf_avg_yr2,q_co2,q_h2o,ps_inst,tsoil_inst,d_h2oice,d_co2ice,co2_ice,h2o_ice,    &
    11                     global_avg_pressure,watersurf_avg,watersoil_avg,m_co2_regolith_phys,deltam_co2_regolith_phys,                    &
    12                     m_h2o_regolith_phys,deltam_h2o_regolith_phys,stratif)
     10                    ice_porefilling,tsurf_avg_yr1,tsurf_avg_yr2,q_co2,q_h2o,ps_timeseries,ps_avg_global,                           &
     11                    watersurf_avg,watersoil_avg,m_co2_regolith_phys,deltam_co2_regolith_phys,                                      &
     12                    d_h2oice,d_co2ice,co2_ice,h2o_ice,m_h2o_regolith_phys,deltam_h2o_regolith_phys,stratif)
    1313
    1414use iostart_PEM,                only: open_startphy, close_startphy, get_field, get_var, inquire_dimension, inquire_dimension_length
    15 use comsoil_h_PEM,              only: soil_pem, layer_PEM, mlayer_PEM, fluxgeo, inertiedat_PEM, ini_huge_h2oice, depth_breccia, depth_bedrock, index_breccia, index_bedrock
    16 use comsoil_h,                  only: volcapa, inertiedat
     15use comsoil_h_PEM,              only: soil_pem, layer_PEM, fluxgeo, inertiedat_PEM, ini_huge_h2oice, depth_breccia, depth_bedrock, index_breccia, index_bedrock
     16use comsoil_h,                  only: inertiedat
    1717use adsorption_mod,             only: regolith_adsorption, adsorption_pem
    1818use ice_table_mod,              only: computeice_table_equilibrium, icetable_equilibrium, icetable_dynamic
     
    2222use abort_pem_mod,              only: abort_pem
    2323use compute_soiltemp_mod,       only: ini_tsoil_pem, compute_tsoil_pem
    24 use comslope_mod,               only: def_slope_mean, subslope_dist
    2524use layering_mod,               only: layering, array2stratif, nb_str_max, layering_algo
    2625
     
    3635include "callkeys.h"
    3736
    38 character(*),                   intent(in) :: filename            ! name of the startfi_PEM.nc
    39 integer,                        intent(in) :: ngrid               ! # of physical grid points
    40 integer,                        intent(in) :: nsoil_PCM           ! # of vertical grid points in the PCM
    41 integer,                        intent(in) :: nsoil_PEM           ! # of vertical grid points in the PEM
    42 integer,                        intent(in) :: nslope              ! # of sub-grid slopes
    43 integer,                        intent(in) :: timelen             ! # time samples
    44 real,                           intent(in) :: timestep            ! time step [s]
    45 real,                           intent(in) :: global_avg_pressure ! mean average pressure on the planet [Pa]
    46 real, dimension(ngrid,nslope),  intent(in) :: tsurf_avg_yr1       ! surface temperature at the first year of PCM call [K]
    47 real, dimension(ngrid,nslope),  intent(in) :: tsurf_avg_yr2       ! surface temperature at the second year of PCM call [K]
    48 real, dimension(ngrid,timelen), intent(in) :: q_co2               ! MMR tracer co2 [kg/kg]
    49 real, dimension(ngrid,timelen), intent(in) :: q_h2o               ! MMR tracer h2o [kg/kg]
    50 real, dimension(ngrid,timelen), intent(in) :: ps_inst            ! surface pressure [Pa]
    51 real, dimension(ngrid,nslope),  intent(in) :: d_h2oice        ! tendencies on h2o ice
    52 real, dimension(ngrid,nslope),  intent(in) :: d_co2ice        ! tendencies on co2 ice
    53 real, dimension(ngrid,nslope),  intent(in) :: watersurf_avg       ! surface water ice density, yearly averaged (kg/m^3)
     37character(*),                   intent(in) :: filename      ! name of the startfi_PEM.nc
     38integer,                        intent(in) :: ngrid         ! # of physical grid points
     39integer,                        intent(in) :: nsoil_PCM     ! # of vertical grid points in the PCM
     40integer,                        intent(in) :: nsoil_PEM     ! # of vertical grid points in the PEM
     41integer,                        intent(in) :: nslope        ! # of sub-grid slopes
     42integer,                        intent(in) :: timelen       ! # time samples
     43real,                           intent(in) :: timestep      ! time step [s]
     44real,                           intent(in) :: ps_avg_global ! mean average pressure on the planet [Pa]
     45real, dimension(ngrid,nslope),  intent(in) :: tsurf_avg_yr1 ! surface temperature at the first year of PCM call [K]
     46real, dimension(ngrid,nslope),  intent(in) :: tsurf_avg_yr2 ! surface temperature at the second year of PCM call [K]
     47real, dimension(ngrid,timelen), intent(in) :: q_co2         ! MMR tracer co2 [kg/kg]
     48real, dimension(ngrid,timelen), intent(in) :: q_h2o         ! MMR tracer h2o [kg/kg]
     49real, dimension(ngrid,timelen), intent(in) :: ps_timeseries ! surface pressure [Pa]
     50real, dimension(ngrid,nslope),  intent(in) :: d_h2oice      ! tendencies on h2o ice
     51real, dimension(ngrid,nslope),  intent(in) :: d_co2ice      ! tendencies on co2 ice
     52real, dimension(ngrid,nslope),  intent(in) :: watersurf_avg ! surface water ice density, yearly averaged (kg/m^3)
    5453! outputs
    55 real, dimension(ngrid),                          intent(out) :: deltam_co2_regolith_phys ! mass of co2 that is exchanged due to adsorption desorption [kg/m^2]
    56 real, dimension(ngrid),                          intent(out) :: deltam_h2o_regolith_phys ! mass of h2o that is exchanged due to adsorption desorption [kg/m^2]
    57 real, dimension(ngrid,nslope),                   intent(out) :: h2o_ice                  ! h2o ice amount [kg/m^2]
    58 real, dimension(ngrid,nslope),                   intent(out) :: co2_ice                  ! co2 ice amount [kg/m^2]
    59 type(layering), dimension(ngrid,nslope),         intent(inout) :: stratif             ! stratification (layerings)
    60 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: TI_PEM              ! soil (mid-layer) thermal inertia in the PEM grid [SI]
    61 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: tsoil_PEM           ! soil (mid-layer) temperature [K]
    62 real, dimension(ngrid,nslope),                   intent(inout) :: icetable_depth      ! Ice table depth [m]
    63 real, dimension(ngrid,nslope),                   intent(inout) :: icetable_thickness  ! Ice table thickness [m]
    64 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: ice_porefilling     ! Subsurface ice pore filling [m3/m3]
    65 real, dimension(ngrid,nsoil_PEM,nslope,timelen), intent(inout) :: tsoil_inst          ! instantaneous soil (mid-layer) temperature [K]
    66 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: m_co2_regolith_phys ! mass of co2 adsorbed [kg/m^2]
    67 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: m_h2o_regolith_phys ! mass of h2o adsorbed [kg/m^2]
    68 real, dimension(ngrid,nsoil_PEM,nslope),         intent(inout) :: watersoil_avg       ! surface water ice density, yearly averaged (kg/m^3)
     54real, dimension(ngrid),                  intent(out) :: deltam_co2_regolith_phys ! mass of co2 that is exchanged due to adsorption desorption [kg/m^2]
     55real, dimension(ngrid),                  intent(out) :: deltam_h2o_regolith_phys ! mass of h2o that is exchanged due to adsorption desorption [kg/m^2]
     56real, dimension(ngrid,nslope),           intent(out) :: h2o_ice                  ! h2o ice amount [kg/m^2]
     57real, dimension(ngrid,nslope),           intent(out) :: co2_ice                  ! co2 ice amount [kg/m^2]
     58type(layering), dimension(ngrid,nslope), intent(inout) :: stratif             ! stratification (layerings)
     59real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: TI_PEM              ! soil (mid-layer) thermal inertia in the PEM grid [SI]
     60real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: tsoil_PEM           ! soil (mid-layer) temperature [K]
     61real, dimension(ngrid,nslope),           intent(inout) :: icetable_depth      ! Ice table depth [m]
     62real, dimension(ngrid,nslope),           intent(inout) :: icetable_thickness  ! Ice table thickness [m]
     63real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: ice_porefilling     ! Subsurface ice pore filling [m3/m3]
     64real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: m_co2_regolith_phys ! mass of co2 adsorbed [kg/m^2]
     65real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: m_h2o_regolith_phys ! mass of h2o adsorbed [kg/m^2]
     66real, dimension(ngrid,nsoil_PEM,nslope), intent(inout) :: watersoil_avg       ! surface water ice density, yearly averaged (kg/m^3)
    6967! local
    70 real, dimension(ngrid,nsoil_PEM,nslope) :: tsoil_startPEM                  ! soil temperature saved in the start [K]
    71 real, dimension(ngrid,nsoil_PEM,nslope) :: TI_startPEM                     ! soil thermal inertia saved in the start [SI]
    72 logical                                 :: found, found2                   ! check if variables are found in the start
    73 integer                                 :: iloop, ig, islope, it, isoil, k ! index for loops
    74 real                                    :: kcond                           ! Thermal conductivity, intermediate variable [SI]
    75 real                                    :: delta                           ! Depth of the interface regolith-breccia, breccia -bedrock [m]
    76 character(2)                            :: num                             ! intermediate string to read PEM start sloped variables
    77 real, dimension(ngrid,nsoil_PEM,nslope) :: tsoil_tmp_yr1                   ! intermediate soil temperature during yr 1 [K]
    78 real, dimension(ngrid,nsoil_PEM,nslope) :: tsoil_tmp_yr2                   ! intermediate soil temperature during yr 2 [K]
    79 logical                                 :: startpem_file                   ! boolean to check if we read the startfile or not
    80 real, dimension(:,:,:,:), allocatable   :: stratif_array                   ! Array for stratification (layerings)
     68real, dimension(ngrid,nsoil_PEM,nslope) :: tsoil_startpem           ! soil temperature saved in the start [K]
     69real, dimension(ngrid,nsoil_PEM,nslope) :: TI_startPEM              ! soil thermal inertia saved in the start [SI]
     70logical                                 :: found, found2            ! check if variables are found in the start
     71integer                                 :: iloop, ig, islope, isoil ! index for loops
     72real                                    :: delta                    ! Depth of the interface regolith-breccia, breccia -bedrock [m]
     73character(2)                            :: num                      ! intermediate string to read PEM start sloped variables
     74logical                                 :: startpem_file            ! boolean to check if we read the startfile or not
     75real, dimension(:,:,:,:), allocatable   :: stratif_array            ! Array for stratification (layerings)
    8176
    8277#ifdef CPP_STD
     
    210205            else ! found
    211206                do iloop = nsoil_PCM + 1,nsoil_PEM
    212                     TI_PEM(:,iloop,islope) = TI_startPEM(:,iloop,islope)  ! ! 1st layers can change because of the presence of ice at the surface, so we don't change it here.
     207                    TI_PEM(:,iloop,islope) = TI_startPEM(:,iloop,islope) ! 1st layers can change because of the presence of ice at the surface, so we don't change it here.
    213208                enddo
    214209            endif ! not found
     
    258253!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    259254!2. Soil Temperature
    260         do islope=1,nslope
     255        do islope = 1,nslope
    261256            write(num,fmt='(i2.2)') islope
    262             call get_field("tsoil_PEM_slope"//num,tsoil_startPEM(:,:,islope),found)
     257            call get_field("tsoil_PEM_slope"//num,tsoil_startpem(:,:,islope),found)
    263258            if (.not. found) then
    264259                write(*,*)'PEM settings: failed loading <tsoil_PEM_slope'//num//'>'
     
    267262                call compute_tsoil_pem(ngrid,nsoil_PEM,.true.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr2(:,islope),tsoil_PEM(:,:,islope))
    268263            else
    269 ! predictor corrector: restart from year 1 of the PCM and build the evolution of tsoil at depth
    270                 tsoil_tmp_yr1(:,:,islope) = tsoil_startPEM(:,:,islope)
    271                 call compute_tsoil_pem(ngrid,nsoil_PEM,.true.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr1(:,islope),tsoil_tmp_yr1(:,:,islope))
    272                 call compute_tsoil_pem(ngrid,nsoil_PEM,.false.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr1(:,islope),tsoil_tmp_yr1(:,:,islope))
    273                 tsoil_tmp_yr2(:,:,islope) = tsoil_tmp_yr1(:,:,islope)
    274                 call compute_tsoil_pem(ngrid,nsoil_PEM,.false.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr2(:,islope),tsoil_tmp_yr2(:,:,islope))
     264! predictor-corrector: due to changes of surface temperature in the PCM, the tsoil_startpem is adapted firstly
     265!                      for PCM year 1 and then for PCM year 2 in order to build the evolution of the profile at depth
     266                call compute_tsoil_pem(ngrid,nsoil_PEM,.true.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr1(:,islope),tsoil_startpem(:,:,islope))
     267                call compute_tsoil_pem(ngrid,nsoil_PEM,.false.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr1(:,islope),tsoil_startpem(:,:,islope))
     268                call compute_tsoil_pem(ngrid,nsoil_PEM,.false.,TI_PEM(:,:,islope),timestep,tsurf_avg_yr2(:,islope),tsoil_startpem(:,:,islope))
    275269
    276270                do iloop = nsoil_PCM + 1,nsoil_PEM
    277                     tsoil_PEM(:,iloop,islope) = tsoil_tmp_yr2(:,iloop,islope)
     271                    tsoil_PEM(:,iloop,islope) = tsoil_startpem(:,iloop,islope)
    278272                enddo
    279273            endif !found
    280274
    281             do it = 1,timelen
    282                 tsoil_inst(:,nsoil_PCM + 1:nsoil_PEM,islope,it) = tsoil_PEM(:,nsoil_PCM + 1:nsoil_PEM,islope)
    283             enddo
    284275            do isoil = nsoil_PCM + 1,nsoil_PEM
    285276                watersoil_avg(:,isoil,islope) = exp(beta_clap_h2o/tsoil_PEM(:,isoil,islope) + alpha_clap_h2o)/tsoil_PEM(:,isoil,islope)*mmol(igcm_h2o_vap)/(mugaz*r)
     
    296287                write(*,*)'will reconstruct the values of the ice table given the current state'
    297288                call computeice_table_equilibrium(ngrid,nslope,nsoil_PEM,watercaptag,watersurf_avg,watersoil_avg,TI_PEM(:,1,:),icetable_depth,icetable_thickness)
    298                 call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,global_avg_pressure,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
     289                call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,ps_avg_global,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
    299290                do islope = 1,nslope
    300291                    call ini_tsoil_pem(ngrid,nsoil_PEM,TI_PEM(:,:,islope),tsurf_avg_yr2(:,islope),tsoil_PEM(:,:,islope))
     
    309300                write(*,*)'PEM settings: failed loading <icetable_depth>'
    310301                write(*,*)'will reconstruct the values of the ice table given the current state'
    311                 call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,global_avg_pressure,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
     302                call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,ps_avg_global,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
    312303                do islope = 1,nslope
    313304                    call ini_tsoil_pem(ngrid,nsoil_PEM,TI_PEM(:,:,islope),tsurf_avg_yr2(:,islope),tsoil_PEM(:,:,islope))
     
    328319                endif
    329320            enddo
    330             do islope=1,nslope
     321            do islope = 1,nslope
    331322                write(num,fmt='(i2.2)') islope
    332323                call get_field("mh2o_reg_ads_slope"//num,m_h2o_regolith_phys(:,:,islope),found2)
     
    337328            enddo
    338329
    339             call regolith_adsorption(ngrid,nslope,nsoil_PEM,timelen,d_h2oice,d_co2ice,h2o_ice,co2_ice,tsoil_PEM,TI_PEM,ps_inst,q_co2,q_h2o, &
    340                                         m_h2o_regolith_phys,deltam_h2o_regolith_phys, m_co2_regolith_phys,deltam_co2_regolith_phys)
     330            call regolith_adsorption(ngrid,nslope,nsoil_PEM,timelen,d_h2oice,d_co2ice,h2o_ice,co2_ice,tsoil_PEM,TI_PEM,ps_timeseries,q_co2,q_h2o, &
     331                                     m_h2o_regolith_phys,deltam_h2o_regolith_phys,m_co2_regolith_phys,deltam_co2_regolith_phys)
    341332
    342333            if (.not. found) deltam_co2_regolith_phys = 0.
     
    441432
    442433! First raw initialization
    443             do it = 1,timelen
    444                 do isoil = nsoil_PCM + 1,nsoil_PEM
    445                     tsoil_inst(:,isoil,islope,it) = tsoil_PEM(:,isoil,islope)
    446                 enddo
    447             enddo
    448 
    449             do it = 1,timelen
    450                 do isoil = nsoil_PCM + 1,nsoil_PEM
    451                     call ini_tsoil_pem(ngrid,nsoil_PEM,TI_PEM(:,:,islope),tsurf_avg_yr2(:,islope),tsoil_inst(:,:,islope,it))
    452                 enddo
    453             enddo
    454 
    455434            do isoil = nsoil_PCM + 1,nsoil_PEM
    456435                do ig = 1,ngrid
     
    465444        if (icetable_equilibrium) then
    466445            call computeice_table_equilibrium(ngrid,nslope,nsoil_PEM,watercaptag,watersurf_avg,watersoil_avg,TI_PEM(:,1,:),icetable_depth,icetable_thickness)
    467             call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,global_avg_pressure,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
     446            call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,ps_avg_global,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
    468447            do islope = 1,nslope
    469448                call ini_tsoil_pem(ngrid,nsoil_PEM,TI_PEM(:,:,islope),tsurf_avg_yr2(:,islope),tsoil_PEM(:,:,islope))
     
    471450            write(*,*) 'PEMETAT0: Ice table done'
    472451        else if (icetable_dynamic) then
    473             call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,global_avg_pressure,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
     452            call update_soil_thermalproperties(ngrid,nslope,nsoil_PEM,d_h2oice,h2o_ice,ps_avg_global,icetable_depth,icetable_thickness,ice_porefilling,icetable_equilibrium,icetable_dynamic,TI_PEM)
    474453            do islope = 1,nslope
    475454                call ini_tsoil_pem(ngrid,nsoil_PEM,TI_PEM(:,:,islope),tsurf_avg_yr2(:,islope),tsoil_PEM(:,:,islope))
     
    483462            m_co2_regolith_phys = 0.
    484463            m_h2o_regolith_phys = 0.
    485             call regolith_adsorption(ngrid,nslope,nsoil_PEM,timelen,d_h2oice,d_co2ice,h2o_ice,co2_ice,tsoil_PEM,TI_PEM,ps_inst,q_co2,q_h2o, &
     464            call regolith_adsorption(ngrid,nslope,nsoil_PEM,timelen,d_h2oice,d_co2ice,h2o_ice,co2_ice,tsoil_PEM,TI_PEM,ps_timeseries,q_co2,q_h2o, &
    486465                                     m_h2o_regolith_phys,deltam_h2o_regolith_phys, m_co2_regolith_phys,deltam_co2_regolith_phys)
    487466            deltam_co2_regolith_phys = 0.
  • trunk/LMDZ.COMMON/libf/evolution/pemredem.F90

    r3554 r3571  
    7777real, dimension(ngrid,nsoil_PEM,nslope), intent(in) :: tsoil_slope_PEM       ! under mesh bining according to slope
    7878real, dimension(ngrid,nsoil_PEM,nslope), intent(in) :: inertiesoil_slope_PEM ! under mesh bining according to slope
    79 real, dimension(ngrid,nslope),           intent(in) :: icetable_depth       ! under mesh bining according to slope
    80 real, dimension(ngrid,nslope),           intent(in) :: icetable_thickness   ! under mesh bining according to slope
     79real, dimension(ngrid,nslope),           intent(in) :: icetable_depth        ! under mesh bining according to slope
     80real, dimension(ngrid,nslope),           intent(in) :: icetable_thickness    ! under mesh bining according to slope
    8181real, dimension(ngrid,nsoil_PEM,nslope), intent(in) :: ice_porefilling       ! under mesh bining according to slope
    8282real, dimension(ngrid,nsoil_PEM,nslope), intent(in) :: m_co2_regolith, m_h2o_regolith
     
    119119        call put_field("tsoil_PEM_slope"//num,"Soil temperature by slope type",tsoil_slope_PEM(:,:,islope),Year)
    120120        call put_field("TI_PEM_slope"//num,"Soil Thermal Inertia by slope type",inertiesoil_slope_PEM(:,:,islope),Year)
    121         call put_field("mco2_reg_ads_slope"//num, "Mass of co2 adsorbed in the regolith",m_co2_regolith(:,:,islope),Year)
    122         call put_field("mh2o_reg_ads_slope"//num, "Mass of h2o adsorbed in the regolith",m_h2o_regolith(:,:,islope),Year)
     121        call put_field("mco2_reg_ads_slope"//num, "Mass of CO2 adsorbed in the regolith",m_co2_regolith(:,:,islope),Year)
     122        call put_field("mh2o_reg_ads_slope"//num, "Mass of H2O adsorbed in the regolith",m_h2o_regolith(:,:,islope),Year)
    123123    enddo
    124124    call put_field("icetable_depth","Depth of ice table",icetable_depth,Year)
  • trunk/LMDZ.COMMON/libf/evolution/read_data_PCM_mod.F90

    r3367 r3571  
    1515!=======================================================================
    1616
    17 SUBROUTINE read_data_PCM(filename,timelen,iim_input,jjm_input,ngrid,nslope,vmr_co2_PCM_phys,ps_timeseries, &
    18                          min_co2_ice,min_h2o_ice,tsurf_avg,tsoil_avg,tsurf_PCM,tsoil_PCM,q_co2,q_h2o,      &
    19                          watersurf_density_avg,watersoil_density)
     17SUBROUTINE read_data_PCM(filename1,filename2,timelen,iim_input,jjm_input,ngrid,nslope,vmr_co2_PCM,ps_timeseries,ps_avg,tsurf_avg_yr1,tsurf_avg, &
     18                         tsoil_avg,tsoil_timeseries,min_co2_ice,min_h2o_ice,q_co2,q_h2o,watersurf_density_avg,watersoil_density_timeseries)
    2019use comsoil_h,             only: nsoilmx
    2120use comsoil_h_PEM,         only: soil_pem
     
    3433
    3534!=======================================================================
    36 ! Arguments:
    37 character(*), intent(in) :: filename                            ! File name
    38 integer,      intent(in) :: timelen                             ! number of times stored in the file
    39 integer,      intent(in) :: iim_input, jjm_input, ngrid, nslope ! number of points in the lat x lon dynamical grid, number of subgrid slopes
     35! Inputs:
     36character(*), intent(in) :: filename1, filename2                ! File names
     37integer,      intent(in) :: timelen                             ! Number of times stored in the file
     38integer,      intent(in) :: iim_input, jjm_input, ngrid, nslope ! Number of points in the lat x lon dynamical grid, number of subgrid slopes
    4039! Ouputs
    41 real, dimension(ngrid,nslope),         intent(out) :: min_co2_ice      ! Minimum of co2 ice per slope of the year [kg/m^2]
    42 real, dimension(ngrid,nslope),         intent(out) :: min_h2o_ice      ! Minimum of h2o ice per slope of the year [kg/m^2]
    43 real, dimension(ngrid,timelen),        intent(out) :: vmr_co2_PCM_phys ! Physics x Times co2 volume mixing ratio retrieve from the PCM [m^3/m^3]
    44 real, dimension(ngrid,timelen),        intent(out) :: ps_timeseries    ! Surface Pressure [Pa]
    45 real, dimension(ngrid,timelen),        intent(out) :: q_co2            ! CO2 mass mixing ratio in the first layer [kg/m^3]
    46 real, dimension(ngrid,timelen),        intent(out) :: q_h2o            ! H2O mass mixing ratio in the first layer [kg/m^3]
    47 !SOIL
    48 real, dimension(ngrid,nslope),                 intent(out) :: tsurf_avg             ! Average surface temperature of the concatenated file [K]
    49 real, dimension(ngrid,nsoilmx,nslope),         intent(out) :: tsoil_avg             ! Average soil temperature of the concatenated file [K]
    50 real, dimension(ngrid,nslope,timelen),         intent(out) :: tsurf_PCM             ! Surface temperature of the concatenated file, time series [K]
    51 real, dimension(ngrid,nsoilmx,nslope,timelen), intent(out) :: tsoil_PCM             ! Soil temperature of the concatenated file, time series [K]
    52 real, dimension(ngrid,nslope),                 intent(out) :: watersurf_density_avg ! Water density at the surface [kg/m^3]
    53 real, dimension(ngrid,nsoilmx,nslope,timelen), intent(out) :: watersoil_density     ! Water density in the soil layer, time series [kg/m^3]
    54 !=======================================================================
    55 ! Local Variables
    56 integer                         :: i, j, l, t                                                    ! loop variables
    57 real                            :: A, B, mmean                                                   ! Molar Mass of co2 and no co2, A;B intermediate variables to compute the mean molar mass of the layer
    58 integer                         :: islope                                                        ! loop for variables
    59 character(2)                    :: num                                                           ! for reading sloped variables
    60 real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: h2o_ice_s_dyn             ! h2o ice per slope of the concatenated file [kg/m^2]
     40real, dimension(ngrid,nslope,2),               intent(out) :: min_co2_ice                  ! Minimum of co2 ice per slope of the year [kg/m^2]
     41real, dimension(ngrid,nslope,2),               intent(out) :: min_h2o_ice                  ! Minimum of h2o ice per slope of the year [kg/m^2]
     42real, dimension(ngrid,timelen),                intent(out) :: vmr_co2_PCM                  ! Grid points x Times co2 volume mixing ratio retrieve from the PCM [m^3/m^3]
     43real, dimension(ngrid,timelen),                intent(out) :: q_co2                        ! CO2 mass mixing ratio in the first layer [kg/m^3]
     44real, dimension(ngrid,timelen),                intent(out) :: q_h2o                        ! H2O mass mixing ratio in the first layer [kg/m^3]
     45real, dimension(ngrid,timelen),                intent(out) :: ps_timeseries                ! Surface pressure timeseries [Pa]
     46real, dimension(ngrid),                        intent(out) :: ps_avg                       ! Averaged surface pressure [K]
     47real, dimension(ngrid,nslope),                 intent(out) :: tsurf_avg                    ! Averaged surface temperature [K]
     48real, dimension(ngrid,nslope),                 intent(out) :: tsurf_avg_yr1                ! Averaged surface temperature for year 1 [K]
     49real, dimension(ngrid,nsoilmx,nslope),         intent(out) :: tsoil_avg                    ! Averaged soil temperature for year 2 [K]
     50real, dimension(ngrid,nsoilmx,nslope,timelen), intent(out) :: tsoil_timeseries             ! Soil temperature timeseries [K]
     51real, dimension(ngrid,nslope),                 intent(out) :: watersurf_density_avg        ! Water density at the surface [kg/m^3]
     52real, dimension(ngrid,nsoilmx,nslope,timelen), intent(out) :: watersoil_density_timeseries ! Water density timeseries in the soil layer [kg/m^3]
     53! Local variables
     54integer                                                             :: i, j, l, t, islope        ! Loop variables
     55real                                                                :: A, B, mmean               ! Molar Mass of co2 and no co2, A;B intermediate variables to compute the mean molar mass of the layer
     56character(2)                                                        :: num                       ! Hor reading sloped variables
     57real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: h2o_ice_s_dyn             ! H2O ice per slope of the concatenated file [kg/m^2]
    6158real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: watercap
    6259real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: perennial_co2ice
    63 real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: vmr_co2_PCM               ! CO2 volume mixing ratio in the first layer [mol/m^3]
    64 real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: ps_PCM                    ! Surface Pressure [Pa]
     60real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: vmr_co2_dyn               ! CO2 volume mixing ratio in the first layer [mol/m^3]
     61real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: ps_dyn                   ! Surface pressure [Pa]
     62real, dimension(iim_input + 1,jjm_input + 1)                        :: ps_avg_dyn                ! Averaged surface pressure of the concatenated file [Pa]
    6563real, dimension(iim_input + 1,jjm_input + 1,nslope)                 :: min_co2_ice_dyn
    6664real, dimension(iim_input + 1,jjm_input + 1,nslope)                 :: min_h2o_ice_dyn
    67 real, dimension(iim_input + 1,jjm_input + 1,nslope)                 :: tsurf_avg_dyn             ! Average surface temperature of the concatenated file [K]
    68 real, dimension(iim_input + 1,jjm_input + 1,nsoilmx,nslope)         :: tsoil_avg_dyn             ! Average soil temperature of the concatenated file [K]
    69 real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: tsurf_PCM_dyn             ! Surface temperature of the concatenated file, time series [K]
    70 real, dimension(iim_input + 1,jjm_input + 1,nsoilmx,nslope,timelen) :: tsoil_PCM_dyn             ! Soil temperature of the concatenated file, time series [K]
     65real, dimension(iim_input + 1,jjm_input + 1,nslope)                 :: tsurf_avg_dyn             ! Averaged surface temperature of the concatenated file [K]
     66real, dimension(iim_input + 1,jjm_input + 1,nsoilmx,nslope)         :: tsoil_avg_dyn             ! Averaged soil temperature of the concatenated file [K]
     67real, dimension(iim_input + 1,jjm_input + 1,nslope,timelen)         :: tsurf_dyn                ! Surface temperature of the concatenated file, time series [K]
     68real, dimension(iim_input + 1,jjm_input + 1,nsoilmx,nslope,timelen) :: tsoil_dyn                ! Soil temperature of the concatenated file, time series [K]
    7169real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: q_co2_dyn                 ! CO2 mass mixing ratio in the first layer [kg/m^3]
    7270real, dimension(iim_input + 1,jjm_input + 1,timelen)                :: q_h2o_dyn                 ! H2O mass mixing ratio in the first layer [kg/m^3]
     
    7674real, dimension(iim_input + 1,jjm_input + 1,nsoilmx,nslope,timelen) :: watersoil_density_dyn     ! Water density in the soil layer, time series [kg/m^3]
    7775!-----------------------------------------------------------------------
     76
     77!------------------ Year 1 ------------------
    7878! Open the NetCDF file
    79 write(*,*) "Opening "//filename//"..."
    80 call error_msg(NF90_OPEN(filename,NF90_NOWRITE,fID),"open",filename)
    81 
    82 ! Download the data from the file
    83 call get_var3("ps",ps_PCM)
    84 write(*,*) "Data for surface pressure downloaded!"
    85 
    86 call get_var3("co2_layer1",q_co2_dyn)
    87 write(*,*) "Data for vmr co2 downloaded!"
    88 
    89 call get_var3("h2o_layer1",q_h2o_dyn)
    90 write(*,*) "Data for vmr h2o downloaded!"
    91 
     79write(*,*) "Opening "//filename1//"..."
     80call error_msg(NF90_OPEN(filename1,NF90_NOWRITE,fID),"open",filename1)
     81
     82! Compute averages over the year for each point
     83write(*,*) "Computing the average of tsurf..."
    9284if (nslope == 1) then ! There is no slope
    9385    call get_var3("co2ice",co2_ice_slope_dyn(:,:,1,:))
     
    9789    write(*,*) "Data for h2o_ice_s downloaded!"
    9890
    99     call get_var3("tsurf",tsurf_PCM_dyn(:,:,1,:))
     91    call get_var3("tsurf",tsurf_dyn(:,:,1,:))
    10092    write(*,*) "Data for tsurf downloaded!"
    10193
     
    10698    call get_var3("perennial_co2ice",perennial_co2ice(:,:,1,:))
    10799    write(*,*) "Data for perennial_co2ice downloaded!"
    108 
    109     if (soil_pem) then
    110         call get_var4("soiltemp",tsoil_PCM_dyn(:,:,:,1,:))
    111         write(*,*) "Data for soiltemp downloaded!"
    112 
    113         call get_var4("waterdensity_soil",watersoil_density_dyn(:,:,:,1,:))
    114         write(*,*) "Data for waterdensity_soil downloaded!"
    115 
    116         call get_var3("waterdensity_surface",watersurf_density_dyn(:,:,1,:))
    117         write(*,*) "Data for waterdensity_surface downloaded!"
    118     endif !soil_pem
    119100#endif
    120101else ! We use slopes
     
    133114    do islope = 1,nslope
    134115        write(num,'(i2.2)') islope
    135         call get_var3("tsurf_slope"//num,tsurf_PCM_dyn(:,:,islope,:))
     116        call get_var3("tsurf_slope"//num,tsurf_dyn(:,:,islope,:))
    136117    enddo
    137118    write(*,*) "Data for tsurf downloaded!"
     
    149130    enddo
    150131    write(*,*) "Data for perennial_co2ice downloaded!"
    151 
    152     if (soil_pem) then
    153         do islope = 1,nslope
    154             write(num,'(i2.2)') islope
    155             call get_var4("soiltemp_slope"//num,tsoil_PCM_dyn(:,:,:,islope,:))
    156         enddo
    157         write(*,*) "Data for soiltemp downloaded!"
    158 
    159         do islope = 1,nslope
    160             write(num,'(i2.2)') islope
    161             call get_var4("waterdensity_soil_slope"//num,watersoil_density_dyn(:,:,:,islope,:))
    162         enddo
    163         write(*,*) "Data for waterdensity_soil downloaded!"
    164 
    165         do islope = 1,nslope
    166             write(num,'(i2.2)') islope
    167             call get_var3("waterdensity_surface"//num,watersurf_density_dyn(:,:,islope,:))
    168         enddo
    169         write(*,*) "Data for waterdensity_surface downloaded!"
    170     endif !soil_pem
    171132#endif
    172133endif
    173134
    174135! Close the NetCDF file
    175 write(*,*) "Closing "//filename//"..."
    176 call error_msg(nf90_close(fID),"close",filename)
     136write(*,*) "Closing "//filename1//"..."
     137call error_msg(nf90_close(fID),"close",filename1)
    177138
    178139! Compute the minimum over the year for each point
     
    186147! Compute averages over the year for each point
    187148write(*,*) "Computing the average of tsurf..."
    188 tsurf_avg_dyn = sum(tsurf_PCM_dyn,4)/timelen
     149tsurf_avg_dyn = sum(tsurf_dyn,4)/timelen
     150
     151#ifndef CPP_1D
     152    call gr_dyn_fi(nslope,iim_input + 1,jjm_input + 1,ngrid,tsurf_avg_dyn,tsurf_avg)
     153    do islope = 1,nslope
     154        call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_co2_ice_dyn(:,:,islope),min_co2_ice(:,islope,1))
     155        call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_h2o_ice_dyn(:,:,islope),min_h2o_ice(:,islope,1))
     156    enddo
     157#else
     158    tsurf_avg_yr1(1,:) = tsurf_avg_dyn(1,1,:)
     159    min_co2_ice(1,:,1) = min_co2_ice_dyn(1,1,:)
     160    min_h2o_ice(1,:,1) = min_h2o_ice_dyn(1,1,:)
     161#endif
     162write(*,*) "Downloading data Y1 done!"
     163
     164!------------------ Year 2 ------------------
     165
     166! Open the NetCDF file
     167write(*,*) "Opening "//filename2//"..."
     168call error_msg(NF90_OPEN(filename2,NF90_NOWRITE,fID),"open",filename2)
     169
     170! Download the data from the file
     171call get_var3("ps",ps_dyn)
     172write(*,*) "Data for surface pressure downloaded!"
     173
     174call get_var3("co2_layer1",q_co2_dyn)
     175write(*,*) "Data for vmr co2 downloaded!"
     176
     177call get_var3("h2o_layer1",q_h2o_dyn)
     178write(*,*) "Data for vmr h2o downloaded!"
     179
     180if (nslope == 1) then ! There is no slope
     181    call get_var3("co2ice",co2_ice_slope_dyn(:,:,1,:))
     182    write(*,*) "Data for co2_ice downloaded!"
     183
     184    call get_var3("h2o_ice_s",h2o_ice_s_dyn(:,:,1,:))
     185    write(*,*) "Data for h2o_ice_s downloaded!"
     186
     187    call get_var3("tsurf",tsurf_dyn(:,:,1,:))
     188    write(*,*) "Data for tsurf downloaded!"
     189
     190#ifndef CPP_STD
     191    call get_var3("watercap",watercap(:,:,1,:))
     192    write(*,*) "Data for watercap downloaded!"
     193
     194    call get_var3("perennial_co2ice",perennial_co2ice(:,:,1,:))
     195    write(*,*) "Data for perennial_co2ice downloaded!"
     196
     197    if (soil_pem) then
     198        call get_var4("soiltemp",tsoil_dyn(:,:,:,1,:))
     199        write(*,*) "Data for soiltemp downloaded!"
     200
     201        call get_var4("waterdensity_soil",watersoil_density_dyn(:,:,:,1,:))
     202        write(*,*) "Data for waterdensity_soil downloaded!"
     203
     204        call get_var3("waterdensity_surface",watersurf_density_dyn(:,:,1,:))
     205        write(*,*) "Data for waterdensity_surface downloaded!"
     206    endif !soil_pem
     207#endif
     208else ! We use slopes
     209    do islope = 1,nslope
     210        write(num,'(i2.2)') islope
     211        call get_var3("co2ice_slope"//num,co2_ice_slope_dyn(:,:,islope,:))
     212    enddo
     213    write(*,*) "Data for co2_ice downloaded!"
     214
     215    do islope = 1,nslope
     216        write(num,'(i2.2)') islope
     217        call get_var3("h2o_ice_s_slope"//num,h2o_ice_s_dyn(:,:,islope,:))
     218    enddo
     219    write(*,*) "Data for h2o_ice_s downloaded!"
     220
     221    do islope = 1,nslope
     222        write(num,'(i2.2)') islope
     223        call get_var3("tsurf_slope"//num,tsurf_dyn(:,:,islope,:))
     224    enddo
     225    write(*,*) "Data for tsurf downloaded!"
     226
     227#ifndef CPP_STD
     228    do islope = 1,nslope
     229        write(num,'(i2.2)') islope
     230        call get_var3("watercap_slope"//num,watercap(:,:,islope,:))
     231    enddo
     232    write(*,*) "Data for watercap downloaded!"
     233
     234    do islope = 1,nslope
     235        write(num,'(i2.2)') islope
     236        call get_var3("perennial_co2ice_slope"//num,perennial_co2ice(:,:,islope,:))
     237    enddo
     238    write(*,*) "Data for perennial_co2ice downloaded!"
     239
     240    if (soil_pem) then
     241        do islope = 1,nslope
     242            write(num,'(i2.2)') islope
     243            call get_var4("soiltemp_slope"//num,tsoil_dyn(:,:,:,islope,:))
     244        enddo
     245        write(*,*) "Data for soiltemp downloaded!"
     246
     247        do islope = 1,nslope
     248            write(num,'(i2.2)') islope
     249            call get_var4("waterdensity_soil_slope"//num,watersoil_density_dyn(:,:,:,islope,:))
     250        enddo
     251        write(*,*) "Data for waterdensity_soil downloaded!"
     252
     253        do islope = 1,nslope
     254            write(num,'(i2.2)') islope
     255            call get_var3("waterdensity_surface"//num,watersurf_density_dyn(:,:,islope,:))
     256        enddo
     257        write(*,*) "Data for waterdensity_surface downloaded!"
     258    endif !soil_pem
     259#endif
     260endif
     261
     262! Close the NetCDF file
     263write(*,*) "Closing "//filename2//"..."
     264call error_msg(nf90_close(fID),"close",filename2)
     265
     266! Compute the minimum over the year for each point
     267write(*,*) "Computing the min of h2o_ice..."
     268where (h2o_ice_s_dyn < 0.) h2o_ice_s_dyn = 0.
     269min_h2o_ice_dyn = minval(h2o_ice_s_dyn + watercap,4)
     270write(*,*) "Computing the min of co2_ice..."
     271where (co2_ice_slope_dyn < 0.) co2_ice_slope_dyn = 0.
     272min_co2_ice_dyn = minval(co2_ice_slope_dyn + perennial_co2ice,4)
     273
     274! Compute averages over the year for each point
     275write(*,*) "Computing the average of tsurf..."
     276tsurf_avg_dyn = sum(tsurf_dyn,4)/timelen
     277
     278write(*,*) "Computing the average of Ps..."
     279ps_avg_dyn = sum(ps_dyn,3)/timelen
    189280
    190281if (soil_pem) then
    191     write(*,*) "Computing average of tsoil..."
    192     tsoil_avg_dyn = sum(tsoil_PCM_dyn,5)/timelen
    193     write(*,*) "Computing average of waterdensity_surface..."
     282    write(*,*) "Computing the average of tsoil..."
     283    tsoil_avg_dyn = sum(tsoil_dyn,5)/timelen
     284    write(*,*) "Computing the average of waterdensity_surface..."
    194285    watersurf_density_dyn_avg = sum(watersurf_density_dyn,4)/timelen
    195286endif
     
    212303            endif
    213304            mmean = 1/(A*q_co2_dyn(i,j,t) + B)
    214             vmr_co2_PCM(i,j,t) = q_co2_dyn(i,j,t)*mmean/m_co2
     305            vmr_co2_dyn(i,j,t) = q_co2_dyn(i,j,t)*mmean/m_co2
    215306        enddo
    216307    enddo
     
    218309
    219310#ifndef CPP_1D
    220     call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,vmr_co2_PCM,vmr_co2_PCM_phys)
    221     call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,ps_PCM,ps_timeseries)
     311    call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,vmr_co2_dyn,vmr_co2_PCM)
     312    call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,ps_dyn,ps_timeseries)
     313    call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,ps_avg_dyn,ps_avg)
    222314    call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,q_co2_dyn,q_co2)
    223315    call gr_dyn_fi(timelen,iim_input + 1,jjm_input + 1,ngrid,q_h2o_dyn,q_h2o)
    224 
    225     do islope = 1,nslope
    226         call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_co2_ice_dyn(:,:,islope),min_co2_ice(:,islope))
    227         call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_h2o_ice_dyn(:,:,islope),min_h2o_ice(:,islope))
     316    do islope = 1,nslope
     317        call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_co2_ice_dyn(:,:,islope),min_co2_ice(:,islope,2))
     318        call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,min_h2o_ice_dyn(:,:,islope),min_h2o_ice(:,islope,2))
    228319        if (soil_pem) then
    229320            do l = 1,nsoilmx
    230321                call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,tsoil_avg_dyn(:,:,l,islope),tsoil_avg(:,l,islope))
    231322                do t = 1,timelen
    232                     call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,tsoil_PCM_dyn(:,:,l,islope,t),tsoil_PCM(:,l,islope,t))
    233                     call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,watersoil_density_dyn(:,:,l,islope,t),watersoil_density(:,l,islope,t))
     323                    call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,tsoil_dyn(:,:,l,islope,t),tsoil_timeseries(:,l,islope,t))
     324                    call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,watersoil_density_dyn(:,:,l,islope,t),watersoil_density_timeseries(:,l,islope,t))
    234325                enddo
    235326            enddo
    236327            call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,watersurf_density_dyn_avg(:,:,islope),watersurf_density_avg(:,islope))
    237328        endif ! soil_pem
    238         do t = 1,timelen
    239             call gr_dyn_fi(1,iim_input + 1,jjm_input + 1,ngrid,tsurf_PCM_dyn(:,:,islope,t),tsurf_PCM(:,islope,t))
    240         enddo
    241     enddo
    242 
     329    enddo
    243330    call gr_dyn_fi(nslope,iim_input + 1,jjm_input + 1,ngrid,tsurf_avg_dyn,tsurf_avg)
    244331#else
    245     vmr_co2_PCM_phys(1,:) = vmr_co2_PCM(1,1,:)
    246     ps_timeseries(1,:) = ps_PCM(1,1,:)
     332    vmr_co2_PCM(1,:) = vmr_co2_dyn(1,1,:)
     333    ps_timeseries(1,:) = ps_dyn(1,1,:)
     334    ps_avg(1) = ps_avg_dyn(1,1)
    247335    q_co2(1,:) = q_co2_dyn(1,1,:)
    248336    q_h2o(1,:) = q_h2o_dyn(1,1,:)
    249     min_co2_ice(1,:) = min_co2_ice_dyn(1,1,:)
    250     min_h2o_ice(1,:) = min_h2o_ice_dyn(1,1,:)
     337    min_co2_ice(1,:,2) = min_co2_ice_dyn(1,1,:)
     338    min_h2o_ice(1,:,2) = min_h2o_ice_dyn(1,1,:)
    251339    if (soil_pem) then
     340        tsoil_timeseries(1,:,:,:) = tsoil_dyn(1,1,:,:,:)
    252341        tsoil_avg(1,:,:) = tsoil_avg_dyn(1,1,:,:)
    253         tsoil_PCM(1,:,:,:) = tsoil_PCM_dyn(1,1,:,:,:)
    254         watersoil_density(1,:,:,:) = watersoil_density_dyn(1,1,:,:,:)
     342        watersoil_density_timeseries(1,:,:,:) = watersoil_density_dyn(1,1,:,:,:)
    255343        watersurf_density_avg(1,:) = watersurf_density_dyn_avg(1,1,:)
    256344    endif ! soil_pem
    257     tsurf_PCM(1,:,:) = tsurf_PCM_dyn(1,1,:,:)
    258345    tsurf_avg(1,:) = tsurf_avg_dyn(1,1,:)
    259346#endif
     347write(*,*) "Downloading data Y2 done!"
    260348
    261349END SUBROUTINE read_data_PCM
  • trunk/LMDZ.COMMON/libf/evolution/recomp_tend_co2_mod.F90

    r3570 r3571  
    1 MODULE recomp_tend_co2_slope_mod
     1MODULE recomp_tend_co2_mod
    22
    33implicit none
     
    88
    99SUBROUTINE recomp_tend_co2(ngrid,nslope,timelen,d_co2ice_phys,d_co2ice_ini,co2ice,emissivity, &
    10                            vmr_co2_PCM,vmr_co2_PEM,ps_PCM_2,global_avg_press_PCM,global_avg_press_new)
     10                           vmr_co2_PCM,vmr_co2_PEM,ps_PCM,ps_avg_global_ini,ps_avg_global)
    1111
    1212use constants_marspem_mod, only : alpha_clap_co2, beta_clap_co2, sigmaB, Lco2, sols_per_my, sec_per_sol
     
    2020!=======================================================================
    2121
    22 !   arguments:
    23 !   ----------
    24 !   INPUT
     22! Inputs
     23! ------
    2524integer,                        intent(in) :: timelen, ngrid, nslope
    26 real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PCM          ! physical point field: Volume mixing ratio of co2 in the first layer
    27 real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM          ! physical point field: Volume mixing ratio of co2 in the first layer
    28 real, dimension(ngrid,timelen), intent(in) :: ps_PCM_2             ! physical point field: Surface pressure in the PCM
    29 real,                           intent(in) :: global_avg_press_PCM ! global averaged pressure at previous timestep
    30 real,                           intent(in) :: global_avg_press_new ! global averaged pressure at current timestep
    31 real, dimension(ngrid,nslope),  intent(in) :: d_co2ice_ini         ! physical point field: Evolution of perennial ice over one year
    32 real, dimension(ngrid,nslope),  intent(in) :: co2ice               ! CO2 ice per mesh and sub-grid slope (kg/m^2)
    33 real, dimension(ngrid,nslope),  intent(in) :: emissivity           ! Emissivity per mesh and sub-grid slope(1)
    34 !   OUTPUT
     25real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PCM       ! physical point field: Volume mixing ratio of co2 in the first layer
     26real, dimension(ngrid,timelen), intent(in) :: vmr_co2_PEM       ! physical point field: Volume mixing ratio of co2 in the first layer
     27real, dimension(ngrid,timelen), intent(in) :: ps_PCM            ! physical point field: Surface pressure in the PCM
     28real,                           intent(in) :: ps_avg_global_ini ! global averaged pressure at previous timestep
     29real,                           intent(in) :: ps_avg_global     ! global averaged pressure at current timestep
     30real, dimension(ngrid,nslope),  intent(in) :: d_co2ice_ini      ! physical point field: Evolution of perennial ice over one year
     31real, dimension(ngrid,nslope),  intent(in) :: co2ice            ! CO2 ice per mesh and sub-grid slope (kg/m^2)
     32real, dimension(ngrid,nslope),  intent(in) :: emissivity        ! Emissivity per mesh and sub-grid slope(1)
     33! Outputs
     34! -------
    3535real, dimension(ngrid,nslope), intent(inout) :: d_co2ice_phys ! physical point field: Evolution of perennial ice over one year
    3636
    37 !   local:
    38 !   ------
     37! Local:
     38! ------
    3939integer :: i, t, islope
    40 real    :: coef, ave
     40real    :: coef, avg
    4141
    4242write(*,*) "Update of the CO2 tendency from the current pressure"
     
    4646    do islope = 1,nslope
    4747        coef = sols_per_my*sec_per_sol*emissivity(i,islope)*sigmaB/Lco2
    48         ave = 0.
     48        avg = 0.
    4949        if (co2ice(i,islope) > 1.e-4 .and. abs(d_co2ice_phys(i,islope)) > 1.e-5) then
    5050            do t = 1,timelen
    51                 ave = ave + (beta_clap_co2/(alpha_clap_co2-log(vmr_co2_PCM(i,t)*ps_PCM_2(i,t)/100.)))**4 &
    52                       - (beta_clap_co2/(alpha_clap_co2-log(vmr_co2_PEM(i,t)*ps_PCM_2(i,t)*(global_avg_press_new/global_avg_press_PCM)/100.)))**4
     51                avg = avg + (beta_clap_co2/(alpha_clap_co2-log(vmr_co2_PCM(i,t)*ps_PCM(i,t)/100.)))**4 &
     52                      - (beta_clap_co2/(alpha_clap_co2-log(vmr_co2_PEM(i,t)*ps_PCM(i,t)*(ps_avg_global/ps_avg_global_ini)/100.)))**4
    5353            enddo
    54             if (ave < 1.e-4) ave = 0.
    55             d_co2ice_phys(i,islope) = d_co2ice_ini(i,islope) - coef*ave/timelen
     54            if (avg < 1.e-4) avg = 0.
     55            d_co2ice_phys(i,islope) = d_co2ice_ini(i,islope) - coef*avg/timelen
    5656        endif
    5757    enddo
     
    5959
    6060END SUBROUTINE recomp_tend_co2
     61!=======================================================================
    6162
    62 END MODULE recomp_tend_co2_slope_mod
     63SUBROUTINE recomp_tend_h2o(ngrid,nslope,timelen,d_h2oice,PCM_temp,PEM_temp)
     64
     65implicit none
     66
     67!=======================================================================
     68!
     69!  Routine that compute the evolution of the tendencie for h2o ice
     70!
     71!=======================================================================
     72
     73! Inputs
     74! ------
     75integer,            intent(in) :: timelen, ngrid, nslope
     76real, dimension(:), intent(in) :: PCM_temp, PEM_temp
     77! Outputs
     78! -------
     79real, dimension(ngrid,nslope), intent(inout) :: d_h2oice ! physical point field: Evolution of perennial ice over one year
     80
     81! Local:
     82! ------
     83
     84write(*,*) "Update of the H2O tendency due to lag layer"
     85
     86! Flux correction due to lag layer
     87!~ Rz_old = h2oice_depth_old*0.0325/4.e-4              ! resistance from PCM
     88!~ Rz_new = h2oice_depth_new*0.0325/4.e-4              ! new resistance based on new depth
     89!~ R_dec = (1./Rz_old)/(1./Rz_new)                     ! decrease because of resistance
     90!~ soil_psv_old = psv(max(PCM_temp(h2oice_depth_old))) ! the maxmimum annual mean saturation vapor pressure at the temperature of the GCM run temperature at the old ice location
     91!~ soil_psv_new = psv(max(PEM_temp(h2oice_depth_new))) ! the maxmimum annual mean saturation vapor pressure at the temperature of the PEM run temperature at the new ice location
     92!~ hum_dec = soil_psv_old/soil_psv_new                 ! decrease because of lower water vapor pressure at the new depth
     93!~ d_h2oice = d_h2oice*R_dec*hum_dec                   ! decrease of flux
     94
     95END SUBROUTINE recomp_tend_h2o
     96
     97END MODULE recomp_tend_co2_mod
  • trunk/LMDZ.COMMON/libf/evolution/stopping_crit_mod.F90

    r3432 r3571  
    1414!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    1515
    16 SUBROUTINE stopping_crit_h2o_ice(cell_area,h2oice_ini_surf,ini_h2oice_sublim,h2o_ice,stopPEM,ngrid)
     16SUBROUTINE stopping_crit_h2o_ice(cell_area,h2oice_ini_surf,is_h2oice_sublim_ini,h2o_ice,stopPEM,ngrid)
    1717
    1818use time_evol_mod, only: h2o_ice_crit
     
    2828! Inputs
    2929!-------
    30 integer,                          intent(in) :: ngrid             ! # of physical grid points
    31 real,    dimension(ngrid),        intent(in) :: cell_area         ! Area of the cells
    32 real,    dimension(ngrid,nslope), intent(in) :: h2o_ice           ! Actual density of h2o ice
    33 real,                             intent(in) :: h2oice_ini_surf   ! Initial surface of sublimating h2o ice
    34 logical, dimension(ngrid,nslope), intent(in) :: ini_h2oice_sublim ! Grid points where h2o ice was initially sublimating
     30integer,                          intent(in) :: ngrid                ! # of physical grid points
     31real,    dimension(ngrid),        intent(in) :: cell_area            ! Area of the cells
     32real,    dimension(ngrid,nslope), intent(in) :: h2o_ice              ! Actual density of h2o ice
     33real,                             intent(in) :: h2oice_ini_surf      ! Initial surface of sublimating h2o ice
     34logical, dimension(ngrid,nslope), intent(in) :: is_h2oice_sublim_ini ! Grid points where h2o ice was initially sublimating
    3535! Outputs
    3636!--------
     
    4848do i = 1,ngrid
    4949    do islope = 1,nslope
    50         if (ini_h2oice_sublim(i,islope) .and. h2o_ice(i,islope) > 0.) h2oice_now_surf = h2oice_now_surf + cell_area(i)*subslope_dist(i,islope)
     50        if (is_h2oice_sublim_ini(i,islope) .and. h2o_ice(i,islope) > 0.) h2oice_now_surf = h2oice_now_surf + cell_area(i)*subslope_dist(i,islope)
    5151    enddo
    5252enddo
     
    7575!=======================================================================
    7676
    77 SUBROUTINE stopping_crit_co2(cell_area,co2ice_ini_surf,ini_co2ice_sublim,co2_ice,stopPEM,ngrid,global_avg_press_PCM,global_avg_press_new,nslope)
     77SUBROUTINE stopping_crit_co2(cell_area,co2ice_sublim_surf_ini,is_co2ice_sublim_ini,co2_ice,stopPEM,ngrid,ps_avg_global_ini,ps_avg_global,nslope)
    7878
    7979use time_evol_mod, only: co2_ice_crit, ps_criterion
     
    8989! Inputs
    9090!-------
    91 integer,                          intent(in) :: ngrid, nslope        ! # of grid physical grid points
    92 real,    dimension(ngrid),        intent(in) :: cell_area            ! Area of the cells
    93 real,    dimension(ngrid,nslope), intent(in) :: co2_ice              ! Actual density of co2 ice
    94 real,                             intent(in) :: co2ice_ini_surf      ! Initial surface of sublimatingco2 ice
    95 logical, dimension(ngrid,nslope), intent(in) :: ini_co2ice_sublim    ! Grid points where co2 ice was initially sublimating
    96 real,                             intent(in) :: global_avg_press_PCM ! Planet average pressure from the PCM start files
    97 real,                             intent(in) :: global_avg_press_new ! Planet average pressure from the PEM computations
     91integer,                          intent(in) :: ngrid, nslope          ! # of grid physical grid points
     92real,    dimension(ngrid),        intent(in) :: cell_area              ! Area of the cells
     93real,    dimension(ngrid,nslope), intent(in) :: co2_ice                ! Actual density of co2 ice
     94real,                             intent(in) :: co2ice_sublim_surf_ini ! Initial surface of sublimatingco2 ice
     95logical, dimension(ngrid,nslope), intent(in) :: is_co2ice_sublim_ini   ! Grid points where co2 ice was initially sublimating
     96real,                             intent(in) :: ps_avg_global_ini      ! Planet average pressure from the PCM start files
     97real,                             intent(in) :: ps_avg_global          ! Planet average pressure from the PEM computations
    9898! Outputs
    9999!--------
     
    112112do i = 1,ngrid
    113113    do islope = 1,nslope
    114         if (ini_co2ice_sublim(i,islope) .and. co2_ice(i,islope) > 0.) co2ice_now_surf = co2ice_now_surf + cell_area(i)*subslope_dist(i,islope)
     114        if (is_co2ice_sublim_ini(i,islope) .and. co2_ice(i,islope) > 0.) co2ice_now_surf = co2ice_now_surf + cell_area(i)*subslope_dist(i,islope)
    115115    enddo
    116116enddo
    117117
    118118! Check of the criterion
    119 if (co2ice_now_surf < co2ice_ini_surf*(1. - co2_ice_crit)) then
     119if (co2ice_now_surf < co2ice_sublim_surf_ini*(1. - co2_ice_crit)) then
    120120    stopPEM = 3
    121121    write(*,*) "Reason of stopping: the surface of co2 ice sublimating reaches the threshold"
    122     write(*,*) "co2ice_now_surf < co2ice_ini_surf*(1. - co2_ice_crit)", co2ice_now_surf < co2ice_ini_surf*(1. - co2_ice_crit)
    123     write(*,*) "Initial surface of co2 ice sublimating =", co2ice_ini_surf
     122    write(*,*) "co2ice_now_surf < co2ice_sublim_surf_ini*(1. - co2_ice_crit)", co2ice_now_surf < co2ice_sublim_surf_ini*(1. - co2_ice_crit)
     123    write(*,*) "Initial surface of co2 ice sublimating =", co2ice_sublim_surf_ini
    124124    write(*,*) "Current surface of co2 ice sublimating =", co2ice_now_surf
    125125    write(*,*) "Percentage of change accepted =", co2_ice_crit*100.
    126 else if (co2ice_now_surf > co2ice_ini_surf*(1. + co2_ice_crit)) then
     126else if (co2ice_now_surf > co2ice_sublim_surf_ini*(1. + co2_ice_crit)) then
    127127    stopPEM = 3
    128128    write(*,*) "Reason of stopping: the surface of co2 ice sublimating reaches the threshold"
    129     write(*,*) "co2ice_now_surf > co2ice_ini_surf*(1. + co2_ice_crit)", co2ice_now_surf > co2ice_ini_surf*(1. + co2_ice_crit)
     129    write(*,*) "co2ice_now_surf > co2ice_sublim_surf_ini*(1. + co2_ice_crit)", co2ice_now_surf > co2ice_sublim_surf_ini*(1. + co2_ice_crit)
    130130    write(*,*) "Current surface of co2 ice sublimating =", co2ice_now_surf
    131     write(*,*) "Initial surface of co2 ice sublimating =", co2ice_ini_surf
     131    write(*,*) "Initial surface of co2 ice sublimating =", co2ice_sublim_surf_ini
    132132    write(*,*) "Percentage of change accepted =", co2_ice_crit*100.
    133133endif
    134134
    135 if (abs(co2ice_ini_surf) < 1.e-5) stopPEM = 0
     135if (abs(co2ice_sublim_surf_ini) < 1.e-5) stopPEM = 0
    136136
    137 if (global_avg_press_new < global_avg_press_PCM*(1. - ps_criterion)) then
     137if (ps_avg_global < ps_avg_global_ini*(1. - ps_criterion)) then
    138138    stopPEM = 4
    139139    write(*,*) "Reason of stopping: the global pressure reaches the threshold"
    140     write(*,*) "global_avg_press_new < global_avg_press_PCM*(1. - ps_criterion)", global_avg_press_new < global_avg_press_PCM*(1. - ps_criterion)
    141     write(*,*) "Initial global pressure =", global_avg_press_PCM
    142     write(*,*) "Current global pressure =", global_avg_press_new
     140    write(*,*) "ps_avg_global < ps_avg_global_ini*(1. - ps_criterion)", ps_avg_global < ps_avg_global_ini*(1. - ps_criterion)
     141    write(*,*) "Initial global pressure =", ps_avg_global_ini
     142    write(*,*) "Current global pressure =", ps_avg_global
    143143    write(*,*) "Percentage of change accepted =", ps_criterion*100.
    144 else if (global_avg_press_new > global_avg_press_PCM*(1. + ps_criterion)) then
     144else if (ps_avg_global > ps_avg_global_ini*(1. + ps_criterion)) then
    145145    stopPEM = 4
    146146    write(*,*) "Reason of stopping: the global pressure reaches the threshold"
    147     write(*,*) "global_avg_press_new > global_avg_press_PCM*(1. + ps_criterion)", global_avg_press_new > global_avg_press_PCM*(1. + ps_criterion)
    148     write(*,*) "Initial global pressure =", global_avg_press_PCM
    149     write(*,*) "Current global pressure =", global_avg_press_new
     147    write(*,*) "ps_avg_global > ps_avg_global_ini*(1. + ps_criterion)", ps_avg_global > ps_avg_global_ini*(1. + ps_criterion)
     148    write(*,*) "Initial global pressure =", ps_avg_global_ini
     149    write(*,*) "Current global pressure =", ps_avg_global
    150150    write(*,*) "Percentage of change accepted =", ps_criterion*100.
    151151endif
Note: See TracChangeset for help on using the changeset viewer.