function recentSpectrograms($subnet, $WEBPLOTS, $MINFILES, $MAXDAYS) { # Loop from today and over the $MAXDAYS last days, until at least $MINFILES spectrograms found $filesarray = array(); $time = time() + 1000; # check 1000s ahead in case time is slow on kiska $daysago = 0; do { list($year, $month, $day, $hour, $minute) = epoch2YmdHM($time); $minute = floorminute($minute); $filepath = "{$WEBPLOTS}/{$subnet}/{$year}/{$month}/{$day}/2*.png"; $thisarray = glob($filepath); rsort($thisarray); if (count($thisarray) > 0) { $filesarray = array_merge($filesarray, $thisarray); } $time = $time - 86400; $daysago++; } while (count($filesarray) < $MINFILES && $daysago < $MAXDAYS); rsort($filesarray); $nonzerofilesarray = array(); foreach ($filesarray as $myfile) { $size = filesize($myfile); if ($size > 0) { $nonzerofilesarray[] = $myfile; #print "$myfile<br/>\n"; } } $nonzerofilesarray = array_slice($nonzerofilesarray, 0, $MINFILES); return $nonzerofilesarray; }
echo '<input type="hidden" value="' . $mosaicurl . '" name="mosaicurl" />'; } # Call up the appropriate spectrogram list($previousSubnet, $nextSubnet) = findprevnextsubnets($subnet, $subnets); # make sure the date is valid if (!checkdate($month, $day, $year)) { echo "<p>invalid date</p></body></html>"; } else { # Time parameters of previous spectrogram and its path list($pyear, $pmonth, $pday, $phour, $pminute, $psecs) = addSeconds($year, $month, $day, $hour, $minute, 0, -60 * $numMins); $pminute = floorminute($pminute); $previous_sgram = "{$WEBPLOTS}/{$subnet}/{$pyear}/{$pmonth}/{$pday}/" . $pyear . $pmonth . $pday . "T" . $phour . $pminute . "00.png"; $previous_sgram_url = "{$scriptname}?subnet={$subnet}&year={$pyear}&month={$pmonth}&day={$pday}&hour={$phour}&minute={$pminute}&mosaicurl={$mosaicurl}"; # Time parameters of next spectrogram & its path list($nyear, $nmonth, $nday, $nhour, $nminute, $nsecs) = addSeconds($year, $month, $day, $hour, $minute, 0, 60 * $numMins); $nminute = floorminute($nminute); $next_sgram = "{$WEBPLOTS}/{$subnet}/{$nyear}/{$nmonth}/{$nday}/" . $nyear . $nmonth . $nday . "T" . $nhour . $nminute . "00.png"; $next_sgram_url = "{$scriptname}?subnet={$subnet}&year={$nyear}&month={$nmonth}&day={$nday}&hour={$nhour}&minute={$nminute}&mosaicurl={$mosaicurl}"; ######################### THINGS THAT DEPEND ON KISKA TIME, WHICH MAY NOT BE CURRENT TIME ####################### # The current time - albeit from Kiska which might be slow (or fast) #list ($cyear, $cmonth, $cday, $chour, $c1minute) = epoch2YmdHM(now()); #$cminute = floorminute($c1minute); # Age of previous spectrogram #$pAge = timeDiff($pyear, $pmonth, $pday, $phour, $pminute, $psecs, $cyear, $cmonth, $cday, $chour, $cminute, 0); # Age of current spectrogram #$age = $pAge - 600; # Age of next spectrogram #$nAge = $age - 600; ################################################################################################################## # Add sound file links & imageMap? list($imgwidth, $imgheight, $imgtype, $imgattr) = getimagesize($sgram);
function diagnosticTable($subnet, $year, $month, $day, $hour, $minute, $numhours, $plotsPerRow, $WEBPLOTS, $includeHeader) { $timenow = now(); #################### KISKA TIME ######################### # generate the epoch time for the start date/time requested #$starttime = mktime($hour, $minute, 0, $month, $day, $year); # get local/utc conversion issues $starttime = str2epoch("{$year}/{$month}/{$day} {$hour}:{$minute}:00"); # work out the difference in seconds $starthour = ($timenow - $starttime) / 3600; $endhour = ($timenow - $starttime) / 3600 - $numhours; #if ($starthour < 0) { # $starthour = 0; #} #if ($endhour < 0) { # $endhour = 0; #} $numMins = 10; #$starttime = now() - $starthour * 60 * 60 ; #list ($year, $month, $day, $hour, $minute) = epoch2YmdHM($starttime); $stoptime = now() - $endhour * 60 * 60; list($year_stop, $month_stop, $day_stop, $hour_stop, $minute_stop) = epoch2YmdHM($stoptime); list($year_now, $month_now, $day_now, $hour_now, $minute_now) = epoch2YmdHM($timenow); $webpagetitle = sprintf("%s %4d/%02d/%02d %02d:%02d", $subnet, $year, $month, $day, $hour, $minute); if ($includeHeader) { printf("<h1 title=\"The start date/time of the spectrogram mosaic (UTC)\" align=\"center\">%s %4d/%02d/%02d %02d:%02d (%dh %02dm ago)</h1>\n", $subnet, $year, $month, $day, $hour, $minute, $starthour, 60 * $starthour % 60); } else { printf("<h1 title=\"Start: %4d/%02d/%02d %02d:%02d UTC (%dh %02dm ago)\" align=\"center\">%s</h1>\n", $year, $month, $day, $hour, $minute, $starthour, 60 * $starthour % 60, $subnet); } echo "<table class=\"center\" border=1>\n"; $c = 0; $latestAge = "?"; $firstRow = 1; $oldhhmm = ""; for ($time = $starttime + $numMins * 60; $time < $stoptime; $time += $numMins * 60) { # Get the end date and time for the current image list($year, $month, $day, $hour, $minute) = epoch2YmdHM($time); $floorminute = floorminute($minute); $timestamp = sprintf("%04d%02d%02dT%02d%02d", $year, $month, $day, $hour, $floorminute) . "00"; # Create labels for end hour/minute $hhmm = sprintf("%02d:%02d", $hour, $floorminute); # Get the start date and time for the current image list($syear, $smonth, $sday, $shour, $sminute) = epoch2YmdHM($time - $numMins * 60); $floorsminute = floorminute($sminute); # Create labels for start hour/minute $rowstarthhmm = sprintf("%02d:%02d", $shour, $floorsminute); date_default_timezone_set('UTC'); $floorepochUTC = mktime($shour, $sminute, 0, $smonth, $sday, $syear); date_default_timezone_set('US/Alaska'); $localtime = localtime($floorepochUTC, true); # Cannot just use time (see above vairable) here since it is now "floored" $rowstartlocalhhmm = sprintf("%4d/%02d/%02d %02d:%02d", $localtime[tm_year] + 1900, $localtime[tm_mon] + 1, $localtime[tm_mday], $localtime[tm_hour], $localtime[tm_min]); if ($oldhhmm == "") { $oldhhmm = $rowstarthhmm . " - "; } # work out age of this latest data in this image if ($timenow - $time < 24 * 60 * 60) { $now = strtotime("{$year_now}-{$month_now}-{$day_now} {$hour_now}:{$minute_now}:00"); $tim = strtotime("{$year}-{$month}-{$day} {$hour}:{$floorminute}:00"); $ageSecs = $now - $tim; $ageHours = floor($ageSecs / 3600); $ageMins = floor(($ageSecs - 3600 * $ageHours) / 60); $ageStr = sprintf("%dh%02dm", $ageHours, $ageMins); if ($ageSecs < 0) { $ageHours = floor(-$ageSecs / 3600); $ageMins = floor((-$ageSecs - 3600 * $ageHours) / 60); $ageStr = sprintf("-%dh%02dm", $ageHours, $ageMins); } } # (ROW STARTS HERE) if ($c % $plotsPerRow == 0) { $rowFinished = 0; #echo "<br/>\n"; if ($firstRow == 0) { echo "<tr class=\"mosaicblankrow\"><td> </td></tr>\n"; } else { $firstRow = 0; } $summarymessage = summarystations($stachans); echo "<tr><td height=198 title=\"Start time for this row (UTC). Local time is {$rowstartlocalhhmm}\">{$rowstarthhmm}</td><td>{$summarymessage}</td>\n"; } # CELL STARTS HERE $summaryfile = "{$WEBPLOTS}/{$subnet}/{$year}/{$month}/{$day}/{$timestamp}.txt"; if (file_exists($summaryfile)) { list($stachans, $percentages, $bitranges, $modefractions, $numuniquevalues) = loadsummaryfile($summaryfile); $summarymessage = summarymessage($stachans, $percentages, $bitranges, $modefractions, $numuniquevalues); $latestAge = $ageStr; #echo "<td width=151 title=\"$oldhhmm$hhmm\" class=\"tdimg\"><a href=$summaryfile target=\"diagnostic\">$summarymessage</a></td>\n"; echo "<td width=151 title=\"{$oldhhmm}{$hhmm}\" ><a href={$summaryfile} target=\"diagnostic\">{$summarymessage}</a></td>\n"; } else { echo "<td width=151 title=\"{$oldhhmm}{$hhmm}\">NO DATA</td>\n"; } # CELL ENDS HERE if ($c % $plotsPerRow == $plotsPerRow - 1) { # ROW ENDS HERE date_default_timezone_set('UTC'); $floorepochUTC = mktime($hour, $minute, 0, $month, $day, $year); date_default_timezone_set('US/Alaska'); $localtime = localtime($floorepochUTC, true); # Cannot just use time (see above vairable) here since it is now "floored" $rowendlocalhhmm = sprintf("%4d/%02d/%02d %02d:%02d", $localtime[tm_year] + 1900, $localtime[tm_mon] + 1, $localtime[tm_mday], $localtime[tm_hour], $localtime[tm_min]); echo "<td height=198 title=\"End time for this row (UTC). Local time is {$rowendlocalhhmm}\">{$hhmm}</td>\n"; $rowFinished = 1; } $c++; $oldhhmm = "{$hhmm} - "; } if ($rowFinished == 0) { echo "<td></td></tr>\n"; } echo "</table>\n"; if ($includeHeader) { printf("<h1 title=\"The end date/time of the spectrogram mosaic (UTC)\" align=\"center\">%s %4d/%02d/%02d %02d:%02d (%dh %02dm ago)</h1>\n", $subnet, $year, $month, $day, $hour, $minute, $endhour, 60 * $endhour % 60); } $webpagetitle .= sprintf("- %4d/%02d/%02d %02d:%02d", $year, $month, $day, $hour, $minute); return $webpagetitle; }
function mosaicMaker($numMins, $subnet, $year, $month, $day, $hour, $minute, $numhours, $plotsPerRow, $WEBPLOTS, $thumbs, $includeHeader) { #$epochnow = now(); # antelope $epochnow = time(); # generate the epoch time for the start date/time requested $startepoch = mktime($hour, $minute, 0, $month, $day, $year); # get local/utc conversion issues #$startepoch = str2epoch("$year/$month/$day $hour:$minute:00"); # antelope # work out the difference in seconds $starthour = ($epochnow - $startepoch) / 3600; $endhour = ($epochnow - $startepoch) / 3600 - $numhours; #if ($starthour < 0) { # $starthour = 0; #} #if ($endhour < 0) { # $endhour = 0; #} #$startepoch = now() - $starthour * 60 * 60 ; #list ($year, $month, $day, $hour, $minute) = epoch2YmdHM($startepoch); $stopepoch = $epochnow - $endhour * 60 * 60; list($year_stop, $month_stop, $day_stop, $hour_stop, $minute_stop) = epoch2YmdHM($stopepoch); list($year_now, $month_now, $day_now, $hour_now, $minute_now) = epoch2YmdHM($epochnow); $webpagetitle = sprintf("%s %4d/%02d/%02d %02d:%02d", $subnet, $year, $month, $day, $hour, $minute); if ($includeHeader) { printf("<h1 title=\"The start date/time of the spectrogram mosaic (UTC)\" align=\"center\">%s %4d/%02d/%02d %02d:%02d (%dh %02dm ago)</h1>\n", $subnet, $year, $month, $day, $hour, $minute, $starthour, 60 * $starthour % 60); } else { printf("<h1 title=\"Start: %4d/%02d/%02d %02d:%02d UTC (%dh %02dm ago)\" align=\"center\">%s</h1>\n", $year, $month, $day, $hour, $minute, $starthour, 60 * $starthour % 60, $subnet); } #echo "<table class=\"center\" id=\"mosaictable\">\n"; echo "<table class=\"center\" >\n"; $c = 0; $latestAge = "?"; $firstRow = 1; $oldhhmm = ""; for ($time = $startepoch + $numMins * 60; $time < $stopepoch; $time += $numMins * 60) { # Get the end date and time for the current image list($year, $month, $day, $hour, $minute) = epoch2YmdHM($time); $floorminute = floorminute($minute); $timestamp = sprintf("%04d%02d%02dT%02d%02d", $year, $month, $day, $hour, $floorminute) . "00"; # Create labels for end hour/minute $hhmm = sprintf("%02d:%02d", $hour, $floorminute); # Get the start date and time for the current image list($syear, $smonth, $sday, $shour, $sminute) = epoch2YmdHM($time - $numMins * 60); $floorsminute = floorminute($sminute); # Create labels for start hour/minute $rowstarthhmm = sprintf("%02d:%02d", $shour, $floorsminute); #date_default_timezone_set('UTC'); $floorepochUTC = mktime($shour, $sminute, 0, $smonth, $sday, $syear); #date_default_timezone_set('US/Alaska'); $localtime = localtime($floorepochUTC, true); # Cannot just use time (see above vairable) here since it is now "floored" $rowstartlocalhhmm = sprintf("%4d/%02d/%02d %02d:%02d", $localtime['tm_year'] + 1900, $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_hour'], $localtime['tm_min']); if ($oldhhmm == "") { $oldhhmm = $rowstarthhmm . " - "; } # Set the link to the big image file $sgramphplink = "sgram10min.php?year={$year}&month={$month}&day={$day}&hour={$hour}&minute={$floorminute}&subnet={$subnet}&mosaicurl=" . urlencode(curPageURL()); # work out age of this latest data in this image if ($epochnow - $time < 24 * 60 * 60) { $now = strtotime("{$year_now}-{$month_now}-{$day_now} {$hour_now}:{$minute_now}:00"); $tim = strtotime("{$year}-{$month}-{$day} {$hour}:{$floorminute}:00"); $ageSecs = $now - $tim; $ageHours = floor($ageSecs / 3600); $ageMins = floor(($ageSecs - 3600 * $ageHours) / 60); $ageStr = sprintf("%dh%02dm", $ageHours, $ageMins); if ($ageSecs < 0) { $ageHours = floor(-$ageSecs / 3600); $ageMins = floor((-$ageSecs - 3600 * $ageHours) / 60); $ageStr = sprintf("-%dh%02dm", $ageHours, $ageMins); } } # (ROW STARTS HERE) if ($c % $plotsPerRow == 0) { $rowFinished = 0; #echo "<br/>\n"; if ($firstRow == 0) { echo "<tr class=\"mosaicblankrow\"><td> </td></tr>\n"; } else { $firstRow = 0; } #echo "<tr class=\"sideborder\" ><td class=\"time\" title=\"Start time for this row (UTC). Local time is $rowstartlocalhhmm\">$rowstarthhmm</td>\n"; echo "<tr><td class=\"time\" title=\"Start time for this row (UTC). Local time is {$rowstartlocalhhmm}\">{$rowstarthhmm}</td>\n"; } # CELL STARTS HERE $small_sgram = "{$WEBPLOTS}/{$subnet}/{$year}/{$month}/{$day}/{$thumbs}" . "_{$timestamp}.png"; $big_sgram = "{$WEBPLOTS}/{$subnet}/{$year}/{$month}/{$day}/{$timestamp}.png"; if (file_exists($small_sgram)) { $latestAge = $ageStr; echo "<td title=\"{$oldhhmm}{$hhmm}\" class=\"tdimg\"><a href={$sgramphplink}><img src={$small_sgram}></a></td>\n"; } else { if (file_exists($big_sgram)) { if (filesize($big_sgram) == 0) { echo "<td title=\"An attempt has been made to load data for this timeperiod.\" class=\"tdimg\"><a href={$sgramphplink}><img src=\"images/nothumbnail.png\"></a></td>\n"; } else { echo "<td title=\"No thumbnail image produced.\" class=\"tdimg\"><a href={$sgramphplink}><img src=\"{$big_sgram}\" width=150 height=198></a></td>\n"; } } else { echo "<td title=\"No spectrogram image file found\" class=\"tdimg\"><a href={$sgramphplink}><img src=\"images/nothumbnail.png\"></a></td>\n"; } } # CELL ENDS HERE if ($c % $plotsPerRow == $plotsPerRow - 1) { # ROW ENDS HERE #date_default_timezone_set('UTC'); $floorepochUTC = mktime($hour, $minute, 0, $month, $day, $year); #date_default_timezone_set('US/Alaska'); $localtime = localtime($floorepochUTC, true); # Cannot just use time (see above vairable) here since it is now "floored" $rowendlocalhhmm = sprintf("%4d/%02d/%02d %02d:%02d", $localtime['tm_year'] + 1900, $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_hour'], $localtime['tm_min']); echo "<td class=\"time\" title=\"End time for this row (UTC). Local time is {$rowendlocalhhmm}\">{$hhmm}</td>\n"; $rowFinished = 1; } $c++; $oldhhmm = "{$hhmm} - "; } if ($rowFinished == 0) { echo "<td></td></tr>\n"; } echo "</table>\n"; if ($includeHeader) { printf("<h1 title=\"The end date/time of the spectrogram mosaic (UTC)\" align=\"center\">%s %4d/%02d/%02d %02d:%02d (%dh %02dm ago)</h1>\n", $subnet, $year, $month, $day, $hour, $minute, $endhour, 60 * $endhour % 60); } $webpagetitle .= sprintf("- %4d/%02d/%02d %02d:%02d", $year, $month, $day, $hour, $minute); return $webpagetitle; }