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 | echo "The launching script is starting!" |
---|
10 | echo "The output file is \"loglaunch.txt\"." |
---|
11 | if [ "$1" = "bg" ]; then |
---|
12 | date |
---|
13 | else |
---|
14 | nohup "$0" bg > loglaunch.txt 2>&1 & |
---|
15 | exit 1 |
---|
16 | fi |
---|
17 | |
---|
18 | # Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator |
---|
19 | OLD_LC_NUMERIC=$LC_NUMERIC |
---|
20 | LC_NUMERIC=en_US.UTF-8 |
---|
21 | |
---|
22 | ################################################################ |
---|
23 | # Modify here the parameters for the simulation |
---|
24 | ############################################### |
---|
25 | # Path to the arch.env to source: |
---|
26 | source ../trunk/LMDZ.COMMON/arch.env |
---|
27 | |
---|
28 | # Set the number of Martian years to be simulated: |
---|
29 | n_myears=1000 |
---|
30 | |
---|
31 | # Name of executable for the PCM: |
---|
32 | exePCM="testphys1d_29_phymars_seq.e" |
---|
33 | ################################################################ |
---|
34 | |
---|
35 | |
---|
36 | # Check if files/directories necessary for the script exist |
---|
37 | dir=`pwd` |
---|
38 | machine=`hostname` |
---|
39 | address=`whoami` |
---|
40 | if [ ! -f "$exePCM" ]; then |
---|
41 | echo "Error: file \"$exePCM\" does not exist in $dir!" |
---|
42 | exit 1 |
---|
43 | fi |
---|
44 | if [ ! -d "out_PCM" ]; then |
---|
45 | mkdir out_PCM |
---|
46 | fi |
---|
47 | if [ ! -d "starts" ]; then |
---|
48 | mkdir starts |
---|
49 | fi |
---|
50 | if [ ! -d "diags" ]; then |
---|
51 | mkdir diags |
---|
52 | fi |
---|
53 | |
---|
54 | # Initialization |
---|
55 | dir=`pwd` |
---|
56 | machine=`hostname` |
---|
57 | address=`whoami` |
---|
58 | echo "This is a chained simulation for PCM runs in $dir on $machine." |
---|
59 | echo "Number of years to be simulated: $n_myears Martian years." |
---|
60 | myear=686.9725 # Number of Earth days in Martian year |
---|
61 | eyear=365.256363004 # Number of days in Earth year |
---|
62 | convert_years=$(echo "$myear/$eyear" | bc -l) |
---|
63 | convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year |
---|
64 | i_myear=0 |
---|
65 | iPCM=1 |
---|
66 | cp startfi.nc starts/ |
---|
67 | if [ -f "star1D.nc" ]; then |
---|
68 | cp star1D.txt starts/ |
---|
69 | fi |
---|
70 | |
---|
71 | # Main loop to to run PCM year by year |
---|
72 | while [ $i_myear -lt $n_myears ]; do |
---|
73 | # Run the PCM |
---|
74 | echo "Run PCM $iPCM: year $iPCM/$n_myears..." |
---|
75 | ./$exePCM > out_runPCM${iPCM} 2>&1 |
---|
76 | if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally |
---|
77 | echo "Error: the run PCM $iPCM crashed!" |
---|
78 | exit 1 |
---|
79 | fi |
---|
80 | # Copy data files and prepare the next run |
---|
81 | mv out_runPCM${iPCM} out_PCM/run${iPCM} |
---|
82 | mv diagfi.nc diags/diagfi${iPCM}.nc |
---|
83 | if [ -f "diagsoil.nc" ]; then |
---|
84 | mv diagsoil.nc diags/diagsoil${iPCM}.nc |
---|
85 | fi |
---|
86 | if [ -f "stats.nc" ]; then |
---|
87 | mv stats.nc diags/stats${iPCM}.nc |
---|
88 | fi |
---|
89 | if [ -f "Xdiurnalave.nc" ]; then |
---|
90 | mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc |
---|
91 | fi |
---|
92 | cp restartfi.nc starts/startfi${iPCM}.nc |
---|
93 | mv restartfi.nc startfi.nc |
---|
94 | if [ -f "restart1D.txt" ]; then |
---|
95 | cp restart1D.txt starts/restart1D${iPCM}.txt |
---|
96 | mv restart1D.txt start1D.txt |
---|
97 | fi |
---|
98 | ((iPCM++)) |
---|
99 | ((i_myear++)) |
---|
100 | echo "Done!" |
---|
101 | done |
---|
102 | |
---|
103 | # Restore the previous value of LC_NUMERIC |
---|
104 | LC_NUMERIC=$OLD_LC_NUMERIC |
---|
105 | |
---|
106 | date |
---|
107 | echo "The launching script ended." |
---|