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

Last change on this file since 3556 was 3556, checked in by jbclement, 5 days ago

PEM:
As intended, years computed by the PEM runs are now the only ones to be counted for the duration of the PEM simulation. The possibility to count in addition years computed by the PCM runs is left as an option of "launchPEM.sh" with the variable 'counting' (0 = "only PEM runs count"; any other values = "PCM runs are taken into account") + several small corrections/improvements in the launching scripts.
JBC

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