1 |
baylor |
1.1 |
#!/bin/bash |
2 |
|
|
# This is a shell script to separate an MITgcm mnc output file into |
3 |
|
|
# one file per multi-dimensional variable. |
4 |
|
|
# The file should be in one directory, where this script is run. |
5 |
|
|
# The resulting files will be in the same directory. |
6 |
|
|
|
7 |
|
|
inone=$1 |
8 |
|
|
inone=${1:?"You must input an mnc filename to be xploded"} |
9 |
|
|
|
10 |
|
|
for somefile in $@ |
11 |
|
|
do |
12 |
|
|
echo Extracting from file $somefile... |
13 |
|
|
if [ ! -s $somefile ]; then |
14 |
|
|
echo "Error: $somefile is missing or empty" |
15 |
|
|
exit 1 |
16 |
|
|
fi |
17 |
|
|
|
18 |
|
|
varls=$(ncdump -h $somefile | grep double | grep ,) |
19 |
|
|
IFS=';' |
20 |
|
|
vars= |
21 |
|
|
for somevar in ${varls} |
22 |
|
|
do |
23 |
|
|
somevar1=${somevar%(*} |
24 |
|
|
somevar1=${somevar1#*double } |
25 |
|
|
vars=${vars}$somevar1' ' |
26 |
|
|
done |
27 |
|
|
echo Variables to extract: $vars |
28 |
|
|
IFS=' ' |
29 |
|
|
for somevar in $vars |
30 |
|
|
do |
31 |
|
|
ncks -v $somevar $somefile $somevar.$somefile |
32 |
|
|
done |
33 |
|
|
done |