| 1 | #!/bin/bash |
|---|
| 2 | ######################################################################## |
|---|
| 3 | #### Launching script for a chained simulation of PEM and PCM runs #### |
|---|
| 4 | ######################################################################## |
|---|
| 5 | # This script can take an argument: |
|---|
| 6 | # - If there is no argument, then the script initiates a PEM simulation from scratch. |
|---|
| 7 | # - If the argument is 're', then the script relaunches an existing PEM simulation. |
|---|
| 8 | # It will ask for parameters to know the starting point that you want to. |
|---|
| 9 | ######################################################################## |
|---|
| 10 | set -e |
|---|
| 11 | trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | ######################################################################## |
|---|
| 15 | # Modify here the parameters for the simulation |
|---|
| 16 | ############################################### |
|---|
| 17 | # Set the number of years to be simulated, either Martian or Earth years: |
|---|
| 18 | n_mars_years=100. |
|---|
| 19 | #n_earth_years=300. |
|---|
| 20 | |
|---|
| 21 | # Set the number of initial PCM runs (>= 2): |
|---|
| 22 | nPCM_ini=3 |
|---|
| 23 | |
|---|
| 24 | # Set the number of PCM runs between each PEM run (>= 2): |
|---|
| 25 | nPCM=2 |
|---|
| 26 | |
|---|
| 27 | # Set the counting method for the number of years to be simulated (0 = "only PEM runs count"; any other values = "PCM runs are taken into account"): |
|---|
| 28 | counting=0 |
|---|
| 29 | |
|---|
| 30 | # Set the launching mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on a supercomputer: |
|---|
| 31 | mode=1 |
|---|
| 32 | ######################################################################## |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | dir=`pwd` |
|---|
| 36 | machine=`hostname` |
|---|
| 37 | user=`whoami` |
|---|
| 38 | if [ ! -f "lib_launchPEM.sh" ]; then |
|---|
| 39 | echo "Error: file \"lib_launchPEM.sh\" does not exist in $dir!" |
|---|
| 40 | echo "It can be found in the PEM deftank." |
|---|
| 41 | exit 1 |
|---|
| 42 | fi |
|---|
| 43 | |
|---|
| 44 | source lib_launchPEM.sh |
|---|
| 45 | export counting mode |
|---|
| 46 | |
|---|
| 47 | if [ $# -eq 0 ]; then |
|---|
| 48 | # Starting from scratch |
|---|
| 49 | echo "The launching script is starting!" |
|---|
| 50 | echo "The output file is \"log_launchPEM.txt\"." |
|---|
| 51 | exec > log_launchPEM.txt 2>&1 |
|---|
| 52 | echo "Beginning of the launching script for the PEM simulation." |
|---|
| 53 | date |
|---|
| 54 | checklaunch |
|---|
| 55 | initlaunch |
|---|
| 56 | cyclelaunch $mode $counting $nPCM_ini |
|---|
| 57 | |
|---|
| 58 | else |
|---|
| 59 | # Starting a new cycle |
|---|
| 60 | if [ $1 = "new" ]; then |
|---|
| 61 | exec >> log_launchPEM.txt 2>&1 |
|---|
| 62 | echo |
|---|
| 63 | echo "This is a new cycle for the PEM simulation." |
|---|
| 64 | date |
|---|
| 65 | if [ $mode -ne 0 ]; then |
|---|
| 66 | job_scheduler |
|---|
| 67 | fi |
|---|
| 68 | read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt |
|---|
| 69 | cyclelaunch $mode $counting $nPCM |
|---|
| 70 | |
|---|
| 71 | # Starting a relaunch |
|---|
| 72 | elif [ $1 = "re" ]; then |
|---|
| 73 | if [ ! -f "info_PEM.txt" ]; then |
|---|
| 74 | echo "Error: file \"info_PEM.txt\" does not exist in $dir!" |
|---|
| 75 | echo "It is necessary to relaunch a PEM simulation." |
|---|
| 76 | errlaunch |
|---|
| 77 | fi |
|---|
| 78 | echo "The relaunch is initialized with a specific previous successful run." |
|---|
| 79 | while true; do |
|---|
| 80 | echo "Do you want to relaunch from a 'PCM' or 'PEM' run?" |
|---|
| 81 | read relaunch |
|---|
| 82 | if [ $relaunch = "PCM" ] || [ $relaunch = "PEM" ]; then |
|---|
| 83 | break |
|---|
| 84 | else |
|---|
| 85 | echo "Invalid input. Please enter 'PCM' or 'PEM'." |
|---|
| 86 | fi |
|---|
| 87 | done |
|---|
| 88 | read i_myear n_myear_old convert_years iPCM iPEM nPCM_old nPCM_ini_old < info_PEM.txt |
|---|
| 89 | while true; do |
|---|
| 90 | if [ $relaunch = "PCM" ]; then |
|---|
| 91 | echo "What is the number of the PCM run?" |
|---|
| 92 | echo "It should be between 1 and $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 ))." |
|---|
| 93 | read irelaunch |
|---|
| 94 | if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 )) ]; then |
|---|
| 95 | break |
|---|
| 96 | else |
|---|
| 97 | echo "Invalid input. Please enter a valid PCM run number." |
|---|
| 98 | fi |
|---|
| 99 | else |
|---|
| 100 | echo "What is the number of the PEM run?" |
|---|
| 101 | echo "It should be between 1 and $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 ))." |
|---|
| 102 | read irelaunch |
|---|
| 103 | if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 )) ]; then |
|---|
| 104 | break |
|---|
| 105 | else |
|---|
| 106 | echo "Invalid input. Please enter a valid PEM run number." |
|---|
| 107 | fi |
|---|
| 108 | fi |
|---|
| 109 | done |
|---|
| 110 | exec >> log_launchPEM.txt 2>&1 |
|---|
| 111 | echo |
|---|
| 112 | echo "This is a relaunch for the PEM simulation from the run $relaunch$irelaunch." |
|---|
| 113 | date |
|---|
| 114 | checklaunch |
|---|
| 115 | convertyears |
|---|
| 116 | if [ $nPCM_ini -ne $nPCM_ini_old ]; then |
|---|
| 117 | echo "The number of initial PCM runs has been modified from $nPCM_ini_old to $nPCM_ini." |
|---|
| 118 | fi |
|---|
| 119 | if [ $nPCM -ne $nPCM_old ]; then |
|---|
| 120 | echo "The number of PCM runs between each PEM run has been modified from $nPCM_old to $nPCM." |
|---|
| 121 | fi |
|---|
| 122 | if [ "$(echo "$n_myear != $n_myear_old" | bc)" -eq 1 ]; then |
|---|
| 123 | echo "The number of initial PCM runs has been modified from $n_myear_old to $n_myear." |
|---|
| 124 | fi |
|---|
| 125 | sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt |
|---|
| 126 | if [ -f "kill_launchPEM.sh" ]; then |
|---|
| 127 | ./kill_launchPEM.sh |
|---|
| 128 | fi |
|---|
| 129 | if [ $relaunch = "PCM" ]; then |
|---|
| 130 | relaunchPCM $mode $counting |
|---|
| 131 | else |
|---|
| 132 | relaunchPEM $mode $counting |
|---|
| 133 | fi |
|---|
| 134 | |
|---|
| 135 | # Continuing the PEM run |
|---|
| 136 | elif [ $1 = "cont" ]; then |
|---|
| 137 | exec >> log_launchPEM.txt 2>&1 |
|---|
| 138 | echo |
|---|
| 139 | echo "This is a continuation of the previous PEM run." |
|---|
| 140 | date |
|---|
| 141 | submitPEM $mode |
|---|
| 142 | |
|---|
| 143 | # Default case: error |
|---|
| 144 | else |
|---|
| 145 | echo "Error: given argument '$1' for the launching script is unknown!" |
|---|
| 146 | errlaunch |
|---|
| 147 | fi |
|---|
| 148 | fi |
|---|