| 1 |
edhill |
1.1 |
#! /usr/bin/env bash |
| 2 |
|
|
# |
| 3 |
|
|
# $Header: $ |
| 4 |
|
|
# $Name: $ |
| 5 |
|
|
|
| 6 |
|
|
# The purpose of this script is to calculate the exact number of "z" |
| 7 |
|
|
# dimensions needed within a FORTRAN storage array for the MITgcm |
| 8 |
|
|
# diagnostics package. |
| 9 |
|
|
|
| 10 |
|
|
usage() |
| 11 |
|
|
{ |
| 12 |
|
|
cat <<EOF |
| 13 |
|
|
|
| 14 |
|
|
Usage: $0 data_file mitgcm_root var_name [ separator ] |
| 15 |
|
|
|
| 16 |
|
|
where: |
| 17 |
|
|
data_file : is the path and file name for the |
| 18 |
|
|
"data.diagnostics" file |
| 19 |
|
|
mitgcm_root : is the path to the "root" directory of |
| 20 |
|
|
the MITgcm source tree |
| 21 |
|
|
var_name : is the name of the variable(s) containing |
| 22 |
|
|
the diagnostic strings |
| 23 |
|
|
separator : an optional argument specifying the |
| 24 |
|
|
separator character within the data |
| 25 |
|
|
file (default='&') |
| 26 |
|
|
|
| 27 |
|
|
EOF |
| 28 |
|
|
} |
| 29 |
|
|
|
| 30 |
|
|
COMMANDL="$0 $@" |
| 31 |
|
|
|
| 32 |
|
|
DATA_FILE="$1" |
| 33 |
|
|
MITGCM_ROOT="$2" |
| 34 |
|
|
VAR_NAME="$3" |
| 35 |
|
|
SEPARATOR="$4" |
| 36 |
|
|
nd_tot=0 |
| 37 |
|
|
|
| 38 |
|
|
# Check that the arguments were specified and are read-able |
| 39 |
|
|
if test "x$DATA_FILE" = x ; then |
| 40 |
|
|
echo "ERROR: the \"data.diagnostics\" file was not specified" |
| 41 |
|
|
echo " -- please set it using the first argument." |
| 42 |
|
|
usage |
| 43 |
|
|
exit 1 |
| 44 |
|
|
fi |
| 45 |
|
|
pack_h="$MITGCM_ROOT"/pkg/diagnostics/diagnostics.h |
| 46 |
|
|
if test ! -r $pack_h ; then |
| 47 |
|
|
echo "ERROR: cannot read file \"$pack_h\" " |
| 48 |
|
|
echo " -- please check that the file exists and that " |
| 49 |
|
|
echo " \$MITGCM_ROOT is correctly set using the " |
| 50 |
|
|
echo " second argument." |
| 51 |
|
|
usage |
| 52 |
|
|
exit 1 |
| 53 |
|
|
fi |
| 54 |
|
|
init_vals="$MITGCM_ROOT"/pkg/diagnostics/diagnostics_init_vals.F |
| 55 |
|
|
if test ! -r $init_vals ; then |
| 56 |
|
|
echo "ERROR: cannot read file \"$init_vals\" " |
| 57 |
|
|
echo " -- please check that the file exists and that " |
| 58 |
|
|
echo " \$MITGCM_ROOT is correctly set using the " |
| 59 |
|
|
echo " second argument." |
| 60 |
|
|
usage |
| 61 |
|
|
exit 1 |
| 62 |
|
|
fi |
| 63 |
|
|
fizhi_SIZE="$MITGCM_ROOT"/pkg/fizhi/fizhi_SIZE.h |
| 64 |
|
|
if test ! -r $fizhi_SIZE ; then |
| 65 |
|
|
echo "ERROR: cannot read file \"$fizhi_SIZE\" " |
| 66 |
|
|
echo " -- please check that the file exists and that " |
| 67 |
|
|
echo " \$MITGCM_ROOT is correctly set using the " |
| 68 |
|
|
echo " second argument." |
| 69 |
|
|
usage |
| 70 |
|
|
exit 1 |
| 71 |
|
|
fi |
| 72 |
|
|
if test "x$VAR_NAME" = x ; then |
| 73 |
|
|
echo "ERROR: \"\$VAR_NAME\" was not specified -- please set it" |
| 74 |
|
|
echo " using the third argument." |
| 75 |
|
|
usage |
| 76 |
|
|
exit 1 |
| 77 |
|
|
fi |
| 78 |
|
|
if test "x$SEPARATOR" = x ; then |
| 79 |
|
|
SEPARATOR='&' |
| 80 |
|
|
fi |
| 81 |
|
|
if test ! -r $DATA_FILE ; then |
| 82 |
|
|
echo "ERROR: cannot read file \"$DATA_FILE\"" |
| 83 |
|
|
usage |
| 84 |
|
|
exit 1 |
| 85 |
|
|
fi |
| 86 |
|
|
|
| 87 |
|
|
|
| 88 |
|
|
# Get the diagnostic names |
| 89 |
|
|
echo -n "" > ./tmp_diagnostic_names |
| 90 |
|
|
DNAMES= |
| 91 |
|
|
vcode=0 |
| 92 |
|
|
cat $DATA_FILE | while read line ; do |
| 93 |
|
|
r0=t |
| 94 |
|
|
r1=t |
| 95 |
|
|
echo $line | grep '^[ ]*#' > /dev/null 2>&1 && r0=f |
| 96 |
|
|
echo $line | grep "$SEPARATOR" > /dev/null 2>&1 && r1=f |
| 97 |
|
|
if test "x$vcode" = x1 ; then |
| 98 |
|
|
echo $line | grep '=' > /dev/null 2>&1 && vcode=0 |
| 99 |
|
|
fi |
| 100 |
|
|
echo $line | grep "$VAR_NAME"'[ ]*=' > /dev/null 2>&1 && vcode=1 |
| 101 |
|
|
if test $r0 = t -a $r1 = t -a ! "x$vcode" = x0 ; then |
| 102 |
|
|
t1=`echo $line | sed -e "s|$VAR_NAME| |g" | sed -e 's|=| |g'` |
| 103 |
|
|
t2=`echo $t1 | sed -e "s|'| |g" | sed -e 's|,| |g'` |
| 104 |
|
|
echo "$t2" >> ./tmp_diagnostic_names |
| 105 |
|
|
fi |
| 106 |
|
|
done |
| 107 |
|
|
DNAMES=`cat ./tmp_diagnostic_names` |
| 108 |
|
|
rm -rf ./tmp_diagnostic_names |
| 109 |
|
|
|
| 110 |
|
|
# Get the size of $NRPHYS |
| 111 |
|
|
t1=`cat $fizhi_SIZE | grep -i Nrphys | grep -i "^[ ]*parameter"` |
| 112 |
|
|
t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g' | sed -e 's|=| |g'` |
| 113 |
|
|
NRPHYS=`echo $t2 | awk '{print $3}'` |
| 114 |
|
|
|
| 115 |
|
|
# Get the number of "z" dimensions |
| 116 |
|
|
numz=0 |
| 117 |
|
|
for dnam in $DNAMES ; do |
| 118 |
|
|
t1=`grep -i "n"$dnam $pack_h | grep -i '^[ ]*EQUIVALENCE'` |
| 119 |
|
|
t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g'` |
| 120 |
|
|
t3=`echo $t2 | awk '{print $3}'` |
| 121 |
|
|
if test ! "x$t3" = x ; then |
| 122 |
|
|
t1=`cat $init_vals | grep -i '^[ ]*KDIAG' | grep $t3` |
| 123 |
|
|
t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g'` |
| 124 |
|
|
t3=`echo $t2 | sed -e 's|=| |g' | awk '{print $3}'` |
| 125 |
|
|
t1=`echo $t3 | sed -e "s|nrphys|$NRPHYS|g"` |
| 126 |
|
|
numz=$(( $numz + $t1 )) |
| 127 |
|
|
fi |
| 128 |
|
|
done |
| 129 |
|
|
echo "$numz" |