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

Last change on this file since 3918 was 3918, checked in by jbclement, 2 months ago

Mars PCM 1D:

  • "profile.F" is transformed into a module "profile_temp_mod.F90" with F90 format. The file "profile" where the temperature is read is renamed into "profile_temp" to avoid any confusion.
  • Small corrections and improvements throughout the code and scripts in the deftank.

JBC

  • Property svn:executable set to *
File size: 3.3 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
9################################################################
10# Modify here the parameters for the simulation
11###############################################
12# Path to the arch.env to source:
13source ../trunk/LMDZ.COMMON/arch.env
14
15# Set the number of Martian years to be simulated:
16n_myear=100
17
18# Name of executable for the PCM:
19exePCM="testphys1d_32_phymars_seq.e"
20################################################################
21
22
23echo "The launching script is starting!"
24echo "The output file is \"launch.log\"."
25exec > launch.log 2>&1
26
27# Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator
28OLD_LC_NUMERIC=$LC_NUMERIC
29LC_NUMERIC=en_US.UTF-8
30
31# To end the launching script with error
32errlaunch() {
33    # Restore the previous value of LC_NUMERIC
34    LC_NUMERIC=$OLD_LC_NUMERIC
35
36    date
37    echo "Error: an issue occured in the launching script!"
38    exit 1
39}
40
41
42# Check if the set-up is correct
43dir=`pwd`
44machine=`hostname`
45address=`whoami`
46if [ -v n_myear ]; then
47    if [ $(echo "$n_myear <= 0." | bc -l) -eq 1 ]; then
48        echo "Error: 'n_myear' must be > 0!"
49        errlaunch
50    fi
51else
52    echo "Error: the number of years to be simulated is not set!"
53    errlaunch
54fi
55if [ ! -f "$exePCM" ]; then
56    echo "Error: file \"$exePCM\" does not exist in $dir!"
57    errlaunch
58fi
59if [ ! -d "logs" ]; then
60    mkdir logs
61fi
62if [ ! -d "starts" ]; then
63    mkdir starts
64fi
65if [ ! -d "diags" ]; then
66    mkdir diags
67fi
68
69# Initialization
70dir=`pwd`
71machine=`hostname`
72address=`whoami`
73echo "This is a chained simulation for PCM 1D runs in $dir on $machine."
74echo "Number of years to be simulated: $n_myear Martian years."
75i_myear=0
76iPCM=1
77if [ -f "startfi.nc" ]; then
78    cp startfi.nc starts/
79fi
80if [ -f "start1D.txt" ]; then
81    cp start1D.txt starts/
82fi
83
84# Main loop to to run PCM year by year
85while [ $i_myear -lt $n_myear ]; do
86    # Run the PCM
87    echo "Run $iPCM: year $iPCM/$n_myear..."
88    ./$exePCM > run.log 2>&1
89    if [ ! -f "restartfi.nc" ] || ! (tail -n 100 run.log | grep -iq "everything is cool!"); then # Check if it ended abnormally
90        echo "Error: the run $iPCM crashed!"
91        errlaunch
92    fi
93    # Copy data files and prepare the next run
94    mv run.log logs/run${iPCM}.log
95    if [ -f "diagfi.nc" ]; then
96        mv diagfi.nc diags/diagfi${iPCM}.nc
97    fi
98    if [ -f "diagsoil.nc" ]; then
99        mv diagsoil.nc diags/diagsoil${iPCM}.nc
100    fi
101    if [ -f "stats.nc" ]; then
102        mv stats.nc diags/stats${iPCM}.nc
103    fi
104    if [ -f "Xdiurnalave.nc" ]; then
105        mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc
106    fi
107    cp restartfi.nc starts/startfi${iPCM}.nc
108    mv restartfi.nc startfi.nc
109    if [ -f "restart1D.txt" ]; then
110        cp restart1D.txt starts/restart1D${iPCM}.txt
111        mv restart1D.txt start1D.txt
112    fi
113    ((iPCM++))
114    ((i_myear++))
115    echo "Done!"
116done
117
118# Restore the previous value of LC_NUMERIC
119LC_NUMERIC=$OLD_LC_NUMERIC
120
121date
122echo "Success: the launching script completed normally!"
123exit 0
Note: See TracBrowser for help on using the repository browser.