THEMIS.php
4.22 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
135
136
137
138
139
<?php
/**
* @class THEMIS
* @brief
*/
class THEMIS extends RemoteDataCenterClientClass
{
public $defaultFillValue = -1.e31;
// <param xml:id="imf">
// <info>
// <name>imf</name>
// <short_name>b_gse</short_name>
// <components>bx,by,bz</components>
// <units>nT</units>
// <coordinates_system>GSE</coordinates_system>
// <tensor_order/>
// <si_conversion>1e-9>T</si_conversion>
// <fill_value>-1.0E31</fill_value>
// <ucd>phys.magField</ucd>
// <dataset_id>ace-imf-all</dataset_id>
// <instrument_id>ACE_MAG</instrument_id>
// </info>
// <get>
// <vi name="ace:imf:all">
// <baseParam name="IMF"/>
// </vi>
// </get>
// <process/>
// <output/>
// </param>
protected function makeInternalParamXml($param)
{
$xml = new DomDocument("1.0");
$paramNode = $xml->createElement("param");
$xml->appendChild($paramNode);
$paramId = $param->getAttribute('xml:id');
$paramNode->setAttribute("xml:id", $paramId);
$ViId = substr($param->parentNode->getAttribute('xml:id'), strlen($this->baseID)+1);
$infoNode = $xml->createElement("info");
$infoNode->appendChild($xml->createElement("name",$paramId));
$infoNode->appendChild($xml->createElement("short_name",$param->getAttribute('name')));
$size = $param->getAttribute('size');
//TODO spectra components
if ($size > 1 && $param->hasAttribute('labels'))
{
$components = $param->getAttribute('labels');
}
else {
$components = null;
}
$infoNode->appendChild($xml->createElement("components",$components));
$infoNode->appendChild($xml->createElement("units",$param->getAttribute('units')));
$infoNode->appendChild($xml->createElement("coordinates_system"));
$infoNode->appendChild($xml->createElement("tensor_order"));
$infoNode->appendChild($xml->createElement("si_conversion"));
$infoNode->appendChild($xml->createElement("fill_value", $this->fillValue));
$infoNode->appendChild($xml->createElement("ucd"));
$infoNode->appendChild($xml->createElement("dataset_id",strtolower($ViId)));
$infoNode->appendChild($xml->createElement("instrument_id",strtolower($this->baseID." ".$ViId)));
$getNode = $xml->createElement("get");
$viNode = $xml->createElement("vi");
$baseParamNode = $xml->createElement("baseParam");
$arr = explode("_",$paramId); // tha_peif_density -> only last part
$baseParamName = $arr[2];
if ( count($arr) > 3 ) {
for ($i = 3; $i < count($arr); $i++)
$baseParamName .= "_".$arr[$i];
}
$baseParamNode->setAttribute("name", $baseParamName);
$viNode->setAttribute("name", strtolower(strtr($ViId,"_", ":")));
$viNode->appendChild($baseParamNode);
$getNode->appendChild($viNode);
$paramNode->appendChild($infoNode);
$paramNode->appendChild($getNode);
$paramNode->appendChild($xml->createElement("process"));
$paramNode->appendChild($xml->createElement("output"));
$xmlNameRemote = RemoteData."/PARAMS/".$paramId.".xml";
return $xml->save($xmlNameRemote);
}
public function makeAllParams()
{
$params = $this->baseDom->getElementsByTagName('parameter');
foreach ($params as $param)
{
if (!$this->makeInternalParamXml($param))
echo 'Error while making '.$param->getAttribute('xml:id').PHP_EOL;;
}
}
// make components description from base.xml
public function makeCenterNode($xmlDom)
{
$nodeBase = $this->baseDom->getElementsByTagName('dataCenter')->item(0);
$node = $xmlDom->importNode($nodeBase, true);
$parameters = $node->getElementsByTagName('parameter');
foreach ($parameters as $param) {
if ($param->hasAttribute("labels"))
{
$labels = $param->getAttribute('labels');
$id = $param->getAttribute('xml:id');
$name = $param->getAttribute('name');
// if (!$labels) {
// $param->setAttribute('needsArgs', true);
// return true;
$labelArr = explode(",",$labels);
for ($i = 0; $i < count($labelArr); $i++)
{
$component = $xmlDom->createElement('component');
$component->setAttribute('xml:id',$id.'('.$i.')');
$component->setAttribute('name',$labelArr[$i]);
$param->appendChild($component);
}
}
}
return $node;
}
}
?>