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;
}
?>
	</li>
  	<li>
		<?php 
echo "<a title=\"Jump forward in time 10 minutes\" href=\"{$next_sgram_url}\">&#9658 Later</a>\n";
?>
	</li>
  	<li>
		<?php 
echo "<a title=\"Jump to the most recent spectrogram for {$subnet}\" href=\"{$scriptname}?subnet={$subnet}&mosaicurl={$mosaicurl}\">Latest</a>\n";
?>
	</li>
	<li title="Return to last spectrogram mosaic. This is useful when performing twice-daily seismicity checks.">
		<?php 
$spectrogram_epoch = strtotime("{$year}-{$month}-{$day} {$hour}:{$minute}:00");
list($syear, $smonth, $sday, $shour, $sminute) = epoch2YmdHM($spectrogram_epoch - 3600);
if ($mosaicurl == "") {
    print "<a href=\"mosaicMaker.php?subnet={$subnet}&year={$syear}&month={$smonth}&day={$sday}&hour={$shour}&minute={$sminute}&numhours=2&numMins={$numMins}\">Mosaic</a>\n";
} else {
    print "<a href=\"" . urldecode($mosaicurl) . "\">Mosaic</a>\n";
}
?>
	</li>

        </ul>
</div>
<p/>

<form method="get" id="menu_absolutetime" class="hidden">

        <table class="center" border=0>
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>&nbsp;</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;
}
    $timestart = now() - $starthour * 3600;
    ###### KISKA TIME ################################################
    list($year, $month, $day, $hour, $minute) = epoch2YmdHM($timestart);
    $minute = floorminute($minute);
    $numhours = $starthour - $endhour;
    $_REQUEST['year'] = $year;
    $_REQUEST['month'] = $month;
    $_REQUEST['day'] = $day;
    $_REQUEST['hour'] = $hour;
    $_REQUEST['minute'] = $minute;
    $_REQUEST['numhours'] = $numhours;
} else {
    # Called with year/month/day hour:minute, or with nothing. In the latter case, we default to last 2 hours
    $timestart = now() - 2 * 3600;
    ###### KISKA TIME ################################################
    list($year, $month, $day, $hour, $minute) = epoch2YmdHM($timestart);
    $year = !isset($_REQUEST['year']) ? $year : $_REQUEST['year'];
    $month = !isset($_REQUEST['month']) ? $month : $_REQUEST['month'];
    $day = !isset($_REQUEST['day']) ? $day : $_REQUEST['day'];
    $hour = !isset($_REQUEST['hour']) ? $hour : $_REQUEST['hour'];
    $minute = !isset($_REQUEST['minute']) ? $minute : $_REQUEST['minute'];
    $minute = floorminute($minute);
    $numhours = !isset($_REQUEST['numhours']) ? 2 : $_REQUEST['numhours'];
    $starttime = str2epoch("{$year}/{$month}/{$day} {$hour}:{$minute}:00");
    $starthour = ($timenow - $starttime) / 3600;
    $endhour = ($timenow - $starttime) / 3600 - $numhours;
}
# Degugging
if ($debugging == 1) {
    #var_dump($_REQUEST);
    var_dump($_GET);
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>&nbsp;</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;
}