getSwStop.php 1.32 KB
<?php

    if ($argv[1] == '') exit('ERROR');

    $DDBASE = getenv('DDBASE');
    if ($DDBASE == '') exit('ERROR');

    switch ($argv[1]) {
        case 'OMNI':
                $file = $DDBASE.'/OMNI/HOUR/SWStop';
                if (!file_exists($file)) exit('ERROR');
                $timeArray = file($file);
                $timeValue = trim($timeArray[0]).'.000Z';
            break;
        case 'ACE_RealTime' :
                $fileMAG = $DDBASE.'/ACE/RealTime/MAG/mag_info.xml';
                $fileSW =  $DDBASE.'/ACE/RealTime/SWEPAM/swepam_info.xml';
                if (!file_exists($fileMAG) || !file_exists($fileSW)) exit('ERROR');

                $xml = new DomDocument('1.0');
                if (!$xml->load($fileMAG)) exit('ERROR');
                $timeMAG = $xml->getElementsByTagName('GlobalStop');
                if ($timeMAG->length == 0) exit('ERROR');
                $timeMagValue = $timeMAG->item(0)->nodeValue;

                if (!$xml->load($fileSW)) exit('ERROR');
                $timeSW = $xml->getElementsByTagName('GlobalStop');
                if ($timeSW->length == 0) exit('ERROR');
                $timeSwValue = $timeSW->item(0)->nodeValue;
                
                $timeValue = $timeSwValue > $timeMagValue ? $timeSwValue : $timeMagValue;
 
            break;
    }
 
  exit($timeValue);

?>