createVI.php
3.96 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**----------------------------------------------------------------------
* DD SERVER TOOLS
* data update collection
* @file createVI.php
* @brief DD_Server tool <br> Creates New Virtual Instrument
* @version
* Creates New VI at DD_Server Side \n
* Args: dataBaseID ddDataSetID remoteDataSetID \n
* Env Vars: $DDBASE $DDBASEBIN $DDLIB \n
* Executables: makeDDsys info2nc TimesUpdate \n
*
* @arg Checks if VI already exists in dataBase desctiptor DDsys.xml
* @arg Adds non-existing VI to DDres.xml
* @arg makeDDsys creats refer.nc file from DDsys.xml
* @arg Gets dataSet Info from INFO/DDServer dir
* @arg Creates dir, *_cache.nc, *_info.nc and empty *_times.nc
*
*/
if (!function_exists('__autoload'))
{
function __autoload($class_name) {
require_once $class_name . '.php';
}
}
date_default_timezone_set('UTC');
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."/addVI.log");
define("err",$LOGDIR."/addVI.err");
if ($argc != 4)
{
error_log("Usage: php createVI.php <BaseID> <RemSetID> <NewVIName>".PHP_EOL, 3, err);
exit("Usage: php createVI.php <BaseID> <RemSetID> <NewVIName>".PHP_EOL);
}
$base = strtoupper($argv[1]);
$remSetID = $argv[2];
$ViId = strtolower($argv[3]);
if ($verbose)
error_log(date("Y-m-d\TH:i:s")." Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, log);
error_log(date("Y-m-d\TH:i:s")." Request to add Data Set ".$base.":".$remSetID." as ".$ViId.PHP_EOL, 3, err);
$baseMgr = new DDBaseMgr();
$nc_prefix = strlen($ViId) > RemoteDataCenterClass::$MAX_VI_NAME_LENGTH ?
substr($ViId, 0, RemoteDataCenterClass::$MAX_VI_NAME_LENGTH - 1): $ViId;
if ($baseMgr->viExists($ViId, $base)) {
if ($verbose)
error_log($base." : ".$ViId." already Exists!!!".PHP_EOL, 3, log);
die("$ViId Already Exists!!!".PHP_EOL);
}
$baseMgr->setViId($ViId);
$baseMgr->setViInfo($nc_prefix);
$status = $baseMgr->setViInfoFromFile($base, $remSetID);
if ($status === 0)
{
$baseMgr->createVi();
$center = new $base();
$startStamp = strtotime($baseMgr->globalStart);
$stopStamp = strtotime($baseMgr->globalStart."+1 day");
$start = date( "Ymd\THis\Z", $startStamp);
$stop = date( "Ymd\THis\Z", $stopStamp-60.0);
$startIso = date( "Y-m-d\TH:i:s\.000\Z", $startStamp);
$stopIso = date( "Y-m-d\TH:i:s\.000\Z", $stopStamp);
// Get Full Dataset Info file from distant database
$infoFile = $center->getDatasetInfo($remSetID);
if ($infoFile)
{
$baseMgr->setInfo($infoFile);
}
$ncFiles = $center->getData($remSetID, $start, $stop);
if (!$infoFile && $ncFiles)
{
if ($verbose)
error_log("No dataset info file for ".$remSetID." from ".$ViId." uses regular file".PHP_EOL, 3, log);
$infoFileName = strtolower($remSetID).".nc";
copy($ncFiles[0], $infoFileName);
$baseMgr->setInfo($infoFileName);
}
$baseMgr->addRemoteData($remSetID, $ncFiles, $startIso, $stopIso);
// put real Global Start from file - IMPORTANT for new AMDA Kernel
$baseMgr->updateRemoteStart();
// if ($verbose) error_log("Get dataset info for ".$remSetID." from ".$dataBaseID." returns ".$res.PHP_EOL, 3, log);
// if ($AddInfo)
// {
// $function_name = "createHeader".$dataBaseID;
// require_once(DDLIB.$function_name.".php");
// $function_name($remSetID);
// }
// if (verbose) error_log("Added ".$VIID.PHP_EOL, 3, log);
}
else
{
if ($verbose) error_log("No DDServer Info File for $base $ViId".PHP_EOL, 3, log);
}
?>