getDataCDPP.php
3.9 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
<?php
/**
* @file getDataCDPP.php
* @version $Id: getDataCDPP.php,v 1.4 2009/08/26 09:32:56 budnik Exp $
* @brief DD_Server tools <br> Gets Data from CDPP
*
* Args: remDataSetID ddVIdir StartTime StopTime \n
* Env Vars: $DDBASE $DDBASEBIN \n
* Executables: TimesUpdate TimesUpdateNoData clean
*
*
* @todo General getData.php(dataBaseID)
*/
/*----------------------------------------------------------------------
* DD SERVER TOOLS
* data update collection
* getDataCDPP.php
*-----------------------------------------------------------------------*/
// Args
$id = $argv[1];
$ViDir = $argv[2];
$Start = $argv[3];
$Stop = $argv[4];
// Env variables
$DDBASEBIN = getenv("DDBASEBIN");
$DDBASE = getenv("DDBASE");
$MAX_NAME_LENGTH = 31;
$MAX_VI_NAME_LENGTH = 16;
$wsdl = "http://cdpp2.cesr.fr:8080/AMDA/services/AMDAServer?WSDL";
// Opent STDERR stream
$STDERR = fopen("php://stderr","w");
define("restrictions", $DDBASE."/../INFO/CDPP_restrictions.xml");
try {
$client = new SoapClient($wsdl);
}
catch (SoapFault $exception) {
fprintf($STDERR,"CDPP WSDL is unreachable \n");
exit(-1);
}
// Stamp -> this directory is being updated
$LockName = $ViDir."/LOCK";
touch($LockName);
fprintf($STDERR,$ViDir." is LOCKED\n");
system("cd ".$ViDir."; ./clean");
// If name is too long....
$nc_prefix = strlen($id) > $MAX_VI_NAME_LENGTH ? substr(strtolower($id),0,15): strtolower($id);
// If restrictions exists...
$dataset->parameters = null;
if (file_exists(restrictions)) {
$restrictionsDom = new DomDocument('1.0');
$restrictionsDom -> load(restrictions);
$dataSetRestrictions = $restrictionsDom->getElementById($id);
if ($dataSetRestrictions != null) {
$parametres = $dataSetRestrictions->getElementsByTagName("PARAMETER_ID");
foreach ($parametres as $parameter) {
$param_id = phpversion() >= "5.2.0" ? $parameter->getAttribute("xml:id") : $parameter->getAttribute("id");
$dataset->parameters .= strtoupper($param_id)." ";
}
}
}
$dataset->datasetID = $id;
$dataset->timeStart = $Start;
$dataset->timeStop = $Stop;
try
{
$result = $client->__soapCall("getNcdfUrls", array($dataset));
}
catch (SoapFault $exception)
{
unlink($LockName);
fprintf($STDERR, "EXCEPTION".$exception->faultstring."\n");
exit(-1);
}
$files = $result->getNcdfUrlsReturn;
fprintf($STDERR, "FILES GOT ".count($files)."\n");
if (count($files) > 0)
{
for ($i = 0; $i < count($files); $i++) {
$file = count($files) == 1 ? $files : $files[$i];
$fileArr = split("/",$file);
$ncFile = $fileArr[count($fileArr)-1];
$ncFileTrue = ($strLength = strlen($ncFile)) > $MAX_NAME_LENGTH ?
$nc_prefix."_".time().$i.".nc" : $ncFile;
if (copy($file,$ViDir."/".$ncFileTrue)) {
if (strpos($ViDir, "CP_CIS_CODIF_HS_H1_MOMENTS") !== false) system("nc2nc ".$ViDir."/".$ncFileTrue);
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdate -u ".strtolower($id)."_times.nc ".$ncFileTrue);
fprintf($STDERR, "TIMES IS UPDATED ".$i."\n");
}
else fprintf($STDERR, $file." is not found\n");
}
}
system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdateNoData ".strtolower($id)."_times.nc ".$argv[3]." ".$argv[4]);
unlink($LockName);
fprintf($STDERR, "UNLOCK \n");
?>