Back to home page

MITgcm

 
 

    


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

view on githubraw file Latest commit f955de4b on 2025-01-19 04:15:59 UTC
8baeb68a7a Ed H*0001 #! /usr/bin/env bash
                0002 
f955de4ba2 Jean*0003 #  Explain usage
                0004 usage()
                0005 {
                0006   echo "Usage: `basename $0` [OPTIONS]"
                0007   echo "    -> suggest OPTFILE name for MITgcm 'genmake2' script"
                0008   echo
                0009   echo "where possible OPTIONS are:"
                0010   echo "  (-help|-h)            just print this and return"
                0011   echo "  (-keep|-k)            keep log-file and temp-script file"
                0012   echo "  (-rootdir NAME | -rd NAME ) Specify the location of the"
                0013   echo "                        MITgcm root directory as 'NAME'."
                0014   echo "                 By default, will try to find the location by"
                0015   echo "                 looking in parent directories (up to the 5th parent)."
                0016   exit 1
8baeb68a7a Ed H*0017 }
                0018 
f955de4ba2 Jean*0019 #-- Settings:
                0020 LOC_SH_FIND='find_optfile'
                0021 LOGFILE="$LOC_SH_FIND.log"
                0022 AWK=awk
                0023 rm -f $LOC_SH_FIND $LOGFILE
                0024 keep=0;
8baeb68a7a Ed H*0025 
f955de4ba2 Jean*0026 #-- Set MITgcm root directory (ROOTDIR) from environment variable "MITGCM_ROOTDIR":
309b5c610e Jean*0027 if test "x$MITGCM_ROOTDIR" = x ; then
                0028   if test "x$ROOTDIR" != x ; then
51a1c30199 Jean*0029     echo "WARNING: Environment Variable 'ROOTDIR' no longer recognized"
309b5c610e Jean*0030     echo "WARNING:  use instead 'MITGCM_ROOTDIR'" ; ROOTDIR=
                0031   fi
                0032 else
                0033   ROOTDIR=$MITGCM_ROOTDIR
                0034 fi
8baeb68a7a Ed H*0035 
f955de4ba2 Jean*0036 #-- Parse_options
                0037 yy=
                0038 for xx in "$@" ; do
8baeb68a7a Ed H*0039 
f955de4ba2 Jean*0040   # If the previous option needs an argument, assign it.
                0041   if test -n "$yy"; then
                0042     eval "$yy=\$xx"
                0043     yy=
                0044     continue
                0045   fi
                0046 
                0047   case $xx in
                0048       -help | -h )      usage ;;
                0049       -rootdir | -rd )  yy=ROOTDIR ;;
                0050       -keep | -k )      keep=1 ;;
                0051       *)                echo "Error: unrecognized argument: "$xx
                0052                         usage ;;
                0053    esac
                0054 done
                0055 
                0056 #-- Find the MITgcm root directory (${ROOTDIR})
8baeb68a7a Ed H*0057 if test "x${ROOTDIR}" = x ; then
f955de4ba2 Jean*0058     tmp=`echo $PWD | sed -e 's/\// /g' | $AWK '{print $NR}'`
                0059     if test "x$tmp" = "xbin" -a -d ../model -a -d ../eesupp -a -d ../pkg ; then
                0060         ROOTDIR=".."
8baeb68a7a Ed H*0061     else
f955de4ba2 Jean*0062         for d in . .. ../.. ../../.. ../../../.. ../../../../.. ; do
                0063             if [ -d "$d/model" -a -d "$d/eesupp" -a -d "$d/pkg" ]; then
                0064                 ROOTDIR=$d
                0065                 printf "Warning: MITgcm root directory was not specified ;"
                0066                 echo " try using a local copy of MITgcm found at \"$ROOTDIR\""
                0067                 break
                0068             fi
                0069         done
8baeb68a7a Ed H*0070     fi
                0071 fi
f955de4ba2 Jean*0072 if test "x${ROOTDIR}" = x ; then
                0073     echo "Error: Cannot determine MITgcm root directory for MITgcm code."
                0074     echo "  Please specify a root directory using either the command line"
                0075     echo "   option '-rootdir' or the environment variable 'MITGCM_ROOTDIR'."
                0076     exit 1
                0077 fi
                0078 if test ! -d ${ROOTDIR} ; then
                0079     echo "Error: the specified MITgcm root directory (\"$ROOTDIR\") does not exist!"
                0080     exit 1
                0081 fi
8baeb68a7a Ed H*0082 
f955de4ba2 Jean*0083 #---------------------------------------
                0084 #-- start to build script LOC_SH_FIND
                0085 #   by taking function "find_possible_optfile" from script "genmake2":
                0086 
                0087 sed -n '1 p' $ROOTDIR/tools/genmake2 > $LOC_SH_FIND
                0088 echo '' >> $LOC_SH_FIND
                0089 sed -n \
                0090 '/^find_possible_optfile()/,/^#---- keep this line unchanged after the end of find_possible_optfile/ p' \
                0091        $ROOTDIR/tools/genmake2 >> $LOC_SH_FIND
                0092 echo '' >> $LOC_SH_FIND
8baeb68a7a Ed H*0093 
f955de4ba2 Jean*0094 cat >> $LOC_SH_FIND <<EOF
                0095 #-- Sequential part of script starts here ---------------
                0096 ROOTDIR=\$1
                0097 LOGFILE=\$2
8baeb68a7a Ed H*0098 
f955de4ba2 Jean*0099 find_possible_optfile
8baeb68a7a Ed H*0100 
f955de4ba2 Jean*0101 #echo "  The default optfile is:  "\$PLATFORM"_"\$FC
                0102 
                0103 EOF
                0104 
                0105 chmod 744 $LOC_SH_FIND
                0106 echo "-- running: './$LOC_SH_FIND $ROOTDIR $LOGFILE' :"
                0107 ./$LOC_SH_FIND $ROOTDIR $LOGFILE
                0108 
                0109 if test $keep = 0 ; then
                0110   rm -r $LOC_SH_FIND $LOGFILE
                0111 fi
                0112 exit 0