greda.f 82.8 KB
Newer Older
1
2
3
c this is <greda.f>
c------------------------------------------------------------------------------
c
thomas.forbriger's avatar
thomas.forbriger committed
4
c Copright 1997,2010 by Thomas Forbriger (IfG Stuttgart)
5
c
6
c wavefield transform for single-shot profiles
7
c
thomas.forbriger's avatar
thomas.forbriger committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
c ----
c This program is free software; you can redistribute it and/or modify
c it under the terms of the GNU General Public License as published by
c the Free Software Foundation; either version 2 of the License, or
c (at your option) any later version. 
c 
c This program is distributed in the hope that it will be useful,
c but WITHOUT ANY WARRANTY; without even the implied warranty of
c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c GNU General Public License for more details.
c 
c You should have received a copy of the GNU General Public License
c along with this program; if not, write to the Free Software
c Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
c ----
c
24
25
26
27
c REVISIONS and CHANGES
c    24/06/97   V1.0   Thomas Forbriger
c    03/07/97   V1.1   included hankel functions
c    08/07/97   V1.2   correct 1/2 factors for hankel functions
thomas.forbriger's avatar
thomas.forbriger committed
28
c    25/07/97   V1.3   calculate Fourier Bessel transform
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
c                      first slowness to be calculated is larger than zero
c                      included distance taper
c                      included special handling for u=zero
c    04/08/97   V1.4   now optional matrix inversion method
c                      and correct linear inversion
c    07/08/97   V1.5   build a correct algorithm using wielandt gauss
c    08/08/97   V2.0   reorganized the whole thing
c                      added edge setting
c    14/08/97   V2.1   added direct matrix method
c                      added K_0 damping method
c                      added discrete gram method
c    22/10/97   Vx.x   special version using imsl
c                      change matrix routine and L-rho
c    23/10/97   V2.2   - use double precision (real) matrix methods
c                      - introduced a workspace common block
c    29/10/97   V2.3   - introduced definition for damping factor
c                        relativ to omega, r_max and s_max
c    30/10/97   V2.4   - all methods should be correct now
c    31/10/97   V2.5   - now with gaussian distance taper
c                      - and gaussian time domain taper
c    06/11/97   V2.6   - starting work on Henry, Orcutt Parker method
c                      - fix problem with frequency=zero
c    12/01/98   V2.7   - fix use of minr (to be able to more than
c                        on receiver at the same offset)
c                      - rearrange help and add some more help
c                      - new option -Q
c                      - stacking of seismograms with same offset
c                      - allow different numbers of samples
c    14/01/98   V2.8   - be more verbose when stacking
c    08/06/98   V3.0   - added the plane wave stacking algorithm
c                        new major version as option naming changed
c    12/08/98   V3.1   - ok there was false information in the help text...
c                        it was a misuse of -P option
c    18/08/98   V3.2   - correct stacking algorithm 
c                        did refer to r(i) and not to r(i)/n
c    28/02/99   V3.3   - allow negative slowness values when stacking plane
c                        waves
c                      - changed order of if,elseif,.. section setting
c                        planewaves to the front
c    02/03/99   V3.4   - there was a servere bug in the spectra calculation
c                        routine - the transform array was not initialized
c                        correctly
c    13/05/99   V3.5   - allow scaling of individual spectral coefficients
72
73
74
75
c    20/04/00   V3.6   - there was an error in trace sorting in subroutine
c                        parker which should have lead to wrong results with
c                        non-sorted offset data
c                      - and gram(ntr,ntr) was zero
thomas.forbriger's avatar
thomas.forbriger committed
76
c    27/04/00   V3.7   - report HOP expansion numbers
thomas.forbriger's avatar
thomas.forbriger committed
77
c                      - scale Fourier Bessel transform with HOP factors
78
79
c    29/04/00   V3.8   - hooo - there was still an error in the HOP gram
c                        inverse expansion to alpha
80
81
c    24/05/00   V3.9   - changed cosine distance taper to apply factor greater
c                        than zero to last trace
82
83
c    21/06/00   V3.10  the trapezoid rule in subroutine backcoeff was awfully
c                      misbehaved
84
c    23/06/00   V3.11  trapezoid rule was still wrong by a constant factor 2
85
86
87
88
89
90
91
c    12/06/02   V3.12  two years later :-)
c                      Introduce a "number of wavelength" taper (option -W).
c                      This functionality is implemented into the subroutines
c                      planestack for the Slant Stack algorithm and into
c                      subroutine expmodel. In expmodel it makes only sense
c                      together with the Bessel transform, since only in that
c                      case the inverse of the Gram matrix is diagonal.
92
93
c    13/09/02   V3.13  - add extra offset taper
c                      - output seismogram spectra
thomas.forbriger's avatar
thomas.forbriger committed
94
c    16/09/02   V3.14  - write phasor walkout to file
thomas.forbriger's avatar
thomas.forbriger committed
95
96
97
c    28/03/06   V3.15  - apply special (offset dependent taper) after
c                        rescaling waveforms
c                      - corrected subroutine specialtap
98
c    27/11/09   V3.16  - some corrections to satify gfortran
thomas.forbriger's avatar
thomas.forbriger committed
99
c               V3.17  - pwo_init takes an argument!
100
c    10/03/10   V3.19  - correction in taper function: second index of array
thomas.forbriger's avatar
thomas.forbriger committed
101
c                        spectra is sample index
thomas.forbriger's avatar
thomas.forbriger committed
102
103
104
c    13/11/10   V3.20  - do not expose misleading term "green" to the
c                        user
c                      - use GSL instead of numerical recipes
105
c    30.12.2010 V3.21  - implemented libfapidxx
thomas.forbriger's avatar
thomas.forbriger committed
106
107
c    12/01/2011 V3.21b - added definition of Fourier transformation 
c                        online help text
108
109
110
111
112
113
114
115
116
117
118
c    10/01/2012 V3.22  - implemented radial component
c                        tested with Fourier-Bessel transformation and
c                        HOP inversion both with Bessel kernel and
c                        Hankel(1) kernel; both work well or at least as
c                        well as reconstruction tests for vertical
c                        components (HOP apparently looses some signal
c                        energy due to damping); K-damping, exp-damping, and
c                        boxcar damping all producde nuemrical errors in
c                        the test; slant stack analysis does not
c                        distinguish between vertical and radial
c                        component
119
120
121
122
123
124
125
c
c==============================================================================
c
      program greda
c
c first we declare some general variables
c
126
      character*79 version
127
      parameter(version=
128
     &'GREDA   V3.22   Calculate Fourier-Bessel expansion coefficients')
129
130
c
c calculations common block
131
      include 'greda_dim.inc'
132
133
134
135
136
137
138
139
140
141
      include 'greda.inc'
c any
      integer i,j
      real pi2
      parameter(pi2=2.*3.141592653589793)
