-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStorm.php
More file actions
1533 lines (1303 loc) · 38.3 KB
/
Storm.php
File metadata and controls
1533 lines (1303 loc) · 38.3 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
<?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 storm code
in format RF6/04 WAREP, and convert it to an array of data parameters. WAREP 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 WAREP.
In addition to the return parameters, the script also displays the interpreted
(easy to understand) information of these parameters.
*/
/***********BEGIN STORM STRUCTURE ******************************************************/
# section 0
# YYGGGGi IIiii
# section 1
# CC: 11, 12, 17, 18, 19, 36, 78
# 1ddfffxfx
# section 2
# CC: 19, 91
# 2ddww
# section 3
# CC: 61, 62, 64, 65, 66, 71, 75
# 3RRRtt
# section 4
# CC: 36, 40, 41, 78
# 7VVwwtt
# section 5
# CC: 30, 40
# 8NChh
# section 6
# CC: 90, 92
# 932RR
# section 7
# CC: 50, 51, 52, 53, 54, 55, 56, 57
# RRsTTk
# section 8
# CC: 68
# sTT
# section 9
# CC: all
# 950Nn
/***********END STORM STRUCTURE ******************************************************/
class Storm
{
/*
* Array of decoded result, by default all parameters is null.
*/
private $result = array
(
'raw' => NULL,
'observed_date' => NULL,
'observed_time' => NULL,
'monthdayr' => NULL,
'hourr' => NULL,
'minuter' => NULL,
'station_id' => NULL,
'storm_code_1' => NULL,
'wind_direction' => NULL,
'wind_speed' => NULL,
'wind_gust' => NULL,
'storm_code_2' => NULL,
'current_weather' => NULL,
'storm_code_3' => NULL,
'precip' => NULL,
'storm_period' => NULL,
'storm_code_4' => NULL,
'visibility' => NULL,
'amount_cloudiness' => NULL,
'clouds_shape' => NULL,
'cld_low_height' => NULL,
'storm_code_6' => NULL,
'hail_size' => NULL,
'storm_code_7' => NULL,
'rime_ice_size' => NULL,
'temperature' => NULL,
'trend_phenomena' => NULL,
'storm_code_8' => NULL,
'storm_code_9' => NULL,
'cloudness_over_mount' => NULL,
'cloud_evolution' => NULL
);
/*
* Methods used for parsing in the order of data
*/
private $method_names = array
(
'station_id',
'date',
'time',
//'station_type',
'storm_code_1',
'wind',
'wind_recent_weather', // additional group for section 1
'storm_code_2',
'wind_recent_weather',
'storm_code_3',
'precip_period',
'storm_code_4',
'vis_weather_period',
'wind', // additional group for section 4
'storm_code_5',
'cloud_report',
'wind', // additional group for section 5
'storm_code_6',
'hail_size',
'storm_code_7',
'rime_temp_trend',
'storm_code_8',
'temperature',
'storm_code_9',
'cloud_mount'
);
/*
* Interpretation station type codes.
*/
/*
private $STATION_TYPE_CODE = array
(
'AAXX' => 'Landstation (FM 12)',
'BBXX' => 'Seastation (FM 13)',
'OOXX' => 'Mobile landstation (FM 14)'
);
*/
/***********BEGIN STORM OPTIONS ******************************************************/
#section 0 - YYGGGGi group
private $WIND_UNIT_CODE = array
(
"0" => "meters per second estimate",
"1" => "meters per second measured",
"3" => "knots estimate",
"4" => "knots measured"
);
#section 1-9 - CC group
/*
* Interpretation phenomena codes.
*/
private $PHENOMENA_CODE = array
(
'10' /*11*/ => 'Сильный ветер',
'11' /*11*/ => 'Сильный ветер',
'12' /*11*/ => 'Сильный ветер',
'17' /*18*/ => 'Шквал',
'18' /*18*/ => 'Шквал',
'19' /*19*/ => 'Смерч',
'29' /*29*/ => 'Гроза',
'30' /*30*/ => 'Низкая облачность',
'35' /*35*/ => 'Пыльная или песчаная буря',
'36' /*35*/ => 'Пыльная или песчаная буря',
'39' /*39*/ => 'Метель',
'40' /*40*/ => 'Горизонтальная видимость',
'41' /*40*/ => 'Горизонтальная видимость',
'48' /*49*/ => 'Изморозь',
'49' /*49*/ => 'Изморозь',
'50' /*67*/ => 'Гололед',
'52' /*69*/ => 'Налипание мокрого снега',
'53' /*67*/ => 'Гололед',
'54' /*49*/ => 'Изморозь',
'55' /*68*/ => 'Сложное отложение',
'56' /*67*/ => 'Гололед',
'57' /*57*/ => 'Гололедица',
'61' /*65*/ => 'Интенсивные осадки',
'62' /*65*/ => 'Интенсивные осадки',
'64' /*65*/ => 'Интенсивные осадки',
'65' /*65*/ => 'Интенсивные осадки',
'67' /*67*/ => 'Гололед',
'68' /*68*/ => 'Сложное отложение',
'69' /*69*/ => 'Налипание мокрого снега',
'71' /*65*/ => 'Интенсивные осадки',
'75' /*65*/ => 'Интенсивные осадки',
'76' /*39*/ => 'Метель',
'78' /*39*/ => 'Метель',
'79' /*79*/ => 'Ледяной дождь',
'82' /*65*/ => 'Интенсивные осадки',
'86' /*65*/ => 'Интенсивные осадки',
'89' /*90*/ => 'Град',
'90' /*90*/ => 'Град',
'91' /*29*/ => 'Гроза',
'92' /*90*/ => 'Град'
);
#section 1 or 2 - 1ddfffxfx or 2ddww group
private $wind_dir_degrees = array
(
"01" => "05-14",
"02" => "15-24",
"03" => "25-34",
"04" => "35-44",
"05" => "45-54",
"06" => "55-64",
"07" => "65-74",
"08" => "75-84",
"09" => "85-94",
"10" => "95-104",
"11" => "105-114",
"12" => "115-124",
"13" => "125-134",
"14" => "135-144",
"15" => "145-154",
"16" => "155-164",
"17" => "165-174",
"18" => "175-184",
"19" => "185-194",
"20" => "195-204",
"21" => "205-214",
"22" => "215-224",
"23" => "225-234",
"24" => "235-244",
"25" => "245-254",
"26" => "255-264",
"27" => "265-274",
"28" => "275-284",
"29" => "285-294",
"30" => "295-304",
"31" => "305-314",
"32" => "315-324",
"33" => "325-334",
"34" => "335-344",
"35" => "345-354",
"36" => "355-04",
"99" => "VRB", //wind_direction_varies
"00" => "calm wind",
"//" => NULL
);
#section 1 or 2 - 1ddfffxfx or 2ddww group
private $wind_dir_compass = array
(
"01" => "NNE",
"02" => "NNE",
"03" => "NNE",
"04" => "NNE",
"05" => "NE",
"06" => "ENE",
"07" => "ENE",
"08" => "ENE",
"09" => "E",
"10" => "ESE",
"11" => "ESE",
"12" => "ESE",
"13" => "ESE",
"14" => "SE",
"15" => "SSE",
"16" => "SSE",
"17" => "SSE",
"18" => "S",
"19" => "SSW",
"20" => "SSW",
"21" => "SSW",
"22" => "SSW",
"23" => "SW",
"24" => "WSW",
"25" => "WSW",
"26" => "WSW",
"27" => "W",
"28" => "WNW",
"29" => "WNW",
"30" => "WNW",
"31" => "WNW",
"32" => "NW",
"33" => "NNW",
"34" => "NNW",
"35" => "NNW",
"36" => "N",
"99" => "VRB", //wind direction varies
"00" => "calm wind",
"//" => NULL
);
#7wwWW
#section 2 or 4 - 2ddww or 7VVwwtt group
private $CURRENT_WEATHER_CODE = array
(
"00" => "Bewölkungsentwicklung nicht beobachtet",
"01" => "Bewölkung abnehmend",
"02" => "Bewölkung unverändert",
"03" => "Bewölkung zunehmend",
"04" => "Sicht durch Rauch oder Asche vermindert",
"05" => "trockener Dunst (relative Feuchte < 80 %)",
"06" => "verbreiteter Schwebstaub, nicht vom Wind herangeführt",
"07" => "Staub oder Sand bzw. Gischt, vom Wind herangeführt",
"08" => "gut entwickelte Staub- oder Sandwirbel",
"09" => "Staub- oder Sandsturm im Gesichtskreis, aber nicht an der Station",
"10" => "feuchter Dunst (relative Feuchte > 80 %)",
"11" => "Schwaden von Bodennebel",
"12" => "durchgehender Bodennebel",
"13" => "Wetterleuchten sichtbar, kein Donner gehört",
"14" => "Niederschlag im Gesichtskreis, nicht den Boden erreichend",
"15" => "Niederschlag in der Ferne (> 5 km), aber nicht an der Station",
"16" => "Niederschlag in der Nähe (< 5 km), aber nicht an der Station",
"17" => "Gewitter (Donner hörbar), aber kein Niederschlag an der Station",
"18" => "Markante Böen im Gesichtskreis, aber kein Niederschlag an der Station",
"19" => "Tromben (trichterförmige Wolkenschläuche) im Gesichtskreis",
"20" => "nach Sprühregen oder Schneegriesel",
"21" => "nach Regen",
"22" => "nach Schneefall",
"23" => "nach Schneeregen oder Eiskörnern",
"24" => "nach gefrierendem Regen",
"25" => "nach Regenschauer",
"26" => "nach Schneeschauer",
"27" => "nach Graupel- oder Hagelschauer",
"28" => "nach Nebel",
"29" => "nach Gewitter",
"30" => "leichter oder mäßiger Sandsturm, an Intensität abnehmend",
"31" => "leichter oder mäßiger Sandsturm, unveränderte Intensität",
"32" => "leichter oder mäßiger Sandsturm, an Intensität zunehmend",
"33" => "schwerer Sandsturm, an Intensität abnehmend",
"34" => "schwerer Sandsturm, unveränderte Intensität",
"35" => "schwerer Sandsturm, an Intensität zunehmend",
"36" => "leichtes oder mäßiges Schneefegen, unter Augenhöhe",
"37" => "starkes Schneefegen, unter Augenhöhe",
"38" => "leichtes oder mäßiges Schneetreiben, über Augenhöhe",
"39" => "starkes Schneetreiben, über Augenhöhe",
"40" => "Nebel in einiger Entfernung",
"41" => "Nebel in Schwaden oder Bänken",
"42" => "Nebel, Himmel erkennbar, dünner werdend",
"43" => "Nebel, Himmel nicht erkennbar, dünner werdend",
"44" => "Nebel, Himmel erkennbar, unverändert",
"45" => "Nebel, Himmel nicht erkennbar, unverändert",
"46" => "Nebel, Himmel erkennbar, dichter werdend",
"47" => "Nebel, Himmel nicht erkennbar, dichter werdend",
"48" => "Nebel mit Reifansatz, Himmel erkennbar",
"49" => "Nebel mit Reifansatz, Himmel nicht erkennbar",
"50" => "unterbrochener leichter Sprühregen",
"51" => "durchgehend leichter Sprühregen",
"52" => "unterbrochener mäßiger Sprühregen",
"53" => "durchgehend mäßiger Sprühregen",
"54" => "unterbrochener starker Sprühregen",
"55" => "durchgehend starker Sprühregen",
"56" => "leichter gefrierender Sprühregen",
"57" => "mäßiger oder starker gefrierender Sprühregen",
"58" => "leichter Sprühregen mit Regen",
"59" => "mäßiger oder starker Sprühregen mit Regen",
"60" => "unterbrochener leichter Regen oder einzelne Regentropfen",
"61" => "durchgehend leichter Regen",
"62" => "unterbrochener mäßiger Regen",
"63" => "durchgehend mäßiger Regen",
"64" => "unterbrochener starker Regen",
"65" => "durchgehend starker Regen",
"66" => "leichter gefrierender Regen",
"67" => "mäßiger oder starker gefrierender Regen",
"68" => "leichter Schneeregen",
"69" => "mäßiger oder starker Schneeregen",
"70" => "unterbrochener leichter Schneefall oder einzelne Schneeflocken",
"71" => "durchgehend leichter Schneefall",
"72" => "unterbrochener mäßiger Schneefall",
"73" => "durchgehend mäßiger Schneefall",
"74" => "unterbrochener starker Schneefall",
"75" => "durchgehend starker Schneefall",
"76" => "Eisnadeln (Polarschnee)",
"77" => "Schneegriesel",
"78" => "Schneekristalle",
"79" => "Eiskörner (gefrorene Regentropfen)",
"80" => "leichter Regenschauer",
"81" => "mäßiger oder starker Regenschauer",
"82" => "äußerst heftiger Regenschauer",
"83" => "leichter Schneeregenschauer",
"84" => "mäßiger oder starker Schneeregenschauer",
"85" => "leichter Schneeschauer",
"86" => "mäßiger oder starker Schneeschauer",
"87" => "leichter Graupelschauer",
"88" => "mäßiger oder starker Graupelschauer",
"89" => "leichter Hagelschauer",
"90" => "mäßiger oder starker Hagelschauer",
"91" => "Gewitter in der letzten Stunde, zurzeit leichter Regen",
"92" => "Gewitter in der letzten Stunde, zurzeit mäßiger oder starker Regen",
"93" => "Gewitter in der letzten Stunde, zurzeit leichter Schneefall/Schneeregen/Graupel/Hagel",
"94" => "Gewitter in der letzten Stunde, zurzeit mäßiger oder starker Schneefall/Schneeregen/Graupel/Hagel",
"95" => "leichtes oder mäßiges Gewitter mit Regen oder Schnee",
"96" => "leichtes oder mäßiges Gewitter mit Graupel oder Hagel",
"97" => "starkes Gewitter mit Regen oder Schnee",
"98" => "starkes Gewitter mit Sandsturm",
"99" => "starkes Gewitter mit Graupel oder Hagel",
"" => NULL
);
#section 5 - 8NChh group
private $cloud_cover_code = array
(
"0" => 0, // "0/8 (wolkenlos)",
"1" => 1, // "1/8 oder weniger (fast wolkenlos)",
"2" => 3, // "2/8 (leicht bewölkt)",
"3" => 4, // "3/8",
"4" => 5, // "4/8 (wolkig)",
"5" => 6, // "5/8",
"6" => 8, // "6/8 (stark bewölkt)",
"7" => 9, // "7/8 oder mehr (fast bedeckt)",
"8" => 10, // "8/8 (bedeckt)",
"9" => NULL, // "Himmel nicht erkennbar",
"/" => NULL // "nicht beobachtet"
);
#section 5 - 8NChh group
private $CLOUD_TYPE_CODE = array
(
"0" => "Cirrus (Ci)",
"1" => "Cirrocumulus (Cc)",
"2" => "Cirrostratus (Cs)",
"3" => "Altocumulus (Ac)",
"4" => "Altostratus (As)",
"5" => "Nimbostratus (Ns)",
"6" => "Stratocumulus (Sc)",
"7" => "Stratus (St)",
"8" => "Cumulus (Cu)",
"9" => "Cumulonimbus (Cb)",
"/" => "Wolkengattung nicht erkennbar"
);
#section 7 - RRsTTk group
/*
* Interpretation of phenomena tendency codes.
*/
private $P_TENDENCY_CODE = array
(
'1' => 'increasing',
'2' => 'conservating or completing'
);
#section 9 - 950Nn group
/*
* Interpretation of cloudness over mountains codes.
*/
private $CLOUDNESS_OVER_MOUNT_CODE = array
(
'0' => 'Все горы открыты (или имеется небольшое количество облаков)',
'1' => 'Горы частично закрыты разрозненными облаками (видно не более половины вершин гор)',
'2' => 'Все склоны гор закрыты облаками, вершины гор и перевалы открыты',
'3' => 'Горы открыты со стороны наблюдателя (или имеется небольшое количество облаков), но за горами – сплошная стена облаков',
'4' => 'Над горами низко нависла облачность, вершины гор и склоны открыты (или имеется небольшое количество облаков)',
'5' => 'Над горами низко нависла облачность, вершины гор частично закрыты облаками или полосами падения осадков',
'6' => 'Все вершины гор закрыты облаками, перевалы открыты, склоны открыты или закрыты ',
'7' => 'Горы в основном закрыты облаками (видны лишь отдельные вершины гор, а склоны закрыты полностью или частично)',
'8' => 'Все вершины гор, перевалы и склоны закрыты облаками',
'9' => 'Горы не видны из-за темноты, тумана, метели, осадков и т.д.'
);
#section 9 - 950Nn group
/*
* Interpretation of cloud evolution codes.
*/
private $CLOUD_EVOLUTION_CODE = array
(
'0' => 'No changes', // 'Без изменений',
'1' => 'Development of cumulus cloudiness', // 'Развитие облачности кучевых форм',
'2' => 'The rise of clouds is slow', // 'Подъём облачности медленный',
'3' => 'Clouds rise fast', // 'Подъём облачности быстрый',
'4' => 'The rise of clouds, the clouds rose and became layered', // 'Подъём облачности, облачность поднялась и стала слоистой',
'5' => 'Decrease of cloudiness is slow', // 'Снижение облачности медленное',
'6' => 'Cloudiness is decreasing fast', // 'Снижение облачности быстрое',
'7' => 'Development of cloud layering', // 'Развитие слоистости облачности',
'8' => 'Development of bedding and decrease in cloudiness', // 'Развитие слоистости и снижение облачности',
'9' => 'Rapid changes' // 'Быстрые изменения'
);
/***********END STORM OPTIONS ******************************************************/
/*
* Interpretation of weather conditions type codes.
*/
/*
/*
* 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 STORM information, you want to parse.
*
* Examples of raw STORM for test:
* 26923 09 05101 30 86703=
* 26923 09 05101 19 21881=
* 26923 09 05101 75 362001=
* 26923 09 05101 36 71535//=
* 26923 09 05101 30 88505=
* 26923 09 05101 92 93208=
* 26923 09 05101 55 320032=
* 26923 09 05101 68 102=
* 26923 09 05101 41 95063=
* 26923 09 05101 40 71535// 1180811=
* 26923 09 05101 30 1110209=
* 26509 09 09451 11 12009 1//15=
*/
public function __construct($raw, $debug = FALSE)
{
$this->debug_enabled = $debug;
if (empty($raw))
{
throw new Exception('The STORM information is not presented.');
}
$raw_lines = explode("\n", $raw, 2);
if (isset($raw_lines[1]))
{
$raw = trim($raw_lines[1]);
// Get observed time from a file data
$observed_time = strtotime(trim($raw_lines[0]));
if ($observed_time != 0)
{
$this->set_observed_date($observed_time);
$this->set_debug('Observation date is set from the STORM in first line of the file content: '.trim($raw_lines[0]));
}
}
else
{
$raw = trim($raw_lines[0]);
}
$this->raw = rtrim(trim(preg_replace('/[\s\t]+/s', ' ', $raw)), '=');
$this->set_debug('Infromation presented as STORM.');
$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 STORM 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 observation time.
* Format is YYYYMMddhhmm where YYYY = year, MM = month, dd = day, hh = hours, mm = minutes in UTC time.
*/
/*
private function get_time($part)
{
//if (!preg_match('@^([0-9]{2})([0-9]{2})([0-9]{2})Z$@', $part, $found))
if (!preg_match('@^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$@', $part, $found))
{
return FALSE;
}
$year = intval($found[1]);
$month = intval($found[2]);
$day = intval($found[3]);
$hour = intval($found[4]);
$minute = intval($found[5]);
if (is_null($this->result['observed_date']))
{
// Get observed time from a Storm part
//$observed_time = mktime($hour, $minute, 0, date('n'), $day, date('Y'));
$observed_time = mktime($hour, $minute, 0, 1*$month, $day, $year);
// Take one month, if the observed day is greater than the current day
if ($day > date('j'))
{
$observed_time = strtotime('-1 month');
}
$this->set_observed_date($observed_time);
$this->set_debug('Observation date is set from the Storm information (presented in format: YYYYMMddhhmm)');
}
$this->set_result_value('observed_day', $day);
$this->set_result_value('observed_time', $hour.':'.$minute.' UTC');
$this->method++;
return TRUE;
}
*/
/**
* Decodes station type code.
* section 0 - MMMM group
* A SYNOP report (FM12) from a fixed land station is identified by the symbolic letters MiMiMjMj = AAXX.
* A SHIP report (FM13) from a sea station is identified by the symbolic letters MiMiMjMj = BBXX.
* A SYNOP MOBIL (FM14) report from a mobile land station is identified by the symbolic letters MiMiMjMj = OOXX.
* Parameters
* ----------
* MMMM:
*/
/*
private function get_station($part)
{
if (!preg_match('@^(AAXX|BBXX|OOXX)$@', $part, $found))
{
return FALSE;
}
$this->set_result_value('station_report', $this->STATION_TYPE_CODE[$found[1]]);
$this->method++;
return TRUE;
}
*/
/**
* Ignore station type if present.
*/
/*
private function get_station_type($part)
{
if ($part != 'AUTO' AND $part != 'COR')
{
return FALSE;
}
$this->method++;
return TRUE;
}
*/
/**
* Decodes .
* section 0 - YYGGGGi group
* 99LLL QLLLL group
* Parameters
* ----------
* YY:
* GG:
* i:
*/
private function get_date($part)
{
if (!preg_match('@^([0-9]{2})$@', $part, $found)) // for Ukraine standart
{
return FALSE;
}
$this->set_result_value('monthdayr', $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 Ukraine standart
{
return FALSE;
}
$wind_unit = $this->WIND_UNIT_CODE[$found[3]];
$this->set_result_value('hourr', $found[1]);
$this->set_result_value('minuter', $found[2]);
$this->set_result_value('wind_unit', $wind_unit);
$this->method++;
return TRUE;
}
/**
* Decodes station id.
* section 0 - IIiii group
* Parameters
* ----------
* II:
* 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 code of storm weather №1.
* section 1 - CC group
* Parameters
* ----------
* CC: code of storm weather (11, 12, 17, 18, 19, 36, 78)
*/
private function get_storm_code_1($part)
{
if (!preg_match('@^(11|12|17|18|19|36|78)$@', $part, $found))
{
return FALSE;
}
$this->set_result_value('storm_code_1', $found[1]);
$this->method++;
return TRUE;
}
/**
* Decodes wind direction, speed and gust information.
* section 1 - 1ddfffxfx group
* Parameters
* ----------
* dd: wind direction in dekadegree (10 minute mean)
* ff: wind speed (10 minute mean)
* fxfx: max gust speed (>=12 mps)
*/
private function get_wind($part)
{
if (!preg_match('@^1([0-9/]{2})([0-9/]{2})([0-9/]{0,2})$@', $part, $found))
{
return FALSE;
}
$wind_dir_code = $found[1];
if ($wind_dir_code == "") {
$wind_dir = NULL; //not observed
}
else {
//$wind_dir = $this->wind_dir_degrees[$wind_dir_code]); // in degrees
$wind_dir = $this->wind_dir_compass[$wind_dir_code]; // in rhumb
}
$wind_speed_code = $found[2];
if ($wind_speed_code == "" || $wind_speed_code == "//") {
$wind_speed = NULL; //not observed
}
else {
$wind_speed = intval($wind_speed_code); // in mps
}
$wind_gust_code = $found[3];
if ($wind_gust_code == "" || $wind_gust_code == "//") {
$wind_gust = NULL; //not observed
}
else {
$wind_gust = intval($wind_gust_code); // in mps
}
$this->set_result_value('wind_direction', $wind_dir);
$this->set_result_value('wind_speed', $wind_speed);
$this->set_result_value('wind_gust', $wind_gust);
$this->method++;
return TRUE;
}
/**
* Decodes code of storm weather №2.
* section 2 - CC group
* Parameters
* ----------
* CC: code of storm weather (19, 91)
*/
private function get_storm_code_2($part)
{
if (!preg_match('@^(19|91)$@', $part, $found))
{
return FALSE;
}
$this->set_result_value('storm_code_2', $found[1]);
$this->method++;