-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml_write.f90
More file actions
1182 lines (970 loc) · 43.4 KB
/
Copy pathxml_write.f90
File metadata and controls
1182 lines (970 loc) · 43.4 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
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
module xml_write
use FoX_wxml
use global
use utils
implicit none
private
type(xmlf_t) :: xmlfile
character(len=19) :: xml_time
integer :: i, j, N
save :: xmlfile
public :: initialize_xml_output
public :: add_xml_header
public :: add_ProcessingInfo
public :: end_xml_output
public :: new_element, end_element
public :: new_channel_block, new_data_block, end_block
public :: add_Location, add_Channel
public :: add_DataType, add_Estimate
public :: add_Data, add_Var
public :: add_InvSigCov, add_ResidCov
public :: add_FieldNotes
public :: add_GridOrigin
public :: initialize_xml_freq_block_output
public :: end_xml_freq_block_output
public :: add_PeriodRange
contains
subroutine initialize_xml_output(fname,root)
character(len=*), intent(in) :: fname
character(len=*), intent(in) :: root
character(len=100) :: schemaLocation
!schemaLocation = "http://www.earthscope.org/mt http://www.iris.edu/schema/mt/MT_TF_"//version//".xsd"
call xml_OpenFile(fname, xmlfile)
!call xml_DeclareNamespace(xmlfile, 'http://www.w3.org/2001/XMLSchema-instance','xsi')
!call xml_DeclareNamespace(xmlfile, 'http://www.earthscope.org/mt')
call xml_NewElement(xmlfile, root)
!call xml_AddAttribute(xmlfile, "xsi:schemaLocation",trim(schemaLocation))
end subroutine initialize_xml_output
subroutine new_element(ElementName)
character(len=*), intent(in) :: ElementName
call xml_NewElement(xmlfile, ElementName)
end subroutine new_element
subroutine end_element(ElementName)
character(len=*), intent(in) :: ElementName
call xml_EndElement(xmlfile, ElementName)
end subroutine end_element
subroutine new_channel_block(ElementName)
character(len=*), intent(in) :: ElementName
call xml_NewElement(xmlfile, ElementName)
call xml_AddAttribute(xmlfile, 'ref', 'site')
call xml_AddAttribute(xmlfile, 'units', 'm')
end subroutine new_channel_block
subroutine new_data_block(ElementName,F)
character(len=*), intent(in) :: ElementName
type(FreqInfo_t), intent(in) :: F
call xml_NewElement(xmlfile, ElementName)
call xml_AddAttribute(xmlfile, 'value', F%value, fmt="s7")
call xml_AddAttribute(xmlfile, 'units', trim(F%units))
end subroutine new_data_block
subroutine end_block(ElementName)
character(len=*), intent(in) :: ElementName
call xml_EndElement(xmlfile, ElementName)
end subroutine end_block
subroutine initialize_xml_freq_block_output(nf)
integer, intent(in) :: nf
call xml_NewElement(xmlfile, 'Data')
call xml_AddAttribute(xmlfile, 'count', nf)
end subroutine initialize_xml_freq_block_output
subroutine add_xml_header(Site, UserInfo, Notes, NotesLength)
type(Site_t), intent(in) :: Site
type(UserInfo_t), intent(in) :: UserInfo
character(len=*), dimension(:), pointer, optional :: Notes
integer, optional :: NotesLength
character(len=6) :: iris_siteid
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, trim(UserInfo%Description))
call xml_EndElement(xmlfile, 'Description')
call xml_NewElement(xmlfile, 'ProductId')
! finally decided to use the full ID to ensure uniqueness
call xml_AddCharacters(xmlfile, trim(UserInfo%Project)//'.'//trim(Site%ID))
if (len_trim(UserInfo%YearCollected)>0) call xml_AddCharacters(xmlfile, '.'//trim(UserInfo%YearCollected))
call xml_EndElement(xmlfile, 'ProductId')
call xml_NewElement(xmlfile, 'SubType')
call xml_AddCharacters(xmlfile, trim(UserInfo%SubType))
call xml_EndElement(xmlfile, 'SubType')
call xml_NewElement(xmlfile, 'Notes')
! empty element for now
call xml_EndElement(xmlfile, 'Notes')
call xml_NewElement(xmlfile, 'Tags')
call xml_AddCharacters(xmlfile, trim(UserInfo%Tags))
call xml_EndElement(xmlfile, 'Tags')
if (.not. isempty(UserInfo%ExternalUrl)) then
call xml_NewElement(xmlfile, 'ExternalUrl')
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, trim(UserInfo%ExternalUrlInfo))
call xml_EndElement(xmlfile, 'Description')
call xml_NewElement(xmlfile, 'Url')
call xml_AddCharacters(xmlfile, trim(UserInfo%ExternalUrl))
call xml_EndElement(xmlfile, 'Url')
call xml_EndElement(xmlfile, 'ExternalUrl')
end if
if (UserInfo%TimeSeriesArchived) then
call xml_NewElement(xmlfile, 'ExternalUrl')
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, 'IRIS DMC MetaData')
call xml_EndElement(xmlfile, 'Description')
call xml_NewElement(xmlfile, 'Url')
call xml_AddCharacters(xmlfile, 'http://www.iris.edu/mda/'//UserInfo%Network//'/'//Site%IRIS_ID)
call xml_EndElement(xmlfile, 'Url')
call xml_EndElement(xmlfile, 'ExternalUrl')
end if
if (.not. isempty(UserInfo%Image)) then ! technical info to display a figure in SPUD
call xml_NewElement(xmlfile, 'PrimaryData')
call xml_NewElement(xmlfile, 'Filename')
call xml_AddCharacters(xmlfile, trim(UserInfo%Basename)//'.'//trim(UserInfo%Image))
call xml_EndElement(xmlfile, 'Filename')
call xml_EndElement(xmlfile, 'PrimaryData')
end if
if (.not. isempty(UserInfo%Original)) then ! technical info to attach the original file in SPUD
call xml_NewElement(xmlfile, 'Attachment')
call xml_NewElement(xmlfile, 'Filename')
call xml_AddCharacters(xmlfile, trim(UserInfo%Basename)//'.'//trim(UserInfo%Original))
call xml_EndElement(xmlfile, 'Filename')
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, 'The original used to produce the XML')
call xml_EndElement(xmlfile, 'Description')
call xml_EndElement(xmlfile, 'Attachment')
end if
if (trim(UserInfo%Original) .eq. 'j') then ! exception to include Alan Chave's j-file covariances
call xml_NewElement(xmlfile, 'Attachment')
call xml_NewElement(xmlfile, 'Filename')
call xml_AddCharacters(xmlfile, trim(UserInfo%Basename)//'_cov.'//trim(UserInfo%Original))
call xml_EndElement(xmlfile, 'Filename')
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, 'Alan Chave BIRRP Covariance file')
call xml_EndElement(xmlfile, 'Description')
call xml_EndElement(xmlfile, 'Attachment')
end if
if (.not. isempty(UserInfo%Attachment)) then ! submit the survey attachment to SPUD
call xml_NewElement(xmlfile, 'Attachment')
call xml_NewElement(xmlfile, 'Filename')
call xml_AddCharacters(xmlfile, trim(UserInfo%Attachment))
call xml_EndElement(xmlfile, 'Filename')
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, trim(UserInfo%AttachmentInfo))
call xml_EndElement(xmlfile, 'Description')
call xml_EndElement(xmlfile, 'Attachment')
end if
call date_and_time(date, time, zone)
xml_time = date(1:4)//'-'//date(5:6)//'-'//date(7:8)//&
'T'//time(1:2)//':'//time(3:4)//':'//time(5:6)
call xml_NewElement(xmlfile, 'Provenance')
call xml_NewElement(xmlfile, 'CreateTime')
call xml_AddCharacters(xmlfile, xml_time)
call xml_EndElement(xmlfile, 'CreateTime')
call xml_NewElement(xmlfile, 'CreatingApplication')
call xml_AddCharacters(xmlfile, 'EMTF File Conversion Utilities '//trim(version))
call xml_EndElement(xmlfile, 'CreatingApplication')
if (.not. isempty(UserInfo%Creator%Name)) then ! creator optional
call xml_NewElement(xmlfile, 'Creator')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(UserInfo%Creator%Name))
call xml_EndElement(xmlfile, 'Name')
if (.not. isempty(UserInfo%Creator%Email)) then
call xml_NewElement(xmlfile, 'Email')
call xml_AddCharacters(xmlfile, trim(UserInfo%Creator%Email))
call xml_EndElement(xmlfile, 'Email')
end if
if (.not. isempty(UserInfo%Creator%Org)) then
call xml_NewElement(xmlfile, 'Org')
call xml_AddCharacters(xmlfile, trim(UserInfo%Creator%Org))
call xml_EndElement(xmlfile, 'Org')
end if
if (.not. isempty(UserInfo%Creator%OrgUrl)) then
call xml_NewElement(xmlfile, 'OrgUrl')
call xml_AddCharacters(xmlfile, trim(UserInfo%Creator%OrgUrl))
call xml_EndElement(xmlfile, 'OrgUrl')
end if
call xml_EndElement(xmlfile, 'Creator')
end if
if (.not. isempty(UserInfo%Submitter%Name)) then ! submitter optional
call xml_NewElement(xmlfile, 'Submitter')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(UserInfo%Submitter%Name))
call xml_EndElement(xmlfile, 'Name')
if (.not. isempty(UserInfo%Submitter%Email)) then
call xml_NewElement(xmlfile, 'Email')
call xml_AddCharacters(xmlfile, trim(UserInfo%Submitter%Email))
call xml_EndElement(xmlfile, 'Email')
end if
if (.not. isempty(UserInfo%Submitter%Org)) then
call xml_NewElement(xmlfile, 'Org')
call xml_AddCharacters(xmlfile, trim(UserInfo%Submitter%Org))
call xml_EndElement(xmlfile, 'Org')
end if
if (.not. isempty(UserInfo%Submitter%OrgUrl)) then
call xml_NewElement(xmlfile, 'OrgUrl')
call xml_AddCharacters(xmlfile, trim(UserInfo%Submitter%OrgUrl))
call xml_EndElement(xmlfile, 'OrgUrl')
end if
call xml_EndElement(xmlfile, 'Submitter')
end if
call xml_EndElement(xmlfile, 'Provenance')
call xml_NewElement(xmlfile, 'Copyright')
call xml_NewElement(xmlfile, 'Citation')
call xml_NewElement(xmlfile, 'Title')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%Title))
call xml_EndElement(xmlfile, 'Title')
call xml_NewElement(xmlfile, 'Authors')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%Authors))
call xml_EndElement(xmlfile, 'Authors')
call xml_NewElement(xmlfile, 'Year')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%Year))
call xml_EndElement(xmlfile, 'Year')
if (.not. isempty(UserInfo%Copyright%SurveyDOI)) then
call xml_NewElement(xmlfile, 'SurveyDOI')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%SurveyDOI))
call xml_EndElement(xmlfile, 'SurveyDOI')
end if
if (.not. isempty(UserInfo%Copyright%DOI)) then
call xml_NewElement(xmlfile, 'DOI')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%DOI))
call xml_EndElement(xmlfile, 'DOI')
end if
call xml_EndElement(xmlfile, 'Citation')
if (.not. isempty(UserInfo%Copyright%SelectedPublications(1))) then
call xml_NewElement(xmlfile, 'SelectedPublications')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%SelectedPublications(1)))
do i=2,size(UserInfo%Copyright%SelectedPublications)
if (isempty(UserInfo%Copyright%SelectedPublications(i))) then
cycle
end if
call xml_AddCharacters(xmlfile, achar(ascii_cr))
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%SelectedPublications(i)))
end do
call xml_EndElement(xmlfile, 'SelectedPublications')
end if
if (.not. isempty(UserInfo%Copyright%Acknowledgement(1))) then
call xml_NewElement(xmlfile, 'Acknowledgement')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%Acknowledgement(1)))
do i=2,size(UserInfo%Copyright%Acknowledgement)
if (isempty(UserInfo%Copyright%Acknowledgement(i))) then
cycle
end if
call xml_AddCharacters(xmlfile, achar(ascii_cr))
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%Acknowledgement(i)))
end do
call xml_EndElement(xmlfile, 'Acknowledgement')
end if
call xml_NewElement(xmlfile, 'ReleaseStatus')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%ReleaseStatus))
call xml_EndElement(xmlfile, 'ReleaseStatus')
if (.not. isempty(UserInfo%Copyright%ConditionsOfUse(1))) then
call xml_NewElement(xmlfile, 'ConditionsOfUse')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%ConditionsOfUse(1)))
do i=2,size(UserInfo%Copyright%ConditionsOfUse)
if (isempty(UserInfo%Copyright%ConditionsOfUse(i))) then
cycle
end if
call xml_AddCharacters(xmlfile, achar(ascii_cr))
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%ConditionsOfUse(i)))
end do
call xml_EndElement(xmlfile, 'ConditionsOfUse')
end if
if (.not. isempty(UserInfo%Copyright%RotationInfo)) then
call xml_NewElement(xmlfile, 'RotationInfo')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%RotationInfo))
call xml_EndElement(xmlfile, 'RotationInfo')
end if
if (.not. isempty(UserInfo%Copyright%AdditionalInfo(1))) then
call xml_NewElement(xmlfile, 'AdditionalInfo')
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%AdditionalInfo(1)))
do i=2,size(UserInfo%Copyright%AdditionalInfo)
if (isempty(UserInfo%Copyright%AdditionalInfo(i))) then
cycle
end if
call xml_AddCharacters(xmlfile, achar(ascii_cr))
call xml_AddCharacters(xmlfile, trim(UserInfo%Copyright%AdditionalInfo(i)))
end do
call xml_EndElement(xmlfile, 'AdditionalInfo')
end if
call xml_EndElement(xmlfile, 'Copyright')
call xml_NewElement(xmlfile, 'Site')
call add_Site_header(UserInfo, Site)
call add_Location(Site%Location,Site%Declination,Site%DeclinationModel)
call xml_NewElement(xmlfile, 'Orientation')
if (Site%Orientation .eq. 'orthogonal') then
call xml_AddAttribute(xmlfile, 'angle_to_geographic_north', Site%AngleToGeogrNorth, fmt="r3")
end if
call xml_AddCharacters(xmlfile, Site%Orientation)
call xml_EndElement(xmlfile, 'Orientation')
call xml_NewElement(xmlfile, 'AcquiredBy')
call xml_AddCharacters(xmlfile, trim(UserInfo%AcquiredBy))
call xml_EndElement(xmlfile, 'AcquiredBy')
call xml_NewElement(xmlfile, 'Start')
if(len_trim(Site%Start).gt.0)then
call xml_AddCharacters(xmlfile, trim(Site%Start))
else
call xml_AddCharacters(xmlfile, trim(UserInfo%DefaultStartTime))
endif
call xml_EndElement(xmlfile, 'Start')
call xml_NewElement(xmlfile, 'End')
if(len_trim(Site%End).gt.0)then
call xml_AddCharacters(xmlfile, trim(Site%End))
else
call xml_AddCharacters(xmlfile, trim(UserInfo%DefaultEndTime))
endif
call xml_EndElement(xmlfile, 'End')
call xml_NewElement(xmlfile, 'RunList')
call xml_AddCharacters(xmlfile, trim(Site%RunList))
call xml_EndElement(xmlfile, 'RunList')
call xml_NewElement(xmlfile, 'DataQualityNotes')
call xml_NewElement(xmlfile, 'Rating')
call xml_AddCharacters(xmlfile, Site%QualityRating)
call xml_EndElement(xmlfile, 'Rating')
if (Site%QualityRating > 0) then
call xml_NewElement(xmlfile, 'GoodFromPeriod')
call xml_AddCharacters(xmlfile, Site%GoodFromPeriod, fmt="r3")
call xml_EndElement(xmlfile, 'GoodFromPeriod')
call xml_NewElement(xmlfile, 'GoodToPeriod')
call xml_AddCharacters(xmlfile, Site%GoodToPeriod, fmt="r3")
call xml_EndElement(xmlfile, 'GoodToPeriod')
call xml_NewElement(xmlfile, 'Comments')
call xml_AddAttribute(xmlfile, 'author', trim(UserInfo%Creator%Name))
call xml_AddCharacters(xmlfile, trim(Site%QualityComments))
call xml_EndElement(xmlfile, 'Comments')
else
call xml_NewElement(xmlfile, 'Comments')
call xml_AddCharacters(xmlfile, 'Unrated')
call xml_EndElement(xmlfile, 'Comments')
end if
call xml_EndElement(xmlfile, 'DataQualityNotes')
if (Site%WarningFlag >= 0) then
call xml_NewElement(xmlfile, 'DataQualityWarnings')
call xml_NewElement(xmlfile, 'Flag')
call xml_AddCharacters(xmlfile, Site%WarningFlag)
call xml_EndElement(xmlfile, 'Flag')
call xml_NewElement(xmlfile, 'Comments')
call xml_AddAttribute(xmlfile, 'author', trim(UserInfo%Creator%Name))
call xml_AddCharacters(xmlfile, trim(Site%WarningComments))
call xml_EndElement(xmlfile, 'Comments')
call xml_EndElement(xmlfile, 'DataQualityWarnings')
end if
if (present(Notes)) then
if (associated(Notes)) then
if (.not. silent) then
write(*,*) 'Writing Notes to XML file: '
end if
if (present(NotesLength)) then
N = NotesLength
else
N = size(Notes)
end if
call xml_NewElement(xmlfile, 'Comments')
call xml_AddAttribute(xmlfile, 'author', trim(UserInfo%ProcessedBy))
call xml_AddCharacters(xmlfile, achar(ascii_cr))
if (.not. silent) then
write(*,*) trim(Notes(1)),' (length: ',len_trim(Notes(1)),')'
end if
if (len_trim(Notes(1))>0) then
call xml_AddCharacters(xmlfile, trim(Notes(1)))
end if
do i=2,N
call xml_AddCharacters(xmlfile, achar(ascii_cr))
if (.not. silent) then
write(*,*) trim(Notes(i)),' (length: ',len_trim(Notes(i)),')'
end if
if (len_trim(Notes(i))>0) then
call xml_AddCharacters(xmlfile, trim(Notes(i)))
end if
end do
call xml_EndElement(xmlfile, 'Comments')
end if
end if
call xml_EndElement(xmlfile, 'Site')
end subroutine add_xml_header
subroutine add_Site_header(UserInfo, Site)
type(UserInfo_t), intent(in) :: UserInfo
type(Site_t), optional, intent(in) :: Site
call xml_NewElement(xmlfile, 'Project')
if (.not. isempty(Site%Project)) then
call xml_AddCharacters(xmlfile, trim(Site%Project))
else
call xml_AddCharacters(xmlfile, trim(UserInfo%Project))
end if
call xml_EndElement(xmlfile, 'Project')
call xml_NewElement(xmlfile, 'Survey')
if (.not. isempty(Site%Survey)) then
call xml_AddCharacters(xmlfile, trim(Site%Survey))
else
call xml_AddCharacters(xmlfile, trim(UserInfo%Survey))
end if
call xml_EndElement(xmlfile, 'Survey')
if (.not. isempty(UserInfo%YearCollected)) then
call xml_NewElement(xmlfile, 'YearCollected')
call xml_AddCharacters(xmlfile, trim(UserInfo%YearCollected))
call xml_EndElement(xmlfile, 'YearCollected')
end if
if (.not. isempty(UserInfo%Country)) then
call xml_NewElement(xmlfile, 'Country')
call xml_AddCharacters(xmlfile, trim(UserInfo%Country))
call xml_EndElement(xmlfile, 'Country')
end if
call xml_NewElement(xmlfile, 'Id')
call xml_AddCharacters(xmlfile, trim(Site%ID))
call xml_EndElement(xmlfile, 'Id')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(Site%Description))
call xml_EndElement(xmlfile, 'Name')
end subroutine add_Site_header
subroutine add_ProcessingInfo(UserInfo, RemoteSite, RemoteRun)
type(UserInfo_t), intent(in) :: UserInfo
type(Site_t), optional, intent(in) :: RemoteSite
type(Run_t), optional, dimension(:), intent(in) :: RemoteRun
! local
integer irun
call xml_NewElement(xmlfile, 'ProcessingInfo')
call xml_NewElement(xmlfile, 'SignConvention')
call xml_AddCharacters(xmlfile, trim(UserInfo%SignConvention))
call xml_EndElement(xmlfile, 'SignConvention')
call xml_NewElement(xmlfile, 'RemoteRef')
call xml_AddAttribute(xmlfile, 'type', trim(UserInfo%RemoteRefType))
call xml_EndElement(xmlfile, 'RemoteRef')
if (present(RemoteSite)) then
if (len_trim(RemoteSite%ID)>0) then
call xml_NewElement(xmlfile, 'RemoteInfo')
call xml_NewElement(xmlfile, 'Site')
call add_Site_header(UserInfo,RemoteSite)
call add_Location(RemoteSite%Location)
call xml_EndElement(xmlfile, 'Site')
if (present(RemoteRun)) then
do irun=1,size(RemoteRun)
call add_FieldNotes(RemoteRun(irun))
end do
end if
call xml_EndElement(xmlfile, 'RemoteInfo')
end if
end if
call xml_NewElement(xmlfile, 'ProcessedBy')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessedBy))
call xml_EndElement(xmlfile, 'ProcessedBy')
if (.not. isempty(UserInfo%ProcessDate)) then
call xml_NewElement(xmlfile, 'ProcessDate')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessDate))
call xml_EndElement(xmlfile, 'ProcessDate')
end if
call xml_NewElement(xmlfile, 'ProcessingSoftware')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessingSoftware))
call xml_EndElement(xmlfile, 'Name')
call xml_NewElement(xmlfile, 'LastMod')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessingSoftwareLastMod))
call xml_EndElement(xmlfile, 'LastMod')
call xml_NewElement(xmlfile, 'Author')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessingSoftwareAuthor))
call xml_EndElement(xmlfile, 'Author')
call xml_EndElement(xmlfile, 'ProcessingSoftware')
call xml_NewElement(xmlfile, 'ProcessingTag')
call xml_AddCharacters(xmlfile, trim(UserInfo%ProcessingTag))
call xml_EndElement(xmlfile, 'ProcessingTag')
call xml_EndElement(xmlfile, 'ProcessingInfo')
end subroutine add_ProcessingInfo
subroutine add_FieldNotes(Run, InputChannel, OutputChannel)
type(Run_t), intent(in) :: Run
type(Channel_t), intent(in), optional :: InputChannel(:)
type(Channel_t), intent(in), optional :: OutputChannel(:) ! electric only
! local
integer :: nchoutE
character(len=1) :: location(2)
character(len=10) :: number(2)
call xml_NewElement(xmlfile, 'FieldNotes')
call xml_AddAttribute(xmlfile, 'run', trim(Run%ID))
call xml_NewElement(xmlfile, 'Instrument')
call xml_NewElement(xmlfile, 'Manufacturer')
call xml_AddCharacters(xmlfile, trim(Run%Manufacturer))
call xml_EndElement(xmlfile, 'Manufacturer')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(Run%InstrumentName))
call xml_EndElement(xmlfile, 'Name')
call xml_NewElement(xmlfile, 'Id')
call xml_AddCharacters(xmlfile, trim(Run%InstrumentID))
call xml_EndElement(xmlfile, 'Id')
call xml_NewElement(xmlfile, 'Settings')
call xml_EndElement(xmlfile, 'Settings')
call xml_EndElement(xmlfile, 'Instrument')
if (.not. present(InputChannel)) then
! skip magnetometer information
else
! add full information on magnetometer
call xml_NewElement(xmlfile, 'Magnetometer')
call xml_AddAttribute(xmlfile, 'type', trim(InputChannel(1)%InstrumentType))
call xml_NewElement(xmlfile, 'Manufacturer')
call xml_AddCharacters(xmlfile, trim(InputChannel(1)%Manufacturer))
call xml_EndElement(xmlfile, 'Manufacturer')
call xml_NewElement(xmlfile, 'Name')
call xml_AddCharacters(xmlfile, trim(InputChannel(1)%InstrumentName))
call xml_EndElement(xmlfile, 'Name')
call xml_NewElement(xmlfile, 'Id')
call xml_AddCharacters(xmlfile, trim(InputChannel(1)%InstrumentID))
call xml_EndElement(xmlfile, 'Id')
call xml_NewElement(xmlfile, 'Settings')
call xml_EndElement(xmlfile, 'Settings')
call xml_EndElement(xmlfile, 'Magnetometer')
end if
if (.not. present(OutputChannel)) then
! add minimal information on Ex: wire length
call xml_NewElement(xmlfile, 'Dipole')
call xml_AddAttribute(xmlfile, 'name', 'Ex')
call xml_NewElement(xmlfile, 'Length')
call xml_AddAttribute(xmlfile, 'units', 'meters')
call xml_AddCharacters(xmlfile, Run%Ex_wire_length, fmt="r3")
call xml_EndElement(xmlfile, 'Length')
call xml_EndElement(xmlfile, 'Dipole')
! add minimal information on Ey: wire length
call xml_NewElement(xmlfile, 'Dipole')
call xml_AddAttribute(xmlfile, 'name', 'Ey')
call xml_NewElement(xmlfile, 'Length')
call xml_AddAttribute(xmlfile, 'units', 'meters')
call xml_AddCharacters(xmlfile, Run%Ey_wire_length, fmt="r3")
call xml_EndElement(xmlfile, 'Length')
call xml_EndElement(xmlfile, 'Dipole')
else
! add full information on electric field channels
nchoutE = size(OutputChannel)
do i = 1,nchoutE
call xml_NewElement(xmlfile, 'Dipole')
call xml_AddAttribute(xmlfile, 'name', trim(OutputChannel(i)%ID))
call xml_AddAttribute(xmlfile, 'type', trim(OutputChannel(i)%InstrumentConfig))
call xml_NewElement(xmlfile, 'Manufacturer')
call xml_AddCharacters(xmlfile, trim(OutputChannel(i)%Manufacturer))
call xml_EndElement(xmlfile, 'Manufacturer')
call xml_NewElement(xmlfile, 'Length')
call xml_AddAttribute(xmlfile, 'units', 'meters')
call xml_AddCharacters(xmlfile, OutputChannel(i)%DipoleLength, fmt="r3")
call xml_EndElement(xmlfile, 'Length')
call xml_NewElement(xmlfile, 'Azimuth')
call xml_AddAttribute(xmlfile, 'units', 'degrees')
call xml_AddCharacters(xmlfile, OutputChannel(i)%DipoleAzimuth, fmt="r3")
call xml_EndElement(xmlfile, 'Azimuth')
if (index(OutputChannel(i)%ID,'x')>0) then
location(1) = 'N'
location(2) = 'S'
else if (index(OutputChannel(i)%ID,'y')>0) then
location(1) = 'E'
location(2) = 'W'
end if
j = index(OutputChannel(i)%InstrumentID,';')
number(1) = OutputChannel(i)%InstrumentID(1:j-1)
number(2) = OutputChannel(i)%InstrumentID(j+2:80)
call xml_NewElement(xmlfile, 'Electrode')
call xml_AddAttribute(xmlfile, 'location', location(1))
call xml_AddAttribute(xmlfile, 'number', trim(number(1)))
call xml_AddCharacters(xmlfile, trim(OutputChannel(i)%InstrumentType))
call xml_EndElement(xmlfile, 'Electrode')
call xml_NewElement(xmlfile, 'Electrode')
call xml_AddAttribute(xmlfile, 'location', location(2))
call xml_AddAttribute(xmlfile, 'number', trim(number(2)))
call xml_AddCharacters(xmlfile, trim(OutputChannel(i)%InstrumentType))
call xml_EndElement(xmlfile, 'Electrode')
call xml_EndElement(xmlfile, 'Dipole')
end do
end if
if (len_trim(Run%FieldComments)>0) then
call xml_NewElement(xmlfile, 'Comments')
call xml_AddAttribute(xmlfile, 'author', trim(Run%SiteInstalledBy))
call xml_AddCharacters(xmlfile, trim(Run%FieldComments))
call xml_EndElement(xmlfile, 'Comments')
end if
if (len_trim(Run%Comments)>0) then
call xml_NewElement(xmlfile, 'Comments')
call xml_AddAttribute(xmlfile, 'author', trim(Run%MetaDataCheckedBy))
call xml_AddCharacters(xmlfile, trim(Run%Comments))
call xml_EndElement(xmlfile, 'Comments')
end if
call xml_NewElement(xmlfile, 'Errors')
call xml_AddCharacters(xmlfile, trim(Run%Errors))
call xml_EndElement(xmlfile, 'Errors')
if (Run%SamplingRate > 0.0d0) then
call xml_NewElement(xmlfile, 'SamplingRate')
call xml_AddAttribute(xmlfile, 'units', 'Hz')
call xml_AddCharacters(xmlfile, Run%SamplingRate, fmt="r3")
call xml_EndElement(xmlfile, 'SamplingRate')
end if
call xml_NewElement(xmlfile, 'Start')
call xml_AddCharacters(xmlfile, Run%TimePeriod%StartTime)
call xml_EndElement(xmlfile, 'Start')
call xml_NewElement(xmlfile, 'End')
call xml_AddCharacters(xmlfile, Run%TimePeriod%EndTime)
call xml_EndElement(xmlfile, 'End')
call xml_EndElement(xmlfile, 'FieldNotes')
end subroutine add_FieldNotes
subroutine add_Location(L,decl,model)
type(Location_t), intent(in) :: L
real(8), optional, intent(in) :: decl
character(*), optional, intent(in) :: model
! local
character(6) epoch
call xml_NewElement(xmlfile, 'Location')
call xml_AddAttribute(xmlfile, 'datum', trim(L%datum))
call xml_NewElement(xmlfile, 'Latitude')
call xml_AddCharacters(xmlfile, L%lat, fmt="r6")
call xml_EndElement(xmlfile, 'Latitude')
call xml_NewElement(xmlfile, 'Longitude')
call xml_AddCharacters(xmlfile, L%lon, fmt="r6")
call xml_EndElement(xmlfile, 'Longitude')
call xml_NewElement(xmlfile, 'Elevation')
call xml_AddAttribute(xmlfile, 'units', 'meters')
call xml_AddCharacters(xmlfile, L%elev, fmt="r3")
call xml_EndElement(xmlfile, 'Elevation')
if (present(decl)) then
call xml_NewElement(xmlfile, 'Declination')
! parse IGRF model, if present
if (present(model)) then
if (index(model,'15')>0) then
epoch = '2030.0'
elseif (index(model,'14')>0) then
epoch = '2025.0'
elseif (index(model,'13')>0) then
epoch = '2020.0'
elseif (index(model,'12')>0) then
epoch = '2015.0'
elseif (index(model,'11')>0) then
epoch = '2010.0'
elseif (index(model,'10')>0) then
epoch = '2005.0'
elseif (index(model,'09')>0) then
epoch = '2000.0'
else
epoch = '1995.0'
end if
call xml_AddAttribute(xmlfile, 'epoch', epoch)
else
call xml_AddAttribute(xmlfile, 'epoch', '1995.0')
end if
call xml_AddCharacters(xmlfile, decl, fmt="r3")
call xml_EndElement(xmlfile, 'Declination')
end if
call xml_EndElement(xmlfile, 'Location')
end subroutine add_Location
subroutine add_SiteCoords(C)
type(XYZ_t), intent(in) :: C
call xml_NewElement(xmlfile, 'SiteCoords')
call xml_AddAttribute(xmlfile, 'type', trim(C%type))
call xml_AddAttribute(xmlfile, 'units', trim(C%units))
call xml_NewElement(xmlfile, 'X')
call xml_AddCharacters(xmlfile, C%X, fmt="r6")
call xml_EndElement(xmlfile, 'X')
call xml_NewElement(xmlfile, 'Y')
call xml_AddCharacters(xmlfile, C%Y, fmt="r6")
call xml_EndElement(xmlfile, 'Y')
call xml_NewElement(xmlfile, 'Z')
call xml_AddCharacters(xmlfile, C%Z, fmt="r3")
call xml_EndElement(xmlfile, 'Z')
call xml_EndElement(xmlfile, 'SiteCoords')
end subroutine add_SiteCoords
subroutine add_GridOrigin(Site)
type(Site_t), intent(in) :: Site
call xml_NewElement(xmlfile, 'GridOrigin')
call xml_AddAttribute(xmlfile, 'name', trim(Site%Coords%Origin%ID))
call add_Location(Site%Coords%Origin)
call xml_NewElement(xmlfile, 'SiteCoords')
call xml_AddAttribute(xmlfile, 'type', trim(Site%Coords%Type))
call xml_AddAttribute(xmlfile, 'units', trim(Site%Coords%Units))
call xml_NewElement(xmlfile, 'X')
call xml_AddCharacters(xmlfile, Site%Coords%X, fmt="r6")
call xml_EndElement(xmlfile, 'X')
call xml_NewElement(xmlfile, 'Y')
call xml_AddCharacters(xmlfile, Site%Coords%Y, fmt="r6")
call xml_EndElement(xmlfile, 'Y')
call xml_NewElement(xmlfile, 'Z')
call xml_AddCharacters(xmlfile, Site%Coords%Z, fmt="r3")
call xml_EndElement(xmlfile, 'Z')
call xml_EndElement(xmlfile, 'SiteCoords')
call xml_EndElement(xmlfile, 'GridOrigin')
end subroutine add_GridOrigin
subroutine add_DataType(D)
type(DataType_t), intent(in) :: D
call xml_NewElement(xmlfile, 'DataType')
call xml_AddAttribute(xmlfile, 'name', trim(D%Name))
if (D%isComplex) then
call xml_AddAttribute(xmlfile, 'type', 'complex')
else
call xml_AddAttribute(xmlfile, 'type', 'real')
end if
if (.not. D%isScalar) then
call xml_AddAttribute(xmlfile, 'output', trim(D%Output))
call xml_AddAttribute(xmlfile, 'input', trim(D%Input))
end if
call xml_AddAttribute(xmlfile, 'units', trim(D%Units))
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, trim(D%Description))
call xml_EndElement(xmlfile, 'Description')
call xml_NewElement(xmlfile, 'ExternalUrl')
call xml_AddCharacters(xmlfile, 'http://www.iris.edu/dms/products/emtf/'//trim(D%Tag)//'.html')
call xml_EndElement(xmlfile, 'ExternalUrl')
call xml_NewElement(xmlfile, 'Intention')
call xml_AddCharacters(xmlfile, trim(D%Intention))
call xml_EndElement(xmlfile, 'Intention')
call xml_NewElement(xmlfile, 'Tag')
call xml_AddCharacters(xmlfile, trim(D%Tag))
call xml_EndElement(xmlfile, 'Tag')
if (D%derivedType) then
call xml_NewElement(xmlfile, 'DerivedFrom')
call xml_AddCharacters(xmlfile, trim(D%DerivedFrom))
call xml_EndElement(xmlfile, 'DerivedFrom')
end if
! if you choose to use the hyperlink here, deal with comma-separated lists correctly
if (len_trim(D%SeeAlso) > 0) then
call xml_NewElement(xmlfile, 'SeeAlso')
call xml_AddCharacters(xmlfile, trim(D%SeeAlso))
call xml_EndElement(xmlfile, 'SeeAlso')
end if
call xml_EndElement(xmlfile, 'DataType')
end subroutine add_DataType
subroutine add_Estimate(D)
type(DataType_t), intent(in) :: D ! statistical estimate
call xml_NewElement(xmlfile, 'Estimate')
call xml_AddAttribute(xmlfile, 'name', trim(D%Name))
if (D%isComplex) then
call xml_AddAttribute(xmlfile, 'type', 'complex')
else
call xml_AddAttribute(xmlfile, 'type', 'real')
end if
call xml_NewElement(xmlfile, 'Description')
call xml_AddCharacters(xmlfile, trim(D%Description))
call xml_EndElement(xmlfile, 'Description')
call xml_NewElement(xmlfile, 'ExternalUrl')
call xml_AddCharacters(xmlfile, 'http://www.iris.edu/dms/products/emtf/'//trim(D%Tag)//'.html')
call xml_EndElement(xmlfile, 'ExternalUrl')
call xml_NewElement(xmlfile, 'Intention')
call xml_AddCharacters(xmlfile, trim(D%Intention))
call xml_EndElement(xmlfile, 'Intention')
call xml_NewElement(xmlfile, 'Tag')
call xml_AddCharacters(xmlfile, trim(D%Tag))
call xml_EndElement(xmlfile, 'Tag')
call xml_EndElement(xmlfile, 'Estimate')
end subroutine add_Estimate
subroutine add_Channel(C,location)
type(Channel_t), intent(in) :: C
logical, intent(in) :: location
! local
character(10) :: type
if (C%Type .eq. 'E') then
type = 'Electric'
elseif (C%Type .eq. 'H') then
type = 'Magnetic'
else
write(0,*) 'Unknown channel type ',trim(C%Type),' on output to XML'
stop
end if
call xml_NewElement(xmlfile, trim(type))
call xml_AddAttribute(xmlfile, 'name', trim(C%ID))
call xml_AddAttribute(xmlfile, 'orientation', C%Orientation, fmt="r1")
call xml_AddAttribute(xmlfile, 'x', C%X, fmt="r1")
call xml_AddAttribute(xmlfile, 'y', C%Y, fmt="r1")
call xml_AddAttribute(xmlfile, 'z', C%Z, fmt="r1")
if (index(C%ID,'E')>0) then
call xml_AddAttribute(xmlfile, 'x2', C%X2, fmt="r1")
call xml_AddAttribute(xmlfile, 'y2', C%Y2, fmt="r1")
call xml_AddAttribute(xmlfile, 'z2', C%Z2, fmt="r1")
end if
if (location) then
call add_Location(C%Location)
end if
call xml_EndElement(xmlfile, trim(type))
end subroutine add_Channel
subroutine add_PeriodRange(F)
type(FreqInfo_t), dimension(:), intent(in) :: F
real(8), dimension(:), allocatable :: period
real(8) :: minFreq, minPeriod
real(8) :: maxFreq, maxPeriod
integer :: i, nf
nf = size(F)
allocate(period(nf))
do i=1,nf
if (index(F(i)%info_type,'period')>0) then
period(i) = F(i)%value
else
period(i) = 1.0d0/F(i)%value
end if
end do
maxPeriod = maxval(period)
minPeriod = minval(period)
deallocate(period)
maxFreq = 1.0d0/minPeriod
minFreq = 1.0d0/maxPeriod
if (.not.(silent)) then
print *,'maxPeriod = ',maxPeriod
print *,'minPeriod = ',minPeriod
end if
call xml_NewElement(xmlfile, 'PeriodRange')
call xml_AddAttribute(xmlfile, 'min', minPeriod, fmt="r9")
call xml_AddAttribute(xmlfile, 'max', maxPeriod, fmt="r9")
call xml_EndElement(xmlfile, 'PeriodRange')
!call xml_NewElement(xmlfile, 'FrequencyRange')
!call xml_AddAttribute(xmlfile, 'min', minFreq, fmt="s5")
!call xml_AddAttribute(xmlfile, 'max', maxFreq, fmt="s5")
!call xml_EndElement(xmlfile, 'FrequencyRange')
end subroutine add_PeriodRange
subroutine add_Data(Data, iPer, Input, Output)
type(Data_t), intent(in) :: Data
type(Channel_t), dimension(:), intent(in), optional :: Input, Output
integer, intent(in) :: iPer
! local
character(20) :: str
if (.not. Data%Type%isScalar) then
if (.not. (present(Input) .and. present(Output))) then
write(0,*) 'Warning: unable to write non-scalar data ',trim(Data%Type%Name),' for period ',iPer,' to XML file.'
write(0,*) 'Check your XML tags and make sure that data type input and output are specified correctly.'
return
end if
end if
call xml_NewElement(xmlfile, trim(Data%Type%Name))
if (Data%Type%isComplex) then
call xml_AddAttribute(xmlfile, 'type', 'complex')
else
call xml_AddAttribute(xmlfile, 'type', 'real')
end if
if (Data%Type%isScalar) then
write(str,'(i3,i3)') 1, 1
call xml_AddAttribute(xmlfile, 'size', trim(adjustl(str)))
else