Ignore:
Timestamp:
Jul 18, 2025, 6:30:04 PM (9 days ago)
Author:
jbclement
Message:

PEM:
Setting up an automatic selection of the XIOS output file for the PEM according to the number of slopes.
JBC

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.COMMON/libf/evolution/deftank/lib_launchPEM.sh

    r3850 r3859  
    4545}
    4646
     47# To get the number of slopes for the simulation
     48get_nslope() {
     49    ns=1
     50    if [ -f "startfi.nc" ]; then
     51        ns=$(ncdump -h startfi.nc | sed -n 's/.*nslope = \([0-9]*\) ;.*/\1/p')
     52    else
     53        for f in run_PCM.def callphys.def; do
     54            if [[ -f "$f" ]]; then
     55                while IFS= read -r line; do
     56                    # Remove leading whitespace
     57                    trimmed=$(echo "$line" | sed 's/^[[:space:]]*//')
     58                    # Skip lines that are commented out
     59                    if [[ "$trimmed" == \#* ]]; then
     60                        continue
     61                    fi
     62                    # Check if line contains 'nslope = N'
     63                    if [[ "$trimmed" =~ ^nslope[[:space:]]*=[[:space:]]*([0-9]+) ]]; then
     64                        ns="${BASH_REMATCH[1]}"
     65                        break
     66                    fi
     67                done < "$f"
     68                [[ -n "$ns" ]] && break
     69            fi
     70        done
     71    fi
     72}
     73
     74# To modify the xml file according nslope
     75modify_xml() {
     76    tmp="tmp_file_def.xml"
     77    in_diurnalave=false
     78    in_diurnalave_s=false
     79
     80    sed -i 's/enabled="\.true\.\">/enabled=".false.">/g' file_def_physics_mars.xml
     81    while IFS= read -r line; do
     82        case "$line" in
     83            *'<file id="diurnalave"'*)
     84                in_diurnalave=true
     85                ;;
     86            *'<file id="diurnalave_s"'*)
     87                in_diurnalave_s=true
     88                ;;
     89        esac
     90
     91        if [[ $line == *'enabled="'* ]]; then
     92            if $in_diurnalave; then
     93                if [[ $ns -eq 1 ]]; then
     94                    line='              enabled=".true.">'
     95                else
     96                    line='              enabled=".false.">'
     97                fi
     98            elif $in_diurnalave_s; then
     99                if [[ $ns -eq 1 ]]; then
     100                    line='              enabled=".false.">'
     101                else
     102                    line='              enabled=".true.">'
     103                fi
     104            fi
     105        fi
     106
     107        case "$line" in
     108            *'</file>'*)
     109                in_diurnalave=false
     110                in_diurnalave_s=false
     111                ;;
     112        esac
     113
     114        echo "$line" >> "$tmp"
     115    done < file_def_physics_mars.xml
     116
     117    mv "$tmp" file_def_physics_mars.xml
     118}
     119
    47120# To check if everything necessary for the launching script is ok
    48121checklaunch() {
     
    120193        job_scheduler
    121194    fi
     195    # Set automatically the XIOS output file for the PEM according to the number of slopes
     196    get_nslope
     197    modify_xml
    122198}
    123199
Note: See TracChangeset for help on using the changeset viewer.