* sac macro to set up guide window information for windowing in autowndws
* run inside an event directory  dir1 should include ../dirname
* only need input nearest station  and farest station 
* then use plotpk to pick up the nb ne fb  len= ne -nb
* then use bpcut22.m to cut the data 

echo off
unsetbb all

echo on

* set total length of cut seismogram
* the length of (ctb2 - ctb1) should be 2000 with signals sitting 
*  approximately in the center

setbb ctb1 $ctb1 ctb2 $ctb2

xlim %ctb1 %ctb2

* read in files with nearest and farest distance

setbb nfile $1
setbb ffile $2

rh %nfile
setbb ndist &1,DIST

rh %ffile
setbb fdist &1,DIST

* 0.002-0.012
r %nfile %ffile
rmean 
taper
p1
bp co .002 .012 n 4 p 2
title on 'bp co .002 .012 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb1 &1,t1
evaluate to ne1 &1,t2
evaluate to fb1 &2,t1
evaluate to len1 %ne1 - %nb1


* 0.003-0.013

r %nfile %ffile
rmean 
taper
p1
bp co .003 .013 n 4 p 2
title on 'bp co .003 .013 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb2 &1,t1
evaluate to ne2 &1,t2
evaluate to fb2 &2,t1
evaluate to len2 %ne2 - %nb2


* 0.004-0.014
r %nfile %ffile
rmean 
taper
p1
bp co .004 .014 n 4 p 2
title on 'bp co .004 .014 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb3 &1,t1
evaluate to ne3 &1,t2
evaluate to fb3 &2,t1
evaluate to len3 %ne3 - %nb3


*0.005-0.015
r %nfile %ffile
rmean 
taper
p1
bp co .005 .015 n 4 p 2
title on 'bp co .005 .015 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb4 &1,t1
evaluate to ne4 &1,t2
evaluate to fb4 &2,t1
evaluate to len4 %ne4 - %nb4


*0.007-0.017
r %nfile %ffile
rmean 
taper
p1
bp co .007 .017 n 4 p 2
title on 'bp co .007 .017 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb5 &1,t1
evaluate to ne5 &1,t2
evaluate to fb5 &2,t1
evaluate to len5 %ne5 - %nb5


*0.010-0.020
r %nfile %ffile
rmean 
taper
p1
bp co .010 .020 n 4 p 2
title on 'bp co .010 .020 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb6 &1,t1
evaluate to ne6 &1,t2
evaluate to fb6 &2,t1
evaluate to len6 %ne6 - %nb6


*0.015-0.025 
r %nfile %ffile
rmean 
taper
p1
bp co .015 .025 n 4 p 2
title on 'bp co .015 .025 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb7 &1,t1
evaluate to ne7 &1,t2
evaluate to fb7 &2,t1
evaluate to len7 %ne7 - %nb7


*0.020-0.030
r %nfile %ffile
rmean 
taper
p1
bp co .020 .030 n 4 p 2
title on 'bp co .020 .030 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb8 &1,t1
evaluate to ne8 &1,t2
evaluate to fb8 &2,t1
evaluate to len8 %ne8 - %nb8


*0.025-0.035
r %nfile %ffile
rmean 
taper
p1
bp co .025 .035 n 4 p 2
title on 'bp co .025 .035 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb9 &1,t1
evaluate to ne9 &1,t2
evaluate to fb9 &2,t1
evaluate to len9 %ne9 - %nb9


*0.030-0.040
r %nfile %ffile
rmean 
taper
p1
bp co .030 .040 n 4 p 2
title on 'bp co .030 .040 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb10 &1,t1
evaluate to ne10 &1,t2
evaluate to fb10 &2,t1
evaluate to len10 %ne10 - %nb10


*0.035-0.045
r %nfile %ffile
rmean 
taper
p1
bp co .035 .045 n 4 p 2
title on 'bp co .035 .045 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb11 &1,t1
evaluate to ne11 &1,t2
evaluate to fb11 &2,t1
evaluate to len11 %ne11 - %nb11


*0.040-0.050
r %nfile %ffile
rmean 
taper
p1
bp co .040 .050 n 4 p 2
title on 'bp co .040 .050 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb12 &1,t1
evaluate to ne12 &1,t2
evaluate to fb12 &2,t1
evaluate to len12 %ne12 - %nb12



*
**0.045-0.055
r %nfile %ffile
rmean 
taper
p1
bp co .045 .055 n 4 p 2
title on 'bp co .045 .055 n 4 p 2'
p1
ppk
lh t1 t2
evaluate to nb13 &1,t1
evaluate to ne13 &1,t2
evaluate to fb13 &2,t1
evaluate to len13 %ne13 - %nb13








writebbf 'wndbbf'
unsetbb all
cut off
echo off
