source: trunk/LMDZ.MARS/deftank/run0

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