source: trunk/LMDZ.COMMON/libf/evolution/deftank/inipem_orbit.sh @ 3792

Last change on this file since 3792 was 3666, checked in by jbclement, 4 months ago

PEM:

  • Adjusments of few scripts to handle more situations.
  • Bug correction related to deallocation in case of "soil_pem = .false." or "layering_algo = .true.".

JBC

  • Property svn:executable set to *
File size: 4.4 KB
Line 
1#!/bin/bash
2######################################################################
3### Script to modify the orbital parameters of a file "startfi.nc" ###
4### according to the date set in the file "run_PEM.def"            ###
5######################################################################
6set -e
7trap 'echo -e "\033[31mError: an issue occurred in the script on line $LINENO! Please review the command and try again.\033[0m"' ERR
8
9######################################################################
10# Modify here the parameters for the script
11###########################################
12# Name of the file to be modified
13name_file="startfi.nc"
14
15# Name of the file containing the orbital data
16orb_data="obl_ecc_lsp.asc"
17
18# Name of the file containing the starting date (Earth years)
19date_file="run_PEM.def"
20######################################################################
21
22
23# Check if files necessary for the script exist
24if [ ! -f "$orb_data" ]; then
25    echo "Error: file \"$orb_data\" not found!"
26    exit 1
27fi
28if [ ! -f "$name_file" ]; then
29    echo "Error: file \"$name_file\" not found!"
30    exit 1
31fi
32if [ ! -f "$date_file" ]; then
33    echo "Error: file \"$date_file\" not found!"
34    exit 1
35fi
36
37# Get the number of Earth years before present to start the PEM run
38eyears_bp_ini=$(grep 'year_earth_bp_ini=' $date_file | cut -d '=' -f 2 | tr -d '[:space:]')
39echo "In \"$date_file\":"
40echo "The starting date is $eyears_bp_ini Earth years."
41
42# Get the new values for the orbital parameters
43yearlask=$(echo "$eyears_bp_ini/1000." | bc -l)
44found=false
45read -r y1 obl1 ecc1 lsp1 < "$orb_data"
46while read -r y2 obl2 ecc2 lsp2; do
47    if [ "$first_line" = true ]; then
48        first_line=false
49        continue # Skip the first line as it's already read outside the loop
50    fi
51    if [ "$(echo "$y1 >= $yearlask && $yearlask > $y2" | bc)" -eq 1 ]; then
52        found=true
53        # Calculate linear interpolations for each orbital parameter
54        new_obl=$(echo "($obl2 - $obl1)/($y2 - $y1)*($yearlask - $y1) + $obl1" | bc -l)
55        new_ecc=$(echo "($ecc2 - $ecc1)/($y2 - $y1)*($yearlask - $y1) + $ecc1" | bc -l)
56        if [ "$(echo "$lsp2 - $lsp1 > 300. || $lsp2 - $lsp1 < -300." | bc)" -eq 1 ]; then # If modulo is "crossed" through the interval
57            if [ "$(echo "$lsp1 < $lsp2" | bc -l)" -eq 1 ]; then # Lsp should be decreasing
58                lsp1=$(echo "$lsp1 + 360" | bc -l)
59            else # Lsp should be increasing
60                lsp2=$(echo "$lsp2 + 360" | bc -l)
61            fi
62        fi
63        new_Lsp=$(echo "($lsp2 - $lsp1)/($y2 - $y1)*($yearlask - $y1) + $lsp1" | bc -l)
64        echo "In \"$orb_data\":"
65        echo "Found obliquity    = $new_obl"
66        echo "Found eccentricity = $new_ecc"
67        echo "Found Lsp          = $new_Lsp"
68        break
69    fi
70    y1=$y2
71    obl1=$obl2
72    ecc1=$ecc2
73    lsp1=$lsp2
74done < "$orb_data"
75if [ "$found" = false ]; then
76    echo "Error: the current year could not be found in the file \"$orb_data\"!"
77    exit 1
78fi
79
80
81# Compute the modified values in the file
82if [ ! -f "$name_file" ]; then
83    echo "Error: file \"$name_file\" not found!"
84    exit 1
85fi
86year_day=669.
87halfaxe=227.94
88pi=$(echo "4.*a(1.)" | bc -l)
89degrad=$(echo "180./$pi" | bc -l)
90
91periheli=$(echo "$halfaxe*(1. - $new_ecc)" | bc -l)
92aphelie=$(echo "$halfaxe*(1. + $new_ecc)" | bc -l)
93
94tan=$(echo "s(0.5*$new_Lsp/$degrad)/c(0.5*$new_Lsp/$degrad)" | bc -l)
95zx0=$(echo "-2.*a($tan*sqrt((1. - $new_ecc)/(1. + $new_ecc)))" | bc -l)
96if [ $(echo "$zx0 <= 0." | bc -l) -eq 1 ]; then
97    zx0=$(echo "$zx0 + 2.*$pi" | bc -l)
98fi
99peri_day=$(echo "$year_day*(1. - ($zx0 - $new_ecc*s($zx0))/(2.*$pi))" | bc -l)
100
101# Update the netCDF file
102# controle(15) = periheli ! min. Sun-Mars distance (Mkm)  ̃206.66
103# controle(16) = aphelie  ! max. SUn-Mars distance (Mkm)  ̃249.22
104# controle(17) = peri_day ! date of perihelion (sols since N. spring)
105# controle(18) = obliquit ! Obliquity of the planet (deg)  ̃23.98
106# controle(3)  = day_ini + int(time) ! initial day
107ncap2 -O -s "controle(17)=$new_obl" \
108         -s "controle(14)=$periheli" \
109         -s "controle(15)=$aphelie" \
110         -s "controle(16)=$peri_day" \
111         $name_file $name_file
112
113echo "In \"$name_file\":"
114echo "New obliquit     = $new_obl"
115echo "New eccentricity = $new_ecc -> new periheli = $periheli"
116echo "                                         -> new aphelie  = $aphelie"
117echo "New Lsp          = $new_Lsp -> new peri_day = $peri_day"
118echo "Done!"
Note: See TracBrowser for help on using the repository browser.