source: trunk/LMDZ.COMMON/libf/evolution/deftank/launch_orb_1Dchained.sh @ 3182

Last change on this file since 3182 was 3181, checked in by jbclement, 2 years ago

PEM:

  • Addition of a script "inipem_orbit.sh" in the deftank to modify the orbital parameters of a file "startfi.nc" according to the date set in the file "run_PEM.def" and data found in "obl_ecc_lsp.asc";
  • Flow of glaciers is now computed only when there are slopes;
  • Reversion to the name "diagpem.nc" for the PEM outputs (as decided) which was modified in r3171;
  • Some small cleanings.

JBC

  • Property svn:executable set to *
File size: 6.7 KB
Line 
1#!/bin/bash
2################################################################
3### Launching script for a chained simulation of 1D PCM 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 years for initialization ----------
24## set the number of Earth years before present to start:
25eyears_bp_ini=-1000
26
27#---------- Modify here the number of years to be simulated ------------
28## set the number of Martian years:
29n_myears=500
30
31#------------------ Modify here the name of PCM exe --------------------
32## fill in the name of executable for PCM:
33exePCM="testphys1d_29_phymars_para.e"
34
35#----------- Modify here the name of the orbital data file -------------
36## fill in the name of executable for PCM:
37orb_data="obl_ecc_lsp.asc"
38
39#------ Check if files/directories necessary for the script exist ------
40dir=`pwd`
41machine=`hostname`
42address=`whoami`
43if [ ! -f "$exePCM" ]; then
44    echo "Error: file \"$exePCM\" does not exist in $dir!"
45    exit 1
46fi
47if [ ! -f "$orb_data" ]; then
48    echo "Error: file \"$orb_data\" does not exist in $dir!"
49    exit 1
50fi
51if [ ! -f "startfi.nc" ]; then
52    echo "Error: file \"startfi.nc\" does not exist in $dir!"
53    exit 1
54fi
55if [ ! -d "out_PCM" ]; then
56    mkdir out_PCM
57fi
58if [ ! -d "starts" ]; then
59    mkdir starts
60fi
61if [ ! -d "diags" ]; then
62    mkdir diags
63fi
64
65#---------------------------- Initialization ---------------------------
66dir=`pwd`
67machine=`hostname`
68address=`whoami`
69echo "This is a chained simulation for PCM runs in $dir on $machine."
70echo "Number of years to be simulated: $n_myears Martian years."
71myear=686.9725      # Number of Earth days in Martian year
72eyear=365.256363004 # Number of days in Earth year
73convert_years=$(echo "$myear/$eyear" | bc -l)
74convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year
75i_myear=0
76iPCM=1
77cp startfi.nc starts/
78if [ -f "star1D.nc" ]; then
79    cp star1D.txt starts/
80fi
81
82#---------------- Main loop to to run PCM year by year -----------------
83while [ $i_myear -lt $n_myears ]; do
84    # Get the new values for the orbital parameters
85    yearlask=$(echo "$eyears_bp_ini + $i_myear*$convert_years" | bc -l)
86    found=false
87    read -r y1 obl1 ecc1 lsp1 < "$orb_data"
88    while read -r y2 obl2 ecc2 lsp2; do
89        if [ "$first_line" = true ]; then
90            first_line=false
91            continue # Skip the first line as it's already read outside the loop
92        fi
93        if [ "$(echo "$y1 >= $yearlask && $yearlask > $y2" | bc)" -eq 1 ]; then
94            found=true
95            # Calculate linear interpolations for each orbital parameter
96            new_obl=$(echo "($obl2 - $obl1)/($y2 - $y1)*($yearlask - $y1) + $obl1" | bc -l)
97            new_ecc=$(echo "($ecc2 - $ecc1)/($y2 - $y1)*($yearlask - $y1) + $ecc1" | bc -l)
98            if [ "$(echo "$lsp2 - $lsp1 > 300. || $lsp2 - $lsp1 < -300." | bc)" -eq 1 ]; then # If modulo is "crossed" through the interval
99                if [ "$(echo "$lsp1 < $lsp2" | bc -l)" -eq 1 ]; then # Lsp should be decreasing
100                    lsp1=$(echo "$lsp1 + 360" | bc -l)
101                else # Lsp should be increasing
102                    lsp2=$(echo "$lsp2 + 360" | bc -l)
103                fi
104            fi
105            new_Lsp=$(echo "($lsp2 - $lsp1)/($y2 - $y1)*($yearlask - $y1) + $lsp1" | bc -l)
106            echo "New obliquity    = $new_obl"
107            echo "New eccentricity = $new_ecc"
108            echo "New Lsp          = $new_Lsp"
109            echo "Done!"
110            break
111        fi
112        y1=$y2
113        obl1=$obl2
114        ecc1=$ecc2
115        lsp1=$lsp2
116    done < "$orb_data"
117    if [ "$found" = false ]; then
118        echo "Error: the current year could not be found in the file \"$orb_data\"!"
119        exit 1
120    fi
121    # Compute the modified values in the "starfi.nc"
122    year_day=669.
123    halfaxe=227.94
124    pi=$(echo "4.*a(1.)" | bc -l)
125    degrad=$(echo "180./$pi" | bc -l)
126    periheli=$(echo "$halfaxe*(1. - $new_ecc)" | bc -l)
127    aphelie=$(echo "$halfaxe*(1. + $new_ecc)" | bc -l)
128    tan=$(echo "s(0.5*$new_Lsp/$degrad)/c(0.5*$new_Lsp/$degrad)" | bc -l)
129    zx0=$(echo "-2.*a($tan*sqrt((1. - $new_ecc)/(1. + $new_ecc)))" | bc -l)
130    if [ $(echo "$zx0 <= 0." | bc -l) -eq 1 ]; then
131        zx0=$(echo "$zx0 + 2.*$pi" | bc -l)
132    fi
133    peri_day=$(echo "$year_day*(1. - ($zx0 - $new_ecc*s($zx0))/(2.*$pi))" | bc -l)
134    ztheta=$(echo "($new_iniLs - $new_Lsp)/$degrad" | bc -l)
135    tan=$(echo "s(0.5*$ztheta)/c(0.5*$ztheta)" | bc -l)
136    zx0=$(echo "2.*a($tan*sqrt((1. - $new_ecc)/(1. + $new_ecc)))" | bc -l)
137    xref=$(echo "$zx0 - $new_ecc*s($zx0)" | bc -l)
138    # Modify the orbital parameters
139      # controle(15) = periheli ! min. Sun-Mars distance (Mkm)  ̃206.66
140      # controle(16) = aphelie  ! max. SUn-Mars distance (Mkm)  ̃249.22
141      # controle(17) = peri_day ! date of perihelion (sols since N. spring)
142      # controle(18) = obliquit ! Obliquity of the planet (deg)  ̃23.98
143    ncap2 -O -s "controle(17)=$new_obl" \
144             -s "controle(14)=$periheli" \
145             -s "controle(15)=$aphelie" \
146             -s "controle(16)=$peri_day" \
147             "startfi.nc" "startfi.nc"
148    echo "New periheli = $periheli"
149    echo "New aphelie  = $aphelie"
150    echo "New peri_day = $peri_day"
151    echo "Done!"
152    # Run the PCM
153    echo "Run PCM $iPCM: year $iPCM/$n_myears..."
154    ./$exePCM > out_runPCM${iPCM} 2>&1
155    if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally
156        echo "Error: the run PCM $iPCM has crashed!"
157        exit 1
158    fi
159    # Copy data files and prepare the next run
160    mv out_runPCM${iPCM} out_PCM/run${iPCM}
161    mv diagfi.nc diags/diagfi${iPCM}.nc
162    if [ -f "diagsoil.nc" ]; then
163        mv diagsoil.nc diags/diagsoil${iPCM}.nc
164    fi
165    if [ -f "stats.nc" ]; then
166        mv stats.nc diags/stats${iPCM}.nc
167    fi
168    if [ -f "Xdiurnalave.nc" ]; then
169        mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc
170    fi
171    cp restartfi.nc starts/startfi${iPCM}.nc
172    mv restartfi.nc startfi.nc
173    if [ -f "restart1D.txt" ]; then
174        cp restart1D.txt starts/restart1D${iPCM}.txt
175        mv restart1D.txt start1D.txt
176    fi
177    ((iPCM++))
178    ((i_myear++))
179    echo "Done!"
180done
181
182# Restore the previous value of LC_NUMERIC
183LC_NUMERIC=$OLD_LC_NUMERIC
184
185date
186echo "The launching script has terminated."
Note: See TracBrowser for help on using the repository browser.