-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathksl_ozone_viewer.php
311 lines (230 loc) · 10.8 KB
/
ksl_ozone_viewer.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
<!DOCTYPE html>
<html>
<!-- This page is busted-->
<head>
<title>KSL Flights</title>
<link rel="stylesheet" href="./css/brian_style.css" />
<script src="./js/site/siteopen.js"></script>
<script>
// Change date input to yesterdays date when the page loads
function defult_to_current_date(){
var currentTime = new Date();
var month = currentTime.getMonth()+1;
var day = currentTime.getDate()-1;
var year = currentTime.getFullYear();
//Make date-string for HTML date value. Need two digit month and day...
// ex: need instead of 2015-5-5, needs to be 2015-05-05
if (month < 10 && day <10){
var date_string = String(year)+'-0'+String(month)+'-0'+String(day);
}
else if (month < 10 && day > 9){
var date_string = String(year)+'-0'+String(month)+'-'+String(day);
}
else if (month>9 && day<10){
var date_string = String(year)+'-'+String(month)+'-0'+String(day);
}
else{
var date_string = String(year)+'-'+String(month)+'-'+String(day);
}
document.getElementById("date_input").value = date_string;
}
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
return str;
}
function next_day(){
// dec jan feb mar arp may jun jul aug set oct nov dec jan
var days_per_month = ["31", "31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31", "31"];
year = parseInt(document.getElementById('dateinput').value.slice(0,4));
month = parseInt(document.getElementById('dateinput').value.slice(5,7));
day = parseInt(document.getElementById('dateinput').value.slice(8,10));
if (day < parseInt(days_per_month[month])){
day = day+1;
day = pad(day,2);
month = pad(month,2);
}
else{
day = '01';
if (month==12){
month = '01';
year = year +1
year = pad(year,4)
}
else{
month = month + 1;
month = pad(month,2);
}
}
document.getElementById('dateinput').value = year+'-'+month+'-'+day
}
function previous_day(){
// dec jan feb mar arp may jun jul aug set oct nov dec
var days_per_month = ["31", "31", "28", "31", "30", "31", "30", "31", "31", "30", "31", "30", "31"];
year = parseInt(document.getElementById('dateinput').value.slice(0,4));
month = parseInt(document.getElementById('dateinput').value.slice(5,7));
day = parseInt(document.getElementById('dateinput').value.slice(8,10));
if (day == 1){
day = days_per_month[month-1];
if (month==1){
month = '12';
year = year -1
year = pad(year,4)
}
else{
month = month-1;
month = pad(month,2);
}
}
else{
day = day-1;
day = pad(day,2);
month = pad(month,2);
}
document.getElementById('dateinput').value = year+'-'+month+'-'+day;
}
</script>
</head>
<body onload="set_to_input_date()">
<script src="./js/site/sitemenu.js"></script>
<br>
<!--
View All Images for the date in the KSL_daily Directory
Created by Brian Blaylock
Date: May 10, 2016
Displays all the image names and images in a directory. The images
must be available in a public html file. In this code the Date
and Select input determine which day and image type to display.
I don't know why this code was so hard to find, but I finally found
a way to display all images in a directory using PHP. This is
useful for lots of different applications. Here is the source of where I started:
http://www.webdeveloper.com/forum/showthread.php?243055-RESOLVED-Display-all-images-in-a-set-directory
-->
<?php
// define variables and set to empty values
$name = date ( "Y-m-d", time() - 86400 );
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
$name = test_input($_POST["name"]);
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!-- Instructions and Input -->
<br>
<h1 align="center"><i class="fa fa-cloud fa-fw" aria-hidden="true"></i> KSL Flights
<!-- Large modal (the intrusctions help button)-->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Instructions</button>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content" style="padding:25px">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 style="font-size:22px;">KSL Chopper Plots</h4><hr>
<h5>
<img align=right style="width:100px;" src="https://home.chpc.utah.edu/~u0553130/Brian_Blaylock/images/ksl_logo.png">
<b>Instructions:</b> Select the year, day, month, and image type for
which you wish to display all the available images. Then click the "Get Images" button.
If no images appear then try a different date or image type.
</h5>
<hr>
<h5><b>Note:</b> File name date/time is saved -6 H from UTC so the PHP script can find the flights before local midnight.</h5>
<h5><b>Note:</b> In Fire Fox or IE you must type the date in the form yyyy-mm-dd (ex. 2015-05-06).</h5>
</div>
</div>
</div>
</h1>
<div style="background-color:#f5f5f5; width:85%; margin-left:auto; margin-right:auto;">
<div class="jumbotron;">
<form class="navbar-form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<table>
<tr><td>
<p><b>Date:<br></b> <input class="form-control" type="date" id='dateinput' name="name" min="2015-06-01" value="<?php echo $name;?>" style='width:200px'>
</td>
<td>
<button class="btn btn-success" type="submit" name="submit">Get Images</button>
</td>
</tr>
<tr>
<td>
<div class="btn-group" role="group" aria-label="...">
<input class="btn btn-default" type='button' value="-1 Day" onclick="previous_day();">
<input class="btn btn-default" type='button' value="+1 Day" onclick="next_day();">
</div>
</td>
<td>
</td>
</tr>
</table>
<br>
</form>
</div>
<?php
echo "<h4>Requested Date:</h4>";
echo $name;
echo "<br>";
echo "<br>";
?>
<!-- PHP for getting input values, opening directory, and reading the number of files-->
<?php
$dir = "/uufs/chpc.utah.edu/common/home/u0553130/public_html/oper/KSL_daily/";
$dateHTML = $_POST['name']; // grab the date value from HTML input
$datePHP = DateTime::createFromFormat('Y-m-d',$dateHTML); // convert date value to PHP date format
$date = $datePHP->format('Ymd'); // convert date to format usable in retrieving images
// open this directory
$myDirectory = opendir($dir);
// get each entry
while($entryName = readdir($myDirectory)) {
$dirArray[] = $entryName;
}
// sort the array
array_multisort($dirArray);
// close directory
closedir($myDirectory);
// count elements in array
$indexCount = count($dirArray);
echo $datePHP->format('d M Y');
echo '<hr size=10 noshade><br>';
?>
<!-- HTML and PHP for displaying the images from the directory-->
<div align="center">
<?php
// loop through the array of files and print them all in a list
for($index=0; $index < $indexCount; $index++) {
$day = substr($dirArray[$index], 0,8);
if ($day == $date){ // list only files for the date we requested
// Put those times into an array, getting the hour and minute
$dirDay[] = substr($dirArray[$index],0,12);
}
}
//now with our dirDay array (a litst of dates) we will grab the three plots and show them in the same order
echo '<p>'.(count($dirDay)/3).' Flights on '.$datePHP->format('d M Y').'<br>';
foreach (array_unique($dirDay) as $datei){
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_map_ozone.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_map_ozone.png" alt="no ozone map"><br><br>';
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_scatter_ozone-theta.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_scatter_ozone-theta.png" alt="no ozone scatter"><br><br>';
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_timeseries_ozone-elevation.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_timeseries_ozone-elevation.png" alt="no ozone timeseries"><br><br>';
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_map.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_map_pm25.png" alt="no pm25 map"><br><br>';
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_scatter_pm25-theta.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_scatter_pm25-theta.png" alt="no pm25 scatter"><br><br>';
echo '<a target="_blank"href="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_timeseries_pm25-elevation.png">'.$datei.'</a><br>';
echo '<br><img class="style1" width="60%" src="https://home.chpc.utah.edu/~u0553130/oper/KSL_daily/'.$datei.'_KSL5_timeseries_pm25-elevation.png" alt="no pm25 timeseries"><br><br>';
echo '<hr size=10 noshade><br>';
}
?>
</div>
<br>
<script src="/gslso3s/js/site/siteclose.js"></script>
</body>
</html>