-
Notifications
You must be signed in to change notification settings - Fork 220
/
convolve_source_timefunction.f90
133 lines (103 loc) · 3.69 KB
/
convolve_source_timefunction.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
!=====================================================================
!
! S p e c f e m 3 D V e r s i o n 1 . 4
! ---------------------------------------
!
! Dimitri Komatitsch and Jeroen Tromp
! Seismological Laboratory - California Institute of Technology
! (c) California Institute of Technology September 2006
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along
! with this program; if not, write to the Free Software Foundation, Inc.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
!=====================================================================
program convolve_source_time_function
!
! convolve seismograms computed for a Heaviside with given source time function
!
! we mimic a triangle of half duration equal to half_duration_triangle
! using a Gaussian having a very close shape, as explained in Figure 4.2
! of the manual
implicit none
include "constants.h"
integer :: i,j,N_j,number_remove,nlines
double precision :: alpha,dt,tau_j,source,exponent,t1,t2,displ1,displ2,gamma,height,half_duration_triangle
logical :: triangle
double precision, dimension(:), allocatable :: time,sem,sem_fil
! read file with number of lines in input
open(unit=33,file='input_convolve_code.txt',status='old',action='read')
read(33,*) nlines
read(33,*) half_duration_triangle
read(33,*) triangle
close(33)
! allocate arrays
allocate(time(nlines),sem(nlines),sem_fil(nlines))
! read the input seismogram
do i = 1,nlines
read(5,*) time(i),sem(i)
enddo
! define a Gaussian with the right exponent to mimic a triangle of equivalent half duration
alpha = SOURCE_DECAY_MIMIC_TRIANGLE/half_duration_triangle
! compute the time step
dt = time(2) - time(1)
! number of integers for which the source wavelet is different from zero
if(triangle) then
N_j = ceiling(half_duration_triangle/dt)
else
N_j = ceiling(1.5d0*half_duration_triangle/dt)
endif
do i = 1,nlines
sem_fil(i) = 0.d0
do j = -N_j,N_j
if(i > j .and. i-j <= nlines) then
tau_j = dble(j)*dt
! convolve with a triangle
if(triangle) then
height = 1.d0 / half_duration_triangle
if(abs(tau_j) > half_duration_triangle) then
source = 0.d0
else if (tau_j < 0.d0) then
t1 = - N_j * dt
displ1 = 0.d0
t2 = 0.d0
displ2 = height
gamma = (tau_j - t1) / (t2 - t1)
source= (1.d0 - gamma) * displ1 + gamma * displ2
else
t1 = 0.d0
displ1 = height
t2 = + N_j * dt
displ2 = 0.d0
gamma = (tau_j - t1) / (t2 - t1)
source= (1.d0 - gamma) * displ1 + gamma * displ2
endif
else
! convolve with a Gaussian
exponent = alpha**2 * tau_j**2
if(exponent < 50.d0) then
source = alpha*exp(-exponent)/sqrt(PI)
else
source = 0.d0
endif
endif
sem_fil(i) = sem_fil(i) + sem(i-j)*source*dt
endif
enddo
enddo
! compute number of samples to remove from end of seismograms
number_remove = N_j + 1
do i=1,nlines - number_remove
write(*,*) sngl(time(i)),' ',sngl(sem_fil(i))
enddo
end program convolve_source_time_function