Back to home page

MITgcm

 
 

    


Warning, /tools/calc_diagnostics_dims is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit add29e06 on 2018-01-31 20:35:05 UTC
bce175b958 Ed H*0001 #! /usr/bin/env bash
                0002 #
                0003 #  The purpose of this script is to calculate the exact number of "z"
                0004 #  dimensions needed within a FORTRAN storage array for the MITgcm
                0005 #  diagnostics package.
                0006 
                0007 usage()
                0008 {
                0009     cat <<EOF
                0010 
                0011 Usage:  $0  data_file mitgcm_root var_name [ separator ]
                0012 
                0013 where:
                0014   data_file     : is the path and file name for the 
                0015                     "data.diagnostics" file
                0016   mitgcm_root   : is the path to the "root" directory of
                0017                     the MITgcm source tree
                0018   var_name      : is the name of the variable(s) containing
                0019                     the diagnostic strings
                0020   separator     : an optional argument specifying the 
                0021                     separator character within the data
                0022                     file (default='&')
                0023 
                0024 EOF
                0025 }
                0026 
                0027 COMMANDL="$0 $@"
                0028 
                0029 DATA_FILE="$1"
                0030 MITGCM_ROOT="$2"
                0031 VAR_NAME="$3"
                0032 SEPARATOR="$4"
                0033 nd_tot=0
                0034 
                0035 #  Check that the arguments were specified and are read-able
                0036 if test "x$DATA_FILE" = x ; then
                0037     echo "ERROR: the \"data.diagnostics\" file was not specified"
                0038     echo "  -- please set it using the first argument."
                0039     usage
                0040     exit 1
                0041 fi
                0042 pack_h="$MITGCM_ROOT"/pkg/diagnostics/diagnostics.h
                0043 if test ! -r $pack_h ; then
                0044     echo "ERROR: cannot read file \"$pack_h\" "
                0045     echo "  -- please check that the file exists and that "
                0046     echo "  \$MITGCM_ROOT is correctly set using the "
                0047     echo "  second argument."
                0048     usage
                0049     exit 1
                0050 fi
                0051 init_vals="$MITGCM_ROOT"/pkg/diagnostics/diagnostics_init_vals.F
                0052 if test ! -r $init_vals ; then
                0053     echo "ERROR: cannot read file \"$init_vals\" "
                0054     echo "  -- please check that the file exists and that "
                0055     echo "  \$MITGCM_ROOT is correctly set using the "
                0056     echo "  second argument."
                0057     usage
                0058     exit 1
                0059 fi
                0060 fizhi_SIZE="$MITGCM_ROOT"/pkg/fizhi/fizhi_SIZE.h
                0061 if test ! -r $fizhi_SIZE ; then
                0062     echo "ERROR: cannot read file \"$fizhi_SIZE\" "
                0063     echo "  -- please check that the file exists and that "
                0064     echo "  \$MITGCM_ROOT is correctly set using the "
                0065     echo "  second argument."
                0066     usage
                0067     exit 1
                0068 fi
                0069 if test "x$VAR_NAME" = x ; then
                0070     echo "ERROR: \"\$VAR_NAME\" was not specified -- please set it"
                0071     echo "  using the third argument."
                0072     usage
                0073     exit 1
                0074 fi
                0075 if test "x$SEPARATOR" = x ; then
                0076     SEPARATOR='&'
                0077 fi
                0078 if test ! -r $DATA_FILE ; then
                0079     echo "ERROR: cannot read file \"$DATA_FILE\""
                0080     usage
                0081     exit 1
                0082 fi
                0083 
                0084 
                0085 #  Get the diagnostic names
                0086 echo -n "" > ./tmp_diagnostic_names
                0087 DNAMES=
                0088 vcode=0
                0089 cat $DATA_FILE | while read line ; do
                0090     r0=t
                0091     r1=t
                0092     echo $line | grep '^[ ]*#' > /dev/null 2>&1  &&  r0=f
                0093     echo $line | grep "$SEPARATOR" > /dev/null 2>&1  &&  r1=f
                0094     if test "x$vcode" = x1 ; then
                0095         echo $line | grep '=' > /dev/null 2>&1  &&  vcode=0
                0096     fi
                0097     echo $line | grep "$VAR_NAME"'[ ]*=' > /dev/null 2>&1  &&  vcode=1
                0098     if test $r0 = t -a $r1 = t -a ! "x$vcode" = x0 ; then
                0099         t1=`echo $line | sed -e "s|$VAR_NAME| |g" | sed -e 's|=| |g'`
                0100         t2=`echo $t1 | sed -e "s|'| |g" | sed -e 's|,| |g'`
                0101         echo "$t2" >> ./tmp_diagnostic_names
                0102     fi
                0103 done
                0104 DNAMES=`cat ./tmp_diagnostic_names`
                0105 rm -rf ./tmp_diagnostic_names
                0106 
                0107 #  Get the size of $NRPHYS
                0108 t1=`cat $fizhi_SIZE | grep -i Nrphys | grep -i "^[ ]*parameter"`
                0109 t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g' | sed -e 's|=| |g'`
                0110 NRPHYS=`echo $t2 | awk '{print $3}'`
                0111 
                0112 #  Get the number of "z" dimensions
                0113 numz=0
                0114 for dnam in $DNAMES ; do
                0115     t1=`grep -i "n"$dnam $pack_h | grep -i '^[ ]*EQUIVALENCE'`
                0116     t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g'`
                0117     t3=`echo $t2 | awk '{print $3}'`
                0118     if test ! "x$t3" = x ; then
                0119         t1=`cat $init_vals | grep -i '^[ ]*KDIAG' | grep $t3`
                0120         t2=`echo $t1 | sed -e 's|(| |g' | sed -e 's|)| |g'`
                0121         t3=`echo $t2 | sed -e 's|=| |g' | awk '{print $3}'`
                0122         t1=`echo $t3 | sed -e "s|nrphys|$NRPHYS|g"`
                0123         numz=$(( $numz + $t1 ))
                0124     fi
                0125 done
                0126 echo "$numz"