[3349] | 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 | |
---|
| 11 | |
---|
| 12 | ######################################################################## |
---|
| 13 | # Modify here the parameters for the simulation |
---|
| 14 | ############################################### |
---|
| 15 | # Set the number of years to be simulated, either Martian or Earth years: |
---|
[3498] | 16 | n_mars_years=100. |
---|
| 17 | #n_earth_years=300. |
---|
[3349] | 18 | |
---|
[3495] | 19 | # Set the number of initial PCM runs (>= 2): |
---|
[3349] | 20 | nPCM_ini=3 |
---|
| 21 | |
---|
[3495] | 22 | # Set the number of PCM runs between each PEM run (>= 2): |
---|
[3349] | 23 | nPCM=2 |
---|
[3391] | 24 | |
---|
[3556] | 25 | # 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"): |
---|
| 26 | counting=0 |
---|
| 27 | |
---|
[3498] | 28 | # 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: |
---|
[3495] | 29 | mode=1 |
---|
[3349] | 30 | ######################################################################## |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | dir=`pwd` |
---|
| 34 | machine=`hostname` |
---|
| 35 | user=`whoami` |
---|
| 36 | if [ ! -f "lib_launchPEM.sh" ]; then |
---|
| 37 | echo "Error: file \"lib_launchPEM.sh\" does not exist in $dir!" |
---|
| 38 | echo "It can be found in the PEM deftank." |
---|
| 39 | exit 1 |
---|
| 40 | fi |
---|
| 41 | |
---|
| 42 | source lib_launchPEM.sh |
---|
[3556] | 43 | export counting mode |
---|
[3349] | 44 | |
---|
[3355] | 45 | if [ $# -eq 0 ]; then |
---|
| 46 | # Starting from scratch |
---|
[3349] | 47 | echo "The launching script is starting!" |
---|
| 48 | echo "The output file is \"log_launchPEM.txt\"." |
---|
| 49 | exec > log_launchPEM.txt 2>&1 |
---|
| 50 | echo "Beginning of the launching script for the PEM simulation." |
---|
| 51 | date |
---|
| 52 | checklaunch |
---|
| 53 | initlaunch |
---|
[3556] | 54 | cyclelaunch $mode $counting $nPCM_ini |
---|
[3355] | 55 | |
---|
[3349] | 56 | else |
---|
[3355] | 57 | # Starting a new cycle |
---|
| 58 | if [ $1 = "new" ]; then |
---|
[3349] | 59 | exec >> log_launchPEM.txt 2>&1 |
---|
[3355] | 60 | echo |
---|
[3349] | 61 | echo "This is a new cycle for the PEM simulation." |
---|
| 62 | date |
---|
[3495] | 63 | if [ $mode -ne 0 ]; then |
---|
[3419] | 64 | job_scheduler |
---|
| 65 | fi |
---|
[3349] | 66 | read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < info_PEM.txt |
---|
[3556] | 67 | cyclelaunch $mode $counting $nPCM |
---|
[3355] | 68 | |
---|
| 69 | # Starting a relaunch |
---|
| 70 | elif [ $1 = "re" ]; then |
---|
| 71 | if [ ! -f "info_PEM.txt" ]; then |
---|
| 72 | echo "Error: file \"info_PEM.txt\" does not exist in $dir!" |
---|
| 73 | echo "It is necessary to relaunch a PEM simulation." |
---|
| 74 | errlaunch |
---|
| 75 | fi |
---|
[3363] | 76 | echo "The relaunch is initialized with a specific previous successful run." |
---|
[3355] | 77 | while true; do |
---|
| 78 | echo "Do you want to relaunch from a 'PCM' or 'PEM' run?" |
---|
| 79 | read relaunch |
---|
| 80 | if [ $relaunch = "PCM" ] || [ $relaunch = "PEM" ]; then |
---|
| 81 | break |
---|
| 82 | else |
---|
| 83 | echo "Invalid input. Please enter 'PCM' or 'PEM'." |
---|
| 84 | fi |
---|
| 85 | done |
---|
[3386] | 86 | read i_myear n_myear_old convert_years iPCM iPEM nPCM_old nPCM_ini_old < info_PEM.txt |
---|
[3355] | 87 | while true; do |
---|
| 88 | if [ $relaunch = "PCM" ]; then |
---|
| 89 | echo "What is the number of the PCM run?" |
---|
[3417] | 90 | echo "It should be between 1 and $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 ))." |
---|
[3355] | 91 | read irelaunch |
---|
[3417] | 92 | if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 )) ]; then |
---|
[3355] | 93 | break |
---|
| 94 | else |
---|
| 95 | echo "Invalid input. Please enter a valid PCM run number." |
---|
| 96 | fi |
---|
| 97 | else |
---|
| 98 | echo "What is the number of the PEM run?" |
---|
[3417] | 99 | echo "It should be between 1 and $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 ))." |
---|
[3355] | 100 | read irelaunch |
---|
[3417] | 101 | if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 )) ]; then |
---|
[3355] | 102 | break |
---|
| 103 | else |
---|
| 104 | echo "Invalid input. Please enter a valid PEM run number." |
---|
| 105 | fi |
---|
| 106 | fi |
---|
| 107 | done |
---|
| 108 | exec >> log_launchPEM.txt 2>&1 |
---|
| 109 | echo |
---|
| 110 | echo "This is a relaunch for the PEM simulation from the run $relaunch$irelaunch." |
---|
| 111 | date |
---|
| 112 | checklaunch |
---|
[3386] | 113 | convertyears |
---|
| 114 | if [ $nPCM_ini -ne $nPCM_ini_old ]; then |
---|
| 115 | echo "The number of initial PCM runs has been modified from $nPCM_ini_old to $nPCM_ini." |
---|
| 116 | fi |
---|
| 117 | if [ $nPCM -ne $nPCM_old ]; then |
---|
| 118 | echo "The number of PCM runs between each PEM run has been modified from $nPCM_old to $nPCM." |
---|
| 119 | fi |
---|
[3537] | 120 | if [ "$(echo "$n_myear != $n_myear_old" | bc)" -eq 1 ]; then |
---|
[3386] | 121 | echo "The number of initial PCM runs has been modified from $n_myear_old to $n_myear." |
---|
| 122 | fi |
---|
| 123 | sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" info_PEM.txt |
---|
[3419] | 124 | if [ -f "kill_launchPEM.sh" ]; then |
---|
| 125 | ./kill_launchPEM.sh |
---|
| 126 | fi |
---|
[3355] | 127 | if [ $relaunch = "PCM" ]; then |
---|
[3556] | 128 | relaunchPCM $mode $counting |
---|
[3355] | 129 | else |
---|
[3556] | 130 | relaunchPEM $mode $counting |
---|
[3355] | 131 | fi |
---|
[3363] | 132 | |
---|
| 133 | # Continuing the PEM run |
---|
| 134 | elif [ $1 = "cont" ]; then |
---|
| 135 | exec >> log_launchPEM.txt 2>&1 |
---|
| 136 | echo |
---|
| 137 | echo "This is a continuation of the previous PEM run." |
---|
| 138 | date |
---|
[3495] | 139 | submitPEM $mode |
---|
[3363] | 140 | |
---|
| 141 | # Default case: error |
---|
[3349] | 142 | else |
---|
| 143 | echo "Error: given argument '$1' for the launching script is unknown!" |
---|
| 144 | errlaunch |
---|
| 145 | fi |
---|
| 146 | fi |
---|