c 
c----------------------------------------------------------------------
c here follows everything we need for the input data hold
c
c datafile
142
      character*80 filename, Fourierfile, informat
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
      real fdata(maxsamp)
      integer idata(maxsamp)
      equivalence(fdata, idata)
      real r(maxtr), dt, tfirst, maxr, minr
c receiver chain
      integer chain(maxtr), firstrec
c 
c----------------------------------------------------------------------
c here is everything we need to perform the calculations
c
c inner product damping exponents
      real rho, rhoq, sigma, expon
c 
c----------------------------------------------------------------------
c here follows what we need to hold and write the output data
c
c magic number for binary file identification
      integer magic
      character*4 cmagic
      parameter(cmagic='1234')
163
164
165
166
c magic number for trace spectra binary file identification
      integer spmagic
      character*4 cspmagic
      parameter(cspmagic='SP34')
167
c Fourier-Bessel coefficients
168
169
170
171
172
173
174
175
      character*80 greensfile
      complex green(maxslo, maxom)
      real slo(maxslo), om(maxom), omq
      real smax, fmax
c file
      integer lu
      parameter(lu=20)
c 
thomas.forbriger's avatar
thomas.forbriger committed
176
177
c selected method
      character*70 method
178
      character*4 kernel
thomas.forbriger's avatar
thomas.forbriger committed
179
c 
180
181
182
183
184
c----------------------------------------------------------------------
c here we go with command line parameters
c
c parameters
      real tapfrac, offtapfrac, edgefrac, minoff, stackdelta, rescaleexpo
185
      real hopnumberfrequency, wltaplen, wltapfrac
186
      real tapoffsets(4)
thomas.forbriger's avatar
thomas.forbriger committed
187
188
      real pwofreq, pwoslo
      character*(80) pwofilename, pwffilename, pwafilename
thomas.forbriger's avatar
thomas.forbriger committed
189
      logical hopnumberthis, backtranscale
190
191
192
      logical debug, overwrite, hankel1, hankel2, verbose, uzerospecial
      logical matrixmethod, lininv, offtaper, edgeset, linkinv
      logical disgram, softcosine, gausstaper, gausstime, parkermethod
thomas.forbriger's avatar
thomas.forbriger committed
193
      logical stackso, planewave, rescale, specrescale, hopnumbers
thomas.forbriger's avatar
thomas.forbriger committed
194
      logical applywltaper,specialtaper,writeFourier
thomas.forbriger's avatar
thomas.forbriger committed
195
      logical pwofile, pwoautofile, pwosel
196
197
c command line
      integer maxopt, lastarg, iargc
198
      parameter(maxopt=37)
199
200
      character*4 optid(maxopt)
      character*80 optarg(maxopt)
201
202
203
204
      logical optset(maxopt), opthasarg(maxopt)
c here are the keys to our commandline options
      data optid/2h-d,2h-t,2h-s,2h-n,2h-f,2h-o,2h-1,2h-2,2h-v,2h-T,2h-S,
     &  2h-M,2h-L,2h-q,2h-E,2h-K,2h-D,2h-a,2h-b,2h-g,2h-H,2h-O,2h-Q,2h-B,
205
     &  2h-P,2h-r,2h-F,2h-N,2h-X,2h-W,4h-tap,4h-spo,3h-pw,4h-pwf,4h-pwa,
206
     &  '-ty','-R'/
207
      data opthasarg/.FALSE.,4*.TRUE.,4*.FALSE.,.TRUE.,3*.FALSE.,2*.TRUE.,
208
     &  6*.FALSE.,2*.TRUE.,.TRUE.,.FALSE.,.TRUE.,.FALSE.,.TRUE.,.FALSE.,
209
     &  7*.TRUE.,.false./
210
      data optarg/1h-,3h10.,2h8.,1h5,4h100.,4*1h-,2h0.,3*1h-,5h1.,1.,
211
     &  2h1.,6*1h-,4h0.01,5h1.,1.,4*1h-,3h10.,1h-,6h1.,10.,
212
     &  11h0.,0.,0.,0.,4*3hnil,'sff','-'/
213
214
215
216
217
218
c 
c======================================================================
c 
c go on with executable code
c
      print *,version
219
      print *,'Usage: greda datafile coeffile [-ty format] [-R]'
220
      print *,'             [-L] [-K] [-P] [-D] [-M] [-H]'
221
      print *,'             [-n nslo] [-s smax] [-f fmax]'
222
223
      print *,'             [-t frac] [-T frac] [-E edge]'
      print *,'             [-W n,f] [-a] [-b] [-g]'
224
      print *,'             [-O minoff] [-B delta] [-r expo] [-F]'
225
226
      print *,'             [-1] [-2] [-q f,e] [-Q f,e] [-S]'
      print *,'             [-v] [-o] [-N f] [-X]'
227
228
      print *,'             [-tap o1,o2,o3,o4]'
      print *,'             [-spo filename]'
thomas.forbriger's avatar
thomas.forbriger committed
229
230
231
      print *,'             [-pw f,p,file]'
      print *,'             [-pwf filename]'
      print *,'             [-pwa filename]'
232
      print *,'or     greda -help'
233
      print *,'or     greda -xhelp'
234
235
236
c 
      if (iargc().lt.1) stop 'ERROR: missing parameters'
      call getarg(1, filename)
237
238
239
240
      if (filename(1:6).eq.'-xhelp') then
        call sff_help_details
        stop
      else if (filename(1:5).eq.'-help') then
241
        print *,' '
242
243
244
        print *,'Calculate Fourier-Bessel expansion coefficients'
        print *,'for a single-shot seismic profile'
        print *,'by using linear inverse theory. Actually does'
thomas.forbriger's avatar
thomas.forbriger committed
245
        print *,'a Fourier-Bessel transform by default.'
246
        print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
247
        print *,CVSID
248
        print *,'Copyright 1997,2010 by Thomas Forbriger'
thomas.forbriger's avatar
thomas.forbriger committed
249
        print *,' '
250
251
252
253
254
        print *,'datafile     Name of file containing seismograms.'
        print *,'             The program will expect a homogeneous dataset.'
        print *,'             This means a dataset where all traces have'
        print *,'             the same time of first sample and the same'
        print *,'             sampling interval.'
255
        print *,'coeffile     Name of file to contain results.'
256
        print *,'-ty format   input file format (see list below)'
257
        print *,' '
258
259
260
261
262
263
        print *,'-R           radial component seismograms of a vertical'
        print *,'             single force or an explosion are to be'
        print *,'             transformed.'
        print *,'             (tested for HOP-inversion and'
        print *,'             Fourier-Bessel transformation)'
        print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
264
        print *,'Available alternatives to the Fourier-Bessel transform:'
265
266
267
268
269
270
271
272
273
274
275
276
        print *,'-L           Calculate by linear inversion (exp-damping).'
        print *,'-K           Calculate by linear inversion (K_0-damping).'
        print *,'-H           Use the method following Henry, Orcutt and Parker:'
        print *,'             Calculate by linear inversion (Lorentz-damping).'
        print *,'             This uses a special integral formula that'
        print *,'             leads to a direct matrix inversion.'
        print *,'             The theory is given in:'
        print *,'               Henry, M., Orcutt, J.A., Parker, R.L., 1980,'
        print *,'               A new method for slant stacking refraction data'
        print *,'               Geoph. Res. Lett., vol. 7, 1073-1076'
        print *,'-D           Calculate by linear inversion (gram matrix'
        print *,'             calculated by discrete numerical integration).'
