-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterp.f
More file actions
282 lines (233 loc) · 8.7 KB
/
interp.f
File metadata and controls
282 lines (233 loc) · 8.7 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
subroutine Interp_loglog ( nLevel, nPer_UHS, UHS, UHS_all, MAXPER, period_UHS,
1 period, nPer, period_all, nPer_all)
real UHS(MAXPER,1), period_UHS(1), period(1), UHS_interp(MAXPER)
real UHS_all(MAXPER,1), period_all(1)
integer nPer, nPer_all
c Loop over each level
do iLevel=1,nLevel
c Loop over each period
do iPer=1,nPer_all
c Find the first period in the UHS that is larger than the desired period
do jPer=1,nPer_UHS
if ( period_UHS(jPer) .ge. period_all(iPer) ) then
j2 = jPer
if ( j2 == 1) then
j1 = 1
else
j1 = jPer-1
endif
goto 10
endif
enddo
10 continue
c Interpolate (log-log)
if ( j1 == j2 ) then
uhs_interp(iPer) = UHS(j1,iLevel)
else
slope = alog( UHS(j2,iLevel) / UHS(j1,iLevel) ) / alog( period_UHS(j2) / period_UHS(j1) )
uhs_interp_log = alog(UHS(j1,iLevel)) + slope * alog( period_all(iPer) / period_UHS(j1) )
uhs_interp(iPer) = exp ( uhs_interp_log )
endif
enddo
c Copy back to original array
do iPer=1,nPer_all
uhs_all(iPer,iLevel) = uhs_interp(iPer)
enddo
c Select the period of interest for matching UHS
k = 0
do j=1,nPer_all
if ( period_all(j) .ge. period(1) .and. period_all(j) .le. period(nPer) ) then
if ( k .eq. 0) iPer1 = j
k = k + 1
iPer2 = j
endif
enddo
c Save UHS in the desired range
k = 0
do j=iPer1,iPer2
k = k + 1
UHS(k,iLevel) = uhs_all(j,iLevel)
enddo
enddo
return
end
c -----------------------------------------------------------------------------
subroutine Interp_loglin ( nLevel, nPer_UHS, rho, rho_all, MAXPER, period_UHS,
1 period, nPer, period_all, nPer_all)
implicit none
integer nLevel, nPer_UHS, MAXPER, nPer, nPer_all
real period(1), period_all(1), period_UHS(1), rho(MAXPER,1), rho_all(MAXPER,1)
real rho_interp(MAXPER), slope
integer iPer1, iPer2, iPer, j1, j2, j, k, jPer, ilevel
c Loop over each level
do iLevel=1,nLevel
c Loop over each period
do iPer=1,nPer_all
c Find the first period in the UHS that is larger than the desired period
do jPer=1,nPer_UHS
if ( period_UHS(jPer) .ge. period_all(iPer) ) then
j2 = jPer
if ( j2 == 1) then
j1 = 1
else
j1 = jPer-1
endif
goto 10
endif
enddo
10 continue
c Interpolate (log-lin)
if ( j1 == j2 ) then
rho_interp(iPer) = rho(j1,iLevel)
else
slope = ( rho(j2,iLevel) - rho(j1,iLevel) ) / alog( period_UHS(j2) / period_UHS(j1) )
rho_interp(iPer) = rho(j1,iLevel) + slope * alog( period_all(iPer) / period_UHS(j1) )
endif
enddo
c Copy back to original array
do iPer=1,nPer_all
rho_all(iPer,iLevel) = rho_interp(iPer)
enddo
c Select the period of interest for matching UHS
k = 0
do j=1,nPer_all
if ( period_all(j) .ge. period(1) .and. period_all(j) .le. period(nPer) ) then
if ( k .eq. 0) iPer1 = j
k = k + 1
iPer2 = j
endif
enddo
c Save UHS in the desired range
k = 0
do j=iPer1,iPer2
k = k + 1
rho(k,iLevel) = rho_all(j,iLevel)
enddo
enddo
return
end
c -----------------------------------------------------------------------------
subroutine Interp_loglin_rho ( nLevel, nPer_UHS, rho, rho_all, MAXPER, period_UHS,
1 period, nPer, period_all, nPer_all, Per0)
implicit none
integer nLevel, nPer_UHS, MAXPER, nPer, nPer_all
real period(1), period_all(1), period_UHS(1), rho(MAXPER,1), rho_all(MAXPER,1)
real rho_interp(MAXPER), slope, Per0
integer iPer1, iPer2, iPer, j1, j2, j, k, jPer, ilevel
real rho_temp(MAXPER,100), period_UHS_temp(MAXPER)
integer flag, loc, nPer_UHS_temp
! add the rho =1 at the conditioning period if not part of the UHS period vector
do jPer=1,nPer_UHS
if (period_UHS(jPer) <= Per0) then
loc = jPer
endif
enddo
if ( period_UHS(loc) == Per0 ) then
nPer_UHS_temp = nPer_UHS
do iLevel=1,nLevel
do jPer=1,nPer_UHS_temp
period_UHS_temp(jPer) = period_UHS(jPer)
rho_temp(jPer,iLevel) = rho(jPer,iLevel)
enddo
enddo
else
nPer_UHS_temp = nPer_UHS+1
do iLevel=1,nLevel
flag = 0
do jPer=1,nPer_UHS_temp
if ( jPer <= loc ) then
period_UHS_temp(jPer) = period_UHS(jPer)
rho_temp(jPer,iLevel) = rho(jPer,iLevel)
else
if ( flag == 0 ) then
period_UHS_temp(jPer) = Per0
rho_temp(jPer,iLevel) = 1
flag = 1
else
period_UHS_temp(jPer) = period_UHS(jPer-1)
rho_temp(jPer,iLevel) = rho(jPer-1,iLevel)
endif
endif
enddo
enddo
endif
c Loop over each level
do iLevel=1,nLevel
c Loop over each period
do iPer=1,nPer_all
c Find the first period in the UHS that is larger than the desired period
do jPer=1,nPer_UHS_temp
if ( period_UHS_temp(jPer) .ge. period_all(iPer) ) then
j2 = jPer
if ( j2 == 1) then
j1 = 1
else
j1 = jPer-1
endif
goto 10
endif
enddo
10 continue
c Interpolate (log-lin)
if ( j1 == j2 ) then
rho_interp(iPer) = rho_temp(j1,iLevel)
else
slope = ( rho_temp(j2,iLevel) - rho_temp(j1,iLevel) ) / alog( period_UHS_temp(j2) / period_UHS_temp(j1) )
rho_interp(iPer) = rho_temp(j1,iLevel) + slope * alog( period_all(iPer) / period_UHS_temp(j1) )
endif
enddo
c Copy back to original array
do iPer=1,nPer_all
rho_all(iPer,iLevel) = rho_interp(iPer)
enddo
c Select the period of interest for matching UHS
k = 0
do j=1,nPer_all
if ( period_all(j) .ge. period(1) .and. period_all(j) .le. period(nPer) ) then
if ( k .eq. 0) iPer1 = j
k = k + 1
iPer2 = j
endif
enddo
c Save UHS in the desired range
k = 0
do j=iPer1,iPer2
k = k + 1
rho(k,iLevel) = rho_all(j,iLevel)
enddo
enddo
return
end
c -----------------------------------------------------------------------------
subroutine interp (x1,x2,y1,y2,x,y,iflag)
C This subroutine will perform the Log-linear interpolation
C of the given input values. This routine is used to interpolate
C the regression cofficients of the attenuation models for
C spectral periods other than those defined in the model.
real x1, x2, y1, y2, x, y
integer iflag
C Check to see if the interpolation period is at an end point.
C Return the 'iflag' for output purposes with
C iflag = 0 No interpolation
C = 1 Interpolation need.
if (x .eq. x1 .or. x .eq. x2) then
iflag = 0
else
iflag = 1
endif
C Set the PGA period to 100 Hz (i.e., 0.01 Sec).
if (x1 .eq. 0.0) then
x1 = 0.01
endif
C Take the Log of the Period values.
x1 = alog(x1)
x2 = alog(x2)
x = alog(x)
C Perform the log-linear interpolation.
y = y1 + (y2-y1)*((x-x1)/(x2-x1))
C Convert the Log Periods back to period.
x1 = exp(x1)
x2 = exp(x2)
x = exp(x)
return
end