makeMultiMission.php
7.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/** @file makeMultiMission
* @version $Id: makeMultiMission.php 2321 2014-04-26 12:36:18Z elena $
* @brief StandAlone executable launched in BASE_PATH/php to create LOCALLY
* @brief DD_MISSION.xml and MISSION.xml from templates
* @brief and LocalParamsList.xml and LocalParams.xml
* @brief it is analog of AmdaUpdate.php INSTALL
*/
require_once "config.php";
$missionsDom = new DomDocument("1.0");
$missionsDom->load(missionXml);
$locBases = $missionsDom->getElementsByTagName("MissionID");
foreach ($locBases as $locbase) {
$multi = $locbase->getAttribute("missions");
$nameArr = explode(";",$multi);
$templatename = LocalDataTemplate."DD_".$locbase->nodeValue.".template";
$paramtemplate = LocalDataTemplate.$locbase->nodeValue.".template";
if (count($nameArr) > 1 &&
(file_exists($templatename) && file_exists($paramtemplate))) {
$suffix = array();
foreach ($nameArr as $item) {
$temp = explode("-",$item);
if (count($temp) > 1) {
$suffix[] = $temp[1];
}
else {
$suffix[] = substr($item,-1);
}
}
$template = new DomDocument("1.0");
$status = $template->load($templatename);
$paramdom = new DomDocument("1.0");
$status = $paramdom->load($paramtemplate);
// Create DD_Mission.xml
$locbasename = LocalData."DD_".$locbase->nodeValue.".xml";
$locbasedom = new DomDocument("1.0");
$root = $locbasedom->importNode($template->documentElement);
$amda = $locbasedom->importNode($template->getElementsByTagName("dataCenter")->item(0));
$missionMain = $locbasedom->importNode($template->getElementsByTagName("mission")->item(0));
$mission = $locbasedom->importNode($template->getElementsByTagName("mission")->item(0), true);
$targets = $mission->getElementsByTagName("target");
$targetNames = array();
foreach ($targets as $target)
if ($target->parentNode->tagName == 'mission')
$targetNames[] = $target->nodeValue;
$observatory = $mission->getElementsByTagName("observatory")->item(0);
$instruments = $observatory->getElementsByTagName("instrument");
// create param descriptor Mission.xml
$parambasename = LocalDataParam.$locbase->nodeValue.".xml";
$parambasedom = new DomDocument("1.0");
$paramroot = $parambasedom->importNode($paramdom->documentElement);
$instrumentNon = array();
foreach ($instruments as $instrument) {
if ($instrument->hasAttribute("absent")) {
$absent = $instrument->getAttribute("absent");
$absentArray = explode(";",$absent);
$tempArr = array();
if (count($absentArray) > 1) {
for ($i = 0; $i < count($suffix); $i++) $tempArr[$i] = false;
for ($j = 0; $j < count($absentArray); $j++) {
$temp = array_search($absentArray[$j], $suffix, true);
$tempArr[$temp] = true;
}
}
else {
for ($i = 0; $i < count($suffix); $i++) {
$tempArr[$i] = $absent == $suffix[$i];
}
}
$instrumentNon[$instrument->getAttribute("name")] = $tempArr;
}
}
foreach ($targetNames as $targetName) {
$missionMain->appendChild($locbasedom->createElement("target",$targetName));
}
for ($index = 0; $index < count($suffix); $index++) {
$missionArr[$index] = $observatory->cloneNode();
$missionArr[$index]->setAttribute("name", str_replace("XXX", $suffix[$index], $missionArr[$index]->getAttribute("name")));
$missionArr[$index]->setAttribute("xml:id", str_replace("XXX", $suffix[$index], $missionArr[$index]->getAttribute("name")));
$instruments = $observatory->getElementsByTagName("instrument");
foreach ($instruments as $instrumentReal){
if (!$instrumentNon[$instrumentReal->getAttribute("name")] || !$instrumentNon[$instrumentReal->getAttribute("name")][$index]) {
$instrument = $instrumentReal->cloneNode(true);
$instrument->setAttribute("desc",str_replace("XXX", $suffix[$index], $instrument->getAttribute("desc")));
$instrument->setAttribute("xml:id",str_replace("XXX", $suffix[$index], $instrument->getAttribute("xml:id")));
$tags = array("dataset", "parameter", "component");
foreach ($tags as $tag) {
$all = $instrument->getElementsByTagName($tag);
foreach ($all as $one) {
if ($tag == 'parameter') {
$id = $one->getAttribute("xml:id");
// create param tag in param XML descriptor
$param = $paramdom->getElementById($id);
if ($param){
$paramAdd = $parambasedom->importNode($param, true);
$paramAdd->setAttribute("xml:id",str_replace("XXX", strtolower($suffix[$index]), $id));
$paramAdd->setAttribute("vi",str_replace("XXX", strtolower($suffix[$index]), $paramAdd->getAttribute("vi")));
$yTitle = $paramAdd->getElementsByTagName("YTITLE");
if ($yTitle->length > 0) {
$value = $yTitle->item(0)->nodeValue;
$yTitle->item(0)->nodeValue = str_replace("XXX", $suffix[$index], $value);
}
$paramroot->appendChild($paramAdd);
}
}
$one->setAttribute("xml:id",str_replace("XXX", strtolower($suffix[$index]), $one->getAttribute("xml:id")));
if ($tag == 'dataset' && $one->hasAttribute("vi"))
$one->setAttribute("vi",str_replace("XXX", strtolower($suffix[$index]), $one->getAttribute("vi")));
}
}
$missionArr[$index]->appendChild($instrument);
}
}
$missionMain->appendChild($missionArr[$index]);
}
$amda->appendChild($missionMain);
$root->appendChild($amda);
$locbasedom->appendChild($root);
$locbasedom->save($locbasename);
$parambasedom->appendChild($paramroot);
$parambasedom->save($parambasename);
}
}
// temporary here
$paramsDom = new DomDocument("1.0");
$paramsDom->formatOutput = true;
$paramsDom->preserveWhiteSpace = false;
$paramsRoot = $paramsDom->createElement('LOCAL');
$paramsDom->appendChild($paramsRoot);
$listDom = new DomDocument("1.0");
$listDom->formatOutput = true;
$listDom->preserveWhiteSpace = false;
$listRoot = $listDom->createElement('LOCAL');
$listDom->appendChild($listRoot);
$dom = new DomDocument("1.0");
foreach ($locBases as $locbase)
{
$ddparamfilename = $locbase->nodeValue.".xml";
$status = $dom->load(LocalDataParam.$ddparamfilename);
$params = $dom->getElementsByTagName('PARAM');
// if ($locbase->nodeValue == 'SW_Mars') printf($status.PHP_EOL);
foreach ($params as $param)
{
$node = $paramsDom->importNode($param,TRUE);
$paramsRoot->appendChild($node);
$id = $param->getAttribute('xml:id');
// if ($locbase->nodeValue == 'SW_Mars') printf($id.PHP_EOL);
$node = $listDom->createElement('PARAM',$id);
$listRoot->appendChild($node);
}
}
$paramsDom->save(paramXml);
$listDom->save(paramListXml);
?>