"Ny Alesund",
"LYR" => "Longyearbyen",
"ISR" => "Isfjord Radio",
"HOR" => "Hornsund",
"SDY" => "Sondrestrom",
"POK" => "Poker Flat",
"IQA" => "Iqaluit",
"SNK" => "Sanikiluaq",
"NAQ" => "Narsarsuaq",
"UNH" => "University New Hampshire",
"KSS" => "King Sejong",
"JBS" => "Jang Bogo",
"VNA" => "Von Neumeyer",
"HAL" => "Halley Station",
"RTH" => "Rothera Station",
"SPA" => "South Pole",
"MCM" => "McMurdo Station",
"PG2" => "PG2",
"PG3" => "PG3",
"PG4" => "PG4",
"PG5" => "PG5",
"ZK1" => "ZK1",
"ZK2" => "ZK2",
"ZK3" => "ZK3"
);
// station initials used in filenames
$stationinitials = array(
"NAL" => "N",
"LYR" => "L",
"ISR" => "R",
"HOR" => "H",
"NAQ" => "Q",
"UNH" => "D",
"SNK" => "Y",
"IQA" => "I",
"MCM" => "M",
"SPA" => "A",
"VNA" => "U",
"KSS" => "K",
"JBS" => "J",
"HAL" => "B",
"RTH" => "R",
"ZK1" => "6",
"ZK2" => "7",
"ZK3" => "8",
"SDY" => "S",
"PG2" => "2",
"PG3" => "3",
"PG4" => "4",
"PG5" => "5"
);
// color thresholds in days
$warn_yellow = 30;
$warn_orange = 90;
$warn_red = 365;
// anything beyond $warn_red shown in red
// search for most recent file starting from $start_timestamp and going back
// $max_days limits how far back to look from that starting point
function find_latest_file($dirpath, $initial, $start_timestamp, $max_days) {
$start_year = (int)date("Y", $start_timestamp);
$start_month = (int)date("n", $start_timestamp);
$start_day = (int)date("j", $start_timestamp);
$check_year = $start_year;
$check_month = $start_month;
$days_checked = 0;
while ($days_checked < $max_days) {
$days_in_month = cal_days_in_month(CAL_GREGORIAN, $check_month, $check_year);
// start from current day in first month, otherwise from end of month
$start_day_in_month = ($check_year == $start_year && $check_month == $start_month)
? $start_day
: $days_in_month;
for ($day = $start_day_in_month; $day >= 1; $day--) {
$datestr = sprintf("%04d%02d%02d", $check_year, $check_month, $day);
foreach (array("pdf", "jpg", "png") as $ext) {
$filename = $datestr . "_000000_240000_" . $initial . "." . $ext;
if (file_exists($dirpath . $filename)) {
return mktime(0, 0, 0, $check_month, $day, $check_year);
}
}
$days_checked++;
if ($days_checked >= $max_days) break;
}
// step back one month
$check_month--;
if ($check_month < 1) {
$check_month = 12;
$check_year--;
}
// stop if we've gone back before 2000
if ($check_year < 2000) break;
}
return null;
}
// load existing cache if available
$cache = array();
if (file_exists($cache_file)) {
$json = file_get_contents($cache_file);
if ($json !== false) {
$cache = json_decode($json, true);
if (!is_array($cache)) $cache = array();
}
}
$now = time();
$cache_updated = false;
foreach ($stations as $code) {
$initial = isset($stationinitials[$code]) ? $stationinitials[$code] : "";
$dirpath = $datapath_plot . $code . "/";
$cached_timestamp = isset($cache[$code]['latest']) ? $cache[$code]['latest'] : null;
$cached_age_days = ($cached_timestamp !== null) ? floor(($now - $cached_timestamp) / 86400) : null;
if ($cached_timestamp === null) {
// no cache entry at all - do full historical scan back to 2000
$latest = find_latest_file($dirpath, $initial, $now, 9999);
$cache[$code]['latest'] = $latest;
$cache[$code]['full_scan'] = true;
$cache_updated = true;
} else if ($cached_age_days < 90) {
// recent station - re-check last 90 days on every page load
// to catch new data arriving
$recent = find_latest_file($dirpath, $initial, $now, 90);
if ($recent !== null && $recent > $cached_timestamp) {
// found newer data than what's cached
$cache[$code]['latest'] = $recent;
$cache_updated = true;
}
} else {
// older station - only re-check the last year to see if it's come back online
// if nothing found in last year, keep the cached historical date as-is
$recent = find_latest_file($dirpath, $initial, $now, 365);
if ($recent !== null && $recent > $cached_timestamp) {
// station has new data, update cache
$cache[$code]['latest'] = $recent;
$cache_updated = true;
}
}
}
// write updated cache back to disk if anything changed
if ($cache_updated) {
file_put_contents($cache_file, json_encode($cache, JSON_PRETTY_PRINT));
}
?>
ULF Magnetometer System - Data Status
|
ULF Magnetometer System
Magnetosphere and Ionosphere Research Laboratory at UNH
|
This page shows the date of the most recently received data file for each station.
■ Green = data within days
■ Yellow = – days
■ Orange = – days
■ Red = over days
Page generated:
(cache updated)"); ?>
");
echo("| " . $name . " | ");
echo("(" . $code . ") | ");
if ($latest === null) {
// no data found at all back to 2000
echo(": No data found | ");
} else {
$days_ago = floor(($now - $latest) / 86400);
$date_str = date("Y-m-d", $latest);
if ($days_ago == 0) {
$age_str = "today";
} else if ($days_ago == 1) {
$age_str = "1 day ago";
} else if ($days_ago < 365) {
$age_str = $days_ago . " days ago";
} else {
// express in years and months for older data
$years = floor($days_ago / 365);
$months = floor(($days_ago % 365) / 30);
$age_str = $years . " year" . ($years > 1 ? "s" : "");
if ($months > 0) $age_str .= ", " . $months . " month" . ($months > 1 ? "s" : "");
$age_str .= " ago";
}
if ($days_ago < $warn_yellow) {
$css_class = "station-status-ok";
} else if ($days_ago < $warn_orange) {
$css_class = "station-status-yellow";
} else if ($days_ago < $warn_red) {
$css_class = "station-status-orange";
} else {
$css_class = "station-status-red";
}
echo(": " . $date_str . " — " . $age_str . " | ");
}
echo("");
}
?>