source: trunk/LMDZ.COMMON/libf/evolution/deftank/concat_diagpem.sh @ 3321

Last change on this file since 3321 was 3214, checked in by jbclement, 9 months ago

PEM:

  • It is now possible to set the number of initial PCM calls independently of the number of "inter-PEM" PCM calls. It is useful to get a stable situation for the start of the simulation.
  • Correction of a bug: 'reshape_XIOS_output' treated the first two PCM runs instead of the last two. The numbering has been adapted in "launch_pem.sh" to get it right.
  • PEM outputs ("diagpem.nc" and "diagsoil_pem.nc") has been improved: 'Time' now evolves according to 'dt_pem' (usually year by year) and 'ecritpem' is a full variable of "time_evol_mod.F90".

JBC

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1#!/bin/bash
2################################################################
3### Script to concatenate "diagpem.nc" outputs into one file ###
4################################################################
5
6# Output file name
7output_file="diagpem_concat.nc"
8
9# Frequency of PEM outputs
10ecritpem=1
11
12# Number of initial PCM calls
13nPCM_ini=4
14
15# Number of GCM calls between each PEM call
16nPCM=2
17
18# List of NetCDF files to concatenate
19directory="diags"
20files=($directory/diagpem*.nc)
21output_file=($directory/$output_file)
22
23
24################################################################
25# Checking if everything is ok
26if [ ! -d "$directory" ]; then
27    echo "Error: directory \"$diags\" not found!"
28    exit 1
29fi
30if [ ${#files[@]} -lt 2 ]; then
31    echo "Error: there are not enough files for concatenation!"
32    exit 1
33fi
34if [ -f "$output_file" ]; then
35    rm $output_file
36fi
37
38# Loop to concatenate the NetCDF files
39newTime=$((nPCM_ini + 1))
40for file in "${files[@]}"; do
41    # Extract the 'Time' variable into a temporary file
42    ncks -v Time "$file" > tmp_Time.txt
43
44    # Extract the 'data' block containing the Time values
45    data_block=$(awk '/data:/ {flag=1} flag; /\}/ {flag=0}' tmp_Time.txt | sed '1d;$d')
46    data_block=$(echo "$data_block" | sed -e 's/^[ \t]*//')
47    data_block=$(echo "$data_block" | sed 's/Time =//')
48    data_block=$(echo "$data_block" | sed 's/;$//')
49    IFS=', ' read -ra Time_values <<< "$data_block"
50
51    # Remove the temporary file
52    rm tmp_Time.txt
53
54    # Updating the variable 'Time' with the number of the year
55    for ((i=0; i < ${#Time_values[@]}; i++)); do
56        ncap2 -O -s "Time($i)=$newTime" $file $file
57        newTime=$((newTime + ecritpem))
58    done
59   
60    # Concatenate the NetCDF file to the output
61    if [ ! -f "$output_file" ]; then
62        cp $file $output_file
63    else
64        ncrcat -O $output_file $file -o $output_file
65    fi
66    newTime=$((newTime + nPCM))
67done
68
69echo "Concatenation of \"$directory/diagpem*.nc\" files into \"$output_file\" is complete!"
Note: See TracBrowser for help on using the repository browser.