info.php
3.34 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
<?php
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
$METADATA_DIR = "PARAM_DEF";
$response = array();
$response["HAPI"] = "2.0";
header('Content-Type: application/json');
if (!$_GET["id"]) {
$response["status"] = 404;
$response["msg"] = "No ID !!!";
exit(json_encode($response));
}
$id = $_GET["id"];
if ($_GET["parameters"]) {
$paramRequest = explode(",",$_GET["parameters"]);
}
else {
$paramRequest = null;
}
$pattern = "$id.xml";
$files = rglob($pattern);
$xmlName = $files[0];
if (!file_exists($xmlName)) {;
header("HTTP/1.1 404 NO SUCH ID");
$response["status"] = array("code" => 1406, "message" => "NO SUCH ID");
exit(json_encode($response));
}
$dom = new DomDocument("1.0");
$dom->load($xmlName);
$dataset = $dom->getElementsByTagName("Spase")->item(0);
$parameters = $dataset->getElementsByTagName('Parameter');
if ( $parameters->length == 0 ) {
header("HTTP/1.1 404 NO PARAMETERS");
$response["status"] = array("code" => 1406, "message" => "NO PARAMETERS");
exit(json_encode($response));
}
$paramDom = new DomDocument("1.0");
$parametersResponse = array(array("name" => "Time", "type" => "isotime", "length" => 20, "units" => "", "fill" =>""));
foreach ( $parameters as $param ) {
$oneParam = array();
$oneParam["type"] = "double";
$paramId = $param->getElementsByTagName('ParameterKey')->item(0)->nodeValue;
if (file_exists("$METADATA_DIR/$paramId.xml")) {
$paramDom->load("$METADATA_DIR/$paramId.xml");
$process = $paramDom->getElementsByTagName("process")->item(0)->nodeValue;
if (!$process) {
$baseParam = $paramDom->getElementsByTagName("baseParam")->item(0);
$oneParam["name"] = $baseParam->getAttribute('name');
$oneParam["description"] = $param->getElementsByTagName('Description')->item(0)->nodeValue;
$oneParam["fill"] = $param->getElementsByTagName('FillValue')->item(0)->nodeValue;
$oneParam["units"] = $param->getElementsByTagName('Units')->item(0)->nodeValue;
$size = $param->getElementsByTagName('Size');
if ($size->length > 0) {
$oneParam["size"] = array(intval($size->item(0)->nodeValue));
}
if ($paramRequest && !in_array($baseParam->getAttribute('name'), $paramRequest)) {
//
} else {
$parametersResponse[] = $oneParam;
}
}
}
}
$response["startDate"] = $dataset->getElementsByTagName('StartDate')->item(0)->nodeValue;
$response["stopDate"] = $dataset->getElementsByTagName('StopDate')->item(0)->nodeValue;
$response["cadence"] = $dataset->getElementsByTagName('Cadence')->item(0)->nodeValue;
$response["parameters"] = $parametersResponse;
$response["status"] = array("code" => 1200, "msg" => "OK");
exit(json_encode($response));
?>