277
        print *,'-M           Calculate coefficient matrix by simple matrix'
278
279
280
281
282
283
        print *,'             inversion. (This is a DIRTY way - please don''t'
        print *,'             take it!)'
        print *,'-P           Assume that data represents plane waves. Solve'
        print *,'             by ordinary stacking method (well known as'
        print *,'             ''slant stack'').'
        print *,' '
284
285
286
        print *,'How to define the frequency-slowness range:'
        print *,'-n nslo      Number of slowness for which coefficients'
        print *,'             are calculated. (default is number of'
287
        print *,'             seismic traces read)'
288
289
        print *,'-s smax      Maximum slowness value iin km/s for which'
        print *,'             coefficients are calculated. (default is ',
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
     &          optarg(3)(1:4),')'
        print *,'-f fmax      Maximum frequency value in Hz. (default'
        print *,'             is to take all theoretical frequencies)'
        print *,' '
        print *,'How to apply tapers to the input data:'
        print *,'-t tfrac     Tapering fraction for each end of the time'
        print *,'             series in percent. (default is ',
     &          optarg(2)(1:4),')'
        print *,'             In the case of a gaussian taper this value gives'
        print *,'             the amplitude fraction of the edge samples'
        print *,'             compared to it''s original values.'
        print *,'-T ofrac     Tapering (cosine taper) fraction for the far end'
        print *,'             of the profile in percent.'
        print *,'             In the case of a gaussian taper this value gives'
        print *,'             the amplitude fraction of the last trace'
        print *,'             compared to it''s original value.'
        print *,'             The default is not to apply any offset domain'
        print *,'             taper.'
308
309
310
311
312
313
314
315
316
        print *,'-tap o1,o2,o3,o4'
        print *,'             special offset taper'
        print *,'             the taper is 0. for offsets smaller than'
        print *,'               o1 and offsets larger than o4'
        print *,'             the taper i 1. for offsets between o2'
        print *,'               and o3'
        print *,'             it has a sine edge between o1 and'
        print *,'               and o2 and a cosine edge between o3'
        print *,'               and o4'
317
318
319
320
321
322
323
324
325
326
        print *,'-E edge      Specify the sample from which on all'
        print *,'             samples should be tapered to zero as a'
        print *,'             fraction of the time series length.'
        print *,'             (2.*tfrac <= edge <= 1.)'
        print *,'-a           Apply smooth cosine distance taper ',
     &            '(default is hard).'
        print *,'-b           Apply gaussian distance taper ',
     &            '(default is hard cosine).'
        print *,'-g           Apply gaussian time domain taper ',
     &            '(default is cosine).'
327
328
329
330
331
332
333
334
335
        print *,'-W n,f       Apply an offset domain cosine taper of'
        print *,'             exactly ''n'' wavelengths length, where'
        print *,'             ''n'' may be a floating point value.'
        print *,'             The taper fraction (falling edge) is'
        print *,'             given by ''f'' in percent of the taper'
        print *,'             length. The taper length depends then on'
        print *,'             frequency and slowness.'
        print *,'             This option applies to only to the Slant'
        print *,'             Stack and the Bessel transformation.'
thomas.forbriger's avatar
thomas.forbriger committed
336
337
338
        print *,'             In terms of slowness resolution ''n'' '
        print *,'             defines it to be'
        print *,'             delta p = p / n.'
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
        print *,'-O minoff    Set minimum offset difference that will be'
        print *,'             used to find the minimum receiver distance.'
        print *,'             That is usefull in cases where multiple'
        print *,'             receivers occur at the same offset position.'
        print *,'             (default is ',
     &          optarg(22)(1:4),')'
        print *,'-B delta     Stack all traces lying within the same offset'
        print *,'             interval delta. We will take the mean offset'
        print *,'             value for the stacked result.'
        print *,'-r expo      Rescale seismograms to energy damping of'
        print *,'             r^(-expo) with r being the offset. For'
        print *,'             surface waves without dissipation expo should'
        print *,'             be one.'
        print *,'-F           Do rescaling in the frequency domain to energy'
        print *,'             damping of (omega*r)^(-expo). In this'
thomas.forbriger's avatar
thomas.forbriger committed
354
        print *,'             case every single Fourier coefficient will'
355
356
357
358
        print *,'             be rescaled for itself. This procedure will'
        print *,'             just leave the phase information. No amplitude'
        print *,'             information will be conserved.'
        print *,' '
359
360
        print *,'Parameters defining the expansion:'
        print *,'-1           Use the Hankel function H^(1)_0 instead of J_0'
thomas.forbriger's avatar
thomas.forbriger committed
361
        print *,'             (see remark on Fourier transformation below)'
362
        print *,'-2           Use the Hankel function H^(2)_0 instead of J_0'
thomas.forbriger's avatar
thomas.forbriger committed
363
        print *,'             (see remark on Fourier transformation below)'
364
365
366
367
368
369
        print *,'-q f,e       Damping factor for inner product.'
        print *,'             The inner product damping will be calculated'
        print *,'             as rho=delta_r_min*f*omega**e.'
        print *,'             default is: ',optarg(14)(1:8)
        print *,'-Q f,e       Damping factor for inner product.'
        print *,'             The inner product damping will be calculated'
370
371
372
        print *,'             as rho=f*omega**e. Overrides settings of'
        print *,'             -q option.'
        print *,'             proposed: ',optarg(23)(1:8)
373
374
375
        print *,'-S           Special handling of zero slowness. This option'
        print *,'             is useful together with the hankel functions'
        print *,'             which become singular at argument zero.'
376
        print *,'             To calculate the coefficients at'
thomas.forbriger's avatar
thomas.forbriger committed
377
378
        print *,'             slowness zero we use the Bessel function.'
        print *,'-X           scale Fourier Bessel transform with HOP factors'
379
        print *,'             (crazy option!)'
380
        print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
381
382
383
384
385
386
387
388
389
390
391
        print *,'Phasor walkout:'
        print *,'-pw f,p,file write phasor walkout for frequency f and'
        print *,'             slowness p to file'
        print *,'-pwf file    read phasor walkout selection from file'
        print *,'             each line has three entries:'
        print *,'             frequency, slowness, filename'
        print *,'-pwa file    read phasor walkout selection from file'
        print *,'             but generate output filenames automatic'
        print *,'             each line has two entries:'
        print *,'             frequency, slowness'
        print *,' '
392
393
394
        print *,'Other parameters:'
        print *,'-o           Overwrite existing output file.'
        print *,'-v           Be somehow verbose.'
thomas.forbriger's avatar
thomas.forbriger committed
395
        print *,'-N f         print HOP numbers for frequency f'
