#!/bin/sh
# --------------------------------------------------------------------------- #
# find_switch : Find compiler switches in subroutines and include files.      #
#                                                                             #
# use         : find_switch [switch]                                          #
#                 switch : any strig for which the code is to be scanned.     #
#                                                                             #
#                                                      Hendrik L. Tolman      #
#                                                      May 2009               #
#                                                                             #
#    Copyright 2009 National Weather Service (NWS),                           #
#       National Oceanic and Atmospheric Administration.  All rights          #
#       reserved.  WAVEWATCH III is a trademark of the NWS.                   #
#       No unauthorized use without permission.                               #
#                                                                             #
# --------------------------------------------------------------------------- #
# 1. Preparations                                                             #
# --------------------------------------------------------------------------- #
# 1.a Internal variables

# The following line must not be removed: it is a switch for local install
# so that all bin scripts point to the local wwatch3.env
  export ww3_env=$COAWST_WW3_DIR/wwatch3.env
# For manual install (without install_ww3_tar or install_ww3_svn) make sure to
# either use the generic ww3_env or to add your own ww3_env="${my_directory}"

  if [ ${WWATCH3_ENV} ]; then ww3_env="${WWATCH3_ENV}"; fi # alternate setup file

# 1.b ID header  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  echo ' '
  echo 'Find switches in WAVEWATCH III'
  echo '------------------------------'

# 1.c Process/save input - - - - - - - - - - - - - - - - - - - - - - - - - - - 

  if test "$#" != '0'
  then
    switch="$1"
  else
    echo -n "Switch ? : " ; read switch
    progs="$*"
  fi

  echo ' ' ; echo "Files including $switch :" ; echo ' '

# 1.d Get env. data  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

  if test -f $ww3_env
  then
    set `grep WWATCH3_DIR $ww3_env` ; shift
    main_dir="$*"
  else
    echo "*** Set-up file $ww3_env not found ***"
    exit
  fi

# 1.e Raw data file  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

  cd $main_dir/ftn
  grep "$switch" * | sed 's/\:/ /' | awk '{ print $1}' > ../.switch.files

# 1.f Output - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

  last=$NULL
  for file in `cat ../.switch.files`
  do
    if test "$file" != "$last"
    then
      echo "   $file"
      last="$file"
    fi
  done
  rm -f ../.switch.files
  echo ' '

# End of find_switch -------------------------------------------------------- #
