Example #1
0
$uomOrig = '';
$uom = '';
// usgs isn't sos, so treat it differently
if (isset($_REQUEST['USGS'])) {
    $xml = @simplexml_load_file(substr($_SERVER["REQUEST_URI"], strpos($_SERVER["REQUEST_URI"], '&USGS=') + 6));
    foreach ($xml->children('http://www.cuahsi.org/waterML/1.1/')->{'timeSeries'} as $ts) {
        $var = $ts->children('http://www.cuahsi.org/waterML/1.1/')->{'variable'}[0];
        $p = sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'variableCode'}[0]);
        preg_match('/(.*), ([^,]*)/', sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'variableName'}[0]), $matches);
        $n = $matches[1];
        $noData = sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'noDataValue'}[0]);
        foreach ($ts->children('http://www.cuahsi.org/waterML/1.1/')->{'values'}[0]->children('http://www.cuahsi.org/waterML/1.1/')->{'value'} as $val) {
            $t = sprintf("%s", $val->attributes()->{'dateTime'});
            $v = sprintf("%s", $val);
            if ($v != $noData) {
                $a = makeMks($v, preg_replace('/&\\#...;/', '', $matches[2]));
                $uomOrig = $a['uom'];
                // pretend units came in as mks
                $newVal = convertUnits($a['val'], $a['uom'], $_REQUEST['uom'] == 'english');
                $v = $newVal[0]['val'];
                $uom = $newVal[0]['uom'];
                if (count($newVal) == 2 && isset($_REQUEST['uomB'])) {
                    $v = $newVal[1]['val'];
                    $uom = $newVal[1]['uom'];
                }
                $data[$t] = $v;
            }
        }
    }
} else {
    if (isset($_REQUEST['NERRS'])) {
// assume same time for all obs
$o = array();
$xml = @simplexml_load_file($base);
foreach ($xml->children('http://www.cuahsi.org/waterML/1.1/')->{'timeSeries'} as $ts) {
    $var = $ts->children('http://www.cuahsi.org/waterML/1.1/')->{'variable'}[0];
    $p = sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'variableCode'}[0]);
    preg_match('/(.*), ([^,]*)/', sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'variableName'}[0]), $matches);
    $n = $matches[1];
    $uomOrig = preg_replace('/&\\#...;/', '', $matches[2]);
    $noData = sprintf("%s", $var->children('http://www.cuahsi.org/waterML/1.1/')->{'noDataValue'}[0]);
    $val = $ts->children('http://www.cuahsi.org/waterML/1.1/')->{'values'}[0]->children('http://www.cuahsi.org/waterML/1.1/')->{'value'}[0];
    if ($val) {
        $t = sprintf("%s", $val->attributes()->{'dateTime'});
        $v = sprintf("%s", $val);
        if ($v != $noData) {
            $a = makeMks($v, $uomOrig);
            $uomOrig = $a["uom"];
            $v = $a["val"];
            $a = convertUnits($v, $uomOrig, $_REQUEST['uom'] == 'english');
            $u = $a[0]["uom"];
            $v = $a[0]["val"];
            $dEnd = date('Y-m-d\\TH:i:00\\Z');
            $dBegin = date('Y-m-d\\TH:i:00\\Z', time() - 60 * 60 * (24 * 1 + 1));
            if ($v != '') {
                $uEscape = str_replace('"', '\\"', "graph.php?name={$n}&tz=" . $_REQUEST['tz'] . '&uom=' . $_REQUEST['uom'] . '&lon=' . $_REQUEST['lon'] . '&lat=' . $_REQUEST['lat'] . '&cat=' . $a[0]['cat'] . "&USGS={$base}&parameterCd={$p}&startDt={$dBegin}&endDt={$dEnd}");
                $extra = '';
                if (count($a) == 2) {
                    $extra = "<br><a href='javascript:showObsTimeseries([\"" . str_replace('graph.php?', 'graph.php?uomB&', $uEscape) . "\"])'><img src='img/graph.png' width=10 height=10></a> " . $a[1]["val"] . ' ' . $a[1]["uom"];
                }
                array_push($o, sprintf("<tr><td><b>%s</b></td><td><a href='javascript:showObsTimeseries([\"{$uEscape}\"])'><img src='img/graph.png' width=10 height=10></a> {$v} {$u}{$extra}</td></tr>", $n));
            }