source: trunk/LMDZ.MARS/deftank/pem/launch_pem.sh @ 3090

Last change on this file since 3090 was 3088, checked in by jbclement, 20 months ago

PEM:

  • Addition of the bash script "concat_diagpem.sh" in deftank to concatenate all the "diagpem.nc" outputs into one file;
  • Addition of "writediagpem_mod.F90" inspired by the subroutine "writediagfi.F" in phymars/;
  • Renaming of PEM outputs ('startfi_PEM' -> 'startpem' and 'diagfi' -> 'diagpem');
  • Gathering of all "diagpem.nc" outputs at the same place at the end of the main PEM loop;
  • Update of "launch_pem.sh", "README" and "modify_startfi_orbit.sh" in the deftank.

JBC

  • Property svn:executable set to *
File size: 6.9 KB
Line 
1#!/bin/bash
2#####################################################################
3### Launching script for a chained simulation of PEM and GCM runs ###
4#####################################################################
5
6echo "The launching script is starting!"
7echo "The output file is \"loglaunch.txt\"."
8if [ "$1" = "bg" ]; then
9    date
10else
11    nohup "$0" bg > loglaunch.txt 2>&1 &
12    exit 1
13fi
14
15# A few parameters that might need be changed depending on your setup:
16# Path to the arch.env to source:
17source ../trunk/LMDZ.COMMON/arch.env
18
19# Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator
20OLD_LC_NUMERIC=$LC_NUMERIC
21LC_NUMERIC=en_US.UTF-8
22
23#------- Modify here the number of Earth years to be simulated ---------
24## set the number of years:
25n_earth_years=1000000
26
27#---------------- Modify here the number of GCM calls ------------------
28## set the number of GCM calls between each PEM call:
29nGCM=2
30
31#------------------ Modify here the name of PEM exe --------------------
32## fill in the name of executable for PEM:
33exePEM=pem_29_phymars_seq.e
34
35#-------------- Modify here the name of reshape XIOS exe ---------------
36## fill in the name of executable for reshape XIOS:
37exeReshape=reshape_XIOS_output_64x48x29_phymars_seq.e
38
39#------------------------------ Parameters -----------------------------
40myear=686.9725      # Number of Earth days in Martian year
41eyear=365.256363004 # Number of days in Earth year
42
43#------ Check if files/directories necessary for the script exist ------
44dir=`pwd`
45machine=`hostname`
46address=`whoami`
47if [ ! -f "exeGCM.sh" ]; then
48    echo "Error: file \"exeGCM.sh\" does not exist in $dir!"
49    exit 1
50fi
51if [ ! -f "run_PEM.def" ]; then
52    echo "Error: file \"run_PEM.def\" does not exist in $dir!"
53    exit 1
54fi
55if [ ! -f "run_GCM.def" ]; then
56    echo "Error: file \"run_GCM.def\" does not exist in $dir!"
57    exit 1
58fi
59if [ ! -f "context_lmdz_physics.xml" ]; then
60    echo "Error: file \"context_lmdz_physics.xml\" does not exist in $dir!"
61    exit 1
62fi
63if [ ! -f "field_def_physics_mars.xml" ]; then
64    echo "Error: file \"field_def_physics_mars.xml\" does not exist in $dir!"
65    exit 1
66fi
67if [ ! -f "file_def_physics_mars.xml" ]; then
68    echo "Error: file \"file_def_physics_mars.xml\" does not exist in $dir!"
69    exit 1
70fi
71if [ ! -f "iodef.xml" ]; then
72    echo "Error: file \"iodef.xml\" does not exist in $dir!"
73    exit 1
74fi
75if [ ! -d "out_GCM" ]; then
76    mkdir out_GCM
77fi
78if [ ! -d "out_PEM" ]; then
79    mkdir out_PEM
80fi
81if [ ! -d "starts" ]; then
82    mkdir starts
83fi
84if [ ! -d "diags" ]; then
85    mkdir diags
86fi
87
88#---------------------------- Initialization ---------------------------
89dir=`pwd`
90machine=`hostname`
91address=`whoami`
92echo "This is a chained simulation for PEM and GCM runs in $dir on $machine."
93convert_years=$(echo "$myear/$eyear" | bc -l)
94convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
95n_myear=$(echo "($n_earth_years/$convert_years + 0.999999)/1" | bc) # Ceiling of n_earth_years/convert_years
96echo "Number of years to simulate: $n_earth_years Earth years = $n_myear Martian years."
97i_myear=0
98iPEM=1
99((iGCM = ($iPEM - 1)*$nGCM + 1))
100cp startfi.nc starts/
101if [ -f "start.nc" ]; then
102    cp start.nc starts/
103fi
104
105# Create a temporary file to manage years of the chained simulation
106echo $i_myear $n_myear $convert_years > tmp_PEMyears.txt
107
108#---------------------- Main loop to call PEM/GCM ----------------------
109while [ $i_myear -lt $n_myear ]; do
110    #--- Loop to run GCM year by year
111    cp run_GCM.def run.def
112    if [ -f "diagfi.def" ]; then
113        rm diagfi.def
114    fi
115    if [ -f "diagfi_GCM.def" ]; then
116        cp diagfi_GCM.def diagfi.def
117    fi
118    for ((i = 1; i <= $nGCM; i++)); do
119        echo "Run GCM $iGCM: call $i/$nGCM..."
120        sed -i "s/#SBATCH --job-name=runGCM.*/#SBATCH --job-name=runGCM${iGCM}/" exeGCM.sh
121        sed -i "s/out_runGCM[0-9]\+/out_runGCM${iGCM}/" exeGCM.sh
122        sbatch -W exeGCM.sh
123        if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
124            echo "Error: the run GCM $iGCM has crashed!"
125            exit 1
126        fi
127        # Copy data files and prepare the next run
128        mv out_runGCM${iGCM} out_GCM/run${iGCM}
129        mv diagfi.nc diags/diagfi${iGCM}.nc
130        if [ -f "diagsoil.nc" ]; then
131            mv diagsoil.nc diags/diagsoil${iGCM}.nc
132        fi
133        if [ -f "stats.nc" ]; then
134            mv stats.nc diags/stats${iGCM}.nc
135        fi
136        cp Xdiurnalave.nc diags/data2reshape${iGCM}.nc
137        mv Xdiurnalave.nc data2reshape${i}.nc
138        cp restartfi.nc starts/startfi${iGCM}.nc
139        mv restartfi.nc startfi.nc
140        if [ -f "restart.nc" ]; then
141            cp restart.nc starts/restart${iGCM}.nc
142            mv restart.nc start.nc
143        elif [ -f "restart1D.txt" ]; then
144            cp restart1D.txt starts/restart1D${iGCM}.txt
145            mv restart1D.txt start1D.txt
146        fi
147        ((iGCM++))
148        ((i_myear++))
149        echo "Done!"
150    done
151    echo $i_myear $n_myear $convert_years > tmp_PEMyears.txt
152    #--- Reshaping GCM data with XIOS
153    echo "Reshaping GCM data with XIOS..."
154    ./$exeReshape
155    for file in datareshaped*; do
156        mv $file ${file/reshaped/_GCM_Y}
157    done
158    echo "Done!"
159    #--- Running PEM
160    echo "Run PEM $iPEM..."
161    cp run_PEM.def run.def
162    if [ -f "diagfi.def" ]; then
163        rm diagfi.def
164    fi
165    if [ -f "diagfi_PEM.def" ]; then
166        cp diagfi_PEM.def diagfi.def
167    fi
168    mv startfi.nc startfi_evol.nc
169    if [ -f "start.nc" ]; then
170        mv start.nc start_evol.nc
171    elif [ -f "start1D.txt" ]; then
172        mv start1D.txt start1D_evol.txt
173    fi
174    ./$exePEM > out_runPEM${iPEM} 2>&1
175    if [ ! -f "restartfi_evol.nc" ]; then # Check if run ended abnormally
176        echo "Error: the run PEM $iPEM has crashed!"
177        exit 1
178    fi
179    # Copy data files and prepare the next run
180    mv out_runPEM${iPEM} out_PEM/run${iPEM}
181    mv diagpem.nc diags/diagpem_${iPEM}.nc
182    cp restartpem.nc starts/startpem_${iPEM}.nc
183    mv restartpem.nc startpem.nc
184    cp restartfi_evol.nc starts/startfi_postPEM${iPEM}.nc
185    mv restartfi_evol.nc startfi.nc
186    if [ -f "restart_evol.nc" ]; then
187        cp restart_evol.nc starts/restart_postPEM${iPEM}.nc
188        mv restart_evol.nc start.nc
189    elif [ -f "restart1D_evol.txt" ]; then
190        cp restart1D_evol.txt starts/restart1D_postPEM${iPEM}.txt
191        mv restart1D_evol.txt start1D.txt
192    fi
193    ((iPEM++))
194    read i_myear n_myear convert_years < tmp_PEMyears.txt
195    echo "Done!"
196done
197
198# Delete the temporary file to manage years of the chained simulation
199rm tmp_PEMyears.txt
200
201# Restore the previous value of LC_NUMERIC
202LC_NUMERIC=$OLD_LC_NUMERIC
203
204#----------------- Preparation for relaunch if needed ------------------
205#echo "Reinitializing starting files..."
206#cp starts/startfi.nc .
207#for file in profiles/*_0; do
208#    cp $file ${file/_0/}
209#done
210#echo "Done!"
211
212date
213echo "The launching script has terminated."
Note: See TracBrowser for help on using the repository browser.