source: trunk/LMDZ.MARS/deftank/run0 @ 3766

Last change on this file since 3766 was 3766, checked in by jbclement, 6 months ago

Mars PCM:
Cleaning and improvement of robustness for "run0" and "run_month1" scripts with file checks and clearer errors.
JBC

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