forked from ELY3M/GRLevelx-placefiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lastmcd.php
80 lines (53 loc) · 1.64 KB
/
lastmcd.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
<?php
ini_set('error_reporting', E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE); // Show all errors minus STRICT, DEPRECATED and NOTICES
ini_set('display_errors', 0); // disable error display
ini_set('log_errors', 0); // disable error logging
header('Content-Type: text/plain');
//https://forecast.weather.gov/product.php?site=NWS&issuedby=MCD&product=SWO&format=txt&version=1&glossary=0
//$readmcd = file_get_contents($mcdurl);
//echo $readmcd;
$mcdurl = "http://tgftp.nws.noaa.gov/data/raw/ac/acus11.kwns.swo.mcd.txt";
$readmcd = file_get_contents($mcdurl);
//echo $readmcd;
$finalreadmcd = str_replace("\n"," * ", $readmcd);
//$finalreadmcd = str_replace(" ","-", $readmcd);
//echo $finalreadmcd;
//LAT...LON
//$matchlatlon = "/LAT...LON((?:.|\n)*)$/m";
$matchlatlon = "#LAT...LON (.*?)$#s";
preg_match($matchlatlon, $readmcd, $latlonmatch);
echo "
Refresh: 10
Title: Get Last MCD
Threshold: 999
Color: 232 232 175
Line: 3, 0, \"$finalreadmcd\"
";
//process each latlon pairs
//Thank you to Paul Wetter (https://github.com/paulwetter)
$arr = explode(" ", $latlonmatch[0]);
foreach($arr as $v)
{
if(preg_match("/^[0-9]{8}$/",$v)) {
//echo substr($v,0,8) . "\n";
echo LatLon(substr($v,0,8)) . "\n";
}
}
echo "End:";
function left($str, $length) {
return substr($str, 0, $length);
}
function right($str, $length) {
return substr($str, -$length);
}
function LatLon(String $oldnum) {
$Lat = Left($oldnum,4);
$Lon = Right($oldnum,4);
$Lat = Left($Lat,2) . "." . Right($Lat,2);
$Lon = "-" . Left($Lon,2) . "." . Right($Lon,2);
if(preg_match("/^-0/",$Lon)) {
$Lon = str_replace("-0","-10", $Lon);
}
return $Lat . ", " . $Lon ;
}
?>