Changeset 3574


Ignore:
Timestamp:
Jan 13, 2025, 4:52:20 PM (21 hours ago)
Author:
jbclement
Message:

COMMON:
The compilation generates a Fortran subroutine to track compilation and version (SVN or Git) details through the executable file. Put the argument 'version' as an option when executing the code to display these information and create a file "version_diff.txt" containing the diff result.
It can work with every program but it has been implemented only for: 'gcm', 'parallel gcm', 'pem', '1D Mars PCM', 'Mars newstart', 'Mars start2archive' and '1D Generic PCM'.
JBC

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/dyn3d/gcm.F90

    r3316 r3574  
    3030  USE temps_mod, ONLY: calend,start_time,annee_ref,day_ref, &
    3131                itau_dyn,itau_phy,day_ini,jD_ref,jH_ref,day_end
     32  use version_info_mod, only: print_version_info
    3233
    3334
     
    133134  character (len=20) :: modname
    134135  character (len=80) :: abort_message
     136  character(100)     :: arg ! To read command-line arguments
    135137  ! locales pour gestion du temps
    136138  INTEGER :: an, mois, jour
     
    142144!   Initialisations:
    143145!   ----------------
     146
     147  if (command_argument_count() > 0) then ! Get the number of command-line arguments
     148      call get_command_argument(1,arg) ! Read the argument given to the program
     149      select case (trim(adjustl(arg)))
     150          case('version')
     151              call print_version_info()
     152              stop
     153          case default
     154              error stop "The argument given to the program is unknown!"
     155      end select
     156  endif
    144157
    145158  abort_message = 'last timestep reached'
  • trunk/LMDZ.COMMON/libf/dyn3dpar/gcm.F

    r3316 r3574  
    2727     &                       ecritstart
    2828      use cpdet_mod, only: ini_cpdet
     29      use version_info_mod, only: print_version_info
    2930
    3031
     
    134135      character (len=20) :: modname
    135136      character (len=80) :: abort_message
     137      character(100)     :: arg ! To read command-line arguments
    136138! locales pour gestion du temps
    137139      INTEGER :: an, mois, jour
     
    156158c   Initialisations:
    157159c   ----------------
     160
     161      if (command_argument_count() > 0) then ! Get the number of command-line arguments
     162          call get_command_argument(1,arg) ! Read the argument given to the program
     163          select case (trim(adjustl(arg)))
     164              case('version')
     165                  call print_version_info()
     166                  stop
     167              case default
     168                  error stop 'The argument given to the program '
     169     &//'is unknown!'
     170          end select
     171      endif
    158172
    159173      abort_message = 'last timestep reached'
  • trunk/LMDZ.COMMON/libf/evolution/pem.F90

    r3571 r3574  
    238238real            :: n_myear         ! Maximum number of Martian years of the chained simulations
    239239real            :: timestep        ! Timestep [s]
    240 character(20)   :: job_id          ! Job id provided as argument passed on the command line when the program was invoked
     240character(100)  :: arg             ! To read command-line arguments program was invoked
    241241logical         :: timewall        ! Flag to use the time limit stopping criterion in case of a PEM job
    242242integer(kind=8) :: cr              ! Number of clock ticks per second (count rate)
     
    293293timewall = .true.
    294294timelimit = 86400 ! 86400 seconds = 24 h by default
    295 if (command_argument_count() > 0) then
    296     ! Read the job id passed as argument to the program
    297     call get_command_argument(1,job_id)
    298     ! Execute the system command
    299     call execute_command_line('squeue -j '//trim(job_id)//' -h --Format TimeLimit > tmp_cmdout.txt',cmdstat = cstat)
    300     if (cstat /= 0) then
    301         call execute_command_line('qstat -f '//trim(job_id)//' | grep "Walltime" | awk ''{print $3}'' > tmp_cmdout.txt',cmdstat = cstat)
    302         if (cstat > 0) then
    303             error stop 'pem: command execution failed!'
    304         else if (cstat < 0) then
    305             error stop 'pem: command execution not supported (neither SLURM nor PBS/TORQUE is installed)!'
    306         endif
    307     endif
    308     ! Read the output
    309     open(1,file = 'tmp_cmdout.txt',status = 'old')
    310     read(1,'(a)') chtimelimit
    311     close(1)
    312     chtimelimit = trim(chtimelimit)
    313     call execute_command_line('rm tmp_cmdout.txt',cmdstat = cstat)
    314     if (cstat > 0) then
    315         error stop 'pem: command execution failed!'
    316     else if (cstat < 0) then
    317         error stop 'pem: command execution not supported!'
    318     endif
    319     if (index(chtimelimit,'-') > 0) then ! 'chtimelimit' format is "D-HH:MM:SS"
    320         read(chtimelimit,'(i1,a1,i2,a1,i2,a1,i2)') days, sep, hours, sep, minutes, sep, seconds
    321         timelimit = days*86400 + hours*3600 + minutes*60 + seconds
    322     else if (index(chtimelimit,':') > 0 .and. len_trim(chtimelimit) > 5) then ! 'chtimelimit' format is "HH:MM:SS"
    323         read(chtimelimit,'(i2,a1,i2,a1,i2)') hours, sep, minutes, sep, seconds
    324         timelimit = hours*3600 + minutes*60 + seconds
    325     else ! 'chtimelimit' format is "MM:SS"
    326         read(chtimelimit,'(i2,a1,i2)') minutes, sep, seconds
    327         timelimit = minutes*60 + seconds
    328     endif
    329 else
    330     timewall = .false.
     295timewall = .false.
     296if (command_argument_count() > 0) then ! Get the number of command-line arguments
     297    call get_command_argument(1,arg) ! Read the argument given to the program
     298    select case (trim(adjustl(arg)))
     299        case('version')
     300            call print_version_info()
     301            stop
     302        case default ! This is the job id
     303           ! Execute the system command
     304            call execute_command_line('squeue -j '//trim(adjustl(arg))//' -h --Format TimeLimit > tmp_cmdout.txt',cmdstat = cstat)
     305            if (cstat /= 0) then
     306                call execute_command_line('qstat -f '//trim(adjustl(arg))//' | grep "Walltime" | awk ''{print $3}'' > tmp_cmdout.txt',cmdstat = cstat)
     307                if (cstat > 0) then
     308                    error stop 'pem: command execution failed!'
     309                else if (cstat < 0) then
     310                    error stop 'pem: command execution not supported (neither SLURM nor PBS/TORQUE is installed)!'
     311                endif
     312            endif
     313            ! Read the output
     314            open(1,file = 'tmp_cmdout.txt',status = 'old')
     315            read(1,'(a)') chtimelimit
     316            close(1)
     317            chtimelimit = trim(adjustl(chtimelimit))
     318            call execute_command_line('rm tmp_cmdout.txt',cmdstat = cstat)
     319            if (cstat > 0) then
     320                error stop 'pem: command execution failed!'
     321            else if (cstat < 0) then
     322                error stop 'pem: command execution not supported!'
     323            endif
     324            if (index(chtimelimit,'-') > 0) then ! 'chtimelimit' format is "D-HH:MM:SS"
     325                read(chtimelimit,'(i1,a1,i2,a1,i2,a1,i2)') days, sep, hours, sep, minutes, sep, seconds
     326                timelimit = days*86400 + hours*3600 + minutes*60 + seconds
     327            else if (index(chtimelimit,':') > 0 .and. len_trim(chtimelimit) > 5) then ! 'chtimelimit' format is "HH:MM:SS"
     328                read(chtimelimit,'(i2,a1,i2,a1,i2)') hours, sep, minutes, sep, seconds
     329                timelimit = hours*3600 + minutes*60 + seconds
     330            else ! 'chtimelimit' format is "MM:SS"
     331                read(chtimelimit,'(i2,a1,i2)') minutes, sep, seconds
     332                timelimit = minutes*60 + seconds
     333            endif
     334    end select
    331335endif
    332336
  • trunk/LMDZ.COMMON/makelmdz_fcm

    r3499 r3574  
    7878########################################################################
    7979
     80# Get the compilation command
     81compilation_command="$(basename $0) $@"
     82
     83# Parse arguments and capture options
    8084while (($# > 0))
    8185  do
     
    120124 exec                      : executable to build
    121125fin
    122           exit;;
     126      exit;;
    123127
    124128      "-d")
    125           dim=$2 ; shift ; shift ;;
     129      dim=$2 ; shift ; shift ;;
    126130
    127131      "-p")
    128           physique="$2" ;  shift ; shift ;;
     132      physique="$2" ;  shift ; shift ;;
    129133
    130134      "-s")
    131           scatterers=$2 ; shift ; shift ;;
     135      scatterers=$2 ; shift ; shift ;;
    132136
    133137      "-b")
    134           bands=$2 ; shift ; shift ;;
     138      bands=$2 ; shift ; shift ;;
    135139
    136140      "-g")
    137           grille="$2" ; shift ; shift ;;
     141      grille="$2" ; shift ; shift ;;
    138142
    139143      "-c")
    140           couple="$2" ; shift ; shift ;;
     144      couple="$2" ; shift ; shift ;;
    141145
    142146      "-prod")
    143           compil_mod="prod" ; shift ;;
     147      compil_mod="prod" ; shift ;;
    144148
    145149      "-dev")
    146           compil_mod="dev" ; shift ;;
     150      compil_mod="dev" ; shift ;;
    147151
    148152      "-debug")
    149           compil_mod="debug" ; shift ;;
     153      compil_mod="debug" ; shift ;;
    150154
    151155      "-io")
    152           io="$2" ; shift ; shift ;;
     156      io="$2" ; shift ; shift ;;
    153157
    154158      "-v")
    155           veget="$2" ; shift ; shift ;;
     159      veget="$2" ; shift ; shift ;;
    156160
    157161      "-sisvat")
    158           sisvat="$2" ; shift ; shift ;;
     162      sisvat="$2" ; shift ; shift ;;
    159163
    160164      "-rrtm")
    161           rrtm="$2" ; shift ; shift ;;
     165      rrtm="$2" ; shift ; shift ;;
    162166
    163167      "-dust")
    164           dust="$2" ; shift ; shift ;;
     168      dust="$2" ; shift ; shift ;;
    165169
    166170      "-strataer")
    167           strataer="$2" ; shift ; shift ;;
     171      strataer="$2" ; shift ; shift ;;
    168172
    169173      "-chimie")
    170           chimie="$2" ; shift ; shift ;;
     174      chimie="$2" ; shift ; shift ;;
    171175
    172176      "-parallel")
    173           parallel="$2" ; shift ; shift ;;
     177      parallel="$2" ; shift ; shift ;;
    174178
    175179      "-include")
    176           INCLUDE_DIR="$INCLUDE_DIR -I$2" ; shift ; shift ;;
     180      INCLUDE_DIR="$INCLUDE_DIR -I$2" ; shift ; shift ;;
    177181
    178182      "-cpp")
    179           CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
     183      CPP_KEY="$CPP_KEY $2" ; shift ; shift ;;
    180184
    181185      "-adjnt")
    182           echo "not operational ... work to be done here ";exit 1
    183           opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
    184           optim="$optim -Dadj" ; shift ;;
     186      echo "not operational ... work to be done here ";exit 1
     187      opt_dep="$opt_dep adjnt" ; adjnt="-ladjnt -ldyn3d "
     188      optim="$optim -Dadj" ; shift ;;
    185189
    186190      "-cosp")
     
    191195
    192196      "-filtre")
    193           filtre=$2 ; shift ; shift ;;
     197      filtre=$2 ; shift ; shift ;;
    194198
    195199      "-link")
    196           LIB="$LIB $2" ; shift ; shift ;;
     200      LIB="$LIB $2" ; shift ; shift ;;
    197201
    198202      "-fcm_path")
    199           fcm_path=$2 ; shift ; shift ;;
     203      fcm_path=$2 ; shift ; shift ;;
    200204
    201205      "-ext_src")
    202           EXT_SRC=$2 ; shift ; shift ;;
     206      EXT_SRC=$2 ; shift ; shift ;;
    203207
    204208      "-j")
    205           job=$2 ; shift ; shift ;;
     209      job=$2 ; shift ; shift ;;
    206210
    207211      "-full")
    208           full="-full" ; shift ;;
     212      full="-full" ; shift ;;
    209213
    210214      "-libphy")
    211           libphy="true" ; shift ;;
     215      libphy="true" ; shift ;;
    212216
    213217      "-arch")
    214           arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
     218      arch=$2 ; arch_defined="TRUE" ; shift ; shift ;;
    215219
    216220      "-arch_path")
    217           arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
     221      arch_path=$2 ; arch_path_defined="TRUE"; shift ; shift ;;
    218222
    219223      *)
    220           code="$1" ; shift ;;
     224      code="$1" ; shift ;;
    221225  esac
    222226done
     
    333337    if [[ "$couple" == "MPI1" ]]
    334338    then
    335         CPP_KEY="$CPP_KEY CPP_COUPLE"
    336         export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
    337         export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
    338         INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
    339         LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     339    CPP_KEY="$CPP_KEY CPP_COUPLE"
     340    export OASIS_INCDIR=$LMDGCM/../../prism/X64/build/lib/psmile.MPI1
     341    export OASIS_LIBDIR=$LMDGCM/../../prism/X64/lib
     342    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
     343    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
    340344    else
    341         CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
    342         INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
    343         LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
     345    CPP_KEY="$CPP_KEY CPP_COUPLE CPP_OMCT"
     346    INCLUDE_DIR="$INCLUDE_DIR -I${OASIS_INCDIR}"
     347    LIB="$LIB -L${OASIS_LIBDIR} ${OASIS_LIB}"
    344348    fi
    345349fi
     
    588592  fi
    589593fi
     594
     595
     596########################################################################
     597# Generation of a Fortran subroutine to track compilation and version
     598# details through the executable file
     599########################################################################
     600
     601# Path and name of the generated file
     602info_file="$LIBFGCM/misc/version_info.F90"
     603
     604# Path and name of the file containing the difference result
     605diff_file="version_diff.txt"
     606
     607# Get the current date
     608current_date=$(date)
     609
     610# Determine version control system (SVN, Git or none)
     611if command -v svn > /dev/null && svn info > /dev/null 2>&1; then
     612    vcs="svn"
     613    vcs_info=$(svn info $LMDGCM/..)
     614    vcs_diff=$(svn diff $LMDGCM/..)
     615elif command -v git > /dev/null && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
     616    vcs="git"
     617    vcs_info=$(git log -1 --pretty=format:"%H%n%an%n%ad%n%s" $LMDGCM/..)
     618    vcs_diff=$(git diff $LMDGCM/..)
     619else
     620    vcs="none"
     621fi
     622
     623# Function to escape the simple quotation sign
     624escape_signs() {
     625    echo "$1" | sed "s/'/''/g"
     626}
     627
     628# Generate the Fortran subroutine
     629cat << EOF > "$info_file"
     630!***********************************************************************
     631! File generated automatically at compilation
     632!
     633! DESCRIPTION:
     634!    The subroutine 'print_version_info' prints compilation details, the
     635!    version control information (SVN or Git) and the diff result if
     636!    applicable.
     637!
     638! PARAMETERS:
     639!    None.
     640!
     641! USAGE:
     642!    Put the argument 'version' as an option when executing the code to
     643!    display compilation and version details. It is useful for tracking
     644!    code builds through the executable file.
     645!***********************************************************************
     646
     647MODULE version_info_mod
     648
     649!=======================================================================
     650contains
     651!=======================================================================
     652
     653SUBROUTINE print_version_info()
     654
     655    write(*,*) '=== Compilation details ==='
     656    write(*,*) 'Date: ${current_date}'
     657    write(*,*) 'Command: ${compilation_command}'
     658    write(*,*)
     659EOF
     660
     661if [ "$vcs" == "svn" ]; then # SVN info
     662    echo "    write(*,*) '===== SVN Information ====='" >> "$info_file"
     663    while IFS= read -r line; do
     664        echo "    write(*,*) '${line//\"/\\\"}'" >> "$info_file"
     665    done <<< "$vcs_info"
     666    echo "    write(*,*)" >> "$info_file"
     667    echo "    write(*,*) '======== SVN Diff ========='" >> "$info_file"
     668    echo "    write(*,*) 'Writing SVN diff to file: ${diff_file}'" >> "$info_file"
     669    echo "    open(unit = 1,file = \"${diff_file}\",status = 'replace')" >> "$info_file"
     670    while IFS= read -r line; do
     671        escaped_line=$(escape_signs "$line")
     672        echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
     673    done <<< "$vcs_diff"
     674    echo "    close(1)" >> "$info_file"
     675
     676
     677elif [ "$vcs" == "git" ]; then # Git info
     678    echo "    write(*,*) '===== Git Information ====='" >> "$info_file"
     679    while IFS= read -r line; do
     680        echo "    write(*,*) \"${line//\"/\\\"}\"" >> "$info_file"
     681    done <<< "$vcs_info"
     682    echo "    write(*,*)" >> "$info_file"
     683    echo "    write(*,*) '======== Git Diff ========='" >> "$info_file"
     684    echo "    write(*,*) 'Writing Git diff to file: ${diff_file}'" >> "$info_file"
     685    while IFS= read -r line; do
     686        escaped_line=$(escape_signs "$line")
     687        echo "    write(1,*) '${escaped_line//\"/\\\"}'" >> "$info_file"
     688    done <<< "$vcs_diff"
     689    echo "    close(1)" >> "$info_file"
     690else # Non-versioned code
     691    echo "    write(*,*) 'No version control information available.'" >> "$info_file"
     692fi
     693    echo "    write(*,*) '==========================='" >> "$info_file"
     694
     695cat << EOF >> "$info_file"
     696
     697END SUBROUTINE print_version_info
     698
     699END MODULE version_info_mod
     700EOF
     701
     702# Termination message
     703echo "'$info_file' has been successfully generated."
    590704
    591705
  • trunk/LMDZ.GENERIC/libf/phystd/dyn1d/kcm1d.F90

    r3335 r3574  
    2222  use dimphy, only : init_dimphy
    2323  use gases_h, only: ngasmx
     24  use version_info_mod, only: print_version_info
    2425
    2526  implicit none
     
    109110  integer :: ios
    110111  integer :: k
     112
     113  character(100) :: arg ! To read command-line arguments
    111114 
    112115  ! --------------
    113116  ! Initialisation
    114117  ! --------------
     118  if (command_argument_count() > 0) then ! Get the number of command-line arguments
     119      call get_command_argument(1,arg) ! Read the argument given to the program
     120      select case (trim(adjustl(arg)))
     121          case('version')
     122              call print_version_info()
     123              stop
     124          case default
     125              error stop 'The argument given to the program is unknown!'
     126      end select
     127  endif
    115128
    116129  pi=2.E+0*asin(1.E+0)
  • trunk/LMDZ.GENERIC/libf/phystd/dyn1d/rcm1d.F

    r3562 r3574  
    4343     &                  nf90_strerror,NF90_INQ_VARID, NF90_GET_VAR,
    4444     &                  NF90_CLOSE
     45      use version_info_mod, only: print_version_info
     46
    4547      implicit none
    4648
     
    164166      LOGICAL :: moderntracdef=.false. ! JVO, YJ : modern traceur.def
    165167
     168      character(100) :: arg ! To read command-line arguments
     169
    166170c=======================================================================
    167171c INITIALISATION
    168172c=======================================================================
     173      if (command_argument_count() > 0) then ! Get the number of command-line arguments
     174          call get_command_argument(1,arg) ! Read the argument given to the program
     175          select case (trim(adjustl(arg)))
     176              case('version')
     177                  call print_version_info()
     178                  stop
     179              case default
     180                  error stop 'The argument given to the program is '
     181     &//'unknown!'
     182          end select
     183      endif
     184
    169185! check if 'rcm1d.def' file is around
    170186      open(90,file='rcm1d.def',status='old',form='formatted',
  • trunk/LMDZ.MARS/libf/dynphy_lonlat/phymars/newstart.F

    r3336 r3574  
    6161     &             ini_paleoclimate_h, end_paleoclimate_h
    6262      use subslope_mola_mod, ONLY: subslope_mola
     63      use version_info_mod, only: print_version_info
    6364     
    6465      implicit none
     
    8182c et autres:
    8283c----------
     84      character(100) :: arg ! To read command-line arguments
    8385
    8486c Variables pour les lectures NetCDF des fichiers "start_archive"
     
    211213
    212214
     215
     216if (command_argument_count() > 0) then ! Get the number of command-line arguments
     217    call get_command_argument(1,arg) ! Read the argument given to the program
     218    select case (trim(adjustl(arg)))
     219        case('version')
     220            call print_version_info()
     221            stop
     222        case default
     223            error stop 'The argument given to the program is unknown!'
     224    end select
     225endif
    213226
    214227c sortie visu pour les champs dynamiques
  • trunk/LMDZ.MARS/libf/dynphy_lonlat/phymars/start2archive.F

    r3491 r3574  
    4141      USE surfdat_h, ONLY: phisfi, albedodat, z0, z0_default,
    4242     &    zmea, zstd, zsig, zgam, zthe, hmons, summit, base
     43      use version_info_mod, only: print_version_info
     44
    4345      implicit none
    4446
     
    141143      integer :: nq,numvanle
    142144      character(len=30) :: txt ! to store some text
     145      character(100) :: arg ! To read command-line arguments
    143146
    144147c Netcdf
     
    150153C here we assume and check that if there is an argument #1 then
    151154C it should be --add-sso to signal adding SSO fileds to start_archive.nc
    152 
    153155      CALL get_command_argument(1,txt,j,ierr)
    154156      ! will return ierr==0 if there is an argument #1 to command line
     
    158160          add_sso_fields=.true.
    159161          write(*,*) "SSO fields will be included in start_archive"
     162        ELSE IF (trim(txt) == 'version') then
     163            call print_version_info()
     164            stop
    160165        ELSE
    161166          write(*,*) "start2archive error: unexpected command line "//
  • trunk/LMDZ.MARS/libf/phymars/dyn1d/testphys1d.F90

    r3400 r3574  
    2121use mod_const_mpi,       only: init_const_mpi
    2222use parallel_lmdz,       only: init_parallel
     23use version_info_mod,    only: print_version_info
    2324
    2425implicit none
     
    7778real, dimension(:,:,:), allocatable :: q             ! tracer mixing ratio (e.g. kg/kg)
    7879real, dimension(1)                  :: wstar = 0.    ! Thermals vertical velocity
     80character(100)                      :: arg           ! To read command-line arguments
    7981
    8082! Physical and dynamical tendencies (e.g. m.s-2, K/s, Pa/s)
     
    100102! INITIALISATION
    101103!=======================================================================
     104if (command_argument_count() > 0) then ! Get the number of command-line arguments
     105    call get_command_argument(1,arg) ! Read the argument given to the program
     106    select case (trim(adjustl(arg)))
     107        case('version')
     108            call print_version_info()
     109            stop
     110        case default
     111            error stop 'The argument given to the program is unknown!'
     112    end select
     113endif
     114
    102115#ifdef CPP_XIOS
    103116    call init_const_mpi
Note: See TracChangeset for help on using the changeset viewer.