#! /bin/sh
# Prepare data for VelanBinBig interactive velocity picking.
# Create: Andre Latour, May 1 2022.
# NOTE: Comment lines preceeding user input start with  ##
#set -x

## Basically, here, you specify a list of grid indexes for Subigbincsv
## in both directions and it makes super-cdps by (re)setting the cdp key 
## value for all traces near the cdps at the index intersections
## TO THAT cdp number. 
## The size of the super-cdps is controlled by igilo,igihi,igclo,igchi. 
## Typically you want symmetrical super-cdps which also make a roughly  
## square PHYSICAL area (which is often a different number of cells        
## in the inline and crossline directions).                      
## The output trace file is used by VelanBinBig (or VelanBinBigRandom).
## It is also useful for other purposes (displays, picking mutes).        
##                                                                       
## And, Subinbigcsv also outputs a file which contains the locations
## of the super-cdps (cdp,igi,igc, XY coordinates, other values).       
## This is used by VelanBinBig but not by VelanBinBigRandom.
## This is a csv file which can also be read-into Spreadsheet programs
## and/or otherwise displayed and plotted.
##                                           

## Set parameters for Subigbincsv and Subinqcsv.
tracein=fake6.su        # your input seismic data. 
rfile=kEFG.csv          # your 3D grid file. As output by Subincsv.                 
igilist=20,60,100       # list of grid inlines to create big cdps           
igclist=5,8,12,20       # list of grid crosslines to create big cdps           
igilo=2                 # grid inline low cell extent of big cdps
igihi=$igilo            # grid inline high cell extent of big cdps
igclo=1                 # grid crossline low cell extent of big cdps
igchi=$igclo            # grid crossline high cell extent of big cdps

## For 2D:
#  - set rfile= to nothing. 
#  - all igi parameters are interpreted to mean cdp numbers.                
#  - set igibeg to first cdp and igiend near last cdp you want to binbig, 
#    otherwise you get many empty Velans.
#  - all igc parameters above are ignored.               

## If you change following names, also need to change VelanBinBig
tracebigbin=bigbined.su   # output from Subigbincsv.
velpanel=bbsorted.su      # output from Subigbincsv and susort.                  
qlocations=qlocations.csv # output from Subinqcsv.

echo

if [ $rfile ]
then
echo "            Now running input traces through subinbigcsv, with grid"
subinbigcsv <$tracein >$tracebigbin rfile=$rfile qout=$qlocations \
        igilist=$igilist igclist=$igclist \
        igiext=$igilo,$igihi igcext=$igclo,$igchi
else
echo "            Now running input traces through subinbigcsv, no grid"
subinbigcsv <$tracein >$tracebigbin              qout=$qlocations \
        igilist=$igilist                  \
        igiext=$igilo,$igihi                         
fi

echo
echo "            Now running traces from subinbigcsv into susort by cdp and offset."
echo "               (there is no actual need to sort, but displays are clearer) "
susort <$tracebigbin >$velpanel cdp offset
echo

