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

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