source: trunk/LMDZ.MARS/deftank/pem/modify_startfi_Ls.sh @ 3026

Last change on this file since 3026 was 3026, checked in by jbclement, 16 months ago

Mars PCM/PEM 1D:
Small fixes to be able to run the Mars PCM 1D without "water" + Improvements/addition of scripts in deftank/pem to run the PEM 1D model according to Laskar orbital parameters.
JBC

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/bash
2
3# Bash script to modify the orbital parameters of a file "startfi.nc"
4name_file="startfi.nc"
5
6new_Ls=90.
7Lsp=347.443947402
8
9
10# Extract the 'controle' variable into a temporary file
11ncks -v controle $name_file > tmp_controle.txt
12
13# Extract the 'data' block containing the controle values
14data_block=$(awk '/data:/ {flag=1} flag; /\}/ {flag=0}' tmp_controle.txt | sed '1d;$d')
15
16# Remove unnecessary characters
17data_block=$(echo "$data_block" | sed -e 's/^[ \t]*//')
18data_block=$(echo "$data_block" | sed 's/controle =//')
19data_block=$(echo "$data_block" | sed 's/;$//')
20
21# Convert the data block into an array
22IFS=', ' read -ra controle_values <<< "$data_block"
23#for value in "${controle_values[@]}"; do
24#    echo "$value"
25#done
26
27# Remove the temporary file
28rm tmp_controle.txt
29
30# Calculate modified values
31halfaxe=227.94
32#year_day=668.6
33year_day=${controle_values[13]}
34peri_day=${controle_values[16]}
35pi=$(echo "4*a(1)" | bc -l)
36degrad=$(echo "360./(2.*$pi)" | bc -l)
37timeperi=$(echo "(1. - $Lsp)/$degrad" | bc -l)
38e_elips=$(echo "1.-${controle_values[14]}/$halfaxe" | bc -l)
39abs_new_Ls=$(echo "if($new_Ls < 0) -($new_Ls) else $new_Ls" | bc -l)
40
41if [ $(echo "$abs_new_Ls < 0.00001" | bc -l) -eq 1 ]; then
42  if [ $(echo "$new_Ls >= 0." | bc -l) -eq 1 ]; then
43    new_sol=0.
44  else
45    new_sol=$year_day
46  fi
47else 
48  zteta=$(echo "$new_Ls/$degrad + $timeperi" | bc -l)
49  tan=$(echo "s(0.5*$zteta)/c(0.5*$zteta)" | bc -l)
50  zx0=$(echo "2.*a($tan/sqrt((1.+$e_elips)/(1.-$e_elips)))" | bc -l)
51  xref=$(echo "$zx0-$e_elips*s($zx0)" | bc -l)
52  zz=$(echo "$xref/(2.*$pi)" | bc -l)
53  new_sol=$(echo "$zz*$year_day + $peri_day" | bc -l)
54  if [ $(echo "$new_sol < 0." | bc -l) -eq 1 ]; then
55      new_sol=$(echo "$new_sol + $year_day" | bc -l)
56  fi
57  if [ $(echo "$new_sol >= $year_day" | bc -l) -eq 1 ]; then
58      new_sol=$(echo "$new_sol - $year_day" | bc -l)
59  fi
60fi
61
62# Update the netCDF file
63# tab_cntrl(3) = day_ini + int(time) ! initial day
64ncap2 -O -s "controle(2)=$new_sol" \
65      $name_file $name_file.temp
66
67# Rename the temporary file back to the original filename
68mv $name_file.temp $name_file
69
70echo New initial sol = $new_sol
Note: See TracBrowser for help on using the repository browser.