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

Last change on this file since 3209 was 3145, checked in by jbclement, 2 years ago

PEM:

  • Addition of a script in LMDZ.MARS/deftank/pem/ to launch a chained simulation of 1D PCM runs which follow, year by year, the orbital parameters (obliquity, eccentricity, Ls perihelion) given in a specified file.
  • Small changes to other files of the deftank directory (check and cosmetic).

JBC

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