[2776] | 1 | #!/bin/bash |
---|
[3766] | 2 | ######################################################################## |
---|
[2776] | 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 | # |
---|
[3766] | 11 | ######################################################################## |
---|
[2776] | 12 | set -x |
---|
| 13 | |
---|
| 14 | echo "---------------------------------------------------------" |
---|
[3766] | 15 | echo "Starting run0..." |
---|
[2776] | 16 | |
---|
| 17 | dir=`pwd` |
---|
| 18 | machine=`hostname` |
---|
| 19 | address=`whoami` |
---|
| 20 | |
---|
[3766] | 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 |
---|
[2776] | 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 |
---|
[3766] | 31 | echo "Found file \"num_run\"" |
---|
[2776] | 32 | numold=`cat num_run` |
---|
| 33 | else |
---|
| 34 | numold=0 |
---|
| 35 | fi |
---|
[3766] | 36 | echo "numold is set to" $numold |
---|
[2776] | 37 | |
---|
[3766] | 38 | # Set value of current season |
---|
| 39 | numnew=$((numold + 1 )) |
---|
| 40 | echo "numnew is set to" $numnew |
---|
[2776] | 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 |
---|
[3766] | 47 | if (( numold == 99999 )) ; then |
---|
| 48 | echo "Error: no run because previous run crashed! (99999 in \"num_run\")" |
---|
| 49 | exit 1 |
---|
[2776] | 50 | else |
---|
[3766] | 51 | echo "Error: missing input files \"start${numold}.nc\" or \"startfi${numold}.nc\" in $dir!" |
---|
| 52 | exit 1 |
---|
[2776] | 53 | fi |
---|
| 54 | fi |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | # Run GCM |
---|
[3766] | 58 | ccc_mprun -l $gcm > lrun${numnew} 2>&1 |
---|
[2776] | 59 | |
---|
| 60 | |
---|
| 61 | # Check if run ended normaly and copy datafiles |
---|
| 62 | if [[ ( -r restartfi.nc && -r restart.nc ) ]] ; then |
---|
[3766] | 63 | echo "Run seems to have ended normally." |
---|
[2776] | 64 | \mv -f restartfi.nc startfi${numnew}.nc |
---|
| 65 | \mv -f restart.nc start${numnew}.nc |
---|
| 66 | else |
---|
[3766] | 67 | echo "Error: Run crashed or incomplete output!" |
---|
[2776] | 68 | if [[ -r num_run ]] ; then |
---|
| 69 | \mv -f num_run num_run.crash |
---|
| 70 | else |
---|
[3766] | 71 | echo "No file num_run to build \"num_run.crash\" from!" |
---|
[2776] | 72 | # Impose a default value of 0 for num_run |
---|
| 73 | echo 0 > num_run.crash |
---|
| 74 | fi |
---|
[3766] | 75 | echo 99999 > num_run |
---|
[2776] | 76 | ############## To receive an Email message if the run crashes ######## |
---|
[3766] | 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. |
---|
[2776] | 80 | ENDMAIL |
---|
[3766] | 81 | ############################################# |
---|
| 82 | exit 1 |
---|
[2776] | 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 |
---|
[3766] | 102 | echo $numnew > num_run |
---|
[2776] | 103 | |
---|
| 104 | # If we are over nummax : stop |
---|
| 105 | if (( $numnew + 1 > $nummax )) ; then |
---|
[3766] | 106 | exit 0 |
---|
[2776] | 107 | else |
---|
[3766] | 108 | \cp -f run0 exe_mars |
---|
| 109 | ./exe_mars |
---|
| 110 | fi |
---|