-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHydro.php
4896 lines (3962 loc) · 122 KB
/
Hydro.php
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
<?php
/*
===========================
HYDRO Parser Class
===========================
Version: 1.0
This library is based on GetWx script by Mark Woodward.
(c) 2024, Spin Opel (https://spinopel.top/)
(c) 2013-2020, Information Networks, Ltd. (http://www.hsdn.org/)
(c) 2001-2006, Mark Woodward (http://woody.cowpi.com/phpscripts/)
This script is a PHP library which allows to parse the hydrological code
in format KN-15, and convert it to an array of data parameters. KN-15 code
parsed using the syntactic analysis and regular expressions. It solves
the problem of parsing the data in the presence of any error in the code KN-15.
In addition to the return parameters, the script also displays the interpreted
(easy to understand) information of these parameters.
*/
/***********BEGIN HYDRO STRUCTURE ******************************************************/
# section 0
# MMMM BBiii YYGGi
# section 1
# 1HHHH 2HHHH 3HHHH 4ttTT (5EEii or 5EEEE) (6CCii or 6CCCC) 7DDDS 8kQQQ 0RRRd
# section 2
# 922YY
# 1HHHH 2HHHH 3HHHH 4ttTT (5EEii or 5EEEE) (6CCii or 6CCCC) 7DDDS 8kQQQ 0RRRd
# section 3
# 933TT
# 1HHHH 2HHHH 3HHHH 4kQQQ 5kQQQ 6kQQQ 7YYGG
# section 4
# 944YY
# 1HHHH 2HHHH 3HHHH 4HHHH 5HHHH 6HHHH 7kVVV 8kVVV
# section 5
# 955YY
# 1kQQQ 2kQQQ 3kQQQ 4kQQQ 5kQQQ 6kQQQ 7kQQQ
# section 6
# 966MM
# 1HHHH 2kQQQ 3kFFF 4hhhh 5YYGG 6ddff 7dHHC 8YYGG
# section 7
# 97701
# 1HHHH 2HHHK (5EEii or 5EEEE) (6CCii or 6CCCC)
# 97702
# 1HHHH 2HHHK (5EEii or 5EEEE) (6CCii or 6CCCC)
# 97703
# (5EEii or 5EEEE)
# 97704
# 8kQQQ
# 97705
# 0RRRd
# 97706
#
# 97707
#
/***********END HYDRO STRUCTURE ******************************************************/
class Hydro
{
/*
* Array of decoded result, by default all parameters is null.
*/
private $result = array
(
'raw' => NULL,
'dayr' => NULL,
'hour_obs' => NULL,
'section_state' => NULL,
'station_id' => NULL,
'water_level' => NULL,
'water_level_diff' => NULL,
'water_level_last_20h' => NULL,
'water_temp' => NULL,
'air_temp' => NULL,
'ice_phenomena' => NULL,
'ice_phenomena_2' => NULL,
'ice_p_intensity' => NULL,
'ice_phenomena_1_2' => NULL, // additional property for section 1
'ice_phenomena_1_2_2' => NULL, // additional property for section 1
'ice_p_intensity_1_2' => NULL, // additional property for section 1
'condition_river' => NULL,
'condition_river_2' => NULL,
'cond_river_intensity' => NULL,
'condition_river_1_2' => NULL, // additional property for section 1
'condition_river_1_2_2' => NULL, // additional property for section 1
'cond_river_intensity_1_2' => NULL, // additional property for section 1
'ice_thickness' => NULL,
'snow_depth_on_ice' => NULL,
'w_consumption' => NULL,
'precip' => NULL,
'precip_duration' => NULL,
### section 2_1 - variables ###
'monthdayr__section_2_1' => NULL,
'water_level__section_2_1' => NULL,
'water_level_diff__section_2_1' => NULL,
'water_level_last_20h__section_2_1' => NULL,
'water_temp__section_2_1' => NULL,
'air_temp__section_2_1' => NULL,
'ice_phenomena__section_2_1' => NULL,
'ice_phenomena_2__section_2_1' => NULL,
'ice_p_intensity__section_2_1' => NULL,
'ice_phenomena__section_2_1_2' => NULL, // additional property for section 2
'ice_phenomena_2__section_2_1_2' => NULL, // additional property for section 2
'ice_p_intensity__section_2_1_2' => NULL, // additional property for section 2
'condition_river__section_2_1' => NULL,
'condition_river_2__section_2_1' => NULL,
'cond_river_intensity__section_2_1' => NULL,
'condition_river__section_2_1_2' => NULL, // additional property for section 2
'condition_river_2__section_2_1_2' => NULL, // additional property for section 2
'cond_river_intensity__section_2_1_2' => NULL, // additional property for section 2
'ice_thickness__section_2_1' => NULL,
'snow_depth_on_ice__section_2_1' => NULL,
'w_consumption__section_2_1' => NULL,
'precip__section_2_1' => NULL,
'precip_duration__section_2_1' => NULL,
### section 2_2 - variables ###
'monthdayr__section_2_2' => NULL,
'water_level__section_2_2' => NULL,
'water_level_diff__section_2_2' => NULL,
'water_level_last_20h__section_2_2' => NULL,
'water_temp__section_2_2' => NULL,
'air_temp__section_2_2' => NULL,
'ice_phenomena__section_2_2' => NULL,
'ice_phenomena_2__section_2_2' => NULL,
'ice_p_intensity__section_2_2' => NULL,
'ice_phenomena__section_2_2_2' => NULL, // additional property for section 2
'ice_phenomena_2__section_2_2_2' => NULL, // additional property for section 2
'ice_p_intensity__section_2_2_2' => NULL, // additional property for section 2
'condition_river__section_2_2' => NULL,
'condition_river_2__section_2_2' => NULL,
'cond_river_intensity__section_2_2' => NULL,
'condition_river__section_2_2_2' => NULL, // additional property for section 2
'condition_river_2__section_2_2_2' => NULL, // additional property for section 2
'cond_river_intensity__section_2_2_2' => NULL, // additional property for section 2
'ice_thickness__section_2_2' => NULL,
'snow_depth_on_ice__section_2_2' => NULL,
'w_consumption__section_2_2' => NULL,
'precip__section_2_2' => NULL,
'precip_duration__section_2_2' => NULL,
### section 3_1 - variables ###
'period_avg_extreme_3_1' => NULL,
'water_level_avg__section_3_1' => NULL,
'water_level_highest__section_3_1' => NULL,
'water_level_lowest__section_3_1' => NULL,
'w_consumption_avg__section_3_1' => NULL,
'w_consumption_highest__section_3_1' => NULL,
'w_consumption_lowest__section_3_1' => NULL,
'monthdayr_water_level_highest__section_3_1' => NULL,
'hourr_water_level_highest__section_3_1' => NULL,
### section 3_2 - variables ###
'period_avg_extreme_3_2' => NULL,
'water_level_avg__section_3_2' => NULL,
'water_level_highest__section_3_2' => NULL,
'water_level_lowest__section_3_2' => NULL,
'w_consumption_avg__section_3_2' => NULL,
'w_consumption_highest__section_3_2' => NULL,
'w_consumption_lowest__section_3_2' => NULL,
'monthdayr_water_level_highest__section_3_2' => NULL,
'hourr_water_level_highest__section_3_2' => NULL,
### section 4_1 - variables ###
'monthdayr__section_4_1' => NULL,
'water_level_upper_pool__section_4_1' => NULL,
'water_level_avg_current__section_4_1' => NULL,
'water_level_avg_post__section_4_1' => NULL,
'water_level_lower_pool_current__section_4_1' => NULL,
'water_level_lower_pool_hilevel_post__section_4_1' => NULL,
'water_level_lower_pool_lolevel_post__section_4_1' => NULL,
'w_volume_avg_current__section_4_1' => NULL,
'w_volume_avg_post__section_4_1' => NULL,
### section 4_2 - variables ###
'monthdayr__section_4_2' => NULL,
'water_level_upper_pool__section_4_2' => NULL,
'water_level_avg_current__section_4_2' => NULL,
'water_level_avg_post__section_4_2' => NULL,
'water_level_lower_pool_current__section_4_2' => NULL,
'water_level_lower_pool_hilevel_post__section_4_2' => NULL,
'water_level_lower_pool_lolevel_post__section_4_2' => NULL,
'w_volume_avg_current__section_4_2' => NULL,
'w_volume_avg_post__section_4_2' => NULL,
### section 5_1 - variables ###
'monthdayr__section_5_1' => NULL,
'w_inflow_total_current__section_5_1' => NULL,
'w_inflow_lateral_current__section_5_1' => NULL,
'w_inflow_area_current__section_5_1' => NULL,
'w_inflow_total_post__section_5_1' => NULL,
'w_inflow_lateral_post__section_5_1' => NULL,
'w_inflow_area_post__section_5_1' => NULL,
'w_inflow_discharge_post__section_5_1' => NULL,
### section 5_2 - variables ###
'monthdayr__section_5_2' => NULL,
'w_inflow_total_current__section_5_2' => NULL,
'w_inflow_lateral_current__section_5_2' => NULL,
'w_inflow_area_current__section_5_2' => NULL,
'w_inflow_total_post__section_5_2' => NULL,
'w_inflow_lateral_post__section_5_2' => NULL,
'w_inflow_area_post__section_5_2' => NULL,
'w_inflow_discharge_post__section_5_2' => NULL,
### section 6_1 - variables ###
'month_flow_6_1' => NULL,
'water_level_avg__section_6_1' => NULL,
'w_consumption_avg__section_6_1' => NULL,
'river_area__section_6_1' => NULL,
'max_depth__section_6_1' => NULL,
'monthdayr_water_flow__section_6_1' => NULL,
'hourr_water_flow__section_6_1' => NULL,
'month_surface_6_1' => NULL,
'wind_direction__section_6_1' => NULL,
'wind_speed__section_6_1' => NULL,
'wind_direction_waves__section_6_1' => NULL,
'wave_height__section_6_1' => NULL,
'state_surface__section_6_1' => NULL,
'monthdayr_water_waves__section_6_1' => NULL,
'hourr_water_waves__section_6_1' => NULL,
### section 6_2 - variables ###
'month_flow_6_2' => NULL,
'water_level_avg__section_6_2' => NULL,
'w_consumption_avg__section_6_2' => NULL,
'river_area__section_6_2' => NULL,
'max_depth__section_6_2' => NULL,
'monthdayr_water_flow__section_6_2' => NULL,
'hourr_water_flow__section_6_2' => NULL,
'month_surface_6_2' => NULL,
'wind_direction__section_6_2' => NULL,
'wind_speed__section_6_2' => NULL,
'wind_direction_waves__section_6_2' => NULL,
'wave_height__section_6_2' => NULL,
'state_surface__section_6_2' => NULL,
'monthdayr_water_waves__section_6_2' => NULL,
'hourr_water_waves__section_6_2' => NULL,
### section 7_1 - variables ###
'about_dangerous__section_7_1' => NULL,
'water_level__section_7_1' => NULL,
'water_level_diff__section_7_1' => NULL,
'ice_phenomena__section_7_1' => NULL,
'ice_phenomena_2__section_7_1' => NULL,
'ice_p_intensity__section_7_1' => NULL,
'condition_river__section_7_1' => NULL,
'condition_river_2__section_7_1' => NULL,
'cond_river_intensity__section_7_1' => NULL,
### section 7_2 - variables ###
'about_dangerous__section_7_2' => NULL,
'water_level__section_7_2' => NULL,
'water_level_diff__section_7_2' => NULL,
'ice_phenomena__section_7_2' => NULL,
'ice_phenomena_2__section_7_2' => NULL,
'ice_p_intensity__section_7_2' => NULL,
'condition_river__section_7_2' => NULL,
'condition_river_2__section_7_2' => NULL,
'cond_river_intensity__section_7_2' => NULL,
### section 7_3 - variables ###
'about_dangerous__section_7_3' => NULL,
'ice_phenomena__section_7_3' => NULL,
'ice_phenomena_2__section_7_3' => NULL,
'ice_p_intensity__section_7_3' => NULL,
### section 7_4 - variables ###
'about_dangerous__section_7_4' => NULL,
'w_consumption__section_7_4' => NULL,
### section 7_5 - variables ###
'about_dangerous__section_7_5' => NULL,
'precip__section_7_5' => NULL,
'precip_duration__section_7_5' => NULL,
### section 7_6 - variables ###
'about_dangerous__section_7_6' => NULL,
### section 7_7 - variables ###
'about_dangerous__section_7_7' => NULL
);
/*
* Methods used for parsing in the order of data
*/
private $method_names = array
(
'station_id',
'time',
'water_level',
'water_level_diff',
'water_level_last_20h',
'temperature',
'ice_phenomena',
'ice_phenomena_1_2', // additional group for section 1
'condition_river',
'condition_river_1_2', // additional group for section 1
'ice_thickness',
'w_consumption',
'precipitation',
### section 2_1 - methods ###
'section_2_1',
'water_level__section_2_1',
'water_level_diff__section_2_1',
'water_level_last_20h__section_2_1',
'temperature__section_2_1',
'ice_phenomena__section_2_1',
'ice_phenomena__section_2_1_2', // additional group for section 2
'condition_river__section_2_1',
'condition_river__section_2_1_2', // additional group for section 2
'ice_thickness__section_2_1',
'w_consumption__section_2_1',
'precipitation__section_2_1',
### section 2_2 - methods ###
'section_2_2',
'water_level__section_2_2',
'water_level_diff__section_2_2',
'water_level_last_20h__section_2_2',
'temperature__section_2_2',
'ice_phenomena__section_2_2',
'ice_phenomena__section_2_2_2', // additional group for section 2
'condition_river__section_2_2',
'condition_river__section_2_2_2', // additional group for section 2
'ice_thickness__section_2_2',
'w_consumption__section_2_2',
'precipitation__section_2_2',
### section 3_1 - methods ###
'section_3_1',
'water_level_avg__section_3_1',
'water_level_highest__section_3_1',
'water_level_lowest__section_3_1',
'w_consumption_avg__section_3_1',
'w_consumption_highest__section_3_1',
'w_consumption_lowest__section_3_1',
'time_water_level_highest__section_3_1',
### section 3_2 - methods ###
'section_3_2',
'water_level_avg__section_3_2',
'water_level_highest__section_3_2',
'water_level_lowest__section_3_2',
'w_consumption_avg__section_3_2',
'w_consumption_highest__section_3_2',
'w_consumption_lowest__section_3_2',
'time_water_level_highest__section_3_2',
### section 4_1 - methods ###
'section_4_1',
'water_level_upper_pool__section_4_1',
'water_level_avg_current__section_4_1',
'water_level_avg_post__section_4_1',
'water_level_lower_pool_current__section_4_1',
'water_level_lower_pool_hilevel_post__section_4_1',
'water_level_lower_pool_lolevel_post__section_4_1',
'w_volume_avg_current__section_4_1',
'w_volume_avg_post__section_4_1',
### section 4_2 - methods ###
'section_4_2',
'water_level_upper_pool__section_4_2',
'water_level_avg_current__section_4_2',
'water_level_avg_post__section_4_2',
'water_level_lower_pool_current__section_4_2',
'water_level_lower_pool_hilevel_post__section_4_2',
'water_level_lower_pool_lolevel_post__section_4_2',
'w_volume_avg_current__section_4_2',
'w_volume_avg_post__section_4_2',
### section 5_1 - methods ###
'section_5_1',
'w_inflow_total_current__section_5_1',
'w_inflow_lateral_current__section_5_1',
'w_inflow_area_current__section_5_1',
'w_inflow_total_post__section_5_1',
'w_inflow_lateral_post__section_5_1',
'w_inflow_area_post__section_5_1',
'w_inflow_discharge_post__section_5_1',
### section 5_2 - methods ###
'section_5_2',
'w_inflow_total_current__section_5_2',
'w_inflow_lateral_current__section_5_2',
'w_inflow_area_current__section_5_2',
'w_inflow_total_post__section_5_2',
'w_inflow_lateral_post__section_5_2',
'w_inflow_area_post__section_5_2',
'w_inflow_discharge_post__section_5_2',
### section 6_1 - methods ###
'section_flow_6_1',
'water_level_avg__section_6_1',
'w_consumption_avg__section_6_1',
'river_area__section_6_1',
'max_depth__section_6_1',
'date_water_flow__section_6_1',
'section_surface_6_1',
'wind__section_6_1',
'wind_waves_surface__section_6_1',
'date_water_waves__section_6_1',
### section 6_2 - methods ###
'section_flow_6_2',
'water_level_avg__section_6_2',
'w_consumption_avg__section_6_2',
'river_area__section_6_2',
'max_depth__section_6_2',
'date_water_flow__section_6_2',
'section_surface_6_2',
'wind__section_6_2',
'wind_waves_surface__section_6_2',
'date_water_waves__section_6_2',
### section 7_1 - methods ###
'section_7_1',
'water_level__section_7_1',
'water_level_diff__section_7_1',
'ice_phenomena__section_7_1',
'condition_river__section_7_1',
### section 7_2 - methods ###
'section_7_2',
'water_level__section_7_2',
'water_level_diff__section_7_2',
'ice_phenomena__section_7_2',
'condition_river__section_7_2',
### section 7_3 - methods ###
'section_7_3',
'ice_phenomena__section_7_3',
### section 7_4 - methods ###
'section_7_4',
'w_consumption__section_7_4',
### section 7_5 - methods ###
'section_7_5',
'precipitation__section_7_5',
### section 7_6 - methods ###
'section_7_6',
### section 7_7 - methods ###
'section_7_7'
);
private $WIND_UNIT_CODE = array
(
"0" => "meters per second estimate",
"1" => "meters per second measured",
"3" => "knots estimate",
"4" => "knots measured"
);
/***********BEGIN HYDRO OPTIONS ******************************************************/
#section 1 or 2 or 7 - 5EEii or 5EEEE group
private $ICE_PHENOMENA_CODE = array
(
'00' => null, //
'11' => 'cало', // fat
'12' => 'cнежура', // snowshoe
'13' => 'забереги', // take away
'14' => 'припай шириной более 100 м (для озер водохранилищ)', // fast ice more than 100 m wide (for lakes and reservoirs)
'15' => 'забереги нависшие', // take away the overhanging
'16' => 'ледоход', // ice drift
'17' => 'ледоход', // ice drift
'18' => 'ледоход поверх лед. покрова', // ice drift over the ice. cover
'19' => 'шугоход', // drywall
'20' => 'внутриводный лед', // intrawater ice
'21' => 'пятры', // five
'22' => 'осевший лед', // settled ice
'23' => 'навалы льда на берегах', // piles of ice on the banks
'24' => 'ледяная перемычка', // ice bridge
'25' => 'ледяная перемычка в/п', // ice cofferdam above the hydropost
'26' => 'ледяная перемычка н/п', // ice cofferdam below the hydropost
'30' => 'затор в/п', // congestion above the hydropost
'31' => 'затор н/п', // congestion below the hydropost
'32' => 'затор льда искуственно разрушается', // ice jam is artificially destroyed
'34' => 'зажор в/п', // jam above the hydropost
'35' => 'зажор н/п', // jam below the hydropost
'36' => 'зажор льда искуственно разрушается', // ice jam is artificially destroyed
'37' => 'вода на льду', // water on ice
'38' => 'вода течет поверх льда', // water flows over ice
'39' => 'закраины', // flanges
'40' => 'лед потемнел', // ice darkened
'41' => 'снежница', // puddle
'42' => 'лед подняло', // ice lifted
'43' => 'подвижка льда', // ice movement
'44' => 'разводья', // divorce
'45' => 'лед тает на месте', // ice melts in place
'46' => 'забереги остаточные', // take away the residual
'47' => 'наслуд', // forgiveness
'48' => 'битый лед', // broken ice
'49' => 'блинчатый лед', // pancake ice
'50' => 'ледяные поля (для озер водохранилищ устьев рек)', // ice fields (for lakes and reservoirs of river mouths)
'51' => 'ледяная каша', // ice porridge
'52' => 'стамуха (для озер водохранилищ устьев рек)', // stamukha (for lakes and reservoirs of river mouths)
'53' => 'лед относит от берега', // ice carries away from the shore
'54' => 'лед прижимает к берегу', // the ice is pressing to the shore
'63' => 'ледостав неполный', // incomplete freeze-up
'64' => 'ледостав с полыньями', // freeze-up with openings
'65' => 'ледостав', // freeze-up
'66' => 'ледостав с торосами', // freeze-up with hummocks
'67' => 'ледяной покров с грядами торосов', // ice cover with ridges of hummocks
'68' => 'шуговая дорожка', // sludge track
'69' => 'подо льдом шуга', // under the ice sludge
'70' => 'трещины в ледяном покрове', // cracks in the ice sheet
'71' => 'неледь', // not ice
'72' => 'лед нависший', // overhanging ice
'73' => 'лед ярусный', // longline ice
'74' => 'лед на дне', // ice at the bottom
'75' => 'река промерзла', // the river is frozen
'76' => 'лед искусственно разрушен', // the ice is artificially destroyed
'77' => 'наледная вода' // ice water
);
#section 1 or 2 or 7 - 6CCii or 6CCCC group
private $CONDITION_RIVER_CODE = array
(
'00' => 'чисто', // purely
'11' => 'лесосплав', // timber rafting
'14' => 'залом леса в/п', // forest hall above the hydropost
'15' => 'залом леса н/п', // forest hall below the hydropost
'22' => 'растительность у берега', // coastal vegetation
'23' => 'растительность по всему сечению потока', // vegetation across the entire stream
'24' => 'растительность по сечению потока пятнами', // spotted vegetation along the stream
'25' => 'растительность стелится по дну', // vegetation spreads along the bottom
'26' => 'растительность у гидроствора выкошена', // the vegetation at the hydropower is mown
'27' => 'растительность легла на дно', // vegetation fell to the bottom
'28' => 'растительность занесена илом', // vegetation covered with silt
'29' => 'растительность погибла', // vegetation died
'35' => 'обвал берега', // landfall
'36' => 'обвал берега в/п', // collapse of the coast above the hydropost
'37' => 'обвал берега н/п', // collapse of the coast below the hydropost
'38' => 'дноуглубительные работы в русле', // in-bed dredging
'39' => 'намывные работы в русле', // in-bed reclamation
'40' => 'проведена расчистка русла', // the channel was cleared
'41' => 'русло реки сужено на гидростворе', // the river bed is narrowed at the hydroelectric station
'42' => 'образовалась коса', // a scythe formed
'43' => 'коса', // scythe
'44' => 'образовался осередок', // a mid-point was formed
'45' => 'осередок', // midsection
'46' => 'образовался остров', // an island was formed
'47' => 'остров', // Island
'48' => 'смещение русла в плане', // channel displacement in plan
'52' => 'снежный завал', // snow block
'53' => 'снежный завал в/п', // snow block above the hydropost
'54' => 'снежный завал н/п', // snow block below the hydropost
'55' => 'прорыв снежного завала', // snow block breakthrough
'56' => 'прохождение селя', // mudflow passage
'57' => 'течение реки изменилось', // the course of the river has changed
'58' => 'сгон воды', // drainage of water
'59' => 'нагон воды', // water surge
'60' => 'река пересохла', // the river is dry
'61' => 'волнение слабое', // weak excitement
'62' => 'волнение умеренное', // moderate excitement
'63' => 'волнение сильное', // strong excitement
'64' => 'стоячая вода', // Still water
'65' => 'стоячая вода подо льдом', // standing water under the ice
'66' => 'прекратилась лодочная переправа', // the boat crossing stopped
'67' => 'прекратилось пешее сообщение по льду', // pedestrian traffic on ice stopped
'68' => 'началось пешее сообщение по льду', // pedestrian traffic on ice began
'69' => 'началось движение транспорта по льду', // traffic began on the ice
'70' => 'прекратилось движение транспорта по льду', // traffic on the ice has stopped
'71' => 'началась лодочная переправа', // boat crossing began
'72' => 'подпор (от засорения русла мостовых переправ ледообразования)', // backwater (from clogging of the channel of bridge crossings of ice formation)
'73' => 'начало навигации', // start navigation
'74' => 'конец навигации', // end of navigation
'77' => 'забор воды в/п', // water intake above the hydropost
'78' => 'забор воды н/п', // water intake below the hydropost
'79' => 'забор воды прекратился в/п', // water intake stopped above the hydropost
'80' => 'забор воды прекратился н/п', // water intake has stopped below the hydropost
'81' => 'сброс воды в/п', // discharge of water above the hydropost
'82' => 'сброс воды н/п', // discharge of water below the hydropost
'83' => 'сброс воды прекратился в/п', // water discharge stopped above the hydropost
'84' => 'сброс воды прекратился н/п', // water discharge stopped below the hydropost
'85' => 'плотина в/п', // dam above the hydropost
'86' => 'плотина н/п', // dam below the hydropost
'87' => 'разрушена платина в/п', // platinum destroyed above the hydropost
'88' => 'разрушена платина н/п', // destroyed platinum below the hydropost
'89' => 'подпор от засорения русла', // backwater from blockage of the channel
'90' => 'подпор от мостовых переправ', // bridge support
'91' => 'попуски воды' // water releases
);
#section 1 or 2 - 7DDDS group
private $SNOW_DEPTH_ICE_CODE = array
(
"0" => "0", //0
"1" => "<5", //<5
"2" => "10", //5-10
"3" => "15", //11-15
"4" => "20", //16-20
"5" => "25", //21-25
"6" => "35", //26-35
"7" => "50", //36-50
"8" => "70", //51-70
"9" => ">70" //>70
);
#section 1 or 2 or 7 - 0RRRd group
private $PRECIP_DURATION_CODE = array
(
"0" => "<1", //<1
"1" => "3", //1-3
"2" => "6", //3-6
"3" => "12", //6-12
"4" => ">12" //>12
);
#section 3 - 933TT group
private $PERIOD_AVG_EXTREME_VALUES = array
(
"01" => "over the past day", //за прошедшие сутки
"04" => "for rain flood", //за дождевой паводок
"05" => "for the flood", //за половодье
"11" => "for the first decade", //за первую декаду
"20" => "for 20 days, from 1 to 20", //за 20 дней, с 1 по 20 число
"22" => "for the second decade", //за вторую декаду
"25" => "for 25 days, from 1st to 25th day", //за 25 дней, с 1 по 25 число
"30" => "per month, regardless of the length of the month in days", //за месяц, независимо от продолжительности месяца в днях
"33" => "over the third decade" //за третью декаду
);
#section 6 - 6ddff group
private $WIND_DIR_COMPASS = array
(
"00" => 'calm wind',
"01" => 'NE',
"02" => 'E',
"03" => 'SE',
"04" => 'S',
"05" => 'SW',
"06" => 'W',
"07" => 'NW',
"08" => 'N',
"09" => 'VRB', //wind_direction_varies
"//" => NULL
);
#section 6 - 7dHHC group
private $WIND_DIR_COMPASS_WAVES = array
(
"0" => 'calm wind',
"1" => 'NE',
"2" => 'E',
"3" => 'SE',
"4" => 'S',
"5" => 'SW',
"6" => 'W',
"7" => 'NW',
"8" => 'N',
"9" => 'VRB', //wind_direction_varies
"//" => NULL
);
#section 6 - 7dHHC group
private $POINTS_STATE_SURFACE = array
(
"0" => 'smooth surface', //зеркально-гладкая поверхность
"1" => 'ripples', //рябь, появляются небольшие гребни волн
"2" => 'small wave crests', //небольшие гребни волн начинают опрокидываться, но пена не белая, а стекловидная
"3" => 'small waves', //хорошо заметные небольшие волны, гребни некоторых из них опрокидываются, образуя местами белую клубящуюся пену - "барашки"
"4" => 'well-defined waves', //волны принимают хорошо выраженную форму, повсюду образуются "барашки"
"5" => 'high ridges', //появляются гребни большой высоты, их пенящиеся вершины занимают большие площади, ветер начинает срывать пену с гребней волн
"6" => 'the surface of the water begins to foam', //гребни очерчивают длинные волны ветровых волн; пена, срываемая с гребней ветром, начинает вытягиваться полосами по склонам волн
"7" => 'the surface of the water is covered with long stripes of foam', //длинные полосы пены, срываемые ветром, покрывают склоны волн, а местами, сливаясь, достигают их подошв
"8" => 'the surface of the water is covered with merging foam stripes', //пена широкими, плотными, сливающимися полосами покрывает склоны волн, отчего вся поверхность становится белой; только местами, видны свободные от пены участки
"9" => 'the water surface is covered with a dense layer of foam' //поверхность воды покрыта плотным слоем пены, воздух наполнен водяной пылью и брызгами, видимость значительно уменьшена
);
#section 7 - 977nn group
private $HYDRO_DANGEROUS_CODE = array
(
"01" => 'high water level',
"02" => 'low water level',
"03" => 'early freeze-up and ice formation',
"04" => 'very high or low water consumption',
"05" => 'heavy rain',
"06" => 'dirty water flow',
"07" => 'avalanche'
);
/***********END HYDRO OPTIONS ******************************************************/
/*
* Debug and parse errors information.
*/
private $errors = NULL;
private $debug = NULL;
private $debug_enabled;
/*
* Other variables.
*/
private $raw;
private $raw_parts = array();
private $method = 0;
private $part = 0;
/**
* This method provides HYDRO information, you want to parse.
*
* Examples of raw HYDRO for test:
* 79121 09081 10244 20021 30243 458// 60000=
* 73115 09081 10542 20122 30547 424// 53703 62201 70454 83926 00512 93305 20560 70708=
* 79093 09081 15154 20142 30158 60000 90043 00043=
*/
public function __construct($raw, $debug = FALSE)
{
$this->debug_enabled = $debug;
if (empty($raw))
{
throw new Exception('The HYDRO information is not presented.');
}
$raw_lines = explode("\n", $raw, 2);
if (isset($raw_lines[1]))
{
$raw = trim($raw_lines[1]);
}
else
{
$raw = trim($raw_lines[0]);
}
$this->raw = rtrim(trim(preg_replace('/[\s\t]+/s', ' ', $raw)), '=');
$this->set_debug('Infromation presented as HYDRO.');
$this->set_result_value('raw', $this->raw);
}
/**
* Gets the value from result array as class property.
*/
public function __get($parameter)
{
if (isset($this->result[$parameter]))
{
return $this->result[$parameter];
}
return NULL;
}
/**
* Parses the HYDRO information and returns result array.
*/
public function parse()
{
$this->raw_parts = explode(' ', $this->raw);
$current_method = 0;
// See parts
while ($this->part < sizeof($this->raw_parts))
{
$this->method = $current_method;
// See methods
while ($this->method < sizeof($this->method_names))
{
$method = 'get_'.$this->method_names[$this->method];
$token = $this->raw_parts[$this->part];
if ($this->$method($token) === TRUE)
{
$this->set_debug('Token "'.$token.'" is parsed by method: '.$method.', '.
($this->method - $current_method).' previous methods skipped.');
$current_method = $this->method;
$this->method++;
break;
}
$this->method++;
}
if ($current_method != $this->method - 1)
{
$this->set_error('Unknown token: '.$this->raw_parts[$this->part]);
$this->set_debug('Token "'.$this->raw_parts[$this->part].'" is NOT PARSED, '.
($this->method - $current_method).' methods attempted.');
}
$this->part++;
}
return $this->result;
}
/**
* Returns array with debug information.
*/
public function debug()
{
return $this->debug;
}
/**
* Returns array with parse errors.
*/
public function errors()
{
return $this->errors;
}
/**
* This method formats observation date and time in the local time zone of server,
* the current local time on server, and time difference since observation. $time_utc is a
* UNIX timestamp for Universal Coordinated Time (Greenwich Mean Time or Zulu Time).
*/
private function set_observed_date($time_utc)
{
$local = $time_utc + date('Z');
$now = time();
$this->set_result_value('observed_date', date('r', $local)); // or "D M j, H:i T"
$time_diff = floor(($now - $local) / 60);
if ($time_diff < 91)
{
$this->set_result_value('observed_age', $time_diff.' min. ago');
}
else
{
$this->set_result_value('observed_age', floor($time_diff / 60).':'.sprintf("%02d", $time_diff % 60).' hr. ago');
}
}
/**
* Sets the new value to parameter in result array.
*/
private function set_result_value($parameter, $value, $only_is_null = FALSE)
{
if ($only_is_null)
{
if (is_null($this->result[$parameter]))
{
$this->result[$parameter] = $value;
$this->set_debug('Set value "'.$value.'" ('.gettype($value).') for null parameter: '.$parameter);
}
}
else
{
$this->result[$parameter] = $value;
$this->set_debug('Set value "'.$value.'" ('.gettype($value).') for parameter: '.$parameter);
}
}
/**
* Sets the data group to parameter in result array.
*/
private function set_result_group($parameter, $group)
{
if (is_null($this->result[$parameter]))
{
$this->result[$parameter] = array();
}
array_push($this->result[$parameter], $group);
$this->set_debug('Add new group value ('.gettype($group).') for parameter: '.$parameter);
}
/**
* Sets the report text to parameter in result array.
*/
private function set_result_report($parameter, $report, $separator = ';')
{
$this->result[$parameter] .= $separator.' '.$report;
if (!is_null($this->result[$parameter]))
{
$this->result[$parameter] = ucfirst(ltrim($this->result[$parameter], ' '.$separator));
}
$this->set_debug('Add group report value "'.$report.'" for parameter: '.$parameter);
}
/**
* Adds the debug text to debug information array.
*/
private function set_debug($text)
{
if ($this->debug_enabled)
{
if (is_null($this->debug))
{
$this->debug = array();
}
array_push($this->debug, $text);
}
}
/**
* Adds the error text to parse errors array.
*/
private function set_error($text)
{
if (is_null($this->errors))
{
$this->errors = array();
}
array_push($this->errors, $text);
}
// --------------------------------------------------------------------
// Methods for parsing raw parts
// --------------------------------------------------------------------
/**
* Decodes station id.
* section 0 - BBiii group
* Parameters
* ----------
* BB:
* iii:
*/
private function get_station_id($part)
{
if (!preg_match('@^([0-9]{5})$@', $part, $found))
{
return FALSE;
}
$this->set_result_value('station_id', $found[1]);
$this->method++;
return TRUE;
}
/**
* Decodes .
* section 0 - YYGGGGi group
* Parameters
* ----------
* YY:
* GGGG:
* i:
*/
private function get_time($part)
{
//if (!preg_match('@^([0-9]{2})([0-9]{4})([0-9]{1})$@', $part, $found)) // for WMO standart
if (!preg_match('@^([0-9]{2})([0-9]{2})([0-9]{1})$@', $part, $found)) // for Belarus standart
{
return FALSE;
}
$this->set_result_value('dayr', $found[1]);
$this->set_result_value('hour_obs', $found[2]);
$this->set_result_value('section_state', $found[3]);
$this->method++;
return TRUE;
}
/**
* Decode water level in cm.
* section 1 - 1HHHH 2HHHH 3HHHH group
* Parameters
* ----------
* code : str
* Water level in cm
* Returns
* -------
* int
* Water level in cm
*/
private function set_HHHH($code) {
if ($code == "") {
return NULL;
}
else {
$value = intval($code);
// if code "0218", water level equal 218 cm
// if code "5223", water level equal -223 cm
if (strlen($code) == 4 && substr($code, 0, 1) == 5) {
$value = ($value - 5000) * -1;
}
return $value;
}
}