396
397
398
        print *,'-spo filename'
        print *,'             write seismic traces'' Fourier'
        print *,'             coefficients to file ''filename'' '
399
400
401
402
403
404
405
406
        print *,' '
        print *,'How it works:'
        print *,'In cases -L, -K, -H and -D (linear inversion) we use'
        print *,'a scalar product of the type'
        print *,' '
        print *,'  (f,g) = int_0^P f(p) g(p) D(p) p dp.'
        print *,' '
        print *,'J_0(p*omega*r_j) is called the representer of the data'
thomas.forbriger's avatar
thomas.forbriger committed
407
        print *,'value d_j, which here is the Fourier expansion coefficient'
408
409
410
411
412
413
414
415
416
417
418
419
420
        print *,'for the vartical displacement at frequency omega and'
        print *,'offset r_j.'
        print *,' '
        print *,'In case -D P is equal to the maximum slowness and D(p)=1.'
        print *,'In the other cases P is infinity and D(p) is given by'
        print *,' '
        print *,'  D(p) = exp(-rho^2*p^2),         (case -L)'
        print *,'  D(p) = K_0(rho*p), and          (case -K)'
        print *,'  D(p) = 1/(p^2+1/rho^2).         (case -H)'
        print *,' '
        print *,'rho should be chosen somewhere around delta_r_min*omega,'
        print *,'where delta_r_min is the minimal offset difference.'
        print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
        print *,'Definition of the Fourier transformation:'
        print *,'The Fourier transformation used in this program and in'
        print *,'related programs (like gremlin, syg, and gresy) is'
        print *,'defined as'
        print *,' '
        print *,'  U(omega) = int_-infnity^+infnity u(t) exp(-i*omega*t) dt'
        print *,' '
        print *,'Theoretical descriptions of wave propagation often use'
        print *,'exp(i*omega*t) as transform kernel instead of exp(-i*omega*t)'
        print *,'in order to make positive wavenumbers equivalent to wave'
        print *,'propagation in positive coordinate direction. The Fourier'
        print *,'coefficients calculated by this program consequently are'
        print *,'the complex conjugates of those used in theory. Where'
        print *,'H^(2)_0 is used in theory, you have to use H^(1)_0'
        print *,'in greda.'
        print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
437
438
        call pwo_cvsid
        print *,' '
439
440
441
442
443
        print *,'compiled array dimensions are:'
        print *,'      samples: ',maxsamp
        print *,'       traces: ',maxtr
        print *,'   slownesses: ',maxslo
        print *,'  frequencies: ',maxom
444
445
        print *,' '
        print *,'magic numbers:'
446
        print *,'  Fourier-Bessel coefficient files: ',cmagic
447
        print *,'  Trace coefficient files: ',cspmagic
448
449
        print *,' '
        call sff_help_formats
450
451
452
        stop
      endif
c 
thomas.forbriger's avatar
thomas.forbriger committed
453
454
455
c
c----------------------------------------------------------------------
c 
456
457
c configure from command line
c 
thomas.forbriger's avatar
thomas.forbriger committed
458
c      print *,'DEBUG: call iargc'
459
      if (iargc().lt.2) stop 'ERROR: missing parameters'
thomas.forbriger's avatar
thomas.forbriger committed
460
c      print *,'DEBUG: call tf_cmdline'
461
462
      call tf_cmdline(3, lastarg,
     &     maxopt, optid, optarg, optset, opthasarg)
thomas.forbriger's avatar
thomas.forbriger committed
463
c      print *,'DEBUG: returned from tf_cmdline'
464
465
466
      call getarg(1, filename)
      call getarg(2, greensfile)
      debug=optset(1)
thomas.forbriger's avatar
thomas.forbriger committed
467
468
      if (debug) print *,'DEBUG: in options - place 1'
      read(optarg(2), *, err=99) tapfrac
469
470
      if (tapfrac.gt.50.) stop 'ERROR: silly taper'
      if (tapfrac.lt.0.) stop 'ERROR: negative taper'
thomas.forbriger's avatar
thomas.forbriger committed
471
      read(optarg(3), *, err=99) smax
472
473
474
475
      smax=smax*0.001
      read(optarg(4), '(i10)', err=99) nslo
      if (nslo.lt.1) stop 'ERROR: need positive number of slownesses'
      if (nslo.gt.maxslo) stop 'ERROR: too many slownesses'
thomas.forbriger's avatar
thomas.forbriger committed
476
      read(optarg(5), *, err=99) fmax
477
478
      if (fmax.lt.0.) stop 'ERROR: negative maximum frequency'
      overwrite=optset(6)
thomas.forbriger's avatar
thomas.forbriger committed
479
      if (debug) print *,'DEBUG: in options - place 2'
480
481
482
483
484
      hankel1=optset(7)
      hankel2=optset(8)
      verbose=optset(9)
      offtaper=optset(10)
      if (offtaper) then
thomas.forbriger's avatar
thomas.forbriger committed
485
        read(optarg(10), *, err=99) offtapfrac
486
487
488
        if (offtapfrac.gt.50.) stop 'ERROR: silly taper'
        if (offtapfrac.lt.0.) stop 'ERROR: negative taper'
      endif
thomas.forbriger's avatar
thomas.forbriger committed
489
      if (debug) print *,'DEBUG: in options - place 3'
490
491
492
      uzerospecial=optset(11)
      matrixmethod=optset(12)
      lininv=optset(13)
thomas.forbriger's avatar
thomas.forbriger committed
493
      read (optarg(14), *) sigma,expon
494
495
      edgeset=optset(15)
      if (edgeset) then
thomas.forbriger's avatar
thomas.forbriger committed
496
        read(optarg(15), *, err=99) edgefrac
497
498
499
500
        if (edgefrac.gt.1.) stop 'ERROR: end of taper behind last sample'
        if (edgefrac.lt.(0.02*tapfrac)) 
     &    stop 'ERROR: edge does not leave enough space for taper'
      endif
thomas.forbriger's avatar
thomas.forbriger committed
501
      if (debug) print *,'DEBUG: in options - place 4'
502
503
504
505
506
507
      linkinv=optset(16)
      disgram=optset(17)
      softcosine=optset(18)
      gausstaper=optset(19)
      gausstime=optset(20)
      parkermethod=optset(21)
thomas.forbriger's avatar
thomas.forbriger committed
508
      read (optarg(22), *) minoff
509
      if ((.not.optset(14)).and.(optset(23)))
thomas.forbriger's avatar
thomas.forbriger committed
510
     &  read (optarg(23), *) sigma,expon
511
      stackso=optset(24)
thomas.forbriger's avatar
thomas.forbriger committed
512
      if (stackso) read (optarg(24), *) stackdelta
513
514
      planewave=optset(25)
      rescale=optset(26)
thomas.forbriger's avatar
thomas.forbriger committed
515
      if (debug) print *,'DEBUG: in options - place 5'
