Waveform filter programs
smoos.f
Go to the documentation of this file.
1 c this is <smoos.f>
2 c------------------------------------------------------------------------------
3 c
4 c Copyright 1998, 2010 by Thomas Forbriger (IfG Stuttgart)
5 c
6 c SMOOth Seismograms by sectral extension
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 REVISIONS and CHANGES
25 c 12/02/98 V1.0 Thomas Forbriger
26 c 26/06/03 V1.1 start each trace with a clean array
27 c
28 c==============================================================================
29 c
30  program smoos
31 c
32  character*79 version
33  parameter(version=
34  & 'SMOOS V1.1 SMOOth Seismograms by sectral extension')
35 c
36 c files
37  character*80 infile, outfile, nstring
38  integer luin, luout
39  parameter(luin=10, luout=11)
40 c data
41  integer msamp, nsamp, i
42  parameter(msamp=200000)
43 c calculation
44  integer nfac, npow, powsamp, newpowsamp
45  complex*16 spect(msamp)
46  real*8 singback, singto
47  parameter(singback=1.d0, singto=-1.d0)
48 c sff
49  integer mfree, nfree, ntrace
50  parameter(mfree=300)
51  integer ierr, lenmax
52  real libversion
53  character timestamp*16, code *10
54  character*80 free(mfree)*80
55  character type*25, date*8, time*12, cs*1
56  real c1, c2, c3
57  integer idata(msamp), nstack
58  real fdata(msamp), dt, tanf
59  equivalence(fdata,idata)
60  logical last
61  character wid2line*132
62 c commandline
63  integer maxopt, lastarg, iargc
64  character*80 argument
65  parameter(maxopt=1)
66  character*2 optid(maxopt)
67  character*40 optarg(maxopt)
68  logical optset(maxopt), opthasarg(maxopt)
69 c debugging
70  logical debug
71 c here are the keys to our commandline options
72  data optid/2h-d/
73  data opthasarg/.false./
74  data optarg/1h-/
75 c
76 c------------------------------------------------------------------------------
77 c basic information
78 c
79  print *,version
80  print *,'Usage: smoos infile outfile n'
81  print *,' or: smoos -help'
82 c
83  if (iargc().lt.1) stop 'ERROR: missing arguments'
84  call getarg(1, argument)
85  if (argument(1:5).eq.'-help') then
86  print *,' '
87  print *,'SMOOth Seismograms by sectral extension'
88  print *,' '
89  stop
90  endif
91  if (iargc().ne.3) stop 'ERROR: wrong number of arguments'
92 c
93 c------------------------------------------------------------------------------
94 c read command line arguments
95 c
96  call tf_cmdline(1, lastarg, maxopt, optid,
97  & optarg, optset, opthasarg)
98  debug=optset(1)
99  call getarg(1, infile)
100  call getarg(2, outfile)
101  call getarg(3, nstring)
102  read(nstring, *) nfac
103  nfac=max(0,nfac)
104 c
105 c------------------------------------------------------------------------------
106 c go
107 c
108  print *,'open file ',infile(1:index(infile,' '))
109  call sff_ropenfs(luin, infile,
110  & libversion, timestamp, code,
111  & nfree, free, lenmax, mfree,
112  & type, cs, c1, c2, c3, date, time, ierr)
113  if (ierr.ne.0) stop 'ERROR: opening input file'
114  if (lenmax.gt.80) print *,'WARNING: ',
115  & 'FREE lines read are longer than 80 characters - ',
116  & 'truncated'
117 c
118  if (nfree.lt.mfree) then
119  nfree=nfree+1
120  free(nfree)=version
121  endif
122 c
123  print *,'open file ',outfile(1:index(outfile,' '))
124  if (index(code, 'S').gt.0) then
125  call sff_wopenfs(luout, outfile,
126  & free, nfree,
127  & type, cs, c1, c2, c3, date, time, ierr)
128  else
129  call sff_wopenf(luout, outfile, free, nfree, ierr)
130  endif
131  if (ierr.ne.0) stop 'ERROR: opening output file'
132 c
133  last=.false.
134  ntrace=0
135  do while (.not.last)
136  ntrace=ntrace+1
137  nsamp=msamp
138  print *,'work on trace ',ntrace
139  call sff_rtracefi(luin, tanf, dt,
140  & wid2line, nsamp, fdata, idata, code, last,
141  & nfree, free, mfree, lenmax,
142  & cs, c1, c2, c3, nstack, ierr)
143  if (ierr.ne.0) stop 'ERROR: reading trace'
144  if (lenmax.gt.80) print *,'WARNING: ',
145  & 'FREE lines read are longer than 80 characters - ',
146  & 'truncated'
147 c
148 c start with a clean array
149  do i=1,msamp
150  spect(i)=(0.d0,0.d0)
151  enddo
152 c
153 c extend data
154  npow=0
155  powsamp=2**npow
156  do while (powsamp.lt.nsamp)
157  npow=npow+1
158  powsamp=2**npow
159  enddo
160  newpowsamp=2**(npow+nfac)
161  if (newpowsamp.gt.msamp) then
162  print *,'ERROR: dataset has ',nsamp,' samples'
163  print *,'ERROR: new number of samples should be ',newpowsamp
164  print *,'ERROR: array size is ',msamp
165  stop
166  endif
167  if (last) then
168  print *,'extending from ',nsamp,' to ',newpowsamp,' samples'
169  print *,'using ',powsamp,' samples for the first stage'
170  endif
171 c
172  do i=1,nsamp
173  spect(i)=dcmplx(fdata(i))
174  enddo
175  if (nsamp.gt.powsamp) then
176  do i=nsamp+1,powsamp
177  spect(i)=(0.d0,0.d0)
178  enddo
179  endif
180  call tf_dfork(powsamp, spect, singback)
181 c print *,'Nyquist coefficient of trace ',ntrace,':',spect(powsamp/2+1)
182 c spect(powsamp/2+1)=(0.,0.)
183  do i=0,powsamp/2-1
184  spect(newpowsamp-i)=spect(powsamp-i)
185  enddo
186  do i=powsamp/2+2,newpowsamp-powsamp/2
187  spect(i)=(0.d0,0.d0)
188  enddo
189  call tf_dfork(newpowsamp, spect, singto)
190  do i=1,newpowsamp
191  fdata(i)=sngl(real(spect(i)))*2.**(float(nfac)/2.)
192  enddo
193  nsamp=newpowsamp
194  call sff_modwid2samps(wid2line, nsamp)
195  dt=dt*2.**(-nfac)
196  call sff_modwid2samprat(wid2line, 1./dt)
197 c write free block
198  if (nfree.lt.mfree) then
199  nfree=nfree+1
200  write(free(nfree), 50) npow, npow+nfac
201  endif
202 c
203  if (index(code, 'I').gt.0) then
204  call sff_wtracefi(luout,
205  & wid2line, nsamp, fdata, idata, last,
206  & nfree, free,
207  & cs, c1, c2, c3, nstack, ierr)
208  else
209  call sff_wtracef(luout,
210  & wid2line, nsamp, fdata, idata, last,
211  & nfree, mfree, ierr)
212  endif
213  if (ierr.ne.0) stop 'ERROR: writing trace'
214  enddo
215 c
216  stop
217  50 format('extended number of samples from 2**',i5,' to 2**',i5)
218  end
219 c
220 c ----- END OF smoos.f -----
program smoos
Definition: smoos.f:30