source: trunk/LMDZ.COMMON/libf/evolution/deftank/launchPEM.sh @ 3980

Last change on this file since 3980 was 3980, checked in by jbclement, 2 days ago

PEM:
Renaming the file "info_PEM.txt" into "launchPEM.info".
JBC

  • Property svn:executable set to *
File size: 5.7 KB
Line 
1#!/bin/bash
2########################################################################
3#### Launching script for a chained simulation of PEM and PCM runs  ####
4########################################################################
5# This script can take an argument:
6#     1) None: to start a simulation from scratch;
7#     2) 're': to relaunch a simulation from a starting point (interactive prompt).
8########################################################################
9set -e
10trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
11
12
13########################################################################
14# Modify here the parameters for the simulation
15###############################################
16# Set the number of years to be simulated, either Martian or Earth years (> 0):
17n_mars_years=100.
18#n_earth_years=300.
19
20# Set the number of initial PCM years (>= 2):
21nPCM_ini=3
22
23# Set the number of PCM years between each PEM run (>= 2):
24nPCM=2
25
26# Set the counting method for the number of years to be simulated (0 = "only PEM years count"; any other values = "PCM years are taken into account"). The former option is the usual one:
27counting=0
28
29# Set the launching mode (0 = "processing scripts"; any other values = "submitting jobs"). The former option is usually used to process the script on a local machine while the latter is used to submit jobs on a supercomputer with SLURM or PBS/TORQUE:
30mode=1
31########################################################################
32
33
34dir=`pwd`
35machine=`hostname`
36user=`whoami`
37if [ ! -f "lib_launchPEM.sh" ]; then
38    echo "Error: file \"lib_launchPEM.sh\" does not exist in $dir!"
39    echo "It can be found in the PEM deftank."
40    exit 1
41fi
42
43source lib_launchPEM.sh
44export counting mode
45
46if [ $# -eq 0 ]; then
47    # Starting from scratch
48    echo "The launching script is starting!"
49    echo "The output file is \"launchPEM.log\"."
50    exec > launchPEM.log 2>&1
51    echo "Beginning of the launching script for the PEM simulation."
52    date
53    checklaunch
54    initlaunch
55    cyclelaunch $mode $counting $nPCM_ini
56
57else
58    # Starting a new cycle
59    if [ $1 = "new" ]; then
60        exec >> launchPEM.log 2>&1
61        echo
62        echo "This is a new cycle for the PEM simulation."
63        date
64        if [ $mode -ne 0 ]; then
65            job_scheduler
66            if command -v squeue &> /dev/null; then
67                unset SLURM_MEM_PER_CPU SLURM_MEM_PER_GPU SLURM_MEM_PER_NODE
68            fi
69        fi
70        read i_myear n_myear convert_years iPCM iPEM nPCM nPCM_ini < launchPEM.info
71        cyclelaunch $mode $counting $nPCM
72
73    # Starting a relaunch
74    elif [ $1 = "re" ]; then
75        if [ ! -f "launchPEM.info" ]; then
76            echo "Error: file \"launchPEM.info\" does not exist in $dir!"
77            echo "It is necessary to relaunch a PEM simulation."
78            errlaunch
79        fi
80        echo "The relaunch is initialized with a previous successful run to be specified."
81        while true; do
82            echo "Do you want to relaunch from a 'PCM' or 'PEM' run?"
83            read relaunch
84            if [ $relaunch = "PCM" ] || [ $relaunch = "PEM" ]; then
85                break
86            else
87                echo "Invalid input. Please enter 'PCM' or 'PEM'."
88            fi
89        done
90        read i_myear n_myear_old convert_years iPCM iPEM nPCM_old nPCM_ini_old < launchPEM.info
91        while true; do
92            if [ $relaunch = "PCM" ]; then
93                echo "What is the number of the PCM run?"
94                echo "It should be between 1 and $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 ))."
95                read irelaunch
96                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPCM - 1)) > 1 ? $((iPCM - 1)) : 1 )) ]; then
97                    break
98                else
99                    echo "Invalid input. Please enter a valid PCM run number."
100                fi
101            else
102                echo "What is the number of the PEM run?"
103                echo "It should be between 1 and $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 ))."
104                read irelaunch
105                if [ 1 -le $irelaunch ] && [ $irelaunch -le $(( $((iPEM - 1)) > 1 ? $((iPEM - 1)) : 1 )) ]; then
106                    break
107                else
108                    echo "Invalid input. Please enter a valid PEM run number."
109                fi
110            fi
111        done
112        exec >> launchPEM.log 2>&1
113        echo
114        echo "This is a relaunch for the PEM simulation from the run \"$relaunch $irelaunch\"."
115        date
116        checklaunch
117        convertyears
118        if [ $nPCM_ini -ne $nPCM_ini_old ]; then
119            echo "The number of initial PCM years has been modified from $nPCM_ini_old to $nPCM_ini."
120        fi
121        if [ $nPCM -ne $nPCM_old ]; then
122            echo "The number of PCM years between each PEM run has been modified from $nPCM_old to $nPCM."
123        fi
124        if [ "$(echo "$n_myear != $n_myear_old" | bc)" -eq 1 ]; then
125            echo "The number of initial PCM years has been modified from $n_myear_old to $n_myear."
126        fi
127        sed -i "1s/.*/$i_myear $n_myear $convert_years $iPCM $iPEM $nPCM $nPCM_ini/" launchPEM.info
128        if [ -f "kill_launchPEM.sh" ]; then
129            ./kill_launchPEM.sh
130        fi
131        if [ $relaunch = "PCM" ]; then
132            relaunchPCM $mode $counting
133        else
134            relaunchPEM $mode $counting
135        fi
136
137    # Continuing the PEM run
138    elif [ $1 = "cont" ]; then
139        exec >> launchPEM.log 2>&1
140        echo
141        echo "This is a continuation of the previous PEM run."
142        date
143        submitPEM $mode
144
145    # Default case: error
146    else
147        echo "Error: given argument '$1' for the launching script is unknown!"
148        errlaunch
149    fi
150fi
Note: See TracBrowser for help on using the repository browser.