-
Notifications
You must be signed in to change notification settings - Fork 1
/
GR3-radar-inc.php
370 lines (339 loc) · 12.6 KB
/
GR3-radar-inc.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
<?php
/*
// GRLevel3 Radar image display script
// Version 1.00 - 07-Mar-2008 - Initial release
// Version 1.01 - 15-Mar-2008 - added logic to find web document root on IIS servers
// Version 1.02 - 21-Jul-2008 - added script to allow XHTML validation for output
// Version 1.03 - 23-Dec-2008 - added support for Digital Total Rainfall display
// Version 1.04 - 04-Jun-2012 - added support for Dual Polarization NEXRAD products
//
// the script does NOT generate a complete HTML page and is intended for use
// ONLY by being included in an existing webpage on your site by:
// <?php include("GR3-radar-inc.php"); ?>
// */
// settings -----------------------------
###########################################################################
# GRLevel3 Radar image settings
$GR3radar = 'kmux'; // set to lower-case full name of NEXRAD radar site (ICAO)
$GR3DIR = '/GR3'; // set to directory for GRLevel3 images (or '/' for root directory
$GR3type = 'cr'; // default radar image type 'cr','br','cr248','br1' etc.
$GR3img = 'jpg'; // GR3 image type 'jpg' or 'png'
$GR3cnt = 10; // number of images in series 10=(_0 ... _9 in name of file)
$GR3width = 512; // width of GR3 images
$GR3height = 512; // height of GR3 images
$GR3maxAge = 1200; // image_0 has to be less than 20 minutes old for consideration
$GR3notAvailMsg = 'GRLevel3 radar images are not available at this time.';
$GR3notCurrentMsg = 'GRLevel3 radar image is not current - more than %s seconds old.';
###########################################################################
// end of settings
//------------------------------------------------
if (isset($_REQUEST['sce']) && strtolower($_REQUEST['sce']) == 'view' ) {
//--self downloader --
$filenameReal = __FILE__;
$download_size = filesize($filenameReal);
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header("Content-type: text/plain");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
header('Connection: close');
readfile($filenameReal);
exit;
}
?>
<!-- GR3-radar-inc.php - Version 1.04 - 04-Jun-2012 - http://saratoga-weather.org/scripts.php -->
<?php
//------------------------------------------------
// overrides from Settings.php if available
global $SITE;
if (isset($SITE['GR3radar'])) {$GR3radar = $SITE['GR3radar'];}
if (isset($SITE['GR3DIR'])) {$GR3DIR = $SITE['GR3DIR'];}
if (isset($SITE['GR3type'])) {$GR3type = $SITE['GR3type'];}
if (isset($SITE['GR3img'])) {$GR3img = $SITE['GR3img'];}
if (isset($SITE['GR3cnt'])) {$GR3cnt = $SITE['GR3cnt'];}
if (isset($SITE['GR3width'])) {$GR3width = $SITE['GR3width'];}
if (isset($SITE['GR3width'])) {$GR3height = $SITE['GR3height'];}
if (isset($SITE['GR3maxAge'])) {$GR3maxAge = $SITE['GR3maxAge'];}
if (isset($SITE['GR3notAvailMsg'])) {$GR3notAvailMsg = $SITE['GR3notAvailMsg'];}
if (isset($SITE['$GR3notCurrentMsg'])) {$$GR3notCurrentMsg = $SITE['$GR3notCurrentMsg'];}
// end of overrides from Settings.php if available
$UTCtime = time(); // not random, but needed for URL fetches.
$doDebug = false;
if (isset($_REQUEST['debug'])) {$doDebug = strtolower($_REQUEST['debug']) == 'y'; }
print "<!-- part of the Carterlake/WD/PHP/AJAX template set -->\n";
print "<!-- Thanks to Tim Hanko at http://www.thanko.info/ for the concept and initial radar type selection code -->\n";
?>
<script type="text/javascript">
/*
Interactive Image slideshow with text description
By Christian Carlessi Salvadó ([email protected]). Keep this notice intact.
Visit http://www.dynamicdrive.com for script
Modified by Ken True - Saratoga-Weather.org
*/
var g_fPlayMode = 0;
var g_iimg = -1;
var g_imax = 0;
var g_ImageTable = new Array();
function ChangeImage(fFwd)
{
if (fFwd)
{
if (++g_iimg==g_imax)
g_iimg=0;
}
else
{
if (g_iimg==0)
g_iimg=g_imax;
g_iimg--;
}
Update();
}
function getobject(obj){
if (document.getElementById)
return document.getElementById(obj)
else if (document.all)
return document.all[obj]
}
function Update(){
getobject("_Ath_Slide").src = g_ImageTable[g_iimg][0];
//getobject("_Ath_FileName").innerHTML = g_ImageTable[g_iimg][1];
getobject("_Ath_Img_X").innerHTML = g_iimg + 1;
getobject("_Ath_Img_N").innerHTML = g_imax;
}
function Oldest() {
g_iimg=0;
Update();
}
function Newest() {
g_iimg=g_imax;
g_iimg--;
Update();
}
function Play()
{
g_fPlayMode = !g_fPlayMode;
if (g_fPlayMode)
{
getobject("btnPrev").disabled = getobject("btnNext").disabled = true;
getobject("btnOldest").disabled = getobject("btnNewest").disabled = true;
Next();
}
else
{
getobject("btnPrev").disabled = getobject("btnNext").disabled = false;
getobject("btnOldest").disabled = getobject("btnNewest").disabled = false;
}
}
function OnImgLoad()
{
if (g_fPlayMode)
window.setTimeout("Tick()", g_dwTimeOutSec*1000);
}
function Tick()
{
if (g_fPlayMode)
Next();
}
function Prev()
{
ChangeImage(false);
}
function Next()
{
ChangeImage(true);
}
// configuration section
<?php
// list of all GRLevel3 radar types that may be produced
$RadarTypes = array(
'br1' => 'Base Reflectivity 0.5°',
'br2' => 'Base Reflectivity 0.9°',
'br3' => 'Base Reflectivity 1.5°',
'br4' => 'Base Reflectivity 1.8°',
'br5' => 'Base Reflectivity 2.5°',
'br6' => 'Base Reflectivity 3.5°',
'br248' => 'Base Reflectivity 248nm',
'bv1' => 'Base Velocity 0.5°',
'bv2' => 'Base Velocity 0.9°',
'bv3' => 'Base Velocity 1.5°',
'bv4' => 'Base Velocity 1.8°',
'bv5' => 'Base Velocity 2.5°',
'bv6' => 'Base Velocity 3.5°',
'bv32' => 'Base Velocity 32nm',
'srv1' => 'Storm Relative Velocity 0.5°',
'srv2' => 'Storm Relative Velocity 1.5°',
'srv3' => 'Storm Relative Velocity 2.5°',
'srv4' => 'Storm Relative Velocity 3.5°',
'sw' => 'Spectrum Width',
'sw32' => 'Spectrum Width 32nm',
'cr' => 'Composite Reflectivity',
'cr248' => 'Composite Reflectivity 248nm',
'et' => 'Echo Tops',
'vil' => 'Vertically Integrated Liquid',
'ohr' => 'One Hour Rain',
'thr' => 'Three Hour Rain',
'str' => 'Storm Rain',
'dsp' => 'Digital Total Rainfall',
'zdr1' => 'DP Digital Differential Reflectivity 0.5°',
'zdr2' => 'DP Digital Differential Reflectivity 0.9°',
'zdr3' => 'DP Digital Differential Reflectivity 1.5°',
'zdr4' => 'DP Digital Differential Reflectivity 1.8°',
'zdr5' => 'DP Digital Differential Reflectivity 2.5°',
'zdr6' => 'DP Digital Differential Reflectivity 3.5°',
'cc1' => 'DP Correlation Coefficient 0.5°',
'cc2' => 'DP Correlation Coefficient 0.9°',
'cc3' => 'DP Correlation Coefficient 1.5°',
'cc4' => 'DP Correlation Coefficient 1.8°',
'cc5' => 'DP Correlation Coefficient 2.5°',
'cc6' => 'DP Correlation Coefficient 3.5°',
'kdp1' => 'Specific Differential Phase 0.5°',
'kdp2' => 'Specific Differential Phase 0.9°',
'kdp3' => 'Specific Differential Phase 1.5°',
'kdp4' => 'Specific Differential Phase 1.8°',
'kdp5' => 'Specific Differential Phase 2.5°',
'kdp6' => 'Specific Differential Phase 3.5°',
'hca1' => 'Hydrometeor Class 0.5°',
'hca2' => 'Hydrometeor Class 0.9°',
'hca3' => 'Hydrometeor Class 1.5°',
'hca4' => 'Hydrometeor Class 1.8°',
'hca5' => 'Hydrometeor Class 2.5°',
'hca6' => 'Hydrometeor Class 3.5°',
'hhc' => 'DP Digital Hybrid Hydrometeor Class',
'dod' => 'DP Digital One Hour Difference',
'dsd' => 'DP Digital Storm Total Rainfall',
'tvs' => 'Tornado Vortex Signature',
'ssi' => 'Storm Structure Information',
);
$AvailTypes = array();
$timeLimit = time() - 1200; // time for 'freshness' is 20*60 = 20 minutes.
// Create the list from current files available.
// Obtain Basic Environment
// in APACHE servers it is always defined
if (! isset($_SERVER['DOCUMENT_ROOT'] ) ) {
$path_trans = str_replace( '\\\\', '/', $_SERVER['PATH_TRANSLATED']);
print "// path_trans = '$path_trans' \n";
print "// self = '" . $_SERVER['PHP_SELF'] . "' \n";
$WEBROOT = substr($path_trans, 0, strlen($path_trans)-strlen($_SERVER['PHP_SELF']) );
}
else {
$WEBROOT = $_SERVER['DOCUMENT_ROOT'];
}
$path = realpath($WEBROOT . $GR3DIR . '/' ) . '/';
print "// webroot = '$WEBROOT' \n";
print "// gr3dir = '$GR3DIR'\n";
print "// path = '$path' \n";
$RadarMsg = array();
foreach ($RadarTypes as $type => $legend) {
$tname = $path . strtolower($GR3radar) . '_' .
$type . '_';
$ttype = '.' . $GR3img;
$tfile = $tname . '0' . $ttype;
$shortname = strtolower($GR3radar) . '_' .
$type . '_0.' . $GR3img;
if(file_exists($tfile)) {
$secsOld = filemtime($tfile);
if($secsOld >= time() - $GR3maxAge) {
$AvailTypes[$type] = $legend;
$RadarMsg[$type] = ' ';
} else {
$tage = time() - $secsOld;
print "// -- $shortname too old. Last updated $tage seconds ago\n";
$RadarMsg[$type] = sprintf($GR3notCurrentMsg,$GR3maxAge);
}
} else {
print "// -- $shortname not found \n";
$RadarMsg[$type] = "$GR3notAvailMsg";
}
}
if (!isset($AvailTypes[$GR3type])) { // oops.. our default one is not available
$key = array_shift(array_keys($AvailTypes)); // get the first one available
if ($key) { $GR3type = $key; }
}
// $AvailTypes[$GR3type] = $RadarTypes[$GR3type]; // ensure at least the default is shown
print "/* -- avail \n " . print_r($AvailTypes,true) . " */\n";
if (isset($_REQUEST['map']))
{
$selectedType = preg_replace('|[^\w]|is','',strtolower($_REQUEST['map'])); // no bad juju in input string
if (!isset($AvailTypes[$selectedType]) ) {
print "// type '$selectedType' not valid .. using '" . $GR3type . "' instead.\n";
$selectedType = $GR3type;
}
}
else
{
$selectedType = $GR3type;
}
$tname = $GR3DIR . '/' . strtolower($GR3radar) . '_' .
$selectedType . '_';
$ttype = '.' . $GR3img;
$noCache = '?t=' . time();
for ($i=$GR3cnt-1;$i >= 0;$i--) {
print 'g_ImageTable[g_imax++] = new Array ("' . $tname . $i . $ttype . $noCache . '", "");' . "\n";
}
?>
//end generated function
var g_dwTimeOutSec=1;
////End configuration/////////////////////////////
//if (document.getElementById||document.all)
//window.onload=Play
</script>
<?php
if($doDebug) {
foreach ($RadarMsg as $type => $msg) {
print "<!-- type='$type' radar msg='$msg' -->\n";
}
}
$haveOneFile = isset($AvailTypes[$selectedType]);
if ($haveOneFile) { // got at least one.. do the page normally
?>
<form action="" method="get">
<fieldset style="width: 620px">
<legend>Radar Type</legend>
<select name="map" onchange="this.form.submit();">
<?php
foreach ($AvailTypes as $type => $legend) {
if ($type == $selectedType) {
print " <option selected=\"selected\" value=\"$type\">$legend - ($type)</option>\n";
} else {
print " <option value=\"$type\">$legend - ($type)</option>\n";
}
}
?>
</select>
<noscript><input type="submit" value="Display" name="display" /> [Enable JavaScript for animated display]</noscript>
<script type="text/javascript">
// <![CDATA[
document.write(' <input type="button" id="btnOldest" value="|<<-" onclick="Oldest();" />' +
' <input type="button" id="btnPrev" value="<-" onclick="Prev();" />' +
' <input type="button" id="bntPlay" value="Play - Stop" onclick="Play()" />' +
' <input type="button" id="btnNext" value="->" onclick="Next();" />' +
' <input type="button" id="btnNewest" value="->>|" onclick="Newest();" />'
);
// ]]>
</script>
</fieldset>
</form>
<?php
} // end of got one file at least
if ($haveOneFile) { // hope for the best
echo '<p>' . $RadarMsg[$selectedType] . ' [<b><span id="_Ath_Img_X">' . $GR3cnt .
'</span>/<span id="_Ath_Img_N">' . $GR3cnt . '</span></b>] ' .
"<br/>\n"; ?>
<img src="<?php echo $tname . '0' . $ttype; ?>"
alt="GRLevel3 radar from NWS station <?php echo strtoupper($GR3radar); ?>"
title="GRLevel3 radar from NWS station <?php echo strtoupper($GR3radar); ?>"
width="<?php echo $GR3width; ?>" height="<?php echo $GR3height; ?>"
id="_Ath_Slide"/> </p>
<script type="text/javascript">
if(document.getElementById) {
var img = document.getElementById('_Ath_Slide');
if (img) img.onload = OnImgLoad;
}
</script>
<p>The above image was produced by <a href="http://www.grlevelx.com/grlevel3/">GRLevel3</a> software using NEXRAD Radar data from <a href="http://radar.weather.gov/radar.php?rid=<?php echo substr($GR3radar,1,3); ?>&product=N0R&overlay=11101111&loop=no">station <?php echo strtoupper($GR3radar); ?></a>.</p>
<?php } else { // not one file found ?>
<p><?php echo $GR3notAvailMsg; ?></p>
<?php } // end not one file found ?>
<!-- end of GR3-radar-inc.php -->