source: trunk/LMDZ.MARS/deftank/irene/run0

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

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

File size: 2.9 KB
RevLine 
[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
6nummax=1
7
8# Also, ensure that the gcm executable name is correct below:
9gcm=gcm_64x48x73_phymars_para.e
10#
[3766]11########################################################################
[2776]12set -x
13
14echo "---------------------------------------------------------"
[3766]15echo "Starting run0..."
[2776]16
17dir=`pwd`
18machine=`hostname`
19address=`whoami`
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
[2776]28# the value of the previously computed season
29# (defaults to 0 if file "num_run" does not exist)
30if [[ -r num_run ]] ; then
[3766]31  echo "Found file \"num_run\""
[2776]32  numold=`cat num_run`
33else
34  numold=0
35fi
[3766]36echo "numold is set to" $numold
[2776]37
[3766]38# Set value of current season
39numnew=$((numold + 1 ))
40echo "numnew is set to" $numnew
[2776]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
[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
54fi
55
56
57# Run GCM
[3766]58ccc_mprun -l $gcm > lrun${numnew} 2>&1
[2776]59
60
61# Check if run ended normaly and copy datafiles
62if [[ ( -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
66else
[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]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.
[2776]80ENDMAIL
[3766]81#############################################
82  exit 1
[2776]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
[3766]102echo $numnew > num_run
[2776]103
104# If we are over nummax : stop
105if (( $numnew + 1 > $nummax )) ; then
[3766]106  exit 0
[2776]107else
[3766]108  \cp -f run0 exe_mars
109  ./exe_mars
110fi
Note: See TracBrowser for help on using the repository browser.