| 1 | #!/bin/bash |
|---|
| 2 | ################################################################ |
|---|
| 3 | ### Launching script for a chained simulation of 1D PCM runs ### |
|---|
| 4 | ################################################################ |
|---|
| 5 | set -e |
|---|
| 6 | trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | ################################################################ |
|---|
| 10 | # Modify here the parameters for the simulation |
|---|
| 11 | ############################################### |
|---|
| 12 | # Path to the arch.env to source: |
|---|
| 13 | source ../trunk/LMDZ.COMMON/arch.env |
|---|
| 14 | |
|---|
| 15 | # Set the number of Martian years to be simulated: |
|---|
| 16 | n_myear=100 |
|---|
| 17 | |
|---|
| 18 | # Name of executable for the PCM: |
|---|
| 19 | exePCM="testphys1d_32_phymars_seq.e" |
|---|
| 20 | ################################################################ |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | echo "The launching script is starting!" |
|---|
| 24 | echo "The output file is \"launch.log\"." |
|---|
| 25 | exec > launch.log 2>&1 |
|---|
| 26 | |
|---|
| 27 | # Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator |
|---|
| 28 | OLD_LC_NUMERIC=$LC_NUMERIC |
|---|
| 29 | LC_NUMERIC=en_US.UTF-8 |
|---|
| 30 | |
|---|
| 31 | # To end the launching script with error |
|---|
| 32 | errlaunch() { |
|---|
| 33 | # Restore the previous value of LC_NUMERIC |
|---|
| 34 | LC_NUMERIC=$OLD_LC_NUMERIC |
|---|
| 35 | |
|---|
| 36 | date |
|---|
| 37 | echo "Error: an issue occured in the launching script!" |
|---|
| 38 | exit 1 |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | # Check if the set-up is correct |
|---|
| 43 | dir=`pwd` |
|---|
| 44 | machine=`hostname` |
|---|
| 45 | address=`whoami` |
|---|
| 46 | if [ -v n_myear ]; then |
|---|
| 47 | if [ $(echo "$n_myear <= 0." | bc -l) -eq 1 ]; then |
|---|
| 48 | echo "Error: 'n_myear' must be > 0!" |
|---|
| 49 | errlaunch |
|---|
| 50 | fi |
|---|
| 51 | else |
|---|
| 52 | echo "Error: the number of years to be simulated is not set!" |
|---|
| 53 | errlaunch |
|---|
| 54 | fi |
|---|
| 55 | if [ ! -f "$exePCM" ]; then |
|---|
| 56 | echo "Error: file \"$exePCM\" does not exist in $dir!" |
|---|
| 57 | errlaunch |
|---|
| 58 | fi |
|---|
| 59 | if [ ! -d "logs" ]; then |
|---|
| 60 | mkdir logs |
|---|
| 61 | fi |
|---|
| 62 | if [ ! -d "starts" ]; then |
|---|
| 63 | mkdir starts |
|---|
| 64 | fi |
|---|
| 65 | if [ ! -d "diags" ]; then |
|---|
| 66 | mkdir diags |
|---|
| 67 | fi |
|---|
| 68 | |
|---|
| 69 | # Initialization |
|---|
| 70 | dir=`pwd` |
|---|
| 71 | machine=`hostname` |
|---|
| 72 | address=`whoami` |
|---|
| 73 | echo "This is a chained simulation for PCM 1D runs in $dir on $machine." |
|---|
| 74 | echo "Number of years to be simulated: $n_myear Martian years." |
|---|
| 75 | i_myear=0 |
|---|
| 76 | iPCM=1 |
|---|
| 77 | if [ -f "startfi.nc" ]; then |
|---|
| 78 | cp startfi.nc starts/ |
|---|
| 79 | fi |
|---|
| 80 | if [ -f "start1D.txt" ]; then |
|---|
| 81 | cp start1D.txt starts/ |
|---|
| 82 | fi |
|---|
| 83 | |
|---|
| 84 | # Main loop to to run PCM year by year |
|---|
| 85 | while [ $i_myear -lt $n_myear ]; do |
|---|
| 86 | # Run the PCM |
|---|
| 87 | echo "Run $iPCM: year $iPCM/$n_myear..." |
|---|
| 88 | ./$exePCM > run.log 2>&1 |
|---|
| 89 | if [ ! -f "restartfi.nc" ] || ! (tail -n 100 run.log | grep -iq "everything is cool!"); then # Check if it ended abnormally |
|---|
| 90 | echo "Error: the run $iPCM crashed!" |
|---|
| 91 | errlaunch |
|---|
| 92 | fi |
|---|
| 93 | # Copy data files and prepare the next run |
|---|
| 94 | mv run.log logs/run${iPCM}.log |
|---|
| 95 | if [ -f "diagfi.nc" ]; then |
|---|
| 96 | mv diagfi.nc diags/diagfi${iPCM}.nc |
|---|
| 97 | fi |
|---|
| 98 | if [ -f "diagsoil.nc" ]; then |
|---|
| 99 | mv diagsoil.nc diags/diagsoil${iPCM}.nc |
|---|
| 100 | fi |
|---|
| 101 | if [ -f "stats.nc" ]; then |
|---|
| 102 | mv stats.nc diags/stats${iPCM}.nc |
|---|
| 103 | fi |
|---|
| 104 | if [ -f "Xdiurnalave.nc" ]; then |
|---|
| 105 | mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc |
|---|
| 106 | fi |
|---|
| 107 | cp restartfi.nc starts/startfi${iPCM}.nc |
|---|
| 108 | mv restartfi.nc startfi.nc |
|---|
| 109 | if [ -f "restart1D.txt" ]; then |
|---|
| 110 | cp restart1D.txt starts/restart1D${iPCM}.txt |
|---|
| 111 | mv restart1D.txt start1D.txt |
|---|
| 112 | fi |
|---|
| 113 | ((iPCM++)) |
|---|
| 114 | ((i_myear++)) |
|---|
| 115 | echo "Done!" |
|---|
| 116 | done |
|---|
| 117 | |
|---|
| 118 | # Restore the previous value of LC_NUMERIC |
|---|
| 119 | LC_NUMERIC=$OLD_LC_NUMERIC |
|---|
| 120 | |
|---|
| 121 | date |
|---|
| 122 | echo "Success: the launching script completed normally!" |
|---|
| 123 | exit 0 |
|---|