#! /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, Subigbincsv increments through 3D Grid indexes    
## in both directions and makes super-cdps by (re)setting the cdp key 
## value for all traces near the intersecting cdp 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.                 
igibeg=20               # first grid inline to create big cdps           
igiend=32765            # last grid inline (resets to within grid)  
igiinc=40               # grid inline increment to create big cdps     
igcbeg=5                # first grid crossline to create big cdps           
igcend=32765            # last grid crossline (resets to within grid)     
igcinc=15               # grid crossline increment 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 \
        igiout=$igibeg,$igiend,$igiinc igcout=$igcbeg,$igcend,$igcinc \
        igiext=$igilo,$igihi igcext=$igclo,$igchi
else
echo "            Now running input traces through subinbigcsv, no grid"
subinbigcsv <$tracein >$tracebigbin              qout=$qlocations \
        igiout=$igibeg,$igiend,$igiinc                                \
        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

