Ignore:
Timestamp:
Jul 7, 2025, 2:46:43 PM (7 weeks 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/makelmdz_fcm

    r3830 r3836  
    603603
    604604# Path and name of the generated file
    605 info_file="$LIBFGCM/misc/version_info.F90"
    606 
    607 # Path and name of the file containing the difference result
    608 res_file="pgrm_version_details.txt"
     605version_F90file="$LIBFGCM/misc/pgrm_version.F90"
     606
     607# Path and name of the file containing the compilation and version details
     608default_out_file="pgrm_version_details.txt"
    609609
    610610# Get the current date
     
    653653
    654654# Generate the Fortran subroutine
    655 cat << EOF > "$info_file"
     655cat << EOF > "$version_F90file"
     656MODULE pgrm_version_mod
     657
    656658!***********************************************************************
    657659! File generated automatically at compilation
    658660!
    659661! DESCRIPTION:
    660 !    The subroutine 'print_version_info' prints compilation details, the
    661 !    version control information (SVN or Git), the status and the diff
    662 !    result if applicable.
     662!    The subroutine 'print_pgrm_version' prints compilation details, the version
     663!    control information (SVN or Git), the status and the diff result if applicable.
    663664!
    664665! PARAMETERS:
     
    666667!
    667668! USAGE:
    668 !    Put the argument 'version' as an option when executing the code to
    669 !    display compilation and version details. It is useful for tracking
    670 !    code builds through the executable file.
     669!    Use the command-line option "--version [file]" when running your program:
     670!       ./myprogram --version [file]
     671!    This will write compilation and version details into the specified [file].
     672!    If [file] is omitted, the default name "pgrm_version_details.txt" will be used.
     673!    This feature helps track code builds and their exact compilation context
     674!    directly from the executable.
    671675!***********************************************************************
    672676
    673 MODULE version_info_mod
     677implicit none
     678
     679character(*), parameter :: default_out_file = "${default_out_file}"
    674680
    675681!=======================================================================
     
    677683!=======================================================================
    678684
    679 SUBROUTINE print_version_info()
    680 
    681 integer, parameter :: io_unit = 10
    682 
    683 open(io_unit, file = '${res_file}',status = 'replace',action = 'write')
    684 
    685 write(*,'(a)') '-> Writing compilation details to the file "${res_file}".'
     685SUBROUTINE print_pgrm_version(user_out_file)
     686
     687!---- Arguments
     688character(*), optional, intent(in) :: user_out_file
     689
     690!---- Variables
     691integer, parameter        :: io_unit = 10
     692character(:), allocatable :: out_file
     693
     694!---- Code
     695if (present(user_out_file)) then
     696    out_file = trim(adjustl(user_out_file))
     697else
     698    out_file = trim(adjustl(default_out_file))
     699endif
     700
     701open(io_unit,file = out_file,status = 'replace',action = 'write')
     702
     703write(*,*)
     704write(*,'(a)') '-> Writing compilation details to the file "'//out_file//'".'
    686705write(io_unit,'(a)') '========================= COMPILATION DETAILS =========================='
    687 write(io_unit,'(a)') '-> Date: ${current_date}'
     706write(io_unit,'(a)') '-> Date   : ${current_date}'
    688707write(io_unit,'(a)') '-> Command: ${compilation_command}'
    689708write(io_unit,*)
     
    691710
    692711if [ -n "$vcs_info" ]; then
    693     echo "write(*,'(a)') '-> Writing information result to the file \"${res_file}\".'" >> "$info_file"
    694     echo "write(io_unit,'(a)') '===================== VERSION CONTROL INFORMATION ======================'" >> "$info_file"
     712    echo "write(*,'(a)') '-> Writing information result to the file \"'//out_file//'\".'" >> "$version_F90file"
     713    echo "write(io_unit,'(a)') '===================== VERSION CONTROL INFORMATION ======================'" >> "$version_F90file"
    695714    while IFS= read -r line; do
    696         echo "write(io_unit,'(a)') '${line}'" >> "$info_file"
     715        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
    697716    done <<< "$(echo -e "$vcs_info")"
    698717else
    699     echo "write(io_unit,'(a)') '====================== NO VERSION CONTROL SYSTEM ======================='" >> "$info_file"
     718    echo "write(io_unit,'(a)') '====================== NO VERSION CONTROL SYSTEM ======================='" >> "$version_F90file"
    700719fi
    701720
    702721if [ -n "$vcs_stat" ]; then
    703     echo "write(*,'(a)') '-> Writing status result to the file \"${res_file}\".'" >> "$info_file"
    704     echo "write(io_unit,*)" >> "$info_file"
    705     echo "write(io_unit,'(a)') '======================== VERSION CONTROL STATUS ========================'" >> "$info_file"
     722    echo "write(*,'(a)') '-> Writing status result to the file \"'//out_file//'\".'" >> "$version_F90file"
     723    echo "write(io_unit,*)" >> "$version_F90file"
     724    echo "write(io_unit,'(a)') '======================== VERSION CONTROL STATUS ========================'" >> "$version_F90file"
    706725    while IFS= read -r line; do
    707         echo "write(io_unit,'(a)') '${line}'" >> "$info_file"
     726        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
    708727    done <<< "$(echo -e "$vcs_stat")"
    709728fi
    710729
    711730if [ -n "$vcs_diff" ]; then
    712     echo "write(*,'(a)') '-> Writing diff result to the file \"${res_file}\".'" >> "$info_file"
    713     echo "write(io_unit,*)" >> "$info_file"
    714     echo "write(io_unit,'(a)') '========================= VERSION CONTROL DIFF ========================='" >> "$info_file"
     731    echo "write(*,'(a)') '-> Writing diff result to the file \"'//out_file//'\".'" >> "$version_F90file"
     732    echo "write(io_unit,*)" >> "$version_F90file"
     733    echo "write(io_unit,'(a)') '========================= VERSION CONTROL DIFF ========================='" >> "$version_F90file"
    715734    while IFS= read -r line; do
    716         echo "write(io_unit,'(a)') '${line}'" >> "$info_file"
     735        echo "write(io_unit,'(a)') '${line}'" >> "$version_F90file"
    717736    done <<< "$(echo -e "$vcs_diff")"
    718737fi
    719738
    720 cat << EOF >> "$info_file"
     739cat << EOF >> "$version_F90file"
    721740write(io_unit,'(a)') '========================================================================'
     741write(*,*)
    722742
    723743close(io_unit)
    724744
    725 END SUBROUTINE print_version_info
    726 
    727 END MODULE version_info_mod
     745END SUBROUTINE print_pgrm_version
     746
     747END MODULE pgrm_version_mod
    728748EOF
    729749
    730750# Termination message
    731 echo "'$info_file' has been generated successfully."
     751echo "'$version_F90file' has been generated successfully."
    732752
    733753
Note: See TracChangeset for help on using the changeset viewer.