#! /bin/csh
###changed decimation back to 2 (d2=2) svd
## changed decimation to 1 (d2=1) svd also changed in convsegy_200m

## CHIRP SIS-1000
   echo "Process chirp usage:"
   echo "    chirp tmin tmax sufile hbox"
   echo "       tmin and tmax (seconds) determine vertical plot window"
   echo "       ie, 0 0.25 (window 0 to 250 ms)"
   echo "       the SU input file excluding the .su extension"
   echo "       hbox is the vertical plot size in inches"
#   echo "    edit the chirp script to set the clipping parameter to lighten or darken the plot"
   echo " "

#get number of traces
   echo "getting the total number of traces"
   set numtraces = `surange < $3.su | grep traces | awk ' {print($1)}' `
   echo "number of traces = "$numtraces

# get ffid range for input
   echo "getting the range of FFID's"

   set ffidmin = `surange < $3.su | grep fldr | sed 's/fldr=//; s/(//g; s/)//g' | awk ' {print($3)}' | awk -F , ' {print($1)}' `
   set ffidmax = `surange < $3.su | grep fldr | sed 's/fldr=//; s/(//g; s/)//g' | awk ' {print($3)}' | awk -F , ' {print($2)}' `

   echo "The minimum FFID is "$ffidmin
   echo "The maximum FFID is "$ffidmax
   echo " "
   echo "Setting the sort order (data window), Set gain parameters"

   suwind key=fldr min=$ffidmin max=$ffidmax tmin=$1 tmax=$2 itmin=$1 verbose=0 < $3.su | \
   suchw key1=delrt a=0 | suchw key1=tracr key2=fldr | \
   sugain panel=0 scale=1 tpow=1.1 > $3.tmp

   echo "Set scaling for PS plot"

# set the plot X size based on the number of traces/inch
  set wbox = `expr $numtraces / 200`
  echo "the plot length =" $wbox "inches"
  echo

# set the plot Y size (hbox) in inches
  set tmin = $1
  echo "tmin ="$tmin
  set tmax = $2
  echo "tmax ="$tmax
#  set hbox = echo $1 $1 | awk ' {print($2)}'
#  set hbox = 10
#  set hbox = 12
#  set hbox = 18
#  set hbox = 20
  set hbox = $4
  echo "the plot height=" $hbox "inches"

# PLOT POSTSCRIPT IMAGE
# d1 is the sample interval (SR) in seconds that should be read from the header
# If the vertical scale is not correct - most likely the SR is not correct
# Set d2=decimation factor used in qmipstosegy
# d1=0.000122 d2=1 \

# Change percentile for determining black clip value to adjust plot contrast
# Higher bperc gives lighter plot - wclip=0 sets 0 and - amp. to white

 echo "Making the PostScript plot"

nice  supsimage wbox=$wbox hbox=$hbox \
 ybox=0.5 \
 x1beg=$1 x1end=$2 \
 d1num=0.02 d2num=1000 \
d2=2 \
### d2=1 \
# d1=0.000122 \
 n1tic=20 n2tic=10 \
# bperc=96 wclip=0 \
 bperc=$5 wclip=0 \
 grid1=dot grid2=dot \
 title="SEAX 96004 SIS-1000 CHIRP Line $3 SHOTS $ffidmin-$ffidmax" \
 label1="TWT [s]" label2="SHOT" \
 < $3.tmp > ../seisimag/$3.ps

rm $3.tmp

# convert PS plot to GIF image
makegif ../seisimag/$3

# convert PS plot to raster for Alden printer
#aldenseismic ../seisimag/$3

# convert PS plot to raster for Raytheon TDU printer
#tduseismic ../seisimag/$3

# view the PS with GhostView
#gv -portrait ../seisimag/$3.ps
kview ../seisimag/$3.gif

echo "chirp $1 $2 $3 $4 $5" >> proc_history

rm ../seisimag/*.raw
rm ../seisimag/*.ps