516
517
      specrescale=optset(27)
      if (rescale) then
thomas.forbriger's avatar
thomas.forbriger committed
518
        read(optarg(26), *) rescaleexpo
519
520
521
522
        if (specrescale) rescale=.false.
      else
        specrescale=.false.
      endif
thomas.forbriger's avatar
thomas.forbriger committed
523
524
525
      hopnumbers=optset(28)
      read(optarg(28), *) hopnumberfrequency
      backtranscale=optset(29)
526
527
      applywltaper=optset(30)
      read(optarg(30), *) wltaplen, wltapfrac
thomas.forbriger's avatar
thomas.forbriger committed
528
      if (debug) print *,'DEBUG: in options - place 6'
529
530
      specialtaper=optset(31)
      if (specialtaper) read(optarg(31), *) (tapoffsets(i), i=1,4)
thomas.forbriger's avatar
thomas.forbriger committed
531
532
      writeFourier=optset(32)
      Fourierfile=optarg(32)
thomas.forbriger's avatar
thomas.forbriger committed
533
534
535
536
537
538
      pwosel=optset(33)
      if (pwosel) read(optarg(33), *) pwofreq, pwoslo, pwofilename
      pwofile=optset(34)
      pwffilename=optarg(34)
      pwoautofile=optset(35)
      pwafilename=optarg(35)
539
      informat=optarg(36)
540
      radial=optset(37)
thomas.forbriger's avatar
thomas.forbriger committed
541
      if (debug) print *,'DEBUG: read options'
542
c 
543
544
      if ((.not.(planewave)).and.(smax.lt.0.))
     &  stop 'ERROR: negative maximum slowness'
thomas.forbriger's avatar
thomas.forbriger committed
545
546
547
548
549
550
551

c----------------------------------------------------------------------
c initialize common block for phasor walkout
c      print *,'DEBUG: call pwo_init'
      call pwo_init(verbose)
c      print *,'DEBUG: returned from pwo_init'
c----------------------------------------------------------------------
552
553
c report
      print *,' '
554
555
556
557
558
559
560
561
562
563
564
565
      if (radial) then
        if (hankel1) then
          print *,'I will use the Hankel function H^(1)_1 of order one'
          kernel='H1_1'
        elseif (hankel2) then
          print *,'I will use the Hankel function H^(2)_1 of order one'
          kernel='H2_1'
        else
          print *,'I will use the Bessel function of the first kind',
     &      ' J_1 of order one'
          kernel='J_1'
        endif
566
      else
567
568
569
570
571
572
573
574
575
576
577
        if (hankel1) then
          print *,'I will use the Hankel function H^(1)_0 of order zero'
          kernel='H1_0'
        elseif (hankel2) then
          print *,'I will use the Hankel function H^(2)_0 of order zero'
          kernel='H2_0'
        else
          print *,'I will use the Bessel function of the first kind J_0',
     &      ' of order zero'
          kernel='J_0'
        endif
578
579
580
      endif
      print *,' '
c 
581
c initialize wavelength taper factors
thomas.forbriger's avatar
thomas.forbriger committed
582
      if (debug) print *,'DEBUG: call initwltaper(wltaplen,wltapfrac)'
583
      call initwltaper(wltaplen,wltapfrac)
thomas.forbriger's avatar
thomas.forbriger committed
584
585
586
587
588
589
590
591
c
c----------------------------------------------------------------------
c phasor walkout selection
c
      if (pwosel) 
     &  call pwo_selpair(pwofreq*pi2,pwoslo,pwofilename,verbose)
      if (pwofile) call pwo_readsel(pwffilename, .false., verbose)
      if (pwoautofile) call pwo_readsel(pwafilename, .true., verbose)
592
c 
593
594
595
596
597
c----------------------------------------------------------------------
c 
c go for the real calculations
c 
c read seismic data
thomas.forbriger's avatar
thomas.forbriger committed
598
      if (debug) print *,'DEBUG: call readdata'
599
600
      call sff_select_input_format(informat, ierr)
      if (ierr.ne.0) stop 'ERROR: selecting input file format'
601
602
      call readdata(filename, fdata, idata, spectra, r, maxr,
     &     maxtr, maxsamp, ntr, nsamp, dt, tfirst)
thomas.forbriger's avatar
thomas.forbriger committed
603
      if (debug) print *,'DEBUG: returned from readdata'
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
c 
      if ((.not.optset(4)).or.(matrixmethod)) nslo=ntr
      if (nslo.gt.maxslo) stop 'ERROR: too many slownesses - check code'
c 
c do stacking
      if (stackso) call stackthem(r, stackdelta, maxr, verbose)
c
c get distances in increasing order
      call tf_rchain(r, chain, ntr, firstrec, 1)
c
c find minimum distance step
      j=firstrec
      i=chain(j)
      minr=maxr
      do while (i.gt.0)
        if (abs(r(i)-r(j)).gt.minoff) minr=min(minr,abs(r(i)-r(j)))
        j=i
        i=chain(i)
      enddo
      print *,' '
      print *,' minimum distance between receivers: ',minr
      print *,'maximum source to receiver distance: ',maxr
c 
      if ((.not.optset(14)).and.(optset(23)))
     &  sigma=sigma/minr
c 
      print *,'rho=',minr*sigma,'*omega**',expon
c 
c apply tapers
      call taper(maxsamp, maxtr, ntr, nsamp, tapfrac, offtapfrac,
     &  maxr, spectra, r, offtaper, verbose, edgeset, edgefrac,
     &  softcosine, gausstaper, gausstime)
thomas.forbriger's avatar
thomas.forbriger committed
636
637
638
c 
c rescale traces if we want them to be rescaled
      if (rescale) call dorescale(rescaleexpo, r)
639
640
641
642
643
c
c apply special tapers
      if (specialtaper) 
     &  call specialtap(maxsamp, maxtr, ntr, nsamp, tapoffsets, maxr,
     &    spectra, r, verbose)
644
645
646
647
c 
c calculate complex spectra
      call calcspec(dt, tfirst, om,
     &  fmax, optset(5))
648
649
c
c write Fourier coefficients
thomas.forbriger's avatar
thomas.forbriger committed
650
651
      if (writeFourier) 
     &  call Fourierwrite(Fourierfile, spmagic, cspmagic, overwrite,
652
     &    r, maxr, om)
653
654
655
656
657
658
659
660
661
662
c 
c rescale traces if we want them to be rescaled
      if (specrescale) call dospecrescale(rescaleexpo, r, om)
c 
c set slowness range
      call setslo(maxslo, nslo, smax, slo, 
     &  hankel1, hankel2, uzerospecial)
c 
c----------------------------------------------------------------------
c 
663
c now calculate the Fourier-Bessel matrix
664
665
c handle each frequency individually
c
thomas.forbriger's avatar
thomas.forbriger committed
666
      hopnumberthis=.false.
667
668
      do i=1,nom
c 
thomas.forbriger's avatar
thomas.forbriger committed
669
c init phasor walkout
thomas.forbriger's avatar
thomas.forbriger committed
670
        call pwo_initable(om,slo,nom,nslo,i,verbose)
