-
Notifications
You must be signed in to change notification settings - Fork 0
/
Station.vb
965 lines (887 loc) · 36 KB
/
Station.vb
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
Option Strict Off
Option Explicit On
Imports atcUtility
Friend Class pfqStation
Public Structure ThresholdType
Dim SYear As Integer
Dim EYear As Integer
Dim LowerLimit As Single
Dim UpperLimit As Single
Dim Comment As String
End Structure
Public Class PeakDataType
Implements IComparable
Public Year As Integer
Public Value As Double
Public Code As String = ""
Public LowerLimit As Single = -999
Public UpperLimit As Single = -999
Public Comment As String = ""
Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
Return Year.CompareTo(obj.Year)
End Function
Public Function Clone() As PeakDataType
Dim lNewPeak As New PeakDataType
lNewPeak.Code = Code.Clone
lNewPeak.Comment = Comment.Clone
lNewPeak.LowerLimit = LowerLimit
lNewPeak.UpperLimit = UpperLimit
lNewPeak.Value = Value
lNewPeak.Year = Year
Return lNewPeak
End Function
End Class
Private pID As String
Private pName As String
Private pAnalysisOption As String 'Skip, B17B, EMA
Private pBegYear As Integer
Private pEndYear As Integer
Private pSkewOpt As Integer '0 - Station, 1 - Weighted, 2 - Regional
Private pUrbanRegPeaks As Boolean
Private pHistoricPeriod As Boolean
Private pUseSkewMap As Boolean
Private pGenSkew As Single
Private pHighSysPeak As Single
Private pHighOutlier As Single
Private pLowHistPeak As Single
Private pLOTestType As String
Private pLowOutlier As Single
Private pGageBaseDischarge As Single
Private pSESkew As Single
Private pLat As Single
Private pLng As Single
Private pPlotName As String
Private pPlotMade As Boolean
Public Thresholds As Generic.List(Of ThresholdType)
Private pPeakDataOrig As Generic.List(Of PeakDataType)
Private pPeakData As Generic.List(Of PeakDataType)
Private pFirstSystematic As Integer
Private pLastSystematic As Integer
Private pFirstPeak As Integer
Private pLastPeak As Integer
Private pWeightOpt As String
'the following are for storing comments for various specification records
Private pComment As String
Private pCAnalysisOption As String
Private pCGenSkew As String
Private pCSESkew As String
Private pCBegYear As String
Private pCEndYear As String
Private pCHistoric As String
Private pCSkewOpt As String
Private pCUrban As String
Private pCLowOutlier As String
Private pCHighOutlier As String
Private pCGageBase As String
Private pCLat As String
Private pCLong As String
Private pCPlotName As String
Private pCThresholds As String
Private pCIntervals As String
Private pCLOTestType As String
Private pCUseSkewMap As String
'UPGRADE_ISSUE: Declaration type not supported: Array with lower bound less than zero. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="934BD4FF-1FF9-47BD-888F-D411E47E78FA"'
'Private SOText(-1 To 1) As String
Private SOText(2) As String
Public Property id() As String
Get
id = pID
End Get
Set(ByVal Value As String)
pID = Value
End Set
End Property
Public Property Name() As String
Get
Name = pName
End Get
Set(ByVal Value As String)
pName = Value
End Set
End Property
Public Property AnalysisOption() As String
Get
AnalysisOption = pAnalysisOption
End Get
Set(ByVal Value As String)
pAnalysisOption = Value
End Set
End Property
Public Property BegYear() As Integer
Get
BegYear = pBegYear
End Get
Set(ByVal Value As Integer)
pBegYear = Value
End Set
End Property
Public Property EndYear() As Integer
Get
EndYear = pEndYear
End Get
Set(ByVal Value As Integer)
pEndYear = Value
End Set
End Property
Public Property SkewOpt() As Integer
Get
SkewOpt = pSkewOpt
End Get
Set(ByVal Value As Integer)
pSkewOpt = Value
End Set
End Property
Public Property WeightOpt() As String
Get
WeightOpt = pWeightOpt
End Get
Set(ByVal Value As String)
pWeightOpt = Value
End Set
End Property
Public Property UrbanRegPeaks() As Boolean
Get
UrbanRegPeaks = pUrbanRegPeaks
End Get
Set(ByVal Value As Boolean)
pUrbanRegPeaks = Value
End Set
End Property
Public Property HistoricPeriod() As Boolean
Get
HistoricPeriod = pHistoricPeriod
End Get
Set(ByVal Value As Boolean)
pHistoricPeriod = Value
End Set
End Property
Public Property UseSkewMap() As Boolean
Get
UseSkewMap = pUseSkewMap
End Get
Set(ByVal Value As Boolean)
pUseSkewMap = Value
End Set
End Property
Public Property GenSkew() As Single
Get
GenSkew = pGenSkew
End Get
Set(ByVal Value As Single)
pGenSkew = Value
End Set
End Property
Public Property HighSysPeak() As Single
Get
HighSysPeak = pHighSysPeak
End Get
Set(ByVal Value As Single)
pHighSysPeak = Value
End Set
End Property
Public Property HighOutlier() As Single
Get
HighOutlier = pHighOutlier
End Get
Set(ByVal Value As Single)
pHighOutlier = Value
End Set
End Property
Public Property LowHistPeak() As Single
Get
LowHistPeak = pLowHistPeak
End Get
Set(ByVal Value As Single)
pLowHistPeak = Value
End Set
End Property
Public Property LowOutlier() As Single
Get
LowOutlier = pLowOutlier
End Get
Set(ByVal Value As Single)
pLowOutlier = Value
End Set
End Property
Public Property GageBaseDischarge() As Single
Get
GageBaseDischarge = pGageBaseDischarge
End Get
Set(ByVal Value As Single)
pGageBaseDischarge = Value
End Set
End Property
Public Property SESkew() As Single
Get
SESkew = pSESkew
End Get
Set(ByVal Value As Single)
pSESkew = Value
End Set
End Property
Public Property Lat() As Single
Get
Lat = pLat
End Get
Set(ByVal Value As Single)
pLat = Value
End Set
End Property
Public Property Lng() As Single
Get
Lng = pLng
End Get
Set(ByVal Value As Single)
pLng = Value
End Set
End Property
Public Property PlotName() As String
Get
PlotName = pPlotName
End Get
Set(ByVal Value As String)
pPlotName = Value
End Set
End Property
Public Property PlotMade() As Boolean
Get
PlotMade = pPlotMade
End Get
Set(ByVal Value As Boolean)
pPlotMade = Value
End Set
End Property
'Public Property Thresholds() As Generic.List(Of pfqStation.ThresholdType)
' Get
' If pThresholds Is Nothing Then pThresholds = New Generic.List(Of pfqStation.ThresholdType)
' Thresholds = pThresholds
' End Get
' Set(ByVal Value As Generic.List(Of pfqStation.ThresholdType))
' pThresholds = Value
' End Set
'End Property
Public Property PeakDataOrig() As Generic.List(Of pfqStation.PeakDataType)
Get
If pPeakDataOrig Is Nothing Then pPeakDataOrig = New Generic.List(Of pfqStation.PeakDataType)
Return pPeakDataOrig
End Get
Set(ByVal Value As Generic.List(Of pfqStation.PeakDataType))
pPeakDataOrig = Value
End Set
End Property
Public Property PeakData() As Generic.List(Of pfqStation.PeakDataType)
Get
If pPeakData Is Nothing Then pPeakData = New Generic.List(Of pfqStation.PeakDataType)
Return pPeakData
End Get
Set(ByVal Value As Generic.List(Of pfqStation.PeakDataType))
pPeakData = Value
End Set
End Property
Public Property Comment() As String
Get
Comment = pComment
End Get
Set(ByVal Value As String)
pComment = Value
End Set
End Property
Public Property CAnalysisOption() As String
Get
CAnalysisOption = pCAnalysisOption
End Get
Set(ByVal Value As String)
pCAnalysisOption = Value
End Set
End Property
Public Property CGenSkew() As String
Get
CGenSkew = pCGenSkew
End Get
Set(ByVal Value As String)
pCGenSkew = Value
End Set
End Property
Public Property CSESkew() As String
Get
CSESkew = pCSESkew
End Get
Set(ByVal Value As String)
pCSESkew = Value
End Set
End Property
Public Property CBegYear() As String
Get
CBegYear = pCBegYear
End Get
Set(ByVal Value As String)
pCBegYear = Value
End Set
End Property
Public Property CEndYear() As String
Get
CEndYear = pCEndYear
End Get
Set(ByVal Value As String)
pCEndYear = Value
End Set
End Property
Public Property CHistoric() As String
Get
CHistoric = pCHistoric
End Get
Set(ByVal Value As String)
pCHistoric = Value
End Set
End Property
Public Property CSkewOpt() As String
Get
CSkewOpt = pCSkewOpt
End Get
Set(ByVal Value As String)
pCSkewOpt = Value
End Set
End Property
Public Property CUrban() As String
Get
CUrban = pCUrban
End Get
Set(ByVal Value As String)
pCUrban = Value
End Set
End Property
Public Property CLowOutlier() As String
Get
CLowOutlier = pCLowOutlier
End Get
Set(ByVal Value As String)
pCLowOutlier = Value
End Set
End Property
Public Property CHighOutlier() As String
Get
CHighOutlier = pCHighOutlier
End Get
Set(ByVal Value As String)
pCHighOutlier = Value
End Set
End Property
Public Property CGageBase() As String
Get
CGageBase = pCGageBase
End Get
Set(ByVal Value As String)
pCGageBase = Value
End Set
End Property
Public Property CLat() As String
Get
CLat = pCLat
End Get
Set(ByVal Value As String)
pCLat = Value
End Set
End Property
Public Property CLong() As String
Get
CLong = pCLong
End Get
Set(ByVal Value As String)
pCLong = Value
End Set
End Property
Public Property CPlotName() As String
Get
CPlotName = pCPlotName
End Get
Set(ByVal Value As String)
pCPlotName = Value
End Set
End Property
Public Property CThresholds() As String
Get
CThresholds = pCThresholds
End Get
Set(ByVal Value As String)
pCThresholds = Value
End Set
End Property
Public Property CIntervals() As String
Get
CIntervals = pCIntervals
End Get
Set(ByVal Value As String)
pCIntervals = Value
End Set
End Property
Public Property LOTestType() As String
Get
LOTestType = pLOTestType
End Get
Set(ByVal Value As String)
pLOTestType = Value
End Set
End Property
Public Property CLOTestType() As String
Get
CLOTestType = pCLOTestType
End Get
Set(ByVal Value As String)
pCLOTestType = Value
End Set
End Property
Public Property CUseSkewMap() As String
Get
CUseSkewMap = pCUseSkewMap
End Get
Set(ByVal Value As String)
pCUseSkewMap = Value
End Set
End Property
Public Property FirstSystematic() As Integer
Get
FirstSystematic = pFirstSystematic
End Get
Set(ByVal Value As Integer)
pFirstSystematic = Value
End Set
End Property
Public Property LastSystematic() As Integer
Get
LastSystematic = pLastSystematic
End Get
Set(ByVal Value As Integer)
pLastSystematic = Value
End Set
End Property
Public Property FirstPeak() As Integer
Get
FirstPeak = pFirstPeak
End Get
Set(ByVal Value As Integer)
pFirstPeak = Value
End Set
End Property
Public Property LastPeak() As Integer
Get
LastPeak = pLastPeak
End Get
Set(ByVal Value As Integer)
pLastPeak = Value
End Set
End Property
Public Function WriteSpecsVerbose() As String
Dim s As String
Const pad As String = " "
If Len(pComment) > 0 Then
s = pComment & vbCrLf & "Station " & pID & vbCrLf
Else
s = "Station " & pID & vbCrLf
End If
If Len(pCAnalysisOption) > 0 Then
s = s & pad & pCAnalysisOption & vbCrLf & pad & "Analyze " & pAnalysisOption & vbCrLf
Else
s = s & pad & "Analyze " & pAnalysisOption & vbCrLf
End If
If Thresholds.Count > 0 AndAlso pAnalysisOption.ToUpper = "EMA" Then 'using perception threshholds, not beg/end years and hist. period
For Each vPT As ThresholdType In Thresholds
s = s & pad & "PCPT_Thresh " & vPT.SYear & " " & vPT.EYear & " " & vPT.LowerLimit & " " & vPT.UpperLimit & " " & vPT.Comment & vbCrLf
Next
End If
If Len(pCBegYear) > 0 Then s = s & pad & pCBegYear & vbCrLf
If pBegYear > 0 Then s = s & pad & "BegYear " & CStr(pBegYear) & vbCrLf
If Len(pCEndYear) > 0 Then s = s & pad & pCEndYear & vbCrLf
If pEndYear > 0 Then s = s & pad & "EndYear " & CStr(pEndYear) & vbCrLf
If Len(pCHistoric) > 0 Then s = s & pad & pCHistoric & vbCrLf
If pHistoricPeriod Then
s = s & pad & "HistPeriod " & CStr(pEndYear - pBegYear + 1) & vbCrLf
Else
s = s & pad & "'NO Historic Period in use" & vbCrLf
End If
'write any interval data or updated peak data
For Each vData As PeakDataType In pPeakData
If vData.Year >= pBegYear AndAlso vData.Year <= pEndYear AndAlso
(Not vData.Code.Contains("K") Or Me.UrbanRegPeaks) Then
'within start/end of analysis range; also not an Urb/Reg peak (or UrbReg is YES)
If Not PeakDataOrigContains(vData) Then 'new or revised peak
If vData.Year > 0 AndAlso vData.LowerLimit >= 0 AndAlso vData.UpperLimit > 0 AndAlso
Math.Abs(vData.UpperLimit - vData.LowerLimit) > 0.001 Then 'interval data
s = s & pad & "Interval " & vData.Year & " " & vData.LowerLimit & " " & vData.UpperLimit & " " & vData.Comment & vbCrLf
Else 'just revised peak data
If vData.Value < 100 AndAlso vData.Value > 0 Then
s = s & pad & "Peak " & vData.Year & " " & DoubleToString(vData.Value,,,,, 4) & " " & vData.Code
Else
s = s & pad & "Peak " & vData.Year & " " & vData.Value & " " & vData.Code
End If
If vData.Comment.Length > 0 Then s = s & " '" & vData.Comment & vbCrLf Else s = s & vbCrLf
End If
End If
End If
Next
If Len(pCSkewOpt) > 0 Then s = s & pad & pCSkewOpt & vbCrLf
s = s & pad & "SkewOpt " & SOText(pSkewOpt) & vbCrLf
If Len(pCUseSkewMap) > 0 Then s = s & pad & pCUseSkewMap & vbCrLf
If pUseSkewMap Then
s = s & pad & "UseSkewMap YES" & vbCrLf
Else
s = s & pad & "UseSkewMap NO" & vbCrLf
End If
If Len(pCGenSkew) > 0 Then s = s & pad & pCGenSkew & vbCrLf
s = s & pad & "GenSkew " & pGenSkew & vbCrLf
If Len(pCSESkew) > 0 Then s = s & pad & pCSESkew & vbCrLf
s = s & pad & "SkewSE " & pSESkew & vbCrLf
s = s & pad & "WeightOpt " & pWeightOpt & vbCrLf
If Len(pCUrban) > 0 Then s = s & pad & pCUrban & vbCrLf
If pUrbanRegPeaks Then
s = s & pad & "Urb/Reg YES" & vbCrLf
Else
s = s & pad & "Urb/Reg NO" & vbCrLf
End If
If Len(pCLowOutlier) > 0 Then s = s & pad & pCLowOutlier & vbCrLf
If pLowOutlier > 0 Then 'write record showing specified low outlier
s = s & pad & "LoThresh " & CStr(pLowOutlier) & vbCrLf
'when LO specified there's no need for LO Test type
s = s & pad & "LOType FIXED" & vbCrLf
Else 'need a low outlier test type
If Len(pCLOTestType) > 0 Then s = s & pad & pCLOTestType & vbCrLf
If pLOTestType.StartsWith("Multiple") Then
s = s & pad & "LOType MGBT" & vbCrLf
Else
s = s & pad & "LOType GBT" & vbCrLf
End If
End If
If Len(pCHighOutlier) > 0 Then s = s & pad & pCHighOutlier & vbCrLf
If pHighOutlier > 0 Then s = s & pad & "HiThresh " & CStr(pHighOutlier) & vbCrLf
If Len(pCGageBase) > 0 Then s = s & pad & pCGageBase & vbCrLf
If pGageBaseDischarge > 0 Then s = s & pad & "GageBase " & CStr(pGageBaseDischarge) & vbCrLf
If Len(pCLat) > 0 Then s = s & pad & pCLat & vbCrLf
If pLat > 0 Then s = s & pad & "Latitude " & CStr(pLat) & vbCrLf
If Len(pCLong) > 0 Then s = s & pad & pCLong & vbCrLf
If pLng > 0 Then s = s & pad & "Longitude " & CStr(pLng) & vbCrLf
If Len(pCLowOutlier) > 0 Then s = s & pad & pCLowOutlier & vbCrLf
If Len(pCPlotName) > 0 Then s = s & pad & pCPlotName & vbCrLf
If Len(pPlotName) > 0 Then s = s & pad & "PlotName " & pPlotName & vbCrLf
WriteSpecsVerbose = s
End Function
Public Function WriteSpecsNonDefault(ByRef defsta As pfqStation) As String
Dim s As String
Const pad As String = " "
'!!! KLUGE WARNING: Station comments get lost in active project,
'due to batch program not preserving comments, so comments are
'extracted from default project
If Len(defsta.Comment) > 0 Then
s = defsta.Comment & vbCrLf & "Station " & pID & vbCrLf
Else
s = "Station " & pID & vbCrLf
End If
If Len(defsta.CAnalysisOption) > 0 Then s = s & pad & defsta.CAnalysisOption & vbCrLf
'If pAnalysisOption <> defsta.AnalysisOption Then s = s & pad & "Analyze " & pAnalysisOption & vbCrLf
'always write analysis option
s = s & pad & "Analyze " & pAnalysisOption & vbCrLf
If Thresholds.Count > 0 AndAlso pAnalysisOption.ToUpper = "EMA" Then 'using perception threshholds
For Each vPT As ThresholdType In Thresholds
s = s & pad & "PCPT_Thresh " & vPT.SYear & " " & vPT.EYear & " " & vPT.LowerLimit & " " & vPT.UpperLimit & " " & vPT.Comment & vbCrLf
Next
End If
'write any interval data or updated peak data
For Each vData As PeakDataType In pPeakData
If Not PeakDataOrigContains(vData) Then 'new or revised peak/interval
If Not vData.Code.Contains("K") Or Me.UrbanRegPeaks Then
'don't save any peaks/intervals that are regulated when Urb/Reg=NO
If vData.Year > 0 AndAlso vData.LowerLimit >= 0 AndAlso vData.UpperLimit > 0 AndAlso
Math.Abs(vData.UpperLimit - vData.LowerLimit) > 0.001 Then 'interval data
s = s & pad & "Interval " & vData.Year & " " & vData.LowerLimit & " " & vData.UpperLimit & " " & vData.Comment & vbCrLf
Else 'just revised peak data
s = s & pad & "Peak " & vData.Year & " " & vData.Value & " " & vData.Code
If vData.Comment.Length > 0 Then s = s & " '" & vData.Comment & vbCrLf Else s = s & vbCrLf
End If
End If
End If
Next
'always output begin/end year since Historic record being eliminated (9/2012)
If Len(defsta.CBegYear) > 0 Then s = s & pad & defsta.CBegYear & vbCrLf
'If pBegYear <> defsta.BegYear Then s = s & pad & "BegYear " & CStr(pBegYear) & vbCrLf
If pBegYear > 0 Then s = s & pad & "BegYear " & CStr(pBegYear) & vbCrLf
If Len(defsta.CEndYear) > 0 Then s = s & pad & defsta.CEndYear & vbCrLf
'If pEndYear <> defsta.EndYear Then s = s & pad & "EndYear " & CStr(pEndYear) & vbCrLf
If pEndYear > 0 Then s = s & pad & "EndYear " & CStr(pEndYear) & vbCrLf
If Len(defsta.CHistoric) > 0 Then s = s & pad & defsta.CHistoric & vbCrLf
'If pHistoricPeriod AndAlso pHistoricPeriod <> defsta.HistoricPeriod Then s = s & pad & "HistPeriod " & CStr(pEndYear - pBegYear + 1) & vbCrLf
If pHistoricPeriod Then
s = s & pad & "HistPeriod " & CStr(pEndYear - pBegYear + 1) & vbCrLf
Else
s = s & pad & "'NO Historic Period in use" & vbCrLf
End If
If Len(defsta.CSkewOpt) > 0 Then s = s & pad & defsta.CSkewOpt & vbCrLf
'If pSkewOpt <> defsta.SkewOpt Then s = s & pad & "SkewOpt " & SOText(pSkewOpt) & vbCrLf
'always write skew option to avoid it getting lost
s = s & pad & "SkewOpt " & SOText(pSkewOpt) & vbCrLf
If Len(defsta.CUseSkewMap) > 0 Then s = s & pad & defsta.CUseSkewMap & vbCrLf
If pUseSkewMap <> defsta.UseSkewMap Then s = s & pad & "UseSkewMap YES" & vbCrLf
If Len(defsta.CGenSkew) > 0 Then s = s & pad & defsta.CGenSkew & vbCrLf
If pGenSkew <> defsta.GenSkew Then s = s & pad & "GenSkew " & pGenSkew & vbCrLf
If Len(defsta.CSESkew) > 0 Then s = s & pad & defsta.CSESkew & vbCrLf
If pSESkew <> defsta.SESkew Then s = s & pad & "SkewSE " & pSESkew & vbCrLf
If Len(defsta.CUrban) > 0 Then s = s & pad & defsta.CUrban & vbCrLf
If pUrbanRegPeaks <> defsta.UrbanRegPeaks Then s = s & pad & "Urb/Reg YES" & vbCrLf
If Len(pCLowOutlier) > 0 Then s = s & pad & pCLowOutlier & vbCrLf
If pLowOutlier <> defsta.LowOutlier Then
s = s & pad & "LoThresh " & CStr(pLowOutlier) & vbCrLf
'when LO specified there's no need for LO Test type
s = s & pad & "LOType FIXED" & vbCrLf
Else 'need a low outlier test type
If Len(pCLOTestType) > 0 Then s = s & pad & pCLOTestType & vbCrLf
If pLOTestType.StartsWith("Multiple") Then
s = s & pad & "LOType MGBT" & vbCrLf
Else 'assume Single GB
s = s & pad & "LOType GBT" & vbCrLf
End If
End If
If Len(defsta.CHighOutlier) > 0 Then s = s & pad & defsta.CHighOutlier & vbCrLf
If pHighOutlier <> defsta.HighOutlier Then s = s & pad & "HiThresh " & CStr(pHighOutlier) & vbCrLf
If Len(defsta.CGageBase) > 0 Then s = s & pad & defsta.CGageBase & vbCrLf
If pGageBaseDischarge <> defsta.GageBaseDischarge Then s = s & pad & "GageBase " & CStr(pGageBaseDischarge) & vbCrLf
If Len(defsta.CLat) > 0 Then s = s & pad & defsta.CLat & vbCrLf
If pLat <> defsta.Lat Then s = s & pad & "Latitude " & CStr(pLat) & vbCrLf
If Len(defsta.CLong) > 0 Then s = s & pad & defsta.CLong & vbCrLf
If pLng <> defsta.Lng Then s = s & pad & "Longitude " & CStr(pLng) & vbCrLf
If Len(defsta.CPlotName) > 0 Then s = s & pad & defsta.CPlotName & vbCrLf
If pPlotName <> defsta.PlotName Then s = s & pad & "PlotName " & pPlotName & vbCrLf
WriteSpecsNonDefault = s
End Function
Private Function PeakDataOrigContains(ByVal aPeak As PeakDataType) As Boolean
For Each lPeak As PeakDataType In pPeakDataOrig
If (lPeak.Year = aPeak.Year AndAlso Math.Abs(Math.Abs(lPeak.Value) - Math.Abs(aPeak.Value)) < 0.1 AndAlso _
lPeak.Code = aPeak.Code AndAlso lPeak.Comment = aPeak.Comment AndAlso _
(lPeak.LowerLimit = aPeak.LowerLimit Or aPeak.LowerLimit = -999) AndAlso _
(lPeak.UpperLimit = aPeak.UpperLimit Or aPeak.UpperLimit = -999)) Then
Return True
End If
Next
Return False
End Function
Public Sub SetDefaultThresholds(Optional ByRef aSYear As Integer = 0, Optional ByRef aEYear As Integer = 0, _
Optional ByRef aIncludeHistoricPeaks As Boolean = True)
'sets initial default thresholds for a station that has just read its peaks
Dim lThresh As ThresholdType
Dim inHistoric As Boolean = False
Dim lSYear As Integer
Dim lEYear As Integer
Thresholds = New Generic.List(Of ThresholdType)
'set default for all peaks
lThresh = New ThresholdType
If aSYear > 0 Then
lSYear = aSYear
Else
lSYear = PeakData(0).Year
End If
If aEYear > 0 Then
lEYear = aEYear
Else
lEYear = PeakData(PeakData.Count - 1).Year
End If
lThresh.SYear = lSYear
lThresh.EYear = lEYear
lThresh.LowerLimit = 0.0
lThresh.UpperLimit = 1.0E+20
lThresh.Comment = "Default"
Thresholds.Add(lThresh)
lThresh = New ThresholdType
For Each lPk As PeakDataType In PeakData
If lPk.Year >= lSYear AndAlso lPk.Year <= lEYear Then
If lPk.Code = "H" Then 'AndAlso aIncludeHistoricPeaks Then
If inHistoric Then 'continuing historic period
lThresh.EYear = lPk.Year
If aIncludeHistoricPeaks AndAlso Math.Abs(lPk.Value) < lThresh.LowerLimit AndAlso lPk.Value <> -8888 Then
lThresh.LowerLimit = Math.Abs(lPk.Value)
End If
Else 'start of historic period
lThresh = New ThresholdType
lThresh.SYear = lPk.Year
lThresh.EYear = lPk.Year
If aIncludeHistoricPeaks Then
lThresh.Comment = "Historic " & Thresholds.Count
If lPk.Value <> -8888 Then
lThresh.LowerLimit = Math.Abs(lPk.Value)
Else
lThresh.LowerLimit = 1.0E+20
End If
Else 'not including historic peaks
lThresh.Comment = "Unused Historic " & Thresholds.Count
lThresh.LowerLimit = 1.0E+20
End If
lThresh.UpperLimit = 1.0E+20
inHistoric = True
End If
Else
If inHistoric Then 'end of historic
lThresh.EYear = lPk.Year - 1
Thresholds.Add(lThresh)
lThresh = New ThresholdType
inHistoric = False
End If
If Not lPk.Code Is Nothing Then
If lPk.Code.Contains("L") Or lPk.Code.Contains("4") Then 'peak less than state, create a threshold
lThresh.SYear = lPk.Year
lThresh.EYear = lPk.Year
lThresh.LowerLimit = Math.Abs(lPk.Value)
lThresh.UpperLimit = 1.0E+20
lThresh.Comment = "Peak < stated value"
Thresholds.Add(lThresh)
lThresh.SYear = 0
'also set interval range
lPk.LowerLimit = 0
lPk.UpperLimit = Math.Abs(lPk.Value)
lPk.Comment = "Peak < stated value"
ElseIf lPk.Code.Contains("G") Or lPk.Code = "X" Or lPk.Code.Contains("8") Then
lThresh.SYear = lPk.Year
lThresh.EYear = lPk.Year
lThresh.LowerLimit = 0
lThresh.UpperLimit = Math.Abs(lPk.Value)
lThresh.Comment = "Peak > stated value"
Thresholds.Add(lThresh)
lThresh.SYear = 0
'peak greater than stated value, set interval range
lPk.LowerLimit = Math.Abs(lPk.Value)
lPk.UpperLimit = 1.0E+20
lPk.Comment = "Peak > stated value"
ElseIf lPk.Code.Contains("O") Then
lThresh.SYear = lPk.Year
lThresh.EYear = lPk.Year
lThresh.LowerLimit = 1.0E+20
lThresh.UpperLimit = 1.0E+20
lThresh.Comment = "Opportunistic Peak"
Thresholds.Add(lThresh)
lThresh.SYear = 0
lPk.Value = -Math.Abs(lPk.Value)
lPk.LowerLimit = lPk.Value ' 0
lPk.UpperLimit = lPk.Value '1.0E+20
lPk.Comment = "Opportunistic Peak"
End If
End If
End If
End If
Next
If lThresh.SYear > 0 Then
'start of historic period found, but didn't reach end so need to add to collection
Thresholds.Add(lThresh)
End If
End Sub
Public Function FindMissingYears() As Generic.List(Of Integer)
Dim lMissingYears As New Generic.List(Of Integer)
Dim lPrevYear As Integer = PeakData(0).Year - 1
Dim inHistoric As Boolean = False
Dim lYearMissing As Boolean
Dim lThresh As ThresholdType
Dim lThresholds As New Generic.List(Of ThresholdType)
For Each lThresh In Thresholds
If lThresh.LowerLimit <> 0 OrElse lThresh.UpperLimit < 1.0E+19 Then
'not just the default threshold, use it to track missing years
lThresholds.Add(lThresh)
End If
Next
For lYr As Integer = BegYear To EndYear
lYearMissing = True
Dim curPeak As PeakDataType = Nothing
For Each lPk As PeakDataType In PeakData
'look for peak value for the current year (lYr)
If lPk.Year = lYr Then 'peak exists for this year
curPeak = lPk
Exit For
End If
Next
If curPeak IsNot Nothing AndAlso curPeak.Code.Contains("K") AndAlso Not Me.UrbanRegPeaks Then
'Urb/Reg peak, but UrbReg set to NO
For i As Integer = 0 To lThresholds.Count - 1
lThresh = lThresholds(i)
'check for Perception Thresholds containing peaks w/code that override them
If lYr >= lThresh.SYear AndAlso lYr <= lThresh.EYear Then
'peak w/code K, with UrbReg OFF, found in non-default threshold - delete the threshold
Dim lDeleteInd As Integer = -1
For j As Integer = 0 To Thresholds.Count - 1
Dim lT As ThresholdType = Thresholds(j)
If lT.SYear = lThresh.SYear AndAlso lT.EYear = lThresh.EYear AndAlso
lT.LowerLimit = lThresh.LowerLimit AndAlso lT.UpperLimit = lThresh.UpperLimit Then
lDeleteInd = j
Exit For
End If
Next
If lDeleteInd >= 0 Then Thresholds.RemoveAt(lDeleteInd)
End If
Next
lYearMissing = False
End If
If lYearMissing Then 'see if there is a systematic peak for this year
If curPeak IsNot Nothing Then
If (Not curPeak.Code.Contains("3") And Not curPeak.Code.Contains("D") And Not curPeak.Code.Contains("O") And
(Not curPeak.Code.Contains("K") Or Me.UrbanRegPeaks)) AndAlso (curPeak.Value <> -8888 OrElse
(curPeak.LowerLimit >= 0 AndAlso curPeak.UpperLimit > 0 AndAlso curPeak.Comment.Length > 0)) Then
lYearMissing = False
End If
End If
End If
If lYearMissing Then
lMissingYears.Add(lYr)
End If
Next
'For Each lPk As PeakDataType In PeakData
' If lPk.Code = "H" Then
' inHistoric = True
' Else
' If inHistoric Then 'leaving historic period
' inHistoric = False
' ElseIf lPk.Year > lPrevYear + 1 Then 'missing years
' For i As Integer = lPrevYear + 1 To lPk.Year - 1
' lMissingYears.Add(i)
' Next
' End If
' lPrevYear = lPk.Year
' End If
'Next
Return lMissingYears
End Function
Public Function CheckThreshSpecs() As Boolean
Dim lThreshDefined As Boolean = True
For Each i As Integer In FindMissingYears()
lThreshDefined = False
For Each lThresh As ThresholdType In Thresholds
If i >= lThresh.SYear AndAlso i <= lThresh.EYear AndAlso _
(lThresh.LowerLimit <> 0 Or lThresh.UpperLimit < 1.0E+20) Then
'valid threshold for this missing year
lThreshDefined = True
Exit For
End If
Next
Next
Return lThreshDefined
End Function
Public Sub New()
MyBase.New()
pAnalysisOption = "EMA" 'init all stations to use EMA analysis
'pSkewOpt = 0 'Weighted skew option (middle of -1, 0, 1)
pSkewOpt = 0 'TODO: Need to determine if this should be assigned differently (middle of 0, 1, 2)
pUrbanRegPeaks = False
pBegYear = 0
pEndYear = 0
pHistoricPeriod = True
pUseSkewMap = False
pGenSkew = -999 '-0.5
pHighOutlier = 0.0#
pLowOutlier = 0.0#
pLOTestType = "Multiple"
pGageBaseDischarge = 0.0#
pSESkew = 0.55
pLat = 0.0#
pLng = 0.0#
SOText(0) = "Station"
SOText(1) = "Weighted"
SOText(2) = "Regional"
Thresholds = New Generic.List(Of ThresholdType)
pPeakData = New Generic.List(Of PeakDataType)
pFirstSystematic = 0
pLastSystematic = 0
pFirstPeak = 0
pLastPeak = 0
pWeightOpt = "HWN"
End Sub
End Class