1 | #!/bin/bash |
---|
2 | ######################################################################## |
---|
3 | # Script to perform several chained LMD Mars GCM simulations |
---|
4 | # SET HERE the maximum total number of simulations |
---|
5 | |
---|
6 | nummax=1 |
---|
7 | |
---|
8 | # Also, ensure that the gcm executable name is correct below: |
---|
9 | gcm=gcm.e |
---|
10 | # |
---|
11 | ######################################################################## |
---|
12 | set -x |
---|
13 | |
---|
14 | echo "---------------------------------------------------------" |
---|
15 | echo "Starting run0..." |
---|
16 | |
---|
17 | dir=`pwd` |
---|
18 | machine=`hostname` |
---|
19 | address=`whoami` |
---|
20 | |
---|
21 | # Check if GCM executable exists and is executable |
---|
22 | if [ ! -x $gcm ]; then |
---|
23 | echo "Error: file \"$gcm\" not found or not executable in $dir!" |
---|
24 | exit 1 |
---|
25 | fi |
---|
26 | |
---|
27 | # Look for file "num_run" which should contain |
---|
28 | # the value of the previously computed season |
---|
29 | # (defaults to 0 if file "num_run" does not exist) |
---|
30 | if [[ -r num_run ]] ; then |
---|
31 | echo "Found file \"num_run\"" |
---|
32 | numold=`cat num_run` |
---|
33 | else |
---|
34 | numold=0 |
---|
35 | fi |
---|
36 | echo "numold is set to" $numold |
---|
37 | |
---|
38 | # Set value of current season |
---|
39 | numnew=$((numold + 1 )) |
---|
40 | echo "numnew is set to" $numnew |
---|
41 | |
---|
42 | # Look for initialization data files (exit if none found) |
---|
43 | if [[ ( -r start${numold}.nc && -r startfi${numold}.nc ) ]] ; then |
---|
44 | \cp -f start${numold}.nc start.nc |
---|
45 | \cp -f startfi${numold}.nc startfi.nc |
---|
46 | else |
---|
47 | if (( numold == 99999 )) ; then |
---|
48 | echo "Error: no run because previous run crashed! (99999 in \"num_run\")" |
---|
49 | exit 1 |
---|
50 | else |
---|
51 | echo "Error: missing input files \"start${numold}.nc\" or \"startfi${numold}.nc\" in $dir!" |
---|
52 | exit 1 |
---|
53 | fi |
---|
54 | fi |
---|
55 | |
---|
56 | |
---|
57 | # Run GCM |
---|
58 | ./$gcm > lrun${numnew} |
---|
59 | |
---|
60 | |
---|
61 | # Check if run ended normaly and copy datafiles |
---|
62 | if [[ ( -r restartfi.nc && -r restart.nc ) ]] ; then |
---|
63 | echo "Run seems to have ended normally." |
---|
64 | \mv -f restartfi.nc startfi${numnew}.nc |
---|
65 | \mv -f restart.nc start${numnew}.nc |
---|
66 | else |
---|
67 | echo "Error: Run crashed or incomplete output!" |
---|
68 | if [[ -r num_run ]] ; then |
---|
69 | \mv -f num_run num_run.crash |
---|
70 | else |
---|
71 | echo "No file num_run to build \"num_run.crash\" from!" |
---|
72 | # Impose a default value of 0 for num_run |
---|
73 | echo 0 > num_run.crash |
---|
74 | fi |
---|
75 | echo 99999 > num_run |
---|
76 | ############## To receive an Email message if the run crashes ######## |
---|
77 | mail -s "Crash in GCM run" $address <<ENDMAIL |
---|
78 | The GCM run on $machine in $dir has just crashed. |
---|
79 | Check the output logs for more information. |
---|
80 | ENDMAIL |
---|
81 | ############################################# |
---|
82 | exit 1 |
---|
83 | fi |
---|
84 | |
---|
85 | # Copy other datafiles that may have been generated |
---|
86 | if [[ -r diagfi.nc ]] ; then |
---|
87 | \mv -f diagfi.nc diagfi${numnew}.nc |
---|
88 | fi |
---|
89 | if [[ -r diagsoil.nc ]] ; then |
---|
90 | \mv -f diagsoil.nc diagsoil${numnew}.nc |
---|
91 | fi |
---|
92 | if [[ -r stats.nc ]] ; then |
---|
93 | \mv -f stats.nc stats${numnew}.nc |
---|
94 | fi |
---|
95 | if [[ -f profiles.dat ]] ; then |
---|
96 | \mv -f profiles.dat profiles${numnew}.dat |
---|
97 | \mv -f profiles.hdr profiles${numnew}.hdr |
---|
98 | fi |
---|
99 | |
---|
100 | # Prepare things for upcoming runs by writing |
---|
101 | # value of computed season in file num_run |
---|
102 | echo $numnew > num_run |
---|
103 | |
---|
104 | # If we are over nummax : stop |
---|
105 | if (( $numnew + 1 > $nummax )) ; then |
---|
106 | exit 0 |
---|
107 | else |
---|
108 | \cp -f run0 exe_mars |
---|
109 | ./exe_mars |
---|
110 | fi |
---|