#! /bin/csh

# proc_chirp
   echo "Process chirp usage:"
   echo "    chirp tmin tmax sufile hbox beggining_shot ending_shot Plot_seg"
   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 "       beginning_shot is the first shot to plot"
   echo "       ending_shot is the last shot to plot"
   echo "       Plot_seg is the plot segment of a file (a,b,c...)"
   echo "    edit the chirp script to set the clipping parameter"
   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 " "

   set ffidminplot = $argv[5]
   set ffidmaxplot = $argv[6]
   echo "The minimum FFID to plot is "$ffidminplot
   echo "The maximum FFID tp plot is "$ffidmaxplot
   echo " "
   echo "Setting the data window"

# select data window and gain
  suwind key=fldr min=$5 max=$6 itmin=0 tmin=$1 tmax=$2 verbose=0 < $3.su | suchw key1=delrt a=0 | suchw key1=tracr key2=fldr | sugain panel=0 scale=1 tpow=1.2 > $3.tmp

# set the plot X size based on the number of traces selected and traces/inch
  set newnumtraces = `expr $ffidmaxplot - $ffidminplot`
  set wbox = `expr $newnumtraces / 60`
  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 = 12
#  set hbox = 18
#  set hbox = 20
  set hbox = $4
  echo "the plot hieght=" $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

 supsimage wbox=$wbox hbox=$hbox \
 ybox=0.5 \
 x1beg=$1 x1end=$2 \
 d1num=0.05 d2num=100 \
 d2=2 \
# d1=0.000976 \
 n1tic=10 n2tic=1 \
 bperc=99 wclip=0 \
 brgb=0.0,0.0,0.0 wrgb=1.0,1.0,1.0 bps=12 \
 bhls=0.0,1.0,0.0 whls=0.0,1.0,0.0 \
 grid1=dot grid2=dot \
 title="GYRE 99002 SIS-1000 CHIRP Line $3 SHOTS $ffidminplot-$ffidmaxplot" \
 label1="TWT [s]" label2="SHOT" \
 < $3.tmp > ../seisimag/$3$7.ps

rm $3.tmp

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

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

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

rm ../seisimag/$3$7.raw











