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

Last change on this file since 3603 was 3579, checked in by jbclement, 3 weeks ago

PEM:
Improvement of the Bash script tools in the deftank with an automatic error detection which ends the script with a message.
JBC

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