getData.php 1.82 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];
  
  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;
	
	$LOGDIR = getenv("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
	$baseMgr = new DDBaseMgr();
	$baseMgr->setViDir($ViDir);
	$baseMgr->addRemoteData($id, $ncFiles, $startIso, $stopIso);
        
?>