getData.php
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?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");
?>