[3026] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # Bash script to modify the orbital parameters of a file "startfi.nc" |
---|
| 4 | name_file="startfi.nc" |
---|
| 5 | |
---|
| 6 | new_Ls=90. |
---|
| 7 | Lsp=347.443947402 |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | # Extract the 'controle' variable into a temporary file |
---|
| 11 | ncks -v controle $name_file > tmp_controle.txt |
---|
| 12 | |
---|
| 13 | # Extract the 'data' block containing the controle values |
---|
| 14 | data_block=$(awk '/data:/ {flag=1} flag; /\}/ {flag=0}' tmp_controle.txt | sed '1d;$d') |
---|
| 15 | |
---|
| 16 | # Remove unnecessary characters |
---|
| 17 | data_block=$(echo "$data_block" | sed -e 's/^[ \t]*//') |
---|
| 18 | data_block=$(echo "$data_block" | sed 's/controle =//') |
---|
| 19 | data_block=$(echo "$data_block" | sed 's/;$//') |
---|
| 20 | |
---|
| 21 | # Convert the data block into an array |
---|
| 22 | IFS=', ' read -ra controle_values <<< "$data_block" |
---|
| 23 | #for value in "${controle_values[@]}"; do |
---|
| 24 | # echo "$value" |
---|
| 25 | #done |
---|
| 26 | |
---|
| 27 | # Remove the temporary file |
---|
| 28 | rm tmp_controle.txt |
---|
| 29 | |
---|
| 30 | # Calculate modified values |
---|
| 31 | halfaxe=227.94 |
---|
| 32 | #year_day=668.6 |
---|
| 33 | year_day=${controle_values[13]} |
---|
| 34 | peri_day=${controle_values[16]} |
---|
| 35 | pi=$(echo "4*a(1)" | bc -l) |
---|
| 36 | degrad=$(echo "360./(2.*$pi)" | bc -l) |
---|
| 37 | timeperi=$(echo "(1. - $Lsp)/$degrad" | bc -l) |
---|
| 38 | e_elips=$(echo "1.-${controle_values[14]}/$halfaxe" | bc -l) |
---|
| 39 | abs_new_Ls=$(echo "if($new_Ls < 0) -($new_Ls) else $new_Ls" | bc -l) |
---|
| 40 | |
---|
| 41 | if [ $(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 |
---|
| 47 | else |
---|
| 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 |
---|
| 60 | fi |
---|
| 61 | |
---|
| 62 | # Update the netCDF file |
---|
| 63 | # tab_cntrl(3) = day_ini + int(time) ! initial day |
---|
| 64 | ncap2 -O -s "controle(2)=$new_sol" \ |
---|
| 65 | $name_file $name_file.temp |
---|
| 66 | |
---|
| 67 | # Rename the temporary file back to the original filename |
---|
| 68 | mv $name_file.temp $name_file |
---|
| 69 | |
---|
| 70 | echo New initial sol = $new_sol |
---|