Changeset 4138


Ignore:
Timestamp:
Mar 17, 2026, 4:22:44 PM (4 weeks ago)
Author:
jbclement
Message:

PEM:

  • Move ice table variables from "ice_table" to the main program.
  • Merge "job_id_mod" and "job_timelimit_mod" into "job" which is relocated to the PEM folder.
  • Rename local variables in procedures to avoid masking variables in parent scope.
  • Few cleanings to delete remaining PEM-external "include" and "use".

JBC

Location:
trunk/LMDZ.COMMON/libf
Files:
1 deleted
11 edited
1 moved

Legend:

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

    r4065 r4138  
    2525use frost,      only: ini_frost, end_frost
    2626use soil,       only: ini_soil, end_soil
    27 use ice_table,  only: ini_ice_table, end_ice_table
    2827use surf_ice,   only: ini_surf_ice, end_surf_ice
    2928use orbit,      only: ini_orbit, end_orbit
     
    7675call ini_frost()
    7776call ini_soil()
    78 call ini_ice_table()
    7977call ini_surf_ice()
    8078call ini_orbit()
     
    109107call end_orbit()
    110108call end_surf_ice()
    111 call end_ice_table()
    112109call end_soil()
    113110call end_frost()
  • trunk/LMDZ.COMMON/libf/evolution/atmosphere.F90

    r4134 r4138  
    408408
    409409!=======================================================================
    410 SUBROUTINE compute_alt_coord(pa,preff,ap,bp,aps,bps)
     410SUBROUTINE compute_alt_coord(pa,preff,ap_l,bp_l,aps,bps)
    411411!-----------------------------------------------------------------------
    412412! NAME
     
    449449! ---------
    450450real(dp)                                               :: pa, preff
    451 real(dp), dimension(nlayer + 1), intent(out)           :: ap, bp
     451real(dp), dimension(nlayer + 1), intent(out)           :: ap_l, bp_l
    452452real(dp), dimension(nlayer),     intent(out), optional :: aps, bps
    453453
    454 ! LOCAL VAIRABLES
     454! LOCAL VARIABLES
    455455! ---------------
    456456integer(di)                     :: i
     
    471471        call compute_hybrid_sig(sig(i),pa,preff,newsig)
    472472        bp(i) = exp(1._dp - 1._dp/(newsig**2))
    473         ap(i) = pa*(newsig - bp(i))
     473        ap_l(i) = pa*(newsig - bp(i))
    474474    end do
    475     ap(nlayer + 1) = 0._dp
     475    ap_l(nlayer + 1) = 0._dp
    476476    bp(nlayer + 1) = 0._dp
    477477else
    478478    call print_msg('> Defining sigma altitude coordinates',LVL_NFO)
    479     ap(:) = 0._dp
     479    ap_l(:) = 0._dp
    480480    bp(1:nlayer) = sig(1:nlayer)
    481481    bp(nlayer + 1) = 0._dp
     
    487487
    488488do i = 1,nlayer - 1
    489     aps(i) =  0.5_dp*(ap(i) + ap(i + 1))
     489    aps(i) =  0.5_dp*(ap_l(i) + ap_l(i + 1))
    490490    bps(i) =  0.5_dp*(bp(i) + bp(i + 1))
    491491end do
  • trunk/LMDZ.COMMON/libf/evolution/changelog.txt

    r4136 r4138  
    918918- Temporary memory load reduced in "xios_data".
    919919- Rename local variables in procedures to avoid masking variables in parent scope.
     920
     921== 17/03/2026 == JBC
     922- Move ice table variables from "ice_table" to the main program.
     923- Merge "job_id_mod" and "job_timelimit_mod" into "job" which is relocated to the PEM folder.
     924- Rename local variables in procedures to avoid masking variables in parent scope.
     925- Few cleanings to delete remaining PEM-external "include" and "use".
  • trunk/LMDZ.COMMON/libf/evolution/ice_table.F90

    r4135 r4138  
    2828logical(k4), protected :: icetable_dynamic     ! Flag to compute the icetable depth according to the dynamic method
    2929
    30 ! VARIABLES
    31 ! ---------
    32 real(dp), allocatable, dimension(:,:)   :: icetable_depth     ! Depth of the ice table [m]
    33 real(dp), allocatable, dimension(:,:)   :: icetable_thickness ! Thickness of the ice table [m]
    34 real(dp), allocatable, dimension(:,:,:) :: ice_porefilling    ! Amount of porefilling in each layer in each grid [m^3/m^3]
    35 
    3630contains
    3731!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    38 
    39 !=======================================================================
    40 SUBROUTINE ini_ice_table()
    41 !-----------------------------------------------------------------------
    42 ! NAME
    43 !     ini_ice_table
    44 !
    45 ! DESCRIPTION
    46 !     Allocate module arrays for ice table fields.
    47 !
    48 ! AUTHORS & DATE
    49 !     L. Lange
    50 !     JB Clement, 2023-2025
    51 !
    52 ! NOTES
    53 !
    54 !-----------------------------------------------------------------------
    55 
    56 ! DEPENDENCIES
    57 ! ------------
    58 use geometry, only: ngrid, nslope, nsoil
    59 
    60 ! DECLARATION
    61 ! -----------
    62 implicit none
    63 
    64 ! CODE
    65 ! ----
    66 allocate(icetable_depth(ngrid,nslope))
    67 allocate(icetable_thickness(ngrid,nslope))
    68 allocate(ice_porefilling(ngrid,nsoil,nslope))
    69 icetable_depth(:,:) = 0._dp
    70 icetable_thickness(:,:) = 0._dp
    71 ice_porefilling(:,:,:) = 0._dp
    72 
    73 END SUBROUTINE ini_ice_table
    74 !=======================================================================
    75 
    76 !=======================================================================
    77 SUBROUTINE end_ice_table
    78 !-----------------------------------------------------------------------
    79 ! NAME
    80 !     end_ice_table
    81 !
    82 ! DESCRIPTION
    83 !     Deallocate ice table arrays.
    84 !
    85 ! AUTHORS & DATE
    86 !     L. Lange
    87 !     JB Clement, 2023-2025
    88 !
    89 ! NOTES
    90 !
    91 !-----------------------------------------------------------------------
    92 
    93 ! DECLARATION
    94 ! -----------
    95 implicit none
    96 
    97 ! CODE
    98 ! ----
    99 if (allocated(icetable_depth)) deallocate(icetable_depth)
    100 if (allocated(icetable_thickness)) deallocate(icetable_thickness)
    101 if (allocated(ice_porefilling)) deallocate(ice_porefilling)
    102 
    103 END SUBROUTINE end_ice_table
    104 !=======================================================================
    10532
    10633!=======================================================================
     
    256183
    257184!=======================================================================
    258 SUBROUTINE compute_deltam_icetable(icetable_thickness_old,ice_porefilling_old,tsurf,tsoil,delta_icetable)
     185SUBROUTINE compute_deltam_icetable(icetable_depth,icetable_thickness,ice_porefilling,icetable_thickness_old,ice_porefilling_old,tsurf,tsoil,delta_icetable)
    259186!-----------------------------------------------------------------------
    260187! NAME
     
    286213! ARGUMENTS
    287214! ---------
    288 real(dp),    dimension(:,:),   intent(in)  :: icetable_thickness_old   ! Ice table thickness at the previous iteration [m]
    289 real(dp),    dimension(:,:,:), intent(in)  :: ice_porefilling_old      ! Ice pore filling at the previous iteration [m]
    290 real(dp),    dimension(:,:),   intent(in)  :: tsurf                    ! Surface temperature [K]
    291 real(dp),    dimension(:,:,:), intent(in)  :: tsoil                    ! Soil temperature [K]
    292 real(dp),    dimension(:),     intent(out) :: delta_icetable ! Mass of H2O ice that has been condensed on the ice table / sublimates from the ice table [kg/m^2]
     215real(dp),    dimension(:,:),   intent(in)  :: icetable_depth         ! Ice table depth [m]
     216real(dp),    dimension(:,:),   intent(in)  :: icetable_thickness     ! Ice table thickness [m]
     217real(dp),    dimension(:,:,:), intent(in)  :: ice_porefilling        ! Ice pore filling [m]
     218real(dp),    dimension(:,:),   intent(in)  :: icetable_thickness_old ! Ice table thickness at the previous iteration [m]
     219real(dp),    dimension(:,:,:), intent(in)  :: ice_porefilling_old    ! Ice pore filling at the previous iteration [m]
     220real(dp),    dimension(:,:),   intent(in)  :: tsurf                  ! Surface temperature [K]
     221real(dp),    dimension(:,:,:), intent(in)  :: tsoil                  ! Soil temperature [K]
     222real(dp),    dimension(:),     intent(out) :: delta_icetable         ! Mass of H2O ice that has been condensed on the ice table / sublimates from the ice table [kg/m^2]
    293223
    294224! LOCAL VARIABLES
     
    674604
    675605! Mass of H2O exchange between the ssi and the atmosphere
    676 call compute_deltam_icetable(icetable_thickness_old,ice_porefilling_old,tsurf_avg,tsoil_avg,delta_icetable)
     606call compute_deltam_icetable(icetable_depth,icetable_thickness,ice_porefilling,icetable_thickness_old,ice_porefilling_old,tsurf_avg,tsoil_avg,delta_icetable)
    677607
    678608END SUBROUTINE evolve_ice_table
  • trunk/LMDZ.COMMON/libf/evolution/job.F90

    r4137 r4138  
    1 MODULE job_id_mod
     1MODULE job
    22
    3 !***********************************************************************
    4 ! DESCRIPTION:
    5 !    Retrieves the ID for a given job ID via SLURM or PBS/TORQUE.
    6 !***********************************************************************
     3!-----------------------------------------------------------------------
     4! NAME
     5!     job
     6!
     7! DESCRIPTION
     8!     Management of memory throughout the modules of the code.
     9!
     10! AUTHORS & DATE
     11!     JB Clement, 10/06/2024
     12!
     13! NOTES
     14!
     15!-----------------------------------------------------------------------
    716
     17! DEPENDENCIES
     18! ------------
     19use numerics, only: dp, di, k4
     20
     21! DECLARATION
     22! -----------
    823implicit none
    924
     25! PARAMETERS
     26! ----------
     27real(dp)            :: timelimit = 86400._dp ! Time limit for the job: 86400 s = 24 h by default
     28real(dp), parameter :: antetime  = 3600._dp  ! Anticipation time to prevent reaching the job time limit: 3600 s = 1 h by default
     29logical(k4)         :: timewall = .false.    ! Flag to enable the program self-termination before timeout
     30
     31contains
     32!+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     33
    1034!=======================================================================
    11 contains
    12 !=======================================================================
     35SUBROUTINE get_job_id(jobid)
     36!-----------------------------------------------------------------------
     37! NAME
     38!     get_job_id
     39!
     40! DESCRIPTION
     41!     Retrieves the ID for a given job ID via SLURM or PBS/TORQUE.
     42!
     43! AUTHORS & DATE
     44!     JB Clement, 10/06/2024
     45!
     46! NOTES
     47!
     48!-----------------------------------------------------------------------
    1349
    14 SUBROUTINE get_job_id(jobid)
     50! DEPENDENCIES
     51! ------------
     52use stoppage, only: stop_clean
    1553
     54! DECLARATION
     55! -----------
    1656implicit none
    1757
    18 !---- Arguments
     58! ARGUMENTS
     59! ---------
    1960character(256), intent(out) :: jobid
    2061
    21 !---- Variables
    22 integer        :: stat
     62! LOCAL VARIABLES
     63! ---------------
     64integer(di)    :: sts
    2365character(256) :: tmp
    2466
    25 !---- Code
     67! CODE
     68! ----
    2669! Try SLURM
    27 call get_environment_variable("SLURM_JOBID",tmp,status = stat)
    28 if (stat == 0 .and. len_trim(tmp) > 0) then
     70call get_environment_variable("SLURM_JOBID",tmp,status = sts)
     71if (sts == 0 .and. len_trim(tmp) > 0) then
    2972    jobid = trim(adjustl(tmp))
    3073    return
    3174endif
    32    
     75
    3376! Try PBS/TORQUE 
    34 call get_environment_variable("PBS_JOBID",tmp,status = stat)
    35 if (stat == 0 .and. len_trim(tmp) > 0) then
     77call get_environment_variable("PBS_JOBID",tmp,status = sts)
     78if (sts == 0 .and. len_trim(tmp) > 0) then
    3679    ! Extract only the part before the point in '12345.master.cluster' to get the numeric job ID
    3780    jobid = trim(adjustl(tmp(1:index(tmp,'.') - 1)))
    3881    return
    3982endif
    40    
    41 error stop 'Error: neither SLURM_JOB_ID nor PBS_JOBID found in environment!'
     83
     84call stop_clean(__FILE__,__LINE__,"neither SLURM_JOB_ID nor PBS_JOBID found in environment!",1)
    4285
    4386END SUBROUTINE get_job_id
     87!=======================================================================
    4488
    45 END MODULE job_id_mod
     89!=======================================================================
     90SUBROUTINE get_job_timelimit(jobid)
     91!-----------------------------------------------------------------------
     92! NAME
     93!     get_job_timelimit
     94!
     95! DESCRIPTION
     96!     Retrieves the time limit (in seconds) for a given job ID via SLURM
     97!     or PBS/TORQUE.
     98!
     99! AUTHORS & DATE
     100!     JB Clement, 10/06/2024
     101!
     102! NOTES
     103!
     104!-----------------------------------------------------------------------
     105
     106! DEPENDENCIES
     107! ------------
     108use stoppage, only: stop_clean
     109
     110! DECLARATION
     111! -----------
     112implicit none
     113
     114! ARGUMENTS
     115! ---------
     116character(*), intent(in) :: jobid
     117
     118! LOCAL VARIABLES
     119! ---------------
     120logical(k4)    :: num_str
     121character(256) :: chtimelimit ! Time limit for the job outputted by the SLURM or PBS/TORQUE command
     122integer(di)    :: i, ierr, funit, cstat, days, hours, minutes, seconds
     123character(1)   :: sep
     124
     125! CODE
     126! ----
     127! Check that the job ID is numeric
     128num_str = .true.
     129do i = 1,len_trim(jobid)
     130    if (jobid(i:i) < '0' .or. jobid(i:i) > '9') then
     131        num_str = .false.
     132        exit
     133    endif
     134enddo
     135if (.not. num_str) call stop_clean(__FILE__,__LINE__,"job ID must be numeric!",1)
     136
     137! Try SLURM (squeue)
     138call execute_command_line('squeue -j '//trim(adjustl(jobid))//' -h --Format TimeLimit > tmp_timelimit.txt',cmdstat = cstat)
     139if (cstat /= 0) then
     140    ! On failure, try PBS/TORQUE (qstat)
     141    call execute_command_line('qstat -f '//trim(adjustl(jobid))//' | grep "Walltime" | awk ''{print $3}'' > tmp_timelimit.txt',cmdstat = cstat)
     142    if (cstat > 0) then
     143        call stop_clean(__FILE__,__LINE__,'command execution failed!',1)
     144    else if (cstat < 0) then
     145        call stop_clean(__FILE__,__LINE__,'command execution not supported (neither SLURM nor PBS/TORQUE is installed)!',1)
     146    endif
     147endif
     148
     149! Read the output
     150open(newunit = funit,file = 'tmp_timelimit.txt',status = 'old',form = 'formatted',action = 'read',iostat = ierr)
     151if (ierr /= 0) call stop_clean(__FILE__,__LINE__,'error opening file "tmp_timelimit.txt"!',ierr)
     152read(funit,'(a)') chtimelimit
     153close(funit)
     154chtimelimit = trim(adjustl(chtimelimit))
     155
     156! Remove temporary file
     157call execute_command_line('rm tmp_timelimit.txt',cmdstat = cstat)
     158if (cstat > 0) then
     159    call stop_clean(__FILE__,__LINE__,'command execution failed!',1)
     160else if (cstat < 0) then
     161    call stop_clean(__FILE__,__LINE__,'command execution not supported!',1)
     162endif
     163
     164! Parse D-HH:MM:SS, HH:MM:SS or MM:SS
     165if (index(chtimelimit,'-') > 0) then ! Format "D-HH:MM:SS"
     166    read(chtimelimit,'(i1,a1,i2,a1,i2,a1,i2)') days, sep, hours, sep, minutes, sep, seconds
     167    timelimit = real(days,dp)*86400._dp + real(hours,dp)*3600._dp + real(minutes,dp)*60._dp + real(seconds,dp)
     168else if (index(chtimelimit,':') > 0 .and. len_trim(chtimelimit) > 5) then ! Format "HH:MM:SS"
     169    read(chtimelimit,'(i2,a1,i2,a1,i2)') hours, sep, minutes, sep, seconds
     170    timelimit = real(hours,dp)*3600._dp + real(minutes,dp)*60._dp + real(seconds,dp)
     171else ! Format "MM:SS"
     172    read(chtimelimit,'(i2,a1,i2)') minutes, sep, seconds
     173    timelimit = real(minutes,dp)*60._dp + real(seconds,dp)
     174endif
     175
     176timewall = .true.
     177
     178END SUBROUTINE get_job_timelimit
     179!=======================================================================
     180
     181END MODULE job
  • trunk/LMDZ.COMMON/libf/evolution/maths.F90

    r4110 r4138  
    301301integer(di)            :: i
    302302real(dp)               :: m
    303 real(dp), dimension(n) :: cp, dp
     303real(dp), dimension(n) :: c_p, d_p
    304304
    305305! CODE
     
    323323
    324324! Initialization
    325 cp(1) = c(1)/b(1)
    326 dp(1) = d(1)/b(1)
     325c_p(1) = c(1)/b(1)
     326d_p(1) = d(1)/b(1)
    327327
    328328! Forward sweep
    329329do i = 2,n - 1
    330     m = b(i) - a(i - 1)*cp(i - 1)
    331     cp(i) = c(i)/m
    332     dp(i) = (d(i) - a(i - 1)*dp(i - 1))/m
    333 end do
    334 m = b(n) - a(n - 1)*cp(n - 1)
    335 dp(n) = (d(n) - a(n - 1)*dp(n - 1))/m
     330    m = b(i) - a(i - 1)*c_p(i - 1)
     331    c_p(i) = c(i)/m
     332    d_p(i) = (d(i) - a(i - 1)*d_p(i - 1))/m
     333end do
     334m = b(n) - a(n - 1)*c_p(n - 1)
     335d_p(n) = (d(n) - a(n - 1)*d_p(n - 1))/m
    336336
    337337! Backward substitution
    338 x(n) = dp(n)
     338x(n) = d_p(n)
    339339do i = n - 1,1,-1
    340     x(i) = dp(i) - cp(i)*x(i + 1)
     340    x(i) = d_p(i) - c_p(i)*x(i + 1)
    341341end do
    342342
  • trunk/LMDZ.COMMON/libf/evolution/orbit.F90

    r4134 r4138  
    578578!-----------------------------------------------------------------------
    579579
    580 use evolution,        only: pem_ini_date
    581 use call_dayperi_mod, only: call_dayperi
    582 use stoppage,         only: stop_clean
    583 use display,          only: print_msg, LVL_NFO
    584 use utility,          only: real2str
     580use evolution, only: pem_ini_date
     581use stoppage,  only: stop_clean
     582use display,   only: print_msg, LVL_NFO
     583use utility,   only: real2str
    585584
    586585! DECLARATION
  • trunk/LMDZ.COMMON/libf/evolution/pem.F90

    r4134 r4138  
    1919! ------------
    2020! Common modules
    21 use job_timelimit_mod, only: timelimit, antetime, timewall
    2221use parse_args_mod,    only: parse_args
    23 ! PEM modules
     22
    2423use allocation,         only: ini_allocation, end_allocation
    2524use atmosphere,         only: ps_PCM, evolve_pressure, CO2cond_ps_PCM
     
    3130use geometry,           only: ngrid, nslope, nday, nsoil_PCM, nsoil, cell_area, total_surface, nlayer
    3231use glaciers,           only: h2oice_flow, co2ice_flow, flow_co2glaciers, flow_h2oglaciers
    33 use ice_table,          only: icetable_equilibrium, icetable_dynamic, icetable_depth, icetable_thickness, ice_porefilling, evolve_ice_table
     32use ice_table,          only: icetable_equilibrium, icetable_dynamic, evolve_ice_table
     33use job,                only: timelimit, antetime, timewall
    3434use layered_deposits,   only: layering, do_layering, del_layering, evolve_layering, ptrarray, layering2surfice, surfice2layering, print_layering
    3535use maths,              only: pi
     
    103103real(dp), dimension(:,:,:),   allocatable :: h2o_ads_reg              ! H2O adsorbed in the regolith [kg/m^2]
    104104real(dp), dimension(:,:,:),   allocatable :: co2_ads_reg              ! CO2 adsorbed in the regolith [kg/m^2]
     105real(dp), dimension(:,:),     allocatable :: icetable_depth           ! Depth of the ice table [m]
     106real(dp), dimension(:,:),     allocatable :: icetable_thickness       ! Thickness of the ice table [m]
     107real(dp), dimension(:,:,:),   allocatable :: ice_porefilling          ! Amount of porefilling [m^3/m^3]
    105108real(dp), dimension(:,:),     allocatable :: icetable_depth_old       ! Old depth of the ice table [m]
    106109real(dp), dimension(:),       allocatable :: delta_icetable ! Total mass of the H2O that has sublimated / condenses from the ice table [kg]
     
    191194! Read the "startevo.nc"
    192195allocate(h2o_ice(ngrid,nslope),co2_ice(ngrid,nslope))
     196allocate(icetable_depth(ngrid,nslope),icetable_thickness(ngrid,nslope),ice_porefilling(ngrid,nsoil,nslope))
    193197allocate(h2o_ads_reg(ngrid,nsoil,nslope),co2_ads_reg(ngrid,nsoil,nslope),delta_h2o_ads(ngrid),delta_co2_ads(ngrid))
    194198allocate(layerings_map(ngrid,nslope))
     199icetable_depth(:,:) = 0._dp
     200icetable_thickness(:,:) = 0._dp
     201ice_porefilling(:,:,:) = 0._dp
    195202delta_h2o_ads(:) = 0._dp
    196203delta_co2_ads(:) = 0._dp
     
    485492deallocate(d_h2oice,d_co2ice,d_co2ice_ini)
    486493deallocate(delta_h2o_ads,delta_co2_ads,delta_icetable,icetable_depth_old)
     494deallocate(icetable_depth,icetable_thickness,ice_porefilling)
    487495call end_allocation()
    488496
  • trunk/LMDZ.COMMON/libf/evolution/soil_temp.F90

    r4135 r4138  
    179179! -----------
    180180implicit none
    181 
    182 #include "dimensions.h"
    183181
    184182! ARGUMENTS
     
    297295! -----------
    298296implicit none
    299 
    300 #include "dimensions.h"
    301297
    302298! ARGUMENTS
  • trunk/LMDZ.COMMON/libf/evolution/stoppage.F90

    r4110 r4138  
    5555implicit none
    5656
    57 #include "iniprint.h"
    58 
    5957! ARGUMENTS
    6058! ---------
  • trunk/LMDZ.COMMON/libf/evolution/xios_data.F90

    r4136 r4138  
    194194            end do
    195195        end do
    196         ! Keep deep layers consistent with PCM bottom layer when nsoil > nsoil_PCM.
    197         h2o_soildensity_avg(:,nsoil_PCM + 1:nsoil,islope) = h2o_soildensity_avg(:,nsoil_PCM,islope)
     196        do isoil = nsoil_PCM + 1,nsoil
     197            h2o_soildensity_avg(:,isoil,islope) = h2o_soildensity_avg(:,nsoil_PCM,islope) ! Explicit initialization because dimension with size nsoil > nsoil_PCM
     198        end do
    198199    end do
    199200    h2o_soildensity_avg(:,:,:) = h2o_soildensity_avg(:,:,:)/real(nday,dp)
  • trunk/LMDZ.COMMON/libf/misc/parse_args_mod.F90

    r4003 r4138  
    1414use pgrm_version_mod,  only: print_pgrm_version
    1515#endif
    16 use job_id_mod,        only: get_job_id
    17 use job_timelimit_mod, only: get_job_timelimit
     16use job,               only: get_job_id, get_job_timelimit
    1817
    1918implicit none
Note: See TracChangeset for help on using the changeset viewer.