Index: trunk/LMDZ.COMMON/libf/evolution/pem.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3821)
+++ trunk/LMDZ.COMMON/libf/evolution/pem.F90	(revision 3836)
@@ -73,5 +73,6 @@
                                       print_layering
 use dyn_ss_ice_m_mod,           only: dyn_ss_ice_m
-use version_info_mod,           only: print_version_info
+use parse_args_mod,             only: parse_args
+use job_timelimit_mod,          only: timelimit, antetime, timewall
 use paleoclimate_mod,           only: h2o_ice_depth, zdqsdif_ssi_tot
 
@@ -241,13 +242,6 @@
 real                  :: n_myear         ! Maximum number of Martian years of the chained simulations
 real                  :: timestep        ! Timestep [s]
-character(100)        :: arg             ! To read command-line arguments program was invoked
-logical               :: timewall        ! Flag to use the time limit stopping criterion in case of a PEM job
 integer(kind = 8)     :: cr              ! Number of clock ticks per second (count rate)
 integer(kind = 8)     :: c1, c2          ! Counts of processor clock
-character(100)        :: chtimelimit     ! Time limit for the PEM job outputted by the SLURM command
-real                  :: timelimit       ! Time limit for the PEM job in seconds
-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)
-integer               :: cstat, days, hours, minutes, seconds
-character(1)          :: sep
 character(8)          :: date
 character(10)         :: time
@@ -313,60 +307,5 @@
 call system_clock(count_rate = cr)
 call system_clock(c1)
-timewall = .true.
-timelimit = 86400 ! 86400 seconds = 24 h by default
-if (command_argument_count() > 0) then ! Get the number of command-line arguments
-    call get_command_argument(1,arg) ! Read the argument given to the program
-    num_str = .true.
-    do i = 1,len_trim(arg)
-        if (arg(i:i) < '0' .or. arg(i:i) > '9') then
-            num_str = .false.
-            exit
-        endif
-    enddo
-
-    if (num_str) then ! This is a numeric sting so we considerer this is the job id
-           ! Execute the system command
-            call execute_command_line('squeue -j '//trim(adjustl(arg))//' -h --Format TimeLimit > tmp_cmdout.txt',cmdstat = cstat)
-            if (cstat /= 0) then
-                call execute_command_line('qstat -f '//trim(adjustl(arg))//' | grep "Walltime" | awk ''{print $3}'' > tmp_cmdout.txt',cmdstat = cstat)
-                if (cstat > 0) then
-                    error stop 'pem: command execution failed!'
-                else if (cstat < 0) then
-                    error stop 'pem: command execution not supported (neither SLURM nor PBS/TORQUE is installed)!'
-                endif
-            endif
-            ! Read the output
-            open(1,file = 'tmp_cmdout.txt',status = 'old')
-            read(1,'(a)') chtimelimit
-            close(1)
-            chtimelimit = trim(adjustl(chtimelimit))
-            call execute_command_line('rm tmp_cmdout.txt',cmdstat = cstat)
-            if (cstat > 0) then
-                error stop 'pem: command execution failed!'
-            else if (cstat < 0) then
-                error stop 'pem: command execution not supported!'
-            endif
-            if (index(chtimelimit,'-') > 0) then ! 'chtimelimit' format is "D-HH:MM:SS"
-                read(chtimelimit,'(i1,a1,i2,a1,i2,a1,i2)') days, sep, hours, sep, minutes, sep, seconds
-                timelimit = days*86400 + hours*3600 + minutes*60 + seconds
-            else if (index(chtimelimit,':') > 0 .and. len_trim(chtimelimit) > 5) then ! 'chtimelimit' format is "HH:MM:SS"
-                read(chtimelimit,'(i2,a1,i2,a1,i2)') hours, sep, minutes, sep, seconds
-                timelimit = hours*3600 + minutes*60 + seconds
-            else ! 'chtimelimit' format is "MM:SS"
-                read(chtimelimit,'(i2,a1,i2)') minutes, sep, seconds
-                timelimit = minutes*60 + seconds
-            endif
-    else ! Arg is not a numeric string
-        select case (trim(adjustl(arg)))
-            case('version') ! Handle command‐line argument "version"
-                call print_version_info()
-                stop
-            case default
-                error stop "The argument given to the program is unknown!"
-        end select
-    endif
-else
-    timewall = .false.
-endif
+call parse_args()
 
 ! Some user info
Index: trunk/LMDZ.COMMON/libf/evolution/reshape_XIOS_output.F90
===================================================================
--- trunk/LMDZ.COMMON/libf/evolution/reshape_XIOS_output.F90	(revision 3821)
+++ trunk/LMDZ.COMMON/libf/evolution/reshape_XIOS_output.F90	(revision 3836)
@@ -11,5 +11,5 @@
 
 use netcdf
-use version_info_mod, only: print_version_info
+use parse_args_mod, only: parse_args
 
 implicit none
@@ -39,5 +39,5 @@
 integer                            :: i, j, k
 integer                            :: numDimsVar, numAttsVar
-character(100)                     :: varName, arg
+character(100)                     :: varName
 integer                            :: xtypeVar
 integer, allocatable, dimension(:) :: dimids_var_in
@@ -72,15 +72,6 @@
 
 ! CODE
-! Handle command‐line argument "version"
-if (command_argument_count() > 0) then ! Get the number of command-line arguments
-    call get_command_argument(1,arg) ! Read the argument given to the program
-    select case (trim(adjustl(arg)))
-        case('version')
-            call print_version_info()
-            stop
-        case default
-            error stop 'The argument given to the program is unknown!'
-    end select
-endif
+! Parse command-line options
+call parse_args()
 
 ! Main loop: two PCM years
