-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathminimizer.f90
1848 lines (1459 loc) · 62.2 KB
/
minimizer.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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
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
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!
! 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 minimizer_wrappers
! Comments starting with a double exclamation mark may be extracted and catenated
! by a simple script. I use Trac wiki syntax in these blocks, so that the wiki
! documentation on this program may be inlined here.
!! = The `minimizer` tool =
!
!
! == Usage ==
! {{{
! > minimizer <<EOF
! [minimizer commands]
! ...
! EOF
! }}}
!
! == Minimizer Commands ==
!
use minimizer_engine
use better_varying_string
use constants
use util
use unit
use orthodrome
use source
use receiver
use comparator
! use minimizer_engine
implicit none
! wrappers doing command line processing
public do_set_database
public do_set_local_interpolation
public do_set_spacial_undersampling
public do_set_receivers
public do_set_ref_seismograms
public do_set_source_constraints
public do_set_source_location
public do_set_source_crustal_thickness_limit
public do_get_source_crustal_thickness
public do_set_source_params
public do_set_source_params_mask
public do_set_source_subparams
public do_set_effective_dt
public do_set_misfit_method
public do_set_misfit_filter
public do_set_misfit_filter_1
public do_set_misfit_taper
public do_set_synthetics_factor
public do_minimize_lm
public do_output_seismograms
public do_output_seismogram_spectra
public do_output_source_model
public do_get_source_subparams
public do_get_global_misfit
public do_get_misfits
public do_get_peak_amplitudes
public do_get_principal_axes
public do_output_distances
public do_output_cross_correlations
public do_shift_ref_seismogram
public do_autoshift_ref_seismogram
public do_set_floating_shiftrange
public do_get_floating_shifts
public do_get_cached_traces_memory
public do_set_cached_traces_memory_limit
public do_set_verbose
contains
subroutine do_set_database( args, answer, ok )
!! === {{{set_database dbpath [ nipx nipz ]}}} ===
!
! Select Greens function database to use for the calculation of synthetic seismograms.
!
! {{{dbpath}}} is the path to a Greens function database created with {{{gfdb_build}}}.
! This is the path without the filename extensions {{{.index}}} or {{{.chunk}}}.
!
! {{{nipx}}} {{{nipz}}} turn on Gulunay's interpolation in the Greens function database
! if set to values other than one. A Greens function database opened this way will pretend to have {{{nipx}}} times the
! number of traces in the horizontal direction, inserting interpolated traces as needed.
! Same applies with {{{nipz}}} to the vertical.
! Gulunay's generalized FK interpolation is used to fill the interpolated traces.
! If either of {{{nipx}}} or {{{nipz}}} is set to one, a 2D interpolation (time-distance or time-depth)
! is performed. If both {{{nipx}}} and {{{nipz}}} are set to the same value,
! a 3D (time-distance-depth) interpolation is performed.
! If {{{nipx}}} and {{{nipz}}} are not set to the same value, first horizontal
! 2D interpolation is applied followed by a vertical 2D interpolation.
!
! '''Note:''' Gulunay's interpolation works in the spectral domain and uses FFTs and
! thus has cyclic properties.
! To prevent wrap-around artifacts, the interpolation is done block-wise with some overlap.
! At the boundaries of the database, repeating end points are used to gain a margin and
! enough traces for the interpolation. Nevertheless, this introduces errors
! near to the surface and at the maximum depth, as well as at the ends of the
! distance range of the database.
type(varying_string), intent(in) :: args
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(args)) :: buffer
type(varying_string) :: db_path
integer :: nipx, nipz, iostat
type(varying_string) :: args_mut
answer = ''
ok = .false.
nipx = 1
nipz = 1
if (3 == count_words( char(args) )) then
args_mut = args
call split(args_mut, db_path, ' ')
buffer = char(args_mut)
read (unit=buffer,fmt=*,iostat=iostat) nipx, nipz
if (iostat /= 0) then
call error( "set_database: failed to parse arguments" )
return
end if
else
db_path = args
end if
if (nipx < 1 .or. nipz < 1) then
call error( "set_database: nipx and nipz must be positive" )
return
end if
call set_database( db_path, nipx, nipz, ok )
end subroutine
subroutine do_set_local_interpolation( arg, answer, ok )
!! === {{{set_local_interpolation ( nearest_neighbor | bilinear )}}} ===
!
! Set local interpolation method used during calculation of synthetic seismograms.
!
type(varying_string), intent(in) :: arg
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
ok = .false.
answer = ''
if (arg == 'nearest_neighbor') then
call set_local_interpolation(.false.)
else if (arg == 'bilinear') then
call set_local_interpolation(.true.)
else
call error( "set_local_interpolation: unknown interpolation method: "//arg)
return
end if
ok = .true.
end subroutine
subroutine do_set_spacial_undersampling( line, answer, ok )
!! === {{{set_spacial_undersampling nxunder nzunder }}} ===
!
! Tell minimizer to use only a subset of the databases Green's functions.
!
! nxunder: use every nxunder'th horizontal Green's function distance.
! nzunder: use every nzunder'th vertical Green's function depth.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(line)) :: buffer
integer :: iostat, xunder, zunder
answer = ''
ok = .false.
buffer = char(line)
read (unit=buffer,fmt=*,iostat=iostat) xunder, zunder
if (iostat /= 0) then
call error( "set_spacial_undersampling: failed to parse arguments" )
return
end if
call set_spacial_undersampling( xunder, zunder, ok )
end subroutine
subroutine do_set_receivers( args, answer, ok )
!! === {{{set_receivers filename [ has_depth ]}}} ===
!
! Read a list of receiver coordinates from three column (lat lon components) ascii file {{{filename}}}.
!
! The file format is as follows:
!
! * first column: latitude in degrees
! * second column: longitude in degrees
! * third column: selected components of the station; for every component wanted,
! add one of the characters below:
! * radial component:
! * a = positive is displacement away from source
! * c = positive is displacement coming towards source
! * transversal component:
! * r = positive is rightwards seen from source
! * l = positive is leftwards seen from source
! * vertical component:
! * d = positive is downwards
! * u = positive is upwards
! * horizontal component (north-south)
! * n = positive is north
! * s = positive is south
! * horizontal component (east-west)
! * e = positive is east
! * w = positive is west
!
! Adding the same component more than once is not allowed, so at most 5 components may be given.
! Lines starting with a '#' are considered to be comment lines.
!
! An example receivers file might look like this:
! {{{
! # ok:
! 42.35 13.4 ard
! 49.78 17.54 ard
! # north component broken:
! 45.49 25.95 ed
! # only vertical component available
! 47.92 19.89 d
! 35.87 14.52 d
! }}}
type(varying_string), intent(in) :: args
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
type(varying_string) :: args_mut
logical :: has_depth
type(varying_string) :: receiversfn
has_depth = .false.
if (2 == count_words( char(args) )) then
args_mut = args
call split(args_mut, receiversfn, ' ')
has_depth = (args_mut == "has_depth")
else
receiversfn = args
end if
call set_receivers( receiversfn, has_depth, answer, ok )
end subroutine
subroutine do_switch_receiver( line, answer, ok )
!! === {{{switch_receiver ireceiver ( on | off ) }}} ===
!
! Turn receiver number ireceiver on or off.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(line)) :: buffer, onoff
integer :: nerr, ireceiver
logical :: state
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) ireceiver, onoff
if (nerr /= 0) then
call error( "usage: switch_receiver ireceiver ( on | off )" )
ok = .false.
return
end if
state = .true.
if (onoff == 'on') then
state = .true.
else if (onoff == 'off') then
state = .false.
else
call error( "usage: switch_receiver ireceiver ( on | off )" )
ok = .false.
return
end if
call switch_receiver( ireceiver, state, ok )
end subroutine
subroutine do_set_ref_seismograms( line, answer, ok )
!! === {{{set_ref_seismograms filenamebase format}}} ===
!
! Read a set of reference seismograms.
!
! For every component at every of the receivers which have
! been set with {{{set_receivers}}} one file must be povided.
!
! Currently the following formats are available:
!
! * {{{table}}}: ASCII tables with two columns: time [s] and displacement [m].
! * {{{mseed}}}: Single trace "Data Only SEED Volume"
! (Mini-SEED, http://www.iris.edu/manuals/SEED_appG.htm).
! * {{{sac}}}: [wiki:SacBinaryFile SAC binary file].
! Please note, that this file format is platform dependant.
!
! The files are expected to be named using the following scheme:
!
! {{{$filenamebase-$ReceiverNumber-$ComponentCharacter.$format}}}
!
! where
!
! * {{{$ReceiverNumber}}} is the number of the receiver, as defined by the ordering
! of receivers in the receiver file (see {{{set_receivers}}}).
! * {{{$ComponentCharacter}}} is one of the characters defining receiver components
! as described in {{{set_receivers}}}.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
type(varying_string) :: fformat, reffnbase
answer = ''
ok = .true.
fformat = line
call split(fformat, reffnbase, ' ')
call set_ref_seismograms( reffnbase, fformat, ok )
end subroutine
subroutine do_shift_ref_seismogram( line, answer, ok )
!! === {{{shift_ref_seismogram ireceiver shift}}} ===
!
! Timeshift reference seismogram.
!
! Shift reference seismogram at receiver number `ireceiver` by `shift` seconds.
!
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(line)) :: buffer
integer :: nerr, ireceiver
real :: shift
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) ireceiver, shift
if (nerr /= 0) then
call error( "usage: shift_ref_seismogram ireceiver shift" )
ok = .false.
return
end if
call shift_ref_seismogram( ireceiver, shift, ok )
end subroutine
subroutine do_set_floating_shiftrange( line, answer, ok )
!! === {{{set_floating_shiftrange ireceiver min-shift max-shift}}} ===
!
! Set time shift range for floating norms.
!
! Set shift range for special norms floating_l1norm and floating_l2norm
! for receiver `ireceiver` to [ `min-shift`, `max-shift` ] seconds.
!
! If `ireceiver` is set to zero all receivers are affected.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(line)) :: buffer
integer :: nerr, ireceiver
real, dimension(2) :: shiftrange
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) ireceiver, shiftrange(1), shiftrange(2)
if (nerr /= 0) then
call error( "usage: set_floating_shiftrange ireceiver min-shift max-shift" )
ok = .false.
return
end if
call set_floating_shiftrange( ireceiver, shiftrange, ok )
end subroutine
subroutine do_get_floating_shifts( line, answer, ok )
!! === {{{get_floating_shifts}}} ===
!
! Get current floating shift values.
!
! Disabled stations are omitted in output list.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real, dimension(:), allocatable :: shifts_
ok = line /= '' ! get rid of warning, that line is not used
answer = ""
call get_floating_shifts( shifts_, ok )
if (.not. ok) return
call array_to_string( shifts_, answer )
if (allocated( shifts_)) deallocate(shifts_)
end subroutine
subroutine do_autoshift_ref_seismogram( line, answer, ok )
!! === {{{autoshift_ref_seismogram ireceiver min-shift max-shift}}} ===
!
! Automatically timeshift reference seismogram.
!
! Shift reference seismogram at receiver number `ireceiver` to where
! the cross-correlation has a maximum in the interval [`min-shift`,`max-shift`].
!
! If `ireceiver` is set to zero, all seismograms are auto-shifted.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
character(len=len(line)) :: buffer
integer :: nerr, ireceiver
real, dimension(2) :: shiftrange
real, dimension(:), allocatable :: shifts
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) ireceiver, shiftrange(1), shiftrange(2)
if (nerr /= 0) then
call error( "usage: autoshift_ref_seismogram ireceiver min-shift max-shift" )
ok = .false.
return
end if
call autoshift_ref_seismogram( ireceiver, shiftrange, shifts, ok )
do ireceiver=1,size(shifts,1)
answer = answer // " " // shifts(ireceiver)
end do
if (allocated(shifts)) deallocate(shifts)
end subroutine
subroutine do_set_source_location( line, answer, ok )
!! === {{{set_source_location latitude longitude reference-time}}} ===
!
! Sets the source location and reference time.
!
! * {{{latitude}}}, {{{longitude}}}: Geographical coordinates of source reference point in [degrees].
! All locations given in the source model description are measured relative
! to this reference point.
! * {{{reference-time}}}: source reference time in seconds.
! All times given in the source model description are measured relative
! to this reference time.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: nerr
character(len=len(line)) :: buffer
real :: lat, lon
real(kind=8) :: ref_time
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) lat, lon, ref_time
if (nerr /= 0) then
call error( "usage: set_source_location latitude longitude reference-time" )
ok = .false.
return
end if
call set_source_location(d2r(lat), d2r(lon), ref_time)
end subroutine
subroutine do_set_source_constraints( line, answer, ok )
!! === {{{set_source_constraints px1 py1 pz1 nx1 ny1 nz1 ...}}} ===
!
! Set constraining planes which affect source geometry for certain source models.
!
! Each constraining plane is defined by a point and a normal vector.
! They are specified in the local carthesian coordinate system at the source, which has its principal
! axes pointing north, east, and downward, and whose origin is at the surface
! at the coordinates given with set_source_location.
!
! * {{{px1 py1 pz1}}}: coordinates of point for plane number 1 in [m]
! * {{{nx1 ny1 nz1}}}: components of normal vector of plane number 1
!
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real, dimension(:,:), allocatable :: points, normals
real, dimension(:), allocatable :: numbers
integer :: n, nplanes, iplane, iostat
character(len=len(line)) :: buffer
answer = ''
ok = .true.
buffer = char(line)
n = count_words( buffer )
if (mod(n,6) /= 0) then
ok = .false.
call error( "number of arguments is not divideable by 6" )
return
end if
nplanes = n / 6
allocate( numbers(n) )
allocate( points(3,nplanes) )
allocate( normals(3,nplanes) )
read (unit=buffer,fmt=*,iostat=iostat) numbers(:)
do iplane=1,nplanes
points(:,iplane) = numbers((iplane-1)*6+1:(iplane-1)*6+3)
normals(:,iplane) = numbers((iplane-1)*6+4:(iplane-1)*6+6)
if (iostat > 0) then
ok = .false.
call error( "failed to parse numbers at plane " // iplane )
return
end if
end do
call set_source_constraints( points, normals )
deallocate( points )
deallocate( normals )
deallocate( numbers )
end subroutine
subroutine do_set_source_crustal_thickness_limit( line, answer, ok )
!! === {{{set_source_crustal_thickness_limit thickness-limit}}} ===
!
! Limit crustal thickness at the source.
!
! * {{{thickness-limit}}}: Maximal thickness of crust in [m].
!
! Default values for the thickness are retrieved from the crust2x2 model.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: nerr
character(len=len(line)) :: buffer
real :: thickness_limit
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*, iostat=nerr) thickness_limit
if (nerr /= 0) then
call error( "usage: set_source_crustal_thickness_limit thickness-limit" )
ok = .false.
return
end if
call set_source_crustal_thickness_limit(thickness_limit)
end subroutine
subroutine do_get_source_crustal_thickness( line, answer, ok )
!! === {{{get_source_crustal_thickness}}} ===
!
! Returns crustal thickness at the source in [m].
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real :: thickness
ok = line /= '' ! get rid of warning, that line is not used
answer = ''
ok = .false.
call get_source_crustal_thickness( thickness, ok )
if (ok) answer = thickness
end subroutine
subroutine do_set_source_params( line, answer, ok )
!! === {{{set_source_params source-type source-params ...}}} ===
!
! Sets the source type and parameters.
!
! The available source types and a complete description of their parameters
! are given in the [wiki:SourceTypes source type documentation].
! Short descriptions can be queried using the [wiki:SourceInfoTool source_info] tool.
!
! This function detects if the same source parameters have already been
! set, so that seismograms are not recalculated when the same source
! is set several times.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: sourcetype, nparams, iostat
real, dimension(:), allocatable :: params
type(varying_string) :: sourcetypename, paramsstr
character(len=len(line)) :: buffer
answer = ''
ok = .true.
paramsstr = line
call split( paramsstr, sourcetypename, " " )
call psm_get_source_id( sourcetypename, sourcetype )
if (sourcetype == 0) then
call error("unknown source type name: " // sourcetypename)
ok = .false.
return
end if
nparams = psm_get_n_source_params( sourcetype )
call resize( params, 1, nparams )
buffer = char(paramsstr)
if (count_words( buffer ) /= nparams) then
call error("source of type '" // sourcetypename // "' requires "// nparams // " parameters.")
ok = .false.
return
end if
read (unit=buffer,fmt=*,iostat=iostat) params
if (iostat > 0) then
call error("failed to parse source params" )
ok = .false.
return
end if
call set_source_params( sourcetype, params, ok )
end subroutine
subroutine do_set_source_params_mask( line, answer, ok )
!! === {{{set_source_params_mask mask ...}}} ===
!
! Select inversion parameters for the next minimization with {{{minimize_lm}}}.
!
! {{{mask}}} is built by giving a 'T' or 'F' for every source parameter of
! the source type that is currently in use.
! 'T' makes the corresponding parameter an actual inversion parameter,
! 'F' fixes the corresponding parameter to its current value.
! The 'T's and 'F's must be separated by whitespace.
!
! The values of the selected parameters can be set using {{{set_subparams}}}
! and queried using {{{get_subparams}}}.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
logical, dimension(:), allocatable :: params_mask
integer :: iostat
character(len=len(line)) :: buffer
integer :: nsubparams
answer = ''
ok = .true.
buffer = char(line)
nsubparams = count_words( buffer )
allocate( params_mask(nsubparams) )
read (unit=buffer,fmt=*,iostat=iostat) params_mask(:)
if (iostat > 0) then
ok = .false.
call error( "failed to parse source parameter mask" )
return
end if
call set_source_params_mask( params_mask, ok )
deallocate( params_mask )
end subroutine
subroutine do_set_source_subparams( line, answer, ok )
!! === {{{set_source_subparams subparams ...}}} ===
!
! Assignes values to the currently selected inversion parameters.
!
! This command expects one value for each parameter selected with {{{set_source_params_mask}}}.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real, dimension(:), allocatable :: subparams
character(len=len(line)) :: buffer
integer :: iostat, nsubparams
buffer = char(line)
nsubparams = count_words(buffer )
allocate(subparams(nsubparams))
ok = .true.
answer = ''
read (unit=buffer,fmt=*,iostat=iostat) subparams
if (iostat > 0) then
ok = .false.
call error( "failed to parse source parameters" )
return
end if
call set_source_subparams( subparams, ok )
deallocate(subparams)
end subroutine
subroutine do_set_source_subparams_limits( line, answer, ok )
!! === {{{set_source_subparams_limits subparam_mins ... subparam_maxs ...}}} ===
!
! Assignes limits for minimize_lm. Handled with a penalty technique.
!
! This command expects first all minimum values followed by all maximum
! values. Number of values is as selected with
! {{{set_source_params_mask}}}. Must be called after each call to
! {{{set_source_params_mask}}}. Limits are reset after every call to
! {{{set_source_params_mask}}}.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real, dimension(:), allocatable :: temp
character(len=len(line)) :: buffer
integer :: iostat, nsubparams
buffer = char(line)
nsubparams = count_words(buffer) / 2
allocate(temp(nsubparams*2))
ok = .true.
answer = ''
read (unit=buffer,fmt=*,iostat=iostat) temp
if (iostat > 0) then
ok = .false.
call error( "failed to parse source parameter minimums" )
return
end if
call set_source_subparams_limits(temp(1:nsubparams), &
temp(nsubparams+1:nsubparams*2), ok)
deallocate(temp)
end subroutine
subroutine do_set_effective_dt( line, answer, ok )
!! === {{{set_effective_dt effective_dt}}} ===
!
! Sets the effective dt controlling the source parameterization.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
real :: effective_dt_
integer :: iostat
character(len=len(line)) :: buffer
answer = ''
ok = .true.
buffer = char(line)
read (unit=buffer,fmt=*,iostat=iostat) effective_dt_
if (iostat > 0) then
ok = .false.
call error( "failed to parse effective dt" )
return
end if
call set_effective_dt( effective_dt_ )
end subroutine
subroutine do_set_misfit_method( line, answer, ok )
!! === {{{set_misfit_method ( l2norm | l1norm | ampspec_l2norm | ampspec_l1norm | scalar_product | peak | floating_l2norm | floating_l1norm )}}} ===
!
! Set the misfit calculation method.
!
! Available methods are:
! * {{{l2norm}}}: L2 norm is done on difference of time traces
! * {{{l1norm}}}: L1 norm is done on difference of time traces
! * {{{ampspec_l2norm}}}: L2 norm is done on difference of amplitude spectra
! * {{{ampspec_l1norm}}}: L2 norm is done on difference of amplitude spectra
! * {{{scalar_product}}}: instead of a norm, the scalar product is calculated
! * {{{peak}}}: instead of a norm, the peak amplitudes are returned
! * {{{floating_l2norm}}}: minimum L2 norm on difference of shifted traces
! * {{{floating_l1norm}}}: minimum L1 norm on difference of shifted traces
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: id
ok = .true.
answer = ''
call comparator_get_norm_id( line, id )
if (id == 0) then
ok = .false.
call error( "unknown norm method: "//line )
end if
call set_misfit_method( id )
end subroutine
subroutine do_set_misfit_filter( line, answer, ok )
!! === {{{set_misfit_filter x0 y0 x1 y1 ...}}} ===
!
! Defines a piecewise linear function which is multiplied to the
! spectra before calculating misfits in the frequency domain.
!
! * {{{x0 y0 x1 y1 ...}}}: Control points with {{{xi}}}: frequency [Hz] and
! {{{yi}}}: multiplicator amplitude.
!
! The amplitude drops to zero before the first and after the last control point.
!
! Example: {{{set_misfit_filter 0.2 1 0.5 1}}} defines a rectangular
! window between 0.2 and 0.5 Hz.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: i, n, nwords, iostat
real, dimension(:), allocatable :: x,y
character(len=len(line)) :: buffer
answer = ''
ok = .true.
buffer = char(line)
nwords = count_words( buffer )
n = nwords/2
allocate(x(n),y(n))
buffer = char(line)
read (unit=buffer,fmt=*,iostat=iostat) (x(i), y(i), i=1,n)
if (iostat > 0) then
ok = .false.
deallocate(x,y)
call error( "failed to parse coordinates" )
return
end if
call set_misfit_filter( 0, x, y, ok )
deallocate(x,y)
end subroutine
subroutine do_set_misfit_filter_1( line, answer, ok )
!! === {{{set_misfit_filter_1 ireceiver x0 y0 x1 y1 ...}}} ===
!
! Defines a piecewise linear function which is multiplied to the
! spectra before calculating misfits in the frequency domain.
!
! * {{{ireceiver}}}: Number of the receiver to which the filter shall be applied. 0 for all.
! * {{{x0 y0 x1 y1 ...}}}: Control points with {{{xi}}}: frequency [Hz] and
! {{{yi}}}: multiplicator amplitude.
!
! The amplitude drops to zero before the first and after the last control point.
!
! Example: {{{set_misfit_filter_1 11 0.2 1 0.5 1}}} defines a rectangular
! window between 0.2 and 0.5 Hz for receiver number 11.
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: i, n, nwords, iostat, ireceiver
real, dimension(:), allocatable :: x,y
character(len=len(line)) :: buffer
answer = ''
ok = .true.
buffer = char(line)
nwords = count_words( buffer )
n = (nwords-1)/2
allocate(x(n),y(n))
buffer = char(line)
read (unit=buffer,fmt=*,iostat=iostat) ireceiver, (x(i), y(i), i=1,n)
if (iostat > 0) then
ok = .false.
deallocate(x,y)
call error( "failed to parse values" )
return
end if
call set_misfit_filter( ireceiver, x, y, ok )
deallocate(x,y)
end subroutine
subroutine do_set_misfit_taper( line, answer, ok )
!! === {{{set_misfit_taper ireceiver x0 y0 x1 y1 ...}}} ===
!
! Defines a piecewise linear function which is multiplied to seismogram
! traces before calculating spectra or misfits.
!
! * {{{ireceiver}}}: Number of the receiver to which the taper shall be applied.
! * {{{x0 y0 x1 y1 ...}}}: Control points with {{{xi}}}: time [s] and
! {{{yi}}}: multiplicator amplitude.
!
! The amplitude drops to zero before the first and after the last control point.
!
! Example: {{{set_misfit_taper 120 1 150 1}}} defines a rectangular
! window between 120 and 150 s
type(varying_string), intent(in) :: line
type(varying_string), intent(out) :: answer
logical, intent(out) :: ok
integer :: i, n, nwords, iostat
real, dimension(:), allocatable :: x,y
character(len=len(line)) :: buffer
integer :: ireceiver
answer = ''
ok = .true.
buffer = char(line)
nwords = count_words( buffer )