[3209] | 1 | #!/bin/bash |
---|
| 2 | ################################################################ |
---|
| 3 | ### Launching script for a chained simulation of 1D PCM runs ### |
---|
| 4 | ################################################################ |
---|
| 5 | |
---|
| 6 | echo "The launching script is starting!" |
---|
| 7 | echo "The output file is \"loglaunch.txt\"." |
---|
| 8 | if [ "$1" = "bg" ]; then |
---|
| 9 | date |
---|
| 10 | else |
---|
| 11 | nohup "$0" bg > loglaunch.txt 2>&1 & |
---|
| 12 | exit 1 |
---|
| 13 | fi |
---|
| 14 | |
---|
| 15 | # A few parameters that might need be changed depending on your setup: |
---|
| 16 | # Path to the arch.env to source: |
---|
| 17 | source ../trunk/LMDZ.COMMON/arch.env |
---|
| 18 | |
---|
| 19 | # Save the current value of LC_NUMERIC and set it to a locale that uses a dot as the decimal separator |
---|
| 20 | OLD_LC_NUMERIC=$LC_NUMERIC |
---|
| 21 | LC_NUMERIC=en_US.UTF-8 |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | ################################################################ |
---|
| 25 | #---------- Modify here the number of years to be simulated ------------ |
---|
| 26 | ## set the number of Martian years: |
---|
| 27 | n_myears=1000 |
---|
| 28 | |
---|
| 29 | #------------------ Modify here the name of PCM exe -------------------- |
---|
| 30 | ## fill in the name of executable for PCM: |
---|
| 31 | exePCM="testphys1d_29_phymars_seq.e" |
---|
| 32 | ################################################################ |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | #------ Check if files/directories necessary for the script exist ------ |
---|
| 36 | dir=`pwd` |
---|
| 37 | machine=`hostname` |
---|
| 38 | address=`whoami` |
---|
| 39 | if [ ! -f "$exePCM" ]; then |
---|
| 40 | echo "Error: file \"$exePCM\" does not exist in $dir!" |
---|
| 41 | exit 1 |
---|
| 42 | fi |
---|
| 43 | if [ ! -d "out_PCM" ]; then |
---|
| 44 | mkdir out_PCM |
---|
| 45 | fi |
---|
| 46 | if [ ! -d "starts" ]; then |
---|
| 47 | mkdir starts |
---|
| 48 | fi |
---|
| 49 | if [ ! -d "diags" ]; then |
---|
| 50 | mkdir diags |
---|
| 51 | fi |
---|
| 52 | |
---|
| 53 | #---------------------------- Initialization --------------------------- |
---|
| 54 | dir=`pwd` |
---|
| 55 | machine=`hostname` |
---|
| 56 | address=`whoami` |
---|
| 57 | echo "This is a chained simulation for PCM runs in $dir on $machine." |
---|
| 58 | echo "Number of years to be simulated: $n_myears Martian years." |
---|
| 59 | myear=686.9725 # Number of Earth days in Martian year |
---|
| 60 | eyear=365.256363004 # Number of days in Earth year |
---|
| 61 | convert_years=$(echo "$myear/$eyear" | bc -l) |
---|
| 62 | convert_years=$(printf "%.4f" $convert_years) # Rounding to the 4th decimal to respect the precision of Martian year |
---|
| 63 | i_myear=0 |
---|
| 64 | iPCM=1 |
---|
| 65 | cp startfi.nc starts/ |
---|
| 66 | if [ -f "star1D.nc" ]; then |
---|
| 67 | cp star1D.txt starts/ |
---|
| 68 | fi |
---|
| 69 | |
---|
| 70 | #---------------- Main loop to to run PCM year by year ----------------- |
---|
| 71 | while [ $i_myear -lt $n_myears ]; do |
---|
| 72 | # Run the PCM |
---|
| 73 | echo "Run PCM $iPCM: year $iPCM/$n_myears..." |
---|
| 74 | ./$exePCM > out_runPCM${iPCM} 2>&1 |
---|
| 75 | if [ ! -f "restartfi.nc" ]; then # Check if run ended abnormally |
---|
[3213] | 76 | echo "Error: the run PCM $iPCM crashed!" |
---|
[3209] | 77 | exit 1 |
---|
| 78 | fi |
---|
| 79 | # Copy data files and prepare the next run |
---|
| 80 | mv out_runPCM${iPCM} out_PCM/run${iPCM} |
---|
| 81 | mv diagfi.nc diags/diagfi${iPCM}.nc |
---|
| 82 | if [ -f "diagsoil.nc" ]; then |
---|
| 83 | mv diagsoil.nc diags/diagsoil${iPCM}.nc |
---|
| 84 | fi |
---|
| 85 | if [ -f "stats.nc" ]; then |
---|
| 86 | mv stats.nc diags/stats${iPCM}.nc |
---|
| 87 | fi |
---|
| 88 | if [ -f "Xdiurnalave.nc" ]; then |
---|
| 89 | mv Xdiurnalave.nc diags/Xdiurnalave${iPCM}.nc |
---|
| 90 | fi |
---|
| 91 | cp restartfi.nc starts/startfi${iPCM}.nc |
---|
| 92 | mv restartfi.nc startfi.nc |
---|
| 93 | if [ -f "restart1D.txt" ]; then |
---|
| 94 | cp restart1D.txt starts/restart1D${iPCM}.txt |
---|
| 95 | mv restart1D.txt start1D.txt |
---|
| 96 | fi |
---|
| 97 | ((iPCM++)) |
---|
| 98 | ((i_myear++)) |
---|
| 99 | echo "Done!" |
---|
| 100 | done |
---|
| 101 | |
---|
| 102 | # Restore the previous value of LC_NUMERIC |
---|
| 103 | LC_NUMERIC=$OLD_LC_NUMERIC |
---|
| 104 | |
---|
| 105 | date |
---|
[3213] | 106 | echo "The launching script ended." |
---|