source: trunk/LMDZ.MARS/deftank/launch_1Dchained.sh @ 3580

Last change on this file since 3580 was 3580, checked in by jbclement, 8 hours ago

Mars PCM:
Improvement of Bash scripts for the 1D in the deftank with an automatic error detection which ends the script with a message.
JBC

  • Property svn:executable set to *
File size: 3.1 KB
Line 
1#!/bin/bash
2################################################################
3### Launching script for a chained simulation of 1D PCM runs ###
4################################################################
5set -e
6trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
7
8
9echo "The launching script is starting!"
10echo "The output file is \"loglaunch.txt\"."
11if [ "$1" = "bg" ]; then
12    date
13else
14    nohup "$0" bg > loglaunch.txt 2>&1 &
15    exit 1
16fi
17
18# Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator
19OLD_LC_NUMERIC=$LC_NUMERIC
20LC_NUMERIC=en_US.UTF-8
21
22################################################################
23# Modify here the parameters for the simulation
24###############################################
25# Path to the arch.env to source:
26source ../trunk/LMDZ.COMMON/arch.env
27
28# Set the number of Martian years to be simulated:
29n_myears=1000
30
31# Name of executable for the PCM:
32exePCM="testphys1d_29_phymars_seq.e"
33################################################################
34
35
36# Check if files/directories necessary for the script exist
37dir=`pwd`
38machine=`hostname`
39address=`whoami`
40if [ ! -f "$exePCM" ]; then
41    echo "Error: file \"$exePCM\" does not exist in $dir!"
42    exit 1
43fi
44if [ ! -d "out_PCM" ]; then
45    mkdir out_PCM
46fi
47if [ ! -d "starts" ]; then
48    mkdir starts
49fi
50if [ ! -d "diags" ]; then
51    mkdir diags
52fi
53
54# Initialization
55dir=`pwd`
56machine=`hostname`
57address=`whoami`
58echo "This is a chained simulation for PCM runs in $dir on $machine."
59echo "Number of years to be simulated: $n_myears Martian years."
60myear=686.9725      # Number of Earth days in Martian year
61eyear=365.256363004 # Number of days in Earth year
62convert_years=$(echo "$myear/$eyear" | bc -l)
63convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
64i_myear=0
65iPCM=1
66cp startfi.nc starts/
67if [ -f "star1D.nc" ]; then
68    cp star1D.txt starts/
69fi
70
71# Main loop to to run PCM year by year
72while [ $i_myear -lt $n_myears ]; do
73    # Run the PCM
74    echo "Run PCM $iPCM: year $iPCM/$n_myears..."
75    ./$exePCM > out_runPCM${iPCM} 2>&1
76    if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
77        echo "Error: the run PCM $iPCM crashed!"
78        exit 1
79    fi
80    # Copy data files and prepare the next run
81    mv out_runPCM${iPCM} out_PCM/run${iPCM}
82    mv diagfi.nc diags/diagfi${iPCM}.nc
83    if [ -f "diagsoil.nc" ]; then
84        mv diagsoil.nc diags/diagsoil${iPCM}.nc
85    fi
86    if [ -f "stats.nc" ]; then
87        mv stats.nc diags/stats${iPCM}.nc
88    fi
89    if [ -f "Xdiurnalave.nc" ]; then
90        mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc
91    fi
92    cp restartfi.nc starts/startfi${iPCM}.nc
93    mv restartfi.nc startfi.nc
94    if [ -f "restart1D.txt" ]; then
95        cp restart1D.txt starts/restart1D${iPCM}.txt
96        mv restart1D.txt start1D.txt
97    fi
98    ((iPCM++))
99    ((i_myear++))
100    echo "Done!"
101done
102
103# Restore the previous value of LC_NUMERIC
104LC_NUMERIC=$OLD_LC_NUMERIC
105
106date
107echo "The launching script ended."
Note: See TracBrowser for help on using the repository browser.