thomas.forbriger's avatar
thomas.forbriger committed
671
c 
672
673
674
675
676
677
c damping
c
c something usefull
        omq=om(i)*om(i)
        rho=minr*sigma*om(i)**expon
        rhoq=rho*rho
thomas.forbriger's avatar
thomas.forbriger committed
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
c 
c do we hopnumber? ;-)
        if (hopnumbers) then
          hopnumberthis=.false.
c          print *,abs(hopnumberfrequency-om(i)/pi2)
c          print *,(0.55*(om(2)-om(1))/pi2)
          if (abs(hopnumberfrequency-om(i)/pi2).lt.(0.501*(om(2)-om(1))/pi2)) 
     &    then
            hopnumberthis=.true.
            print *,' '
            print *,'HOP numbers request for ',
     &              hopnumberfrequency,' Hz comes at ',om(i)/pi2,' Hz'
            print *,'rho is ',rho
          endif
        endif
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
c
c algorithm section
c =================
c
c Provided algorithms are:
c
c   1. Slant Stack (assuming plane waves)
c   2. HOP-method (linear inversion with Lorentz-damping)
c   3. linear inversion with exp-damping
c   4. linear inversion with K_0-damping
c   5. linear inversion with boxcar damping
c   6. the dirty direct matrix inversion
c   7. discrete Fourier-Bessel transformation
c
c The following conditionals select one of the provided algorithms.
c The standard sequence of calculations is:
c
c   1. calculate a Gram matrix
c      (subroutines gramex, gramket, gramdis)
c   2. calculate expansion coefficients alpha from Gram matrix
c      by numerical solution of system of linear equations
c      (subroutine modexp) 
c   3. calculate model vector of linear inversion from
c      coefficients alpha and selected representer
c      (subroutine expmodel)
718
c   4. scale model to Fourier-Bessel matrix coefficients
719
720
721
722
723
724
725
726
727
728
729
730
731
c      (subroutines scalpark, scalex, scalkmet)
c
c Deviations from this scheme:
c
c   - the boxcar damping does not need scaling (step 4)
c   - the Bessel transformation combines steps 1 and two in subroutine
c     backcoeff and does not need scaling (step 4)
c   - the HOP-method knows the inverse of the Gram matrix and omits step 2
c   - the slant stack is too easy to use more than one subroutine ;-)
c     (subroutine planestack)
c   - the dirty direct inversion sets up its one system of linear equations
c     (subroutine forwardmat) and uses subroutine modexp to solve it
c     (steps 3 and 4 are not necessary)
732
733
734
c 
        if (planewave) then
c 
735
c 1. Slant Stack (assuming plane waves)
736
737
738
739
740
741
c calculate stacking algorithm with plane wave assumption
c -------------------------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'assume plane waves and use stacking algorithm...'
            print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
742
            method='Slant Stack'
743
          endif
744
          call planestack(om(i), slo, r, green, i, applywltaper)
745
746
747
c 
        elseif (parkermethod) then
c 
748
c 2. HOP-method (linear inversion with Lorentz-damping)
749
750
751
752
753
754
c calculate by Henry Orcutt Parker integral
c -----------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'use gram matrix given by Henry, Orcutt and Parker'
            print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
755
            method='HOP-inversion with '//kernel//' kernel'
756
757
758
759
760
761
762
            call nullmodel(green)
          else
            if (verbose) then
              print *,'f=',om(i)/pi2,'   rho=',rho
            endif
            rho=om(i)/rho
            rhoq=omq/rhoq
thomas.forbriger's avatar
thomas.forbriger committed
763
            call parker(rho, r, spectra(1, i), chain, firstrec, hopnumberthis)
764
            call expmodel(om(i), r, slo, green(1, i),
765
     &        hankel1, hankel2, uzerospecial, .false.)
thomas.forbriger's avatar
thomas.forbriger committed
766
            call scalpark(nslo, rhoq, omq, green(1, i), slo,
thomas.forbriger's avatar
thomas.forbriger committed
767
     &        hopnumberthis,ntr)
768
769
770
771
          endif
c 
        elseif (lininv) then
c 
772
c 3. linear inversion with exp-damping
773
774
775
776
777
778
c calculate by linear inversion exponential damping
c -------------------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'do it by linear inversion (exponential damping)'
            print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
779
            method='inversion with exp-damping and '//kernel//' kernel'
780
781
782
783
784
785
786
787
            call nullmodel(green)
          else
            if (verbose) then
              print *,'f=',om(i)/pi2,'   rho=',rho
            endif
            call gramex(rhoq, omq, r)
            call modexp(i, spectra(1, i))
            call expmodel(om(i), r, slo, green(1, i),
788
     &        hankel1, hankel2, uzerospecial, .false.)
thomas.forbriger's avatar
thomas.forbriger committed
789
            call scalex(nslo, rhoq, green(1, i), slo, ntr)
790
791
792
793
          endif
c 
        elseif (linkinv) then
c 
794
c 4. linear inversion with K_0-damping
795
796
797
798
799
800
c calculate by linear inversion K_0 damping
c -----------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'do it by linear inversion (K_0-damping)'
            print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
801
            method='inversion with K0-damping and '//kernel//' kernel'
802
803
804
805
806
807
808
809
            call nullmodel(green)
          else
            if (verbose) then
              print *,'f=',om(i)/pi2,'   rho=',rho
            endif
            call gramkmet(rhoq, omq, r)
            call modexp(i, spectra(1, i))
            call expmodel(om(i), r, slo, green(1, i),
810
     &        hankel1, hankel2, uzerospecial, .false.)
thomas.forbriger's avatar
thomas.forbriger committed
811
            call scalkmet(nslo, rho, green(1, i), slo, ntr)
812
813
814
815
          endif
c 
        elseif (disgram) then
c 
816
c 5. linear inversion with boxcar damping
817
818
819
820
821
822
823
824
825
826
827
828
829
c calculate by linear inversion with discrete gram
c ------------------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'do it by linear inversion (discrete gram)'
            print *,' '
          endif
          if (verbose) then
            print *,'going for frequency ',i,' of ',nom
          endif
          call gramdis(slo, om(i), r)
          call modexp(i, spectra(1, i))
          call expmodel(om(i), r, slo, green(1, i), 
830
     &      hankel1, hankel2, uzerospecial, .false.)
831
832
833
c 
        elseif (matrixmethod) then
c 
834
c 6. the dirty direct matrix inversion
835
c calculate Fourier-Bessel matrix by matrix inversion method
836
837
838
839
840
841
c -------------------------------------------------
          if (i.eq.1) then
            print *,' '
            print *,'do it by direct matrix inversion'
            print *,' '
            print *,'THIS IS A DIRTY WAY! You will run into trouble...'
thomas.forbriger's avatar
thomas.forbriger committed
842
            method='dirty direct matrix inversion'
