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