source: trunk/LMDZ.MARS/deftank/launch_orb_1Dchained.sh @ 3493

Last change on this file since 3493 was 3465, checked in by jbclement, 2 months ago

Mars PCM:

  • Small update in "analyse_netcdf.py".
  • Putting the 1D launching scripts back to the "deftank" folder.

JBC

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