| 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 |
DEBUG="--dbg_lvl=0" |
| 8 |
|
| 9 |
inone=$1 |
| 10 |
inone=${1:?"You must input an mnc filename to be xploded"} |
| 11 |
|
| 12 |
for somefile in $@ |
| 13 |
do |
| 14 |
echo Extracting from file $somefile... |
| 15 |
if [ ! -s $somefile ]; then |
| 16 |
echo "Error: $somefile is missing or empty" |
| 17 |
exit 1 |
| 18 |
fi |
| 19 |
|
| 20 |
# Finding all the multidimensional variables |
| 21 |
varls=$(ncdump -h $somefile | grep "double\|float" | grep , ) |
| 22 |
IFS=';' |
| 23 |
vars= |
| 24 |
for somevar in ${varls} |
| 25 |
do |
| 26 |
somevar1=${somevar%(*} |
| 27 |
somevar1=${somevar1#*double } |
| 28 |
somevar1=${somevar1#*float } |
| 29 |
# echo $somevar1 |
| 30 |
vars=${vars}$somevar1' ' |
| 31 |
done |
| 32 |
echo Variables to extract: $vars iter |
| 33 |
IFS=' ' |
| 34 |
for somevar in $vars |
| 35 |
do |
| 36 |
ncks $DEBUG -v $somevar $somefile $somevar.$somefile |
| 37 |
done |
| 38 |
ncks $DEBUG -v iter $somefile iter.$somefile |
| 39 |
done |