34 parameter(version=
'DISE V1.2 DIfferential SEismograms')
37 integer maxopt, lastarg, iargc
40 character*2 optid(maxopt)
41 character*40 optarg(maxopt)
42 logical optset(maxopt), opthasarg(maxopt)
44 character*80 infile1,infile2,outfile,intrace1,intrace2,ssecbeg,ssecend
45 integer ifirst,ilast,itrace1,itrace2
47 character*132 wid2line
50 parameter(maxsamp=100000)
51 real data1(maxsamp), data2(maxsamp), data3(maxsamp)
52 integer idata1(maxsamp), idata2(maxsamp), idata3(maxsamp)
53 real dataout1(maxsamp), dataout2(maxsamp),dataout3(maxsamp)
54 real dataout4(maxsamp), dataout5(maxsamp),dataout6(maxsamp)
55 integer idataout1(maxsamp), idataout2(maxsamp),idataout3(maxsamp)
56 integer idataout4(maxsamp), idataout5(maxsamp),idataout6(maxsamp)
57 equivalence(data1,idata1)
58 equivalence(data2,idata2)
59 equivalence(data3,idata3)
60 equivalence(dataout1,idataout1)
61 equivalence(dataout2,idataout2)
62 equivalence(dataout3,idataout3)
63 equivalence(dataout4,idataout4)
64 equivalence(dataout5,idataout5)
65 equivalence(dataout6,idataout6)
67 integer nsamp1, nsamp2, nout
68 real dt1, dt2, tanf1, tanf2
69 double precision rms1, rms2, rms3, rms4
75 logical debug, verbose
77 data optid/2h-d, 2h-v/
78 data opthasarg/2*.false./
86 if (iargc().eq.1)
call getarg(1, argument)
87 if ((argument(1:5).eq.
'-help').or.(iargc().ne.7))
then 89 print *,
'Usage: dise infile1 n1 infile2 n2 outfile tb te' 90 print *,
' or: dise -help' 91 if (argument(1:5).ne.
'-help') stop
'ERROR: wrong number of arguments' 93 print *,
'DIfferential SEismograms' 95 print *,
'infile1 SFF input file for trace A' 96 print *,
'n1 trace number of trace A in file ''infile1'' ' 97 print *,
'infile2 SFF input file for trace B' 98 print *,
'n2 trace number of trace B in file ''infile2'' ' 99 print *,
'outfile results will be written to this file' 100 print *,
'tb time of first sample (in sec)' 101 print *,
'te time of last sample (in sec)' 106 print *,
' This program compares two time series. These may be' 107 print *,
' real data and synthetics or synthetics calculated with' 108 print *,
' two different methods. The two time series are named A' 109 print *,
' and B and are read from the input file. In order to' 110 print *,
' calculate a difference trace (A-B), trace B will be' 111 print *,
' resampled to match the sampling interval and time range' 112 print *,
' of trace A. Root mean square (rms) values are calculated' 113 print *,
' from all three traces within the specified time range' 114 print *,
' (as defined by ''tb'' and ''te''). Ratios of the rms values' 115 print *,
' are reported on the terminal.' 117 print *,
' nA and nB are datasets normalized to an rms of 1.' 124 call tf_cmdline(1, lastarg, maxopt, optid,
125 & optarg, optset, opthasarg)
128 call getarg(1,infile1)
129 call getarg(2,intrace1)
130 call getarg(3,infile2)
131 call getarg(4,intrace2)
132 call getarg(5,outfile)
133 call getarg(6,ssecbeg)
134 call getarg(7,ssecend)
138 read(intrace1, *)itrace1
139 read(intrace2, *)itrace2
140 read(ssecbeg, *)secbeg
141 read(ssecend, *)secend
142 call getfile(infile1, itrace1, data1, idata1, maxsamp, nsamp1,
144 call getfile(infile2, itrace2, data2, idata2, maxsamp, nsamp2,
148 ifirst=1+int((secbeg-tanf1)/dt1)
149 ilast=1+int((secend-tanf1)/dt1)
150 if ((ifirst.gt.ilast).or.(ifirst.lt.1).or.(ilast.gt.nsamp1))
151 & stop
'ERROR: check time range' 153 call resamp(data2, data3, nsamp1, nsamp2, tanf1, dt1, tanf2, dt2,
156 print *,
'calculating difference trace (A-B)...' 162 dataout2(i)=data1(i-1+ifirst)
164 dataout1(i)=dataout2(i)-dataout3(i)
165 rms1=rms1+dataout1(i)*dataout1(i)
166 rms2=rms2+dataout2(i)*dataout2(i)
167 rms3=rms3+dataout3(i)*dataout3(i)
178 dataout5(i)=data1(i-1+ifirst)/rms2
179 dataout6(i)=data3(i)/rms3
180 dataout4(i)=dataout5(i)-dataout6(i)
181 rms4=rms4+dataout4(i)*dataout4(i)
186 print *,
'going to write A-B, A and B to ',
187 & outfile(1:index(outfile,
' ')),
'...' 188 call sff_wopens(lu, outfile,
'nil ',
189 &
'C', 0., 0., 0.,
'990420',
'000000.000', ierr)
190 if (ierr.ne.0) stop
'ERROR: opening output file' 192 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
193 &
'A-B',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr)
194 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace one' 195 call sff_wtrace(lu, wid2line, nout, dataout1, idataout1, last, ierr
196 if (ierr.ne.0) stop
'ERROR: writing first trace to output file' 198 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
199 &
'A',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr)
200 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace two' 201 call sff_wtrace(lu, wid2line, nout, dataout2, idataout2, last, ierr
202 if (ierr.ne.0) stop
'ERROR: writing second trace to output file' 204 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
205 &
'B',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr)
206 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace three' 207 call sff_wtrace(lu, wid2line, nout, dataout3, idataout3, last, ierr
208 if (ierr.ne.0) stop
'ERROR: writing third trace to output file' 210 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
211 &
'nA-nB',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr
212 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace one' 213 call sff_wtrace(lu, wid2line, nout, dataout4, idataout4, last, ierr
214 if (ierr.ne.0) stop
'ERROR: writing fourth trace to output file' 216 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
217 &
'nA',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr)
218 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace two' 219 call sff_wtrace(lu, wid2line, nout, dataout5, idataout5, last, ierr
220 if (ierr.ne.0) stop
'ERROR: writing fifth trace to output file' 222 call sff_prepwid2(nout, 1./dt1,
'NSP ', 1999, 4, 20, 0, 0,
223 &
'nB',
'NSP ',
'NSP ', 0., 1., 1., -1., -1., wid2line, ierr)
224 if (ierr.ne.0) stop
'ERROR: preparing WID2 line for trace three' 226 call sff_wtrace(lu, wid2line, nout, dataout6, idataout6, last, ierr
227 if (ierr.ne.0) stop
'ERROR: writing sixth trace to output file' 229 print *,
'results are:' 230 print *,
' Arms/Brms: ',rms2,
'/',rms3,
'=',rms2/rms3
231 print *,
' (A-B)rms/Arms: ',rms1,
'/',rms2,
'=',rms1/rms2
232 print *,
' (A-B)rms/Brms: ',rms1,
'/',rms3,
'=',rms1/rms3
233 print *,
' (nA-nB)rms: ',rms4
240 subroutine getfile(filename, itrace, data, idata, maxsamp,
243 character filename*(*)
244 integer itrace, nsamp, maxsamp
246 integer idata(maxsamp)
249 character cs*1, code*20, time*20, date*20, tist*20, type*30, rs*1
250 character wid2line*132
252 real c1,c2,c3,r1,r2,r3,sffu_tfirst
253 integer ierr, lu, nstack, i
257 print *,
'going to read ',filename(1:index(filename,
' ')),
'...' 259 call sff_ropens(lu, filename, inv, tist, code,
type, cs, c1, c2, c3
261 if (ierr.ne.0) stop
'ERROR opening input file' 265 if (last) stop
'ERROR: too few traces in input file' 266 call sff_rtracei(lu, tanf, dt, wid2line, nsamp,
data, idata, code
268 if (ierr.ne.0) stop
'ERROR: reading input file' 270 print *,
' read trace no.',itrace
271 if (.not.(last))
close(lu)
272 tanf=sffu_tfirst(wid2line, time, date)
273 print *,
' trace begins at ',tanf,
'sec' 274 print *,
' sampling interval is ',dt,
'sec' 280 subroutine resamp(data2, data3, nsamp1, nsamp2, tanf1, dt1, tanf2, dt2,
283 real data2(nsamp2), data3(nsamp1)
284 integer nsamp1, nsamp2, ifirst, ilast
285 real tanf1, tanf2, dt1, dt2
288 parameter(verbose=.true.)
291 parameter(maxspec=100000)
292 complex spect(maxspec)
295 real pi, t, sum,dper,selbeg,selend,oselbeg,oselend
296 integer ispec,i,oifirst,oilast,onspec,nout
297 integer limit,percount,nextper
298 complex ime, expfac, expfacbase
299 parameter(pi=3.1415926535897931159979,ime=(0.,1.))
303 print *,
'do some resampling...' 306 selbeg=(ifirst-1)*dt1+tanf1
307 selend=(ilast-1)*dt1+tanf1
308 oifirst=int((selbeg-tanf2)/dt2)
309 oilast=2+int((selend-tanf2)/dt2)
310 if ((oifirst.gt.oilast).or.(oifirst.lt.1).or.(oilast.gt.nsamp2))
311 & stop
'ERROR: check times' 312 onspec=oilast-oifirst+1
314 oselbeg=(oifirst-1)*dt2+tanf2
315 oselend=(oilast-1)*dt2+tanf2
317 print *,
' original trace:' 318 print *,
' first sample: ',tanf2,
'sec; last sample: ',
319 & (nsamp2-1)*dt2+tanf2,
'sec' 320 print *,
' sampling interval: ',dt2,
'sec' 321 print *,
' selected first sample: ',oifirst
322 print *,
' selected last sample: ',oilast
323 print *,
' selected start time: ',oselbeg,
'sec' 324 print *,
' selected end time: ',oselend,
'sec' 325 print *,
' master trace:' 326 print *,
' first sample: ',tanf1,
'sec; last sample: ',
327 & (nsamp1-1)*dt1+tanf1,
'sec' 328 print *,
' sampling interval: ',dt1,
'sec' 329 print *,
' selected first sample: ',ifirst
330 print *,
' selected last sample: ',ilast
331 print *,
' selected start time: ',selbeg,
'sec' 332 print *,
' selected end time: ',selend,
'sec' 335 do while(nspec.lt.onspec)
338 if (nspec.gt.maxspec) stop
'ERROR: maxspec too small!' 340 print *,
'preparing spectrum with ',nspec,
' samples' 345 print *,
' extracting' 346 print *,
' original trace ',oifirst,
'-',oifirst-1+onspec
347 print *,
' to spectrum trace ',1,
'-',onspec
349 spect(i)=cmplx(data2(oifirst+i-1))
352 call tf_fork(nspec,spect,-1.)
355 print *,
' we hold the spectrum now' 356 print *,
' going to perform resampling DFT (which will be slow)...' 369 print *,
' old sampling interval (',dt2,
'sec)' 370 print *,
' is less than new one (',dt1,
'sec) !' 372 &
' it''s up to you to perform a correct low pass filtering' 376 expfacbase=2.*pi*ime/(dt2*float(nspec))
380 nextper=nout*dper/100.
385 expfac=expfacbase*(t-oselbeg)
386 if ((t.lt.oselbeg).or.(t.gt.oselend))
then 390 sum=0.5*
real(spect(1))
392 sum=sum+
real(spect(ispec)*cexp(expfac*float(ispec-1)))
394 sum=sum+0.5*
real(spect(limit+1)*cexp(expfac*(limit)))
395 data3(i)=2.*sum/sqrt(float(nspec))
397 if (i.gt.nextper)
then 398 print *,
' finished ',percount*dper,
'%' 400 nextper=percount*nout*dper/100.
403 print *,
' finished 100.%' subroutine getfile(filename, itrace, data, idata, maxsamp, nsamp, tanf, dt)
subroutine resamp(data2, data3, nsamp1, nsamp2, tanf1, dt1, tanf2,