#!/bin/bash ######################################################################## # Script to perform several chained LMD Mars GCM simulations # SET HERE the maximum total number of simulations nummax=1 # Also, ensure that the gcm executable name is correct below: gcm=gcm.e # ######################################################################## set -x echo "---------------------------------------------------------" echo "Starting run0..." dir=`pwd` machine=`hostname` address=`whoami` # Check if GCM executable exists and is executable if [ ! -x $gcm ]; then echo "Error: file \"$gcm\" not found or not executable in $dir!" exit 1 fi # Look for file "num_run" which should contain # the value of the previously computed season # (defaults to 0 if file "num_run" does not exist) if [[ -r num_run ]] ; then echo "Found file \"num_run\"" numold=`cat num_run` else numold=0 fi echo "numold is set to" $numold # Set value of current season numnew=$((numold + 1 )) echo "numnew is set to" $numnew # Look for initialization data files (exit if none found) if [[ ( -r start${numold}.nc && -r startfi${numold}.nc ) ]] ; then \cp -f start${numold}.nc start.nc \cp -f startfi${numold}.nc startfi.nc else if (( numold == 99999 )) ; then echo "Error: no run because previous run crashed! (99999 in \"num_run\")" exit 1 else echo "Error: missing input files \"start${numold}.nc\" or \"startfi${numold}.nc\" in $dir!" exit 1 fi fi # Run GCM ./$gcm > lrun${numnew} # Check if run ended normaly and copy datafiles if [[ ( -r restartfi.nc && -r restart.nc ) ]] ; then echo "Run seems to have ended normally." \mv -f restartfi.nc startfi${numnew}.nc \mv -f restart.nc start${numnew}.nc else echo "Error: Run crashed or incomplete output!" if [[ -r num_run ]] ; then \mv -f num_run num_run.crash else echo "No file num_run to build \"num_run.crash\" from!" # Impose a default value of 0 for num_run echo 0 > num_run.crash fi echo 99999 > num_run ############## To receive an Email message if the run crashes ######## mail -s "Crash in GCM run" $address < num_run # If we are over nummax : stop if (( $numnew + 1 > $nummax )) ; then exit 0 else \cp -f run0 exe_mars ./exe_mars fi