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_64x48x73_phymars_para.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 | # Look for file "num_run" which should contain |
---|
22 | # the value of the previously computed season |
---|
23 | # (defaults to 0 if file "num_run" does not exist) |
---|
24 | if [[ -r num_run ]] ; then |
---|
25 | echo "found file num_run" |
---|
26 | numold=`cat num_run` |
---|
27 | else |
---|
28 | numold=0 |
---|
29 | fi |
---|
30 | echo "numold is set to" ${numold} |
---|
31 | |
---|
32 | |
---|
33 | # Set value of current season |
---|
34 | (( numnew = ${numold} + 1 )) |
---|
35 | echo "numnew is set to" ${numnew} |
---|
36 | |
---|
37 | # Look for initialization data files (exit if none found) |
---|
38 | if [[ ( -r start${numold}.nc && -r startfi${numold}.nc ) ]] ; then |
---|
39 | \cp -f start${numold}.nc start.nc |
---|
40 | \cp -f startfi${numold}.nc startfi.nc |
---|
41 | else |
---|
42 | if (( ${numold} == 99999 )) ; then |
---|
43 | echo "No run because previous run crashed ! (99999 in num_run)" |
---|
44 | exit |
---|
45 | else |
---|
46 | echo "Where is file start"${numold}".nc??" |
---|
47 | exit |
---|
48 | fi |
---|
49 | fi |
---|
50 | |
---|
51 | |
---|
52 | # Run GCM |
---|
53 | ccc_mprun -l $gcm > lrun${numnew} 2>&1 |
---|
54 | |
---|
55 | |
---|
56 | # Check if run ended normaly and copy datafiles |
---|
57 | if [[ ( -r restartfi.nc && -r restart.nc ) ]] ; then |
---|
58 | echo "Run seems to have ended normaly" |
---|
59 | \mv -f restartfi.nc startfi${numnew}.nc |
---|
60 | \mv -f restart.nc start${numnew}.nc |
---|
61 | else |
---|
62 | if [[ -r num_run ]] ; then |
---|
63 | \mv -f num_run num_run.crash |
---|
64 | else |
---|
65 | echo "No file num_run to build num_run.crash from !!" |
---|
66 | # Impose a default value of 0 for num_run |
---|
67 | echo 0 > num_run.crash |
---|
68 | fi |
---|
69 | echo 99999 > num_run |
---|
70 | ############## To receive an Email message if the run crashes ######## |
---|
71 | mail -s "crash run GCM" $address <<ENDMAIL |
---|
72 | The run on $machine in $dir has just crashed. |
---|
73 | ENDMAIL |
---|
74 | ############################################"" |
---|
75 | exit |
---|
76 | fi |
---|
77 | |
---|
78 | # Copy other datafiles that may have been generated |
---|
79 | if [[ -r diagfi.nc ]] ; then |
---|
80 | \mv -f diagfi.nc diagfi${numnew}.nc |
---|
81 | fi |
---|
82 | if [[ -r diagsoil.nc ]] ; then |
---|
83 | \mv -f diagsoil.nc diagsoil${numnew}.nc |
---|
84 | fi |
---|
85 | if [[ -r stats.nc ]] ; then |
---|
86 | \mv -f stats.nc stats${numnew}.nc |
---|
87 | fi |
---|
88 | if [[ -f profiles.dat ]] ; then |
---|
89 | \mv -f profiles.dat profiles${numnew}.dat |
---|
90 | \mv -f profiles.hdr profiles${numnew}.hdr |
---|
91 | fi |
---|
92 | |
---|
93 | # Prepare things for upcoming runs by writing |
---|
94 | # value of computed season in file num_run |
---|
95 | echo ${numnew} > num_run |
---|
96 | |
---|
97 | # If we are over nummax : stop |
---|
98 | if (( $numnew + 1 > $nummax )) ; then |
---|
99 | exit |
---|
100 | else |
---|
101 | \cp -f run0 exe_mars |
---|
102 | ./exe_mars |
---|
103 | fi |
---|