843
844
845
846
847
848
849
850
851
          endif
          call forwardmat(om(i), slo, r, hankel1, hankel2, uzerospecial)
          call modexp(i, spectra(1, i))
          do j=1,nslo
            green(j, i)=alpha(j)
          enddo
c 
        else
c 
852
c 7. discrete Fourier-Bessel transformation
thomas.forbriger's avatar
thomas.forbriger committed
853
854
c perform a Fourier Bessel transform
c ----------------------------------
855
856
          if (i.eq.1) then
            print *,' '
thomas.forbriger's avatar
thomas.forbriger committed
857
            print *,'do it by inverse Fourier Bessel transform'
thomas.forbriger's avatar
thomas.forbriger committed
858
            method='Fourier Bessel transform with '//kernel//' kernel'
859
860
          endif
          call backcoeff((verbose.and.(i.eq.1)), r, om(i), 
thomas.forbriger's avatar
thomas.forbriger committed
861
     &      spectra(1, i), chain, firstrec, hopnumberthis)
862
          call expmodel(om(i), r, slo, green(1, i), 
863
     &      hankel1, hankel2, uzerospecial, applywltaper)
thomas.forbriger's avatar
thomas.forbriger committed
864
865
866
867
868
869
          if (backtranscale) then
            if (i.eq.1) then
              call nullmodel(green)
            else
              rho=om(i)/rho
              rhoq=omq/rhoq
thomas.forbriger's avatar
thomas.forbriger committed
870
              call scalpark(nslo, rhoq, omq, green(1, i), slo,
thomas.forbriger's avatar
thomas.forbriger committed
871
     &          hopnumberthis,ntr)
thomas.forbriger's avatar
thomas.forbriger committed
872
873
            endif
          endif
874
875
876
c 
        endif
c 
thomas.forbriger's avatar
thomas.forbriger committed
877
c write phasor walkout to file
thomas.forbriger's avatar
thomas.forbriger committed
878
        call pwo_write(overwrite, verbose, method, r, ntr)
thomas.forbriger's avatar
thomas.forbriger committed
879
c 
880
881
882
883
884
885
886
c in any case make shure that verbose is switched on only for
c first loop cycle
c        verbose=.false.
      enddo
c 
c----------------------------------------------------------------------
c 
887
c write Fourier-Bessel coefficients (easy to use)
888
889
890
c 
      print *,' '
      if (overwrite) then
891
892
        print *,'opening coefficient file ',
     &    greensfile(1:index(greensfile,' ')),
893
894
895
     &    ' - overwrite mode'
        open(lu, file=greensfile, form='unformatted', err=98)
      else
896
897
        print *,'opening coefficient file ',
     &    greensfile(1:index(greensfile,' '))
898
899
900
901
902
903
904
905
906
907
908
        open(lu, file=greensfile, status='new', form='unformatted', err=98)
      endif
      call tf_magic(cmagic, magic)
      write(lu, err=97) magic
      write(lu, err=97) nom, nslo
      write(lu, err=97) (om(i), i=1,nom), (slo(i), i=1,nslo)
      write(lu, err=97) ((green(j,i), i=1,nom), j=1,nslo)
      close(lu, err=96)
c 
      stop
   99 stop 'ERROR: reading command line argument'
909
910
911
   98 stop 'ERROR: opening coefficient file'
   97 stop 'ERROR: writing coefficient file'
   96 stop 'ERROR: closing coefficient file'
912
913
914
      end
