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