Ignore:
Timestamp:
Jul 7, 2025, 2:46:43 PM (21 hours ago)
Author:
jbclement
Message:

COMMON:
Rework related to the command-line parsing:

  • Replace ad-hoc argument parsing with a unified 'parse_args' subroutine, allowing easier extension to other programs and options across models;;
  • Use of '--version' (with ab optional output file) to print compilation/version details;
  • Addition of 'job_timelimit_mod' module to handle SLURM/PBS job time-limit via '--jobid' (currently only used in the PEM), allowing easier extension to other programs;
  • Replace manual SSO handling with 'parse_args' for the Mars start2archive;
  • Clean-up related legacy code in the programs supporting the version option.

JBC

File:
1 edited

Legend:

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

    r3809 r3836  
    7373                                      print_layering
    7474use dyn_ss_ice_m_mod,           only: dyn_ss_ice_m
    75 use version_info_mod,           only: print_version_info
     75use parse_args_mod,             only: parse_args
     76use job_timelimit_mod,          only: timelimit, antetime, timewall
    7677use paleoclimate_mod,           only: h2o_ice_depth, zdqsdif_ssi_tot
    7778
     
    241242real                  :: n_myear         ! Maximum number of Martian years of the chained simulations
    242243real                  :: timestep        ! Timestep [s]
    243 character(100)        :: arg             ! To read command-line arguments program was invoked
    244 logical               :: timewall        ! Flag to use the time limit stopping criterion in case of a PEM job
    245244integer(kind = 8)     :: cr              ! Number of clock ticks per second (count rate)
    246245integer(kind = 8)     :: c1, c2          ! Counts of processor clock
    247 character(100)        :: chtimelimit     ! Time limit for the PEM job outputted by the SLURM command
    248 real                  :: timelimit       ! Time limit for the PEM job in seconds
    249 real, parameter       :: antetime = 3600 ! Anticipation time to prevent reaching the job time limit: 3600 s by default (it should cover the computing time of the reshaping tool)
    250 integer               :: cstat, days, hours, minutes, seconds
    251 character(1)          :: sep
    252246character(8)          :: date
    253247character(10)         :: time
     
    313307call system_clock(count_rate = cr)
    314308call system_clock(c1)
    315 timewall = .true.
    316 timelimit = 86400 ! 86400 seconds = 24 h by default
    317 if (command_argument_count() > 0) then ! Get the number of command-line arguments
    318     call get_command_argument(1,arg) ! Read the argument given to the program
    319     num_str = .true.
    320     do i = 1,len_trim(arg)
    321         if (arg(i:i) < '0' .or. arg(i:i) > '9') then
    322             num_str = .false.
    323             exit
    324         endif
    325     enddo
    326 
    327     if (num_str) then ! This is a numeric sting so we considerer this is the job id
    328            ! Execute the system command
    329             call execute_command_line('squeue -j '//trim(adjustl(arg))//' -h --Format TimeLimit > tmp_cmdout.txt',cmdstat = cstat)
    330             if (cstat /= 0) then
    331                 call execute_command_line('qstat -f '//trim(adjustl(arg))//' | grep "Walltime" | awk ''{print $3}'' > tmp_cmdout.txt',cmdstat = cstat)
    332                 if (cstat > 0) then
    333                     error stop 'pem: command execution failed!'
    334                 else if (cstat < 0) then
    335                     error stop 'pem: command execution not supported (neither SLURM nor PBS/TORQUE is installed)!'
    336                 endif
    337             endif
    338             ! Read the output
    339             open(1,file = 'tmp_cmdout.txt',status = 'old')
    340             read(1,'(a)') chtimelimit
    341             close(1)
    342             chtimelimit = trim(adjustl(chtimelimit))
    343             call execute_command_line('rm tmp_cmdout.txt',cmdstat = cstat)
    344             if (cstat > 0) then
    345                 error stop 'pem: command execution failed!'
    346             else if (cstat < 0) then
    347                 error stop 'pem: command execution not supported!'
    348             endif
    349             if (index(chtimelimit,'-') > 0) then ! 'chtimelimit' format is "D-HH:MM:SS"
    350                 read(chtimelimit,'(i1,a1,i2,a1,i2,a1,i2)') days, sep, hours, sep, minutes, sep, seconds
    351                 timelimit = days*86400 + hours*3600 + minutes*60 + seconds
    352             else if (index(chtimelimit,':') > 0 .and. len_trim(chtimelimit) > 5) then ! 'chtimelimit' format is "HH:MM:SS"
    353                 read(chtimelimit,'(i2,a1,i2,a1,i2)') hours, sep, minutes, sep, seconds
    354                 timelimit = hours*3600 + minutes*60 + seconds
    355             else ! 'chtimelimit' format is "MM:SS"
    356                 read(chtimelimit,'(i2,a1,i2)') minutes, sep, seconds
    357                 timelimit = minutes*60 + seconds
    358             endif
    359     else ! Arg is not a numeric string
    360         select case (trim(adjustl(arg)))
    361             case('version') ! Handle command‐line argument "version"
    362                 call print_version_info()
    363                 stop
    364             case default
    365                 error stop "The argument given to the program is unknown!"
    366         end select
    367     endif
    368 else
    369     timewall = .false.
    370 endif
     309call parse_args()
    371310
    372311! Some user info
Note: See TracChangeset for help on using the changeset viewer.