getData.php 2.42 KB
<?php
/**
*  @file  getData.php 
*  @version $Id: getData.php,v 1.5 2009/08/26 09:32:40 budnik Exp $
*  @brief DD_Server tools <br> Gets Data from Remote
* 
*   Args:  remDataSetID  ddVIdir StartTime StopTime \n
*   Env Vars:  $DDBASE $DDBASEBIN \n
*   Executables: cdf2nc(DECODERS) TimesUpdate clean
*/

/*----------------------------------------------------------------------
 *                     DD SERVER TOOLS
 *                   data update collection 
 *                   getData.php
 *  php getData.php <baseID> <remDataSetID> <ddVIdir> <StartTime> <StopTime>
 *-----------------------------------------------------------------------*/
 
//  Args
  $base  =  $argv[1];
  $id    =  $argv[2];
  $ViDir =  $argv[3];
  $Start =  $argv[4];
  $Stop  =  $argv[5];
  
  touch($ViDir."LOCK");
  
  if (!function_exists('__autoload')) 
	{
		function __autoload($class_name) {
				require_once $class_name.'.php';
		}
	}
   
   putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
	putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
	set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT"));
	$verbose = true;

	$DDBASE=getenv("DDBASE");
	if (is_link($DDBASE)) {
		$DDBASE=readlink($DDBASE);
		if ($DDBASE === FALSE) {
			exit(0);
		}
	}
	define('RemoteData',  $DDBASE."/../INFO");

	$LOGDIR = $DDBASE."/../LOG/";
	
	if (!is_dir($LOGDIR))
				mkdir($LOGDIR, 0755, true);
				
	define("log",$LOGDIR."/getData.log");
	define("err",$LOGDIR."/getData.err");
	
	date_default_timezone_set('UTC');
	$startStamp = strtotime($Start);
	$stopStamp = strtotime($Stop);
	$start = date("Ymd\THis\Z", $startStamp);
	$stop = date("Ymd\THis\Z", $stopStamp);
	
	$startIso = date("Y-m-d\TH:i:s\.000\Z", $startStamp);
	$stopIso = date("Y-m-d\TH:i:s\.000\Z", $stopStamp);

	// Get data and convert to nc
	$center = new $base();
	$ncFiles = $center->getData($id, $start, $stop);
	
	// Add nc to Vi
    if ( strpos($id, ":") !== false ) {
        $nc_prefix = substr($id,strpos($id, ":")+1);
    } else {                   
        $nc_prefix = strlen($id) > RemoteDataCenterClass::$MAX_VI_NAME_LENGTH ? 
					substr($id, 0, RemoteDataCenterClass::$MAX_VI_NAME_LENGTH - 1): $id;
    }
            

	$baseMgr = new DDBaseMgr();
	// $baseMgr->setViId($id);
	$baseMgr->setViInfo(strtolower($nc_prefix));
	$baseMgr->setViDir($ViDir);
	$baseMgr->addRemoteData($id, $ncFiles, $startIso, $stopIso);
	
   if (file_exists($ViDir."LOCK")) unlink($ViDir."LOCK");    
?>