#!/bin/csh -f 
#
# Script to search for strings in the SSW tree
# One principle use is to find routine references and context
# Note - Script defaults to case insensitive, include context, and remove
# IDL comments prior to search.  If you need to override those defaults, 
# run the IDL version directly from within an sswidl session
# 
# ~ 1-jan-1997  - S.L.Freeland - UNIX front end to 'ssw_strfind.pro'
#   7-oct-1997  - S.L.Freeland - add yymmdd.hhmmss to job name
#                                 (allow parallel runs)
#  12-dec-1997  - S.L.Freeland - Permit optional 2nd parameter which is 
#                                a filename/pathname string (subset of SSW) 
#                                for example, can be an instrument switch
#                                like /mdi, /eit, /sxt, /hessi, etc... 
#
## ssw_strfind - find a string (ex: IDL routine reference) in SSW tree
##
## Calling Sequence:
##  
##   % ssw_strfind <string>                 # search all SSW for 'string'
##   % ssw_strfind <string> <filepattern>   # subset of SSW files/paths which
##                                          # include 'filepattern'
##
## Calling Examples:
##   % ssw_strfind eit_prep        # 'eit_prep' references under $SSW/...   
##   % ssw_strfind eit_prep /eit   #  same but search only under $SSW/soho/eit..
##   % ssw_strfind rd_xda /yohkoh  # 'rd_xda' references under SSW/yohkoh/...
##   % ssw_strfind join_struct     # 'join_struct' ref under $SSW/...
##
## Method: submit "batch" job to find string in ssw tree - runs
##         SSW routines (sswloc.pro and ssw_strfind.pro in background)
##
## Notes:
##      email sent when complete ( 10 or so mins. for FULL $SSW search)
##
#
if ($#argv == 0) then 
   echo "------- need to supply search pattern -------"
   echo ""
   grep -i "##" $SSW_BIN/ssw_strfind | head -20
   echo "---------------------------------------------"
   exit
endif

set fpattern=""                           # default = null => all of SSW
if ($#argv >= 2 ) then 
   set fpattern=$argv[2]                  # user supplied subset/pattern

   echo "Only searching subset of SSW which includes file pattern "$fpattern
endif

setenv IDL_PATH $HOME
set job=$HOME"/ssw_find_"`date2fid _`
set pro=$job".pro"

echo "sswloc,'"$fpattern"',files" > $pro
echo "ssw_strfind,/mail,files=files,/details,'"$argv[1]"'" >> $pro
echo "end" >> $pro
$SSW/gen/bin/ssw_batch $job $SSW/site/logs/ssw_find_`date2fid _`".log" &
sleep 1       # wait 1 second to assure uniq job names
exit

