Waveform filter programs
suspect.f
Go to the documentation of this file.
1 c this is <suspect.f>
2 c------------------------------------------------------------------------------
3 c
4 c Copyright 1999, 2010 by Thomas Forbriger (IfG Stuttgart)
5 c
6 c SUm of SPECtra
7 c
8 c ----
9 c This program is free software; you can redistribute it and/or modify
10 c it under the terms of the GNU General Public License as published by
11 c the Free Software Foundation; either version 2 of the License, or
12 c (at your option) any later version.
13 c
14 c This program is distributed in the hope that it will be useful,
15 c but WITHOUT ANY WARRANTY; without even the implied warranty of
16 c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 c GNU General Public License for more details.
18 c
19 c You should have received a copy of the GNU General Public License
20 c along with this program; if not, write to the Free Software
21 c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 c ----
23 c
24 c uses code from susei.f
25 c
26 c REVISIONS and CHANGES
27 c 19/02/99 V1.0 Thomas Forbriger
28 c 23/03/99 V1.1 introduced -s option
29 c 24/04/99 V1.2 sets zero source time if no source is given in input
30 c
31 c==============================================================================
32 c
33  program suspect
34 c
35  character*79 version
36  parameter(version='SUSPECT V1.2 SUm of SPECTra')
37 c
38 c dimensions
39  integer maxsamps, maxfree
40  parameter(maxsamps=16400, maxfree=20)
41 c
42  integer i
43 c
44  real sffu_seconds
45  integer time_compare
46 c
47  logical spherical
48 c input data
49  real xdata(maxsamps), ydata(maxsamps), zdata(maxsamps)
50  integer ixdata(maxsamps), iydata(maxsamps), izdata(maxsamps)
51  equivalence(xdata,ixdata)
52  equivalence(ydata,iydata)
53  equivalence(zdata,izdata)
54  character*80 inxname, inyname
55  integer lux, luy, luz
56  parameter(lux=10, luy=11, luz=12)
57 c output data
58  real data(maxsamps)
59  integer idata(maxsamps)
60  double complex spect(maxsamps)
61  equivalence(data,idata)
62  character*80 outname
63  character*132 wid2line
64  integer luo
65  parameter(luo=13)
66 c sff extras
67  character*80 free(maxfree)
68  integer nfree
69  real libversion
70  character timestamp*13, code*10, type*20, cs*1, date*6, time*10
71  character code2*10, cs2*1
72  real c1,c2,c3,c12,c22,c32
73  integer ierr,nsamp,nsamp2,nstack,nstack2
74  logical last,last2
75  real tanf,dt,dt2
76  character*132 wid2line2
77 c
78  logical zerosrce
79 c
80  integer sdate1(7), sdate2(7), rdate1(7), rdate2(7), toff1(7), toff2(7)
81  double precision offsec1, offsec2, offseco
82  integer sdateo(7), rdateo(7), toffo(7)
83 c commandline
84  integer maxopt, lastarg, iargc
85  character*80 argument
86  parameter(maxopt=2)
87  character*2 optid(maxopt)
88  character*40 optarg(maxopt)
89  logical optset(maxopt), opthasarg(maxopt)
90 c debugging
91  logical debug
92 c here are the keys to our commandline options
93  data optid/2h-d,2h-s/
94  data opthasarg/2*.false./
95  data optarg/2*1h-/
96 c
97 c------------------------------------------------------------------------------
98 c basic information
99 c
100  print *,version
101  print *,'Usage: suspect file1 file2 outfile [-s]'
102  print *,' or: suspect -help'
103 c
104  if (iargc().lt.1) stop 'ERROR: missing arguments'
105  call getarg(1, argument)
106  if (argument(1:5).eq.'-help') then
107  print *,' '
108  print *,'SUm of SEIsmograms'
109  print *,' '
110  print *,'file1 first input file'
111  print *,'file2 second input file'
112  print *,'outfile output file'
113  print *,' '
114  print *,'-s The default coordinate system for SFF data is set'
115  print *,' to cartesian. This will be set in the case of the'
116  print *,' input file containing no source coordinates.'
117  print *,' Use this option to force using spherical coordinates.'
118  print *,' '
119  print *,'The program read all traces from the first input file'
120  print *,'and stacks them on the corresponding traces of the'
121  print *,'second input file. The resulting traces arw written to the'
122  print *,'the output file. Data is expected to contain a source'
123  print *,'origin time which might differ from the time of first'
124  print *,'for this reason both input traces are first aligned'
125  print *,'to origin time (by application of the time shift in'
126  print *,'the Fourier domain).'
127  print *,' '
128  print *,'The original purpose of this program was to calculate'
129  print *,'appropriate waveforms for seismograms on the global'
130  print *,'sphere for epicentral distances larger than 180 deg'
131  print *,'by applying the focal phase shift first and then'
132  print *,'stacking them with the waves travelling along the'
133  print *,'minor arc.'
134  stop
135  endif
136  if (iargc().lt.3) stop 'ERROR: too few arguments'
137 c
138 c
139 c------------------------------------------------------------------------------
140 c read command line arguments
141 c
142  call tf_cmdline(4, lastarg, maxopt, optid,
143  & optarg, optset, opthasarg)
144  debug=optset(1)
145  spherical=optset(2)
146 c
147  call getarg(1, inxname)
148  call getarg(2, inyname)
149  call getarg(3, outname)
150 c
151 c------------------------------------------------------------------------------
152 c
153 c
154  free(1)=version
155  free(2)='first data from '//inxname(1:index(inxname, ' '))
156  free(3)='second data from '//inyname(1:index(inyname, ' '))
157  free(4)='all information is taken from first data file'
158  free(5)='no plausibility checks were performed'
159  nfree=5
160 c
161  call sff_ropens(luy, inyname,
162  & libversion, timestamp, code,
163  & type, cs, c1, c2, c3, date, time, ierr)
164  if (ierr.ne.0) stop 'ERROR: opening y-component'
165  call sff_new(luo, outname, ierr)
166  if (index(code,'S').gt.0) then
167  call sffu_timesrce(date, time, sdate2)
168  zerosrce=.false.
169  else
170  print *,'WARNING: SRCE line is missing!'
171  print *,'WARNING: setting zero SRCE time!'
172  call time_clear(sdate2)
173  sdate2(1)=1999
174  sdate2(2)=1
175  zerosrce=.true.
176  endif
177 c
178  call sff_ropens(lux, inxname,
179  & libversion, timestamp, code,
180  & type, cs, c1, c2, c3, date, time, ierr)
181  if (ierr.ne.0) stop 'ERROR: opening x-component'
182  call sff_new(luo, outname, ierr)
183  if (zerosrce) then
184  call time_clear(sdate1)
185  sdate1(1)=1999
186  sdate1(2)=1
187  else
188  if (index(code,'S').gt.0) then
189  call sffu_timesrce(date, time, sdate1)
190  zerosrce=.false.
191  else
192  print *,'WARNING: SRCE line is missing!'
193  print *,'WARNING: setting zero SRCE time!'
194  call time_clear(sdate1)
195  sdate1(1)=1999
196  sdate1(2)=1
197  call time_clear(sdate2)
198  sdate2(1)=1999
199  sdate2(2)=1
200  zerosrce=.true.
201  endif
202  endif
203 c
204  if (time_compare(sdate1,sdate2).lt.0) then
205  call time_copy(sdate1,sdateo)
206  else
207  call time_copy(sdate2,sdateo)
208  endif
209  call sffu_srcetime(sdateo,date,time)
210 c
211  if (spherical) cs='S'
212 c
213  call sff_wopenfs(luo, outname,
214  & free, nfree,
215  & type, cs, c1, c2, c3, date, time, ierr)
216  if (ierr.ne.0) stop 'ERROR: opening output file'
217 c
218  last=.false.
219  do while (.not.(last))
220  nsamp=maxsamps
221  call sff_rtracei(lux, tanf, dt, wid2line, nsamp, xdata, ixdata,
222  & code, last, cs, c1, c2, c3, nstack, ierr)
223  if (ierr.ne.0) stop 'ERROR: reading x-data'
224  nsamp2=maxsamps
225  call sffu_timewid2(wid2line, rdate1)
226  if (zerosrce) then
227  rdate1(1)=1999
228  rdate1(2)=1
229  endif
230  call time_sub(rdate1,sdate1,toff1)
231  offsec1=sffu_seconds(toff1)
232 c
233  call sff_rtracei(luy, tanf, dt2, wid2line2, nsamp2, ydata, iydata,
234  & code2, last2, cs2, c12, c22, c32, nstack2, ierr)
235  if (ierr.ne.0) stop 'ERROR: reading y-data'
236  call sffu_timewid2(wid2line2, rdate2)
237  if (zerosrce) then
238  rdate2(1)=1999
239  rdate2(2)=1
240  endif
241  call time_sub(rdate2,sdate2,toff2)
242 c
243 c call time_sprint(sdate1,argument)
244 c print *,'sdate1 ',argument(1:35)
245 c call time_sprint(sdate2,argument)
246 c print *,'sdate2 ',argument(1:35)
247 c call time_sprint(rdate1,argument)
248 c print *,'rdate1 ',argument(1:35)
249 c call time_sprint(rdate2,argument)
250 c print *,'rdate2 ',argument(1:35)
251 c call time_sprint(toff1,argument)
252 c print *,'toff1 ',argument(1:35)
253 c call time_sprint(toff2,argument)
254 c print *,'toff2 ',argument(1:35)
255 c
256  offsec2=sffu_seconds(toff2)
257  if (time_compare(rdate1,rdate2).lt.0) then
258  call time_copy(rdate1,rdateo)
259  else
260  call time_copy(rdate2,rdateo)
261  endif
262  offseco=min(offsec1,offsec2)
263  last=(last.or.last2)
264 c
265  if (nsamp.ne.nsamp2) stop 'ERROR: wrong number of samples in y-data'
266  if (dt.ne.dt2) stop 'ERROR: inconsistent sampling rates'
267 c
268  call shifttrace(maxsamps, nsamp, spect, xdata, dt, offsec1)
269  call shifttrace(maxsamps, nsamp2, spect, ydata, dt, offsec2)
270 c
271  do i=1,nsamp
272  data(i)=(xdata(i)+ydata(i))
273  enddo
274  wid2line(36:38)='NSP'
275 c
276  call time_sub(rdateo,sdateo,toffo)
277  offseco=sffu_seconds(toffo)
278  call shifttrace(maxsamps, nsamp, spect, data, dt, -offseco)
279 c print *,offsec1,offsec2,offseco
280  call sffu_setwid2time(wid2line, rdateo)
281  call sff_modwid2samps(wid2line, nsamp)
282 c
283  call sff_wtracei(luo, wid2line, nsamp, data, idata, last,
284  & cs, c1, c2, c3, nstack, ierr)
285  if (ierr.ne.0) stop 'ERROR: writing trace'
286  enddo
287 c
288  stop
289  end
290 c
291 c----------------------------------------------------------------------
292 c
293  subroutine shifttrace(maxsamp, nsamp, spect, data, dt, timeshift)
294 c
295  integer maxsamp, nsamp
296  double complex spect(maxsamp)
297  real data(maxsamp)
298  real dt
299  double precision timeshift
300 c calculation
301  double precision pi
302  parameter(pi=3.14159265358979311599796346854418516d0)
303 c
304  integer npow, powsamp,i
305  complex*16 factor
306  real*8 singback, singto
307  parameter(singback=1.d0, singto=-1.d0)
308 c
309 c transform data
310  npow=0
311  powsamp=2**npow
312  do while (powsamp.lt.nsamp)
313  npow=npow+1
314  powsamp=2**npow
315  enddo
316  powsamp=powsamp*2
317  if (powsamp.gt.maxsamp) then
318  print *,'ERROR: dataset has ',nsamp,' samples'
319  print *,'ERROR: fourier number of samples should be ',powsamp
320  print *,'ERROR: array size is ',maxsamp
321  stop
322  endif
323 c
324  do i=1,nsamp
325  spect(i)=dcmplx(data(i))
326  enddo
327  do i=nsamp+1,powsamp
328  spect(i)=(0.d0,0.d0)
329  enddo
330  call tf_dfork(powsamp, spect, singback)
331  factor=(0.d0,1.d0)*(1.d0/(powsamp*dt))*2.d0*pi*timeshift
332  do i=0,powsamp/2-1
333  spect(i+1)=spect(i+1)*exp(i*factor)
334  enddo
335  do i=0,powsamp/2-2
336  spect(powsamp-i)=conjg(spect(i+2))
337  enddo
338  call tf_dfork(powsamp, spect, singto)
339 c
340  do i=1,powsamp
341  data(i)=sngl(real(spect(i)))
342  enddo
343  nsamp=powsamp
344 c
345  return
346  end
347 c
348 c ----- END OF suspect.f -----
subroutine shifttrace(maxsamp, nsamp, spect, data, dt, timeshift)
Definition: suspect.f:294
program suspect
Definition: suspect.f:33