#!/bin/sh # /******************* self documentation **********************/ DOC () { echo ' SU2SEP - transform su-data to sep-data su2sep < "in.su" [optional parameters] Optional Parameters: [i[nfile]=]"in.su" replaces the stdin h[drfile]="in.sep" =header_file_name ="stdout", for the standard output d[atafile]="in.sep@" =data_file_name ="stdout", for the standard output b[intype]=to_be_searched =csg,cog,cdp,cmp, for sure verbose=0 =1, for diagnostic print on stdout Note: For the case of stdin, at least one optional parameter is requiredw to activate su2sep; you may simply set "verbose=0 or 1". The algorithm recognizes bintype automatically if it is not given.' } # /**************** end self doc ********************************/ # Author: S. Kim Oct.-22-1996 # Edit: S. Kim Aug.-20-1997 PATH=:/bin:/usr/bin:/usr/ucb:$CWPROOT/bin_${OSTYPE} cmd=`basename $0` infile= hdrfile= datafile= bintype=csg nbingive=0 verbose=0 ##--- read optional parameters -------------- case $# in 0) DOC | more -20 1>&2; exit 1 ;; *) for i do case $i in h*=*) hdrfile=`echo $i | sed 's/h.*=//'` ;; d*=*) datafile=`echo $i | sed 's/d.*=//'` ;; i*=*) infile=`echo $i | sed 's/i.*=//'` ;; b*=*) bintype=`echo $i | sed 's/b.*=//'` ; nbingive=1 ;; verbose=*) verbose=`echo $i | sed 's/verbose=//'` ;; *) infile=$i esac done ;; esac tmpinfile=$HOME/0000_temp_sep tmpparfile=$HOME/0000_temp_par if test "$infile" = "" ; then cat <$stdin> $tmpinfile if test -s $tmpinfile; then infile=$tmpinfile else rm $tmpinfile DOC | more -20 1>&2; exit 1 fi infileflag=stdin elif test -f "$infile" ; then infileflag=$infile else echo 1>&2 echo " $cmd: There is no file named by \"$infile\"" 1>&2 echo 1>&2 echo -n " To stop the program, press ^C " 1>&2 sleep 604800 ; exit 1 fi if test "$hdrfile" = ""; then hdrfile=`basename $infile | sed -e 's/\..*//'`.sep fi if test "$datafile" = ""; then datafile=`basename $infile | sed -e 's/\..*//'`.sep@ fi if test $nbingive -eq 1; then if test "$bintype" = "cog"; then nbingive=2 elif test "$bintype" = "cdp" -o "$bintype" = "cmp"; then nbingive=3 fi fi ##--- the header words ---- hws="sx,gx,offset,cdp,ns,f1,delrt,dt,f2,d2,sdepth,gelev" echo " $cmd: reading header words from \"$infileflag\" key=$hws" 1>&2 ##--- read infile ------------- fields="`sugethw < $infile key=$hws | awk ' BEGIN{ ids=ido=idm=done=count=0; nps=1; ncount=2} NF!=0{count++ if(done==0){ as=substr($1,4); ag=substr($2,4) ao=substr($3,8); am=substr($4,5) if(ao==0) ao=ag-as if(am==0) am=(ag+as)/2 if(count==1){ os0=as; og0=ag; oo0=ao; om0=am print $5,$6,$7,$8,$9,$10,$11,$12 } else { ds=as-asp; dg=ag-agp; dox=ao-aop; dm=am-amp if(ao==0) dox=dg-ds if(am==0) dm=(dg+ds)/2 if(count==2){ ds0=ds; dg0=dg; do0=dox; dm0=dm if( as==asp && ((ag!=agp)||(ao!=aop)) ) ids=1 if( ao==aop && ((as!=asp)||(ag!=agp)) ) ido=1 if( am==amp && ((as!=asp)||(ag!=agp)||(ao!=aop)) ) idm=1 if((ids+ido+idm)>=2){ids=0;ido=0;idm=0} } else{ ncount++ if( (ds!=dsp) || (dg!=dgp) || (dox!=dop) || (dm!=dmp) ) {done=1; nps=count-1} } } asp=as; agp=ag; aop=ao; amp=am dsp=ds; dgp=dg; dop=dox; dmp=dm } } END{if(nps==1 && ncount>=3 && ncount==count) {nps=count} ntr=count; n2=nps; n3=count/nps if(ids==1) {o2=oo0;dd2=do0; o3=os0;d3=ds; nbin=1} else if(ido==1) {o2=os0;dd2=ds0; o3=oo0;d3=dox; nbin=2} else if(idm==1) {o2=oo0;dd2=do0; o3=om0;d3=dm; nbin=3} else {o2=oo0;dd2=do0; o3=os0;d3=ds; nbin=0} print "ntr="ntr,"n2="n2,"n3="n3 print "o2="o2,"dd2="dd2,"o3="o3,"d3="d3 print "nbin="nbin print "os0="os0,"ds0="ds0,"oo0="oo0,"do0="do0,"om0="om0 print "ds="ds,"do="dox,"dm="dm }'`" ##--- get sorting for *.sep ------ for term in $fields do case $term in ns=*) ns=`echo $term | sed s/ns=//` ;; f1=*) f1=`echo $term | sed s/f1=// | awk '{print $1*1000}'` ;; # s -->ms delrt=*) delrt=`echo $term | sed s/delrt=//` ;; dt=*) dt=`echo $term | sed s/dt=// | awk '{print $1/1000}'` ;; # mus-->ms f2=*) f2=`echo $term | sed s/f2=// | awk '{print $1*1000}'` ;; # Km -->m d2=*) d2=`echo $term | sed s/d2=// | awk '{print $1*1000}'` ;; # Km -->m dd2=*) dd2=`echo $term | sed s/dd2=//` ;; sdepth=*) sdepth=`echo $term | sed s/sdepth=//` ;; gelev=*) gelev=`echo $term | sed s/gelev=//` ;; ntr=*) ntr=`echo $term | sed s/ntr=//` ;; n2=*) n2=`echo $term | sed s/n2=//` ;; n3=*) n3=`echo $term | sed s/n3=//` ;; o2=*) o2=`echo $term | sed s/o2=//` ;; d2=*) d2=`echo $term | sed s/d2=//` ;; o3=*) o3=`echo $term | sed s/o3=//` ;; d3=*) d3=`echo $term | sed s/d3=//` ;; nbin=*) nbin=`echo $term | sed s/nbin=//` ;; os0=*) os0=`echo $term | sed s/os0=//` ;; # auxilliary variables ds0=*) ds0=`echo $term | sed s/ds0=//` ;; oo0=*) oo0=`echo $term | sed s/oo0=//` ;; do0=*) do0=`echo $term | sed s/do0=//` ;; om0=*) om0=`echo $term | sed s/om0=//` ;; ds=*) ds=`echo $term | sed s/ds=//` ;; do=*) do=`echo $term | sed s/do=//` ;; dm=*) dm=`echo $term | sed s/dm=//` ;; esac done dt=`echo $dt | awk '{print int(100*$1+0.5)/100}'` #rounding for < 0.005 if test $delrt -gt $f1; then f1=$delrt fi if test $nbin -eq 0; then bindata="no-bintype" elif test $nbin -eq 1; then bindata=csg elif test $nbin -eq 2; then bindata=cog elif test $nbin -eq 3; then bindata=cdp fi ##--- print information ---------- error=0 echo 1>&2 if test $nbingive -eq 0 -o $nbingive -eq $nbin; then echo " Input = SU-data of `echo $bindata | tr a-z A-Z`..." 1>&2 bintype=$bindata if test "$bintype" = "no-bintype"; then bintype=csg fi else echo " WARNING: Your given bintype is \"${bintype}\"," 1>&2 echo " but the data-bintype seems \"${bindata}\"." 1>&2 echo " I will follow your given bintype." 1>&2 error=1 fi ##--- when error=1 ------- if test $error -eq 1; then if test $nbingive -eq 1; then o2=$oo0;dd2=$do0; o3=$os0;d3=$ds elif test $nbingive -eq 2; then o2=$os0;dd2=$ds0; o3=$oo0;d3=$do elif test $nbingive -eq 3; then o2=$oo0;dd2=$do0; o3=$om0;d3=$dm fi fi ##--- print out ----- parprint () { echo "\ n1=$ns n2=$n2 n3=$n3 o1=$f1 o2=$o2 o3=$o3 d1=$dt d2=$dd2 d3=$d3 bintype=$bintype in=\"$datafile\" esize=4 dim=3 rd=2 aXIs1 unit=\"ms\" aXIs2 unit=\"m\" aXIs3 unit=\"m\" data unit=\"x\" " if test $sdepth -ne 0; then echo "zsrc=$sdepth zsrc unit=\"m\" " fi if test $gelev -ne 0; then echo "zrec=$gelev zrec unit=\"m\" " fi } if test "$hdrfile" = "stdout"; then echo 1>&2 parprint 1>&2 else parprint > $hdrfile if test $verbose -eq 1; then echo 1>&2 parprint 1>&2 fi fi if test "$datafile" = "stdout"; then sustrip < $infile outpar=$tmpparfile else sustrip < $infile outpar=$tmpparfile > $datafile fi ##--- clean up ------ /bin/rm $tmpparfile if test -f $tmpinfile; then /bin/rm $tmpinfile fi