1 |
jmc |
1.4 |
#! /usr/bin/env bash |
2 |
|
|
# |
3 |
|
|
# $Header: $ |
4 |
|
|
# $Name: $ |
5 |
|
|
|
6 |
baylor |
1.1 |
# This is a shell script to separate an MITgcm mnc output file into |
7 |
|
|
# one file per multi-dimensional variable. |
8 |
|
|
# The file should be in one directory, where this script is run. |
9 |
|
|
# The resulting files will be in the same directory. |
10 |
|
|
|
11 |
baylor |
1.3 |
DEBUG="--dbg_lvl=0" |
12 |
baylor |
1.2 |
|
13 |
baylor |
1.1 |
inone=$1 |
14 |
|
|
inone=${1:?"You must input an mnc filename to be xploded"} |
15 |
|
|
|
16 |
|
|
for somefile in $@ |
17 |
|
|
do |
18 |
|
|
echo Extracting from file $somefile... |
19 |
|
|
if [ ! -s $somefile ]; then |
20 |
|
|
echo "Error: $somefile is missing or empty" |
21 |
|
|
exit 1 |
22 |
|
|
fi |
23 |
|
|
|
24 |
baylor |
1.2 |
# Finding all the multidimensional variables |
25 |
|
|
varls=$(ncdump -h $somefile | grep "double\|float" | grep , ) |
26 |
baylor |
1.1 |
IFS=';' |
27 |
|
|
vars= |
28 |
|
|
for somevar in ${varls} |
29 |
|
|
do |
30 |
|
|
somevar1=${somevar%(*} |
31 |
|
|
somevar1=${somevar1#*double } |
32 |
baylor |
1.2 |
somevar1=${somevar1#*float } |
33 |
baylor |
1.3 |
# echo $somevar1 |
34 |
baylor |
1.1 |
vars=${vars}$somevar1' ' |
35 |
|
|
done |
36 |
|
|
IFS=' ' |
37 |
jmc |
1.4 |
withIter=$(ncdump -h $somefile | grep -c 'int iter(' ) |
38 |
|
|
if [ $withIter -gt 0 ]; then vars=${vars}iter ; fi |
39 |
|
|
echo Variables to extract: $vars |
40 |
baylor |
1.1 |
for somevar in $vars |
41 |
|
|
do |
42 |
baylor |
1.2 |
ncks $DEBUG -v $somevar $somefile $somevar.$somefile |
43 |
baylor |
1.1 |
done |
44 |
|
|
done |