-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsource_all.f90
496 lines (362 loc) · 17.2 KB
/
source_all.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
!
! Copyright 2011 Sebastian Heimann
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
!
module source_all
! abstraction layer: interface to different source types
! fortran cannot do polymorphy so this ugly thing is needed
! constants, type definition and generic psm subroutines are in parameterized_source.f90
! implementations for different sources are in source_bilat, source_circular, ...
! the mimic of dynamic dispatching is done here
use orthodrome
use better_varying_string
use unit
use util
use parameterized_source
use discrete_source
! implementations:
use source_circular
use source_bilat
use source_point_lp
use source_eikonal
use source_mt_eikonal
use source_moment_tensor
implicit none
private
public psm_set
public psm_to_tdsm
public psm_write_info_file
public psm_set_subparams
public psm_get_n_source_params
public psm_get_source_name
public psm_get_source_id
public psm_get_param_name
public psm_get_param_unit
public psm_get_param_id
public psm_cleanup
public psm_get_param_limits
public psm_get_param_defaults
integer, public , parameter :: nsourcetypes = 6
integer, public , parameter, dimension(nsourcetypes) :: sourcetypes = &
(/ psm_bilat, psm_circular, psm_point_lp, psm_eikonal, psm_mt_eikonal, psm_moment_tensor /)
contains
subroutine psm_cleanup()
call psm_cleanup_bilat()
call psm_cleanup_circular()
call psm_cleanup_point_lp()
call psm_cleanup_eikonal()
call psm_cleanup_mt_eikonal()
call psm_cleanup_moment_tensor()
end subroutine
subroutine psm_get_source_name( sourcetype, name )
integer, intent(in) :: sourcetype
type(varying_string), intent(inout) :: name
name = ""
if (sourcetype .eq. psm_bilat) name = "bilateral"
if (sourcetype .eq. psm_circular) name = "circular"
if (sourcetype .eq. psm_point_lp) name = "point_lp"
if (sourcetype .eq. psm_eikonal) name = "eikonal"
if (sourcetype .eq. psm_mt_eikonal) name = "mt_eikonal"
if (sourcetype .eq. psm_moment_tensor) name = "moment_tensor"
end subroutine
subroutine psm_get_source_id( name, sourcetype )
type(varying_string), intent(in) :: name
integer, intent(out) :: sourcetype
sourcetype = 0
if (name .eq. "bilateral") sourcetype = psm_bilat
if (name .eq. "circular") sourcetype = psm_circular
if (name .eq. "point_lp") sourcetype = psm_point_lp
if (name .eq. "eikonal") sourcetype = psm_eikonal
if (name .eq. "mt_eikonal") sourcetype = psm_mt_eikonal
if (name .eq. "moment_tensor") sourcetype = psm_moment_tensor
end subroutine
integer function psm_get_n_source_params(sourcetype)
integer, intent(in) :: sourcetype
select case(sourcetype)
case (psm_bilat)
psm_get_n_source_params = n_source_params_bilat
case (psm_circular)
psm_get_n_source_params = n_source_params_circular
case (psm_point_lp)
psm_get_n_source_params = n_source_params_point_lp
case (psm_eikonal)
psm_get_n_source_params = n_source_params_eikonal
case (psm_mt_eikonal)
psm_get_n_source_params = n_source_params_mt_eikonal
case (psm_moment_tensor)
psm_get_n_source_params = n_source_params_moment_tensor
end select
end function
subroutine psm_get_param_name( sourcetype, iparam, name )
integer, intent(in) :: sourcetype, iparam
type(varying_string), intent(inout) :: name
select case(sourcetype)
case (psm_bilat)
call psm_get_param_name_bilat( iparam, name )
case (psm_circular)
call psm_get_param_name_circular( iparam, name )
case (psm_point_lp)
call psm_get_param_name_point_lp( iparam, name )
case (psm_eikonal)
call psm_get_param_name_eikonal( iparam, name )
case (psm_mt_eikonal)
call psm_get_param_name_mt_eikonal( iparam, name )
case (psm_moment_tensor)
call psm_get_param_name_moment_tensor( iparam, name )
end select
end subroutine
subroutine psm_get_param_unit( sourcetype, iparam, unit )
integer, intent(in) :: sourcetype, iparam
type(varying_string), intent(inout) :: unit
select case(sourcetype)
case (psm_bilat)
call psm_get_param_unit_bilat( iparam, unit )
case (psm_circular)
call psm_get_param_unit_circular( iparam, unit )
case (psm_point_lp)
call psm_get_param_unit_point_lp( iparam, unit )
case (psm_eikonal)
call psm_get_param_unit_eikonal( iparam, unit )
case (psm_mt_eikonal)
call psm_get_param_unit_mt_eikonal( iparam, unit )
case (psm_moment_tensor)
call psm_get_param_unit_moment_tensor( iparam, unit )
end select
end subroutine
subroutine psm_get_param_id( sourcetype, name, iparam )
integer, intent(in) :: sourcetype
type(varying_string), intent(in) :: name
integer, intent(out) :: iparam
select case(sourcetype)
case (psm_bilat)
call psm_get_param_id_bilat( name, iparam )
case (psm_circular)
call psm_get_param_id_circular( name, iparam )
case (psm_point_lp)
call psm_get_param_id_point_lp( name, iparam )
case (psm_eikonal)
call psm_get_param_id_eikonal( name, iparam )
case (psm_mt_eikonal)
call psm_get_param_id_mt_eikonal( name, iparam )
case (psm_moment_tensor)
call psm_get_param_id_moment_tensor( name, iparam )
end select
end subroutine
subroutine psm_set( psm, sourcetype, params, normalized_, only_moment_changed_)
type(t_psm), intent(inout) :: psm
integer, intent(in) :: sourcetype
real, dimension(:), intent(in) :: params
logical, intent(in), optional :: normalized_
logical, intent(out), optional :: only_moment_changed_
logical :: normalized, only_moment_changed
normalized = .false.
if (present(normalized_)) normalized = normalized_
if (psm%sourcetype /= sourcetype) then
call psm_reset_dependents(psm)
end if
select case(sourcetype)
case (psm_bilat)
call psm_set_bilat( psm, params, normalized, only_moment_changed )
case (psm_circular)
call psm_set_circular( psm, params, normalized, only_moment_changed )
case (psm_point_lp)
call psm_set_point_lp( psm, params, normalized, only_moment_changed )
case (psm_eikonal)
call psm_set_eikonal( psm, params, normalized, only_moment_changed )
case (psm_mt_eikonal)
call psm_set_mt_eikonal( psm, params, normalized, only_moment_changed )
case (psm_moment_tensor)
call psm_set_moment_tensor( psm, params, normalized, only_moment_changed )
end select
call resize( psm%params_mask, 1, size(psm%params) )
if (psm%sourcetype /= sourcetype) then
psm%params_mask(:) = .true.
only_moment_changed = .false.
end if
psm%sourcetype = sourcetype
if (present(only_moment_changed_)) then
only_moment_changed_ = only_moment_changed
end if
end subroutine
subroutine psm_get_param_limits( sourcetype, limits_min, limits_max, hard_ )
integer, intent(in) :: sourcetype
real, intent(inout), dimension(:), allocatable :: limits_min
real, intent(inout), dimension(:), allocatable :: limits_max
logical, intent(in), optional :: hard_
integer :: nparams
logical :: hard
hard = .false.
if (present(hard_)) hard = hard_
nparams = psm_get_n_source_params(sourcetype)
call resize( limits_min, 1, nparams )
call resize( limits_max, 1, nparams )
select case(sourcetype)
case (psm_bilat)
if (hard) then
limits_min(:) = psm_params_min_hard_bilat(:)
limits_max(:) = psm_params_max_hard_bilat(:)
else
limits_min(:) = psm_params_min_soft_bilat(:)
limits_max(:) = psm_params_max_soft_bilat(:)
end if
case (psm_circular)
if (hard) then
limits_min(:) = psm_params_min_hard_circular(:)
limits_max(:) = psm_params_max_hard_circular(:)
else
limits_min(:) = psm_params_min_soft_circular(:)
limits_max(:) = psm_params_max_soft_circular(:)
end if
case (psm_point_lp)
if (hard) then
limits_min(:) = psm_params_min_hard_point_lp(:)
limits_max(:) = psm_params_max_hard_point_lp(:)
else
limits_min(:) = psm_params_min_soft_point_lp(:)
limits_max(:) = psm_params_max_soft_point_lp(:)
end if
case (psm_eikonal)
if (hard) then
limits_min(:) = psm_params_min_hard_eikonal(:)
limits_max(:) = psm_params_max_hard_eikonal(:)
else
limits_min(:) = psm_params_min_soft_eikonal(:)
limits_max(:) = psm_params_max_soft_eikonal(:)
end if
case (psm_mt_eikonal)
if (hard) then
limits_min(:) = psm_params_min_hard_mt_eikonal(:)
limits_max(:) = psm_params_max_hard_mt_eikonal(:)
else
limits_min(:) = psm_params_min_soft_mt_eikonal(:)
limits_max(:) = psm_params_max_soft_mt_eikonal(:)
end if
case (psm_moment_tensor)
if (hard) then
limits_min(:) = psm_params_min_hard_moment_tensor(:)
limits_max(:) = psm_params_max_hard_moment_tensor(:)
else
limits_min(:) = psm_params_min_soft_moment_tensor(:)
limits_max(:) = psm_params_max_soft_moment_tensor(:)
end if
end select
end subroutine
subroutine psm_get_param_defaults( sourcetype, defaults )
integer, intent(in) :: sourcetype
real, intent(inout), dimension(:), allocatable :: defaults
integer :: nparams
nparams = psm_get_n_source_params(sourcetype)
call resize( defaults, 1, nparams )
select case(sourcetype)
case (psm_bilat)
defaults(:) = psm_params_default_bilat(:)
case (psm_circular)
defaults(:) = psm_params_default_circular(:)
case (psm_point_lp)
defaults(:) = psm_params_default_point_lp(:)
case (psm_eikonal)
defaults(:) = psm_params_default_eikonal(:)
case (psm_mt_eikonal)
defaults(:) = psm_params_default_mt_eikonal(:)
case (psm_moment_tensor)
defaults(:) = psm_params_default_moment_tensor(:)
end select
end subroutine
subroutine psm_set_subparams( psm, subparams, normalized_, only_moment_changed_ )
! set params where params_mask is true with values from subparams array
type(t_psm), intent(inout) :: psm
real, intent(in), dimension(:) :: subparams
logical, intent(in), optional :: normalized_
logical, intent(out), optional :: only_moment_changed_
real, dimension(:), allocatable :: paramscopy
integer :: iparam, isub
logical :: normalized, only_moment_changed
normalized = .false.
if (present(normalized_)) normalized = normalized_
if (size(psm%params) /= size(psm%params_mask) .or. &
count(psm%params_mask) /= size(subparams)) then
call die( "wrong sized arrays in psm_set_subparams()")
end if
call psm_get_params( psm, paramscopy, normalized )
isub = 1
do iparam=1, size(paramscopy)
if (psm%params_mask(iparam)) then
paramscopy(iparam) = subparams(isub)
isub = isub+1
end if
end do
select case(psm%sourcetype)
case (psm_bilat)
call psm_set_bilat( psm, paramscopy, normalized, only_moment_changed )
case (psm_circular)
call psm_set_circular( psm, paramscopy, normalized, only_moment_changed )
case (psm_point_lp)
call psm_set_point_lp( psm, paramscopy, normalized, only_moment_changed )
case (psm_eikonal)
call psm_set_eikonal( psm, paramscopy, normalized, only_moment_changed )
case (psm_mt_eikonal)
call psm_set_mt_eikonal( psm, paramscopy, normalized, only_moment_changed )
case (psm_moment_tensor)
call psm_set_moment_tensor( psm, paramscopy, normalized, only_moment_changed )
end select
if (present(only_moment_changed_)) only_moment_changed_ = only_moment_changed
call resize(paramscopy,1,0)
end subroutine
subroutine psm_to_tdsm( psm, tdsm, shortest_doi, ok )
! translate a specific psm to tdsm
! shortest_duration is the shortest duration of interest
! automatically determines shape of output grid
type(t_psm), intent(inout) :: psm
type(t_tdsm), intent(out) :: tdsm
real, intent(in) :: shortest_doi
logical, intent(out) :: ok
call tdsm_destroy( tdsm )
! here we simply hand over to the appropriate implementation
select case(psm%sourcetype)
case (psm_bilat)
call psm_to_tdsm_bilat( psm, tdsm, shortest_doi, ok )
case (psm_circular)
call psm_to_tdsm_circular( psm, tdsm, shortest_doi, ok )
case (psm_point_lp)
call psm_to_tdsm_point_lp( psm, tdsm, shortest_doi, ok )
case (psm_eikonal)
call psm_to_tdsm_eikonal( psm, tdsm, shortest_doi, ok )
case (psm_mt_eikonal)
call psm_to_tdsm_mt_eikonal( psm, tdsm, shortest_doi, ok )
case (psm_moment_tensor)
call psm_to_tdsm_moment_tensor( psm, tdsm, shortest_doi, ok )
end select
tdsm%origin = psm%origin
end subroutine
subroutine psm_write_info_file( psm, fn )
! write some information about the model psm into file fn
type(t_psm), intent(in) :: psm
type(varying_string), intent(in) :: fn
! here we simply hand over to the appropriate implementation
select case(psm%sourcetype)
case (psm_bilat)
call psm_write_info_file_bilat( psm, fn )
case (psm_circular)
call psm_write_info_file_circular( psm, fn )
case (psm_point_lp)
call psm_write_info_file_point_lp( psm, fn )
case (psm_eikonal)
call psm_write_info_file_eikonal( psm, fn )
case (psm_mt_eikonal)
call psm_write_info_file_mt_eikonal( psm, fn )
case (psm_moment_tensor)
call psm_write_info_file_moment_tensor( psm, fn )
end select
end subroutine
end module