c
c======================================================================
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
c
c summary of general subroutines
c ==============================
c
c read sff seismogram traces
c --------------------------
c
c     subroutine readdata(filename, fdata, idata, spectra, r, maxr,
c    &     maxtr, maxsamp, ntr, nsamp, dt, tfirst)
c       
c stack all seismograms within stackdelta (option -B stackdelta)
c ---------------------------------------
c reads common blocks from greda.inc
c
c     subroutine stackthem(r, stackdelta, maxr, verbose)
c
c rescale Fourier coefficients (option -F)
c ----------------------------
c reads common blocks from greda.inc
c
c     subroutine dospecrescale(expon, r, om)
c
c rescale seismogram traces (option -r expon)
c -------------------------
c reads common blocks from greda.inc
c
c     subroutine dorescale(expon, r)
c
c apply time and offset domain tapering (many options)
c -------------------------------------
c
c     subroutine taper(maxsamp, maxtr, ntr, nsamp, tapfrac, offtapfrac,
c    &  maxr, spectra, r, offtaper, verbose, edgeset, edgefrac,
c    &  softcosine, gausstaper, gausstime)
c
950
951
952
953
954
955
c apply special offset domain taper (option -tap tapoffsets)
c ---------------------------------
c
c     subroutine specialtap(maxsamp, maxtr, ntr, nsamp, tapoffsets, maxr
c    &    spectra, r, verbose)
c
956
957
958
959
960
c calculate complex Fourier coefficients from waveform data
c ---------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine calcspec(dt, tfirst, om, fmax, fmaxset)
961
962
963
964
965
c 
c write trace Fourier spectra (easy to use) (option -spo filename)
c ---------------------------------------­-
c reads common blocks from greda.inc
c 
thomas.forbriger's avatar
thomas.forbriger committed
966
c     subroutine Fourierwrite(filename, magic, cmagic, overwrite,
967
c    &  r, maxr, om)
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
c
c set slowness values for different expansion cases
c -------------------------------------------------
c fills the array slo with appropriate values
c
c     subroutine setslo(maxslo, nslo, smax, slo, 
c    &  hankel1, hankel2, uzerospecial)
c
c set coefficients for all slowness values to zero
c ------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine nullmodel(ogreen)
c
c expands the model, using alpha as expnsion coefficients and
c J_0, H^1_0, H^2_0 as a representer
c -----------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine expmodel(omega, r, slo, ogreen, 
988
c    &  hankel1, hankel2, uzerospecial, applywltaper)
989
990
991
992
993
994
995
996
c
c numerically solve the system of linear equations for the gram matrix
c --------------------------------------------------------------------
c claculates the expansion coefficients alpha
c reads common blocks from greda.inc
c
c     subroutine modexp(iom, s)
c
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
c initialize wavelength specific taper parameters
c -----------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine initwltaper(length,fraction)
c
c set wavelength specific taper to given wavelength
c -------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine setwltaper(omega,slo,r)
c
1009
c----------------------------------------------------------------------
1010
c 
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
c summary of subroutines specific to different approaches
c =======================================================
c
c fills expansion coefficients alpha with values appropriate to
c modified Fourier-Bessel transform
c -------------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine backcoeff(verbose, r, omega, spect, chain, firstrec,
c    &                     numbers)
c
c calculate Gram matrix for linear inversion with exp-damping 
c -----------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine gramex(rhoq, omq, r)
c
1028
1029
c scale coefficient matrix appropriate to exp-damping
c ---------------------------------------------------
1030
c
thomas.forbriger's avatar
thomas.forbriger committed
1031
c     subroutine scalex(nslo, rhoq, ogreen, slo, ntr)
1032
c
1033
1034
c calculate coefficient matrix directly by Slant Stack
c ----------------------------------------------------
1035
1036
c reads common blocks from greda.inc
c
1037
c     subroutine planestack(omega, slo, r, green, iomega, applywltaper)
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
c
c fill Gram matrix for a direct inversion (that's a dirty method)
c ---------------------------------------
c reads common blocks from greda.inc
c
c     subroutine forwardmat(omega, slo, r, hankel1, hankel2, uzerospecial)
c
c calculate Gram matrix for linear inversion with K_0-damping
c -----------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine gramkmet(rhoq, omq, r)
c
1051
c scale coefficient matrix appropriate to K_0-damping
1052
1053
c ---------------------------------------------
c
thomas.forbriger's avatar
thomas.forbriger committed
1054
c     subroutine scalkmet(nslo, rho, ogreen, slo, ntr)
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
c
c calculate Gram matrix for linear inversion with boxcar-damping
c --------------------------------------------------------------
c reads common blocks from greda.inc
c
c     subroutine gramdis(slo, om, r)
c
c function used by gramdis for numerical integration
c --------------------------------------------------
c
c     double precision function gramdisint(maxslo, nslo,
c    &  slo, rj, rk, om)
c
1068
1069
1070
c calculate expansion coefficients alpha for linear inversion
c with Lorentz-damping
c -----------------------------------------------------------
1071
1072
1073
1074
c reads common blocks from greda.inc
c
c     subroutine parker(rho, r, s, chain, firstrec, numbers)
c
1075
1076
c scale coefficient matrix appropriate to Lorentz-damping
c -------------------------------------------------------
1077
c
thomas.forbriger's avatar
thomas.forbriger committed
1078
c     subroutine scalpark(nslo, rhoq, omq, ogreen, slo, numbers, ntr)
1079
1080
1081
c
c======================================================================
c
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
c some general subroutines
c
c----------------------------------------------------------------------
c
      subroutine readdata(filename, fdata, idata, spectra, r, maxr,
     &     maxtr, maxsamp, ntr, nsamp, dt, tfirst)
c 
c read sff seismic traces
c
      character filename*(*)
      integer maxtr, maxsamp, ntr, nsamp
      real fdata(maxsamp)
      integer idata(maxsamp)
      complex*16 spectra(maxtr, maxsamp)
      real r(maxtr), dt, tfirst, maxr
c 
      integer lu, ierr, i
      real version
      parameter(lu=20)
      character timestamp*20, code*10, type*20, cs*1, date*6, time*10
      character wid2line*132
      integer srctime(7), datatime(7), tdif(7), itdif(7)
      real sc1, sc2, sc3, c1, c2, c3, tanf, idt, sffu_seconds
      integer nstack, insamp, time_compare
      logical last
c 
c open sff-file
      print *,'open sff data ',filename(1:index(filename,' '))
      call sff_ROpenS(lu, filename, version, timestamp, code,
     &  type, cs, sc1, sc2, sc3, date, time, ierr)
      if (ierr.ne.0) stop 'ERROR: opening seismogram file'
      if (index(code, 'S').eq.0) stop 'ERROR: no SRCE line'
      if (cs.ne.'C') stop 'ERROR: source coordinates are not cartesian'
      call sffu_timesrce(date, time, srctime) 
      ntr=0
      maxr=0.
   1  continue
        ntr=ntr+1
        insamp=maxsamp
        call sff_RTraceI(lu, tanf, idt, wid2line, insamp, fdata, idata,
     &    code, last, cs, c1, c2, c3, nstack, ierr)
        if (ierr.ne.0) stop 'ERROR: reading trace'
        if (index(code, 'I').eq.0) stop 'ERROR: no INFO line'
        if (cs.ne.'C') stop 'ERROR: trace coordinates are not cartesian'
        call sffu_timewid2(wid2line, datatime)
        if (ntr.eq.1) then
          dt=idt
          nsamp=insamp
          call time_sub(datatime, srctime, tdif)
          tfirst=sffu_seconds(tdif)
        else
          call time_sub(datatime, srctime, itdif)
          if (nsamp.ne.insamp)
     &      print *,'NOTICE: your time series have inconsitent numbers ',
     &        'of samples'
          nsamp=max(nsamp,insamp)
          if ((dt.ne.idt).or.
     &        (time_compare(tdif, itdif).ne.0)) then
            print *,'ERROR: sampling interval or'
            stop 'ERROR: time of first sample differs from previous trace'
          endif
        endif
        r(ntr)=sqrt((sc1-c1)**2+(sc2-c2)**2+(sc3-c3)**2)
        maxr=max(maxr,r(ntr))
        do i=1,maxsamp
          spectra(ntr, i)=(0.,0.)
        enddo
thomas.forbriger's avatar
thomas.forbriger committed
1149
        do i=1,insamp
1150
1151
1152
1153
1154
          spectra(ntr, i)=cmplx(fdata(i))
        enddo
        if ((ntr.lt.maxtr).and.(.not.last)) goto 1
      if (.not.(last)) then
        print *,'NOTICE: will ignore traces after ',ntr
1155
        call sff_close(lu)
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
      endif
      print *,'file read and closed'
      return
      end
c 
c----------------------------------------------------------------------
c
      subroutine stackthem(r, stackdelta, maxr, verbose)
c 
c stack all seismograms within stackdelta
c 
c get common block
1168
      include 'greda_dim.inc'
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
      include 'greda.inc'
c 
      real r(maxtr), stackdelta, maxr
      logical verbose
c 
c something to work here
      logical obsolete(maxtr)
      integer i,j,k,n
      real refoff
c 
      print *,' '
      print *,'  stack traces within ',stackdelta,'m offset range'
      print *,'  (entered with ',ntr,' traces)'
c 
      do i=1,ntr
        obsolete(i)=.false.
      enddo
c 
      do i=1,ntr-1
        if (.not.(obsolete(i))) then
          n=1
          do j=i+1,ntr
            if (.not.(obsolete(j))) then
              refoff=r(i)/float(n)
              if (abs(r(j)-refoff).le.stackdelta) then
                n=n+1
                if (verbose) print *,'    stack ',j,' at ',r(j),' --> ',i,
     &            ' at ',r(i)
                obsolete(j)=.true.
                do k=1,nsamp
                  spectra(i,k)=spectra(i,k)+spectra(j,k)
                enddo
                r(i)=r(i)+r(j)
              endif
            endif
          enddo
          if (n.gt.1) then
            do k=1,nsamp
              spectra(i,k)=spectra(i,k)/float(n)
            enddo
            r(i)=r(i)/float(n)
            if (verbose) print *,'    ',n,' traces stacked to trace ',
     &        i,' at ',r(i)
          endif
        endif
      enddo
c 
      n=0
      do i=1,ntr
        if (.not.(obsolete(i))) then
          n=n+1
          if (n.ne.i) then
            do k=1,nsamp
              spectra(n,k)=spectra(i,k)