PostProcessing.php
8.5 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/**
* @class PostProcessing
* @version $Id: PostProcessing.php 2806 2015-03-02 15:31:05Z natacha $
*
*
*/
class PostProcessing {
private $myParamsInfoMgr, $contentDom;
protected $xmlName, $rootTag = 'orbitesList', $objTagName = 'orbites';
protected $attributes = array('name' => '', 'type' => '', 'mission' => '',
'units' => '','time_resolution' => '', 'fillval' => '',
'coordinate_system' => '', 'label' => '');
function __construct() {
$this->myParamsInfoMgr = new ParamsInfoMgr();
$this->xmlName = orbitesXml;
if (file_exists($this->xmlName)) unlink($this->xmlName);
$this->contentDom = new DomDocument("1.0");
$this->contentDom->preserveWhiteSpace = false;
$this->contentDom->formatOutput = true;
$this->createDom();
$this->xp = new domxpath($this->contentDom);
}
protected function createDom() {
$rootElement = $this->contentDom->createElement('orbitesList');
$this->contentDom->appendChild($rootElement);
$this->contentDom->save($this->xmlName);
}
/*
* Add Orbites in Orbites.xml
*/
protected function addOrbites($obj) {
$objList = $this->contentDom->documentElement;
$newObj = $this->contentDom->createElement($this->objTagName);
$newObj->setAttribute('xml:id',$this->id);
$obj_arr = (array)$obj;
foreach ($obj_arr as $key => $value) {
if ($key != 'xml:id') $newObj->setAttribute($key, $value);
}
$objList -> appendChild($newObj);
$this->contentDom->save($this->xmlName);
}
/*****************************************************************
* PUBLIC FUNCTIONS
*****************************************************************/
public function createOrbites() {
$parametresXml = new DomDocument();
if (file_exists(paramXml)) {
$parametresXml -> load(paramXml);
$xpath = new DOMXpath($parametresXml);
$parametres = $xpath->query("//PARAM[@type='orbit']");
if (!is_null($parametres)) {
foreach ($parametres as $parametre) {
$paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($parametre->getAttribute('xml:id'));
$mission = $paramInfo['submission']['id'];
if ($mission == '') $mission = $paramInfo['mission_id'];
echo $parametre->getAttribute('xml:id')." was generated....".$mission.PHP_EOL;
if ($mission != '') {
$obj = (object)array(
"param" => $parametre->getAttribute('xml:id'),
"name" => $parametre->getAttribute('name'),
"type" => $parametre->getAttribute('type'),
"mission" => strtoupper($mission),
"units" => $parametre->getElementsByTagName('UNITS')->item(0)->nodeValue,
"time_resolution" => $parametre->getElementsByTagName('TIME_RESOLUTION')->item(0)->nodeValue,
"fillval" => $parametre->getElementsByTagName('FILLVAL')->item(0)->nodeValue,
"coordinate_system" => $parametre->getElementsByTagName('COORDINATE_SYSTEM')->item(0)->nodeValue,
"label" => $parametre->getElementsByTagName('LABEL_I')->item(0)->nodeValue
);
$this->id = $obj->param;
$this -> addOrbites($obj);
}
}
}
else {
return array('success' => false, 'message' => "Local param file is empty");
}
}
else {
echo "Local param file doesn't exist ".paramXml.PHP_EOL;
return array('success' => false, 'message' => "Local param file doesn't exist");
}
}
public function createOrbitesInfoFiles($locBases){
$domTargets = new DomDocument();
if (!$domTargets->load(targetsSimu)) {
$msg = "Cannot load file ".targetsSimu.PHP_EOL;
if (!$this->updateOnly) error_log($msg,1,email);
continue;
}
$targets = $domTargets->getElementsByTagName('target');
foreach ($targets as $target) {
$help = "<h2> ".$target->nodeValue." </b></a></h2><UL><br/><br/><li><b>Orbits of satellites :</b><br/><br/>";
foreach ($locBases as $locBase)
{
if (strpos($locBase->getAttribute('targets'),$target->nodeValue) !== FALSE){
$sat = $locBase->nodeValue;
echo "Loc Base is $sat & target is ".$target->nodeValue.PHP_EOL;
$domName = LocalData."DD_".$sat.".xml";
$domParamName = LocalDataParam.$sat.".xml";
$help = $help."<p><b>$sat: </b> <br/>";
$dom = new DomDocument();
if (!$dom->load($domName)) {
$msg = "Cannot load file ".$domName.PHP_EOL;
print_r($msg);
if (!$this->updateOnly) error_log($msg,1,email);
continue;
}
$domParam = new DomDocument();
if (!$domParam->load($domParamName)) {
$msg = "Cannot load file ".$domParamName.PHP_EOL;
print_r($msg);
if (!$this->updateOnly) error_log($msg,1,email);
continue;
}
$domOrbites = new DomDocument();
if (!$domOrbites->load(orbitesXml)) {
$msg = "Cannot load file ".orbitesXml.PHP_EOL;
print_r($msg);
if (!$this->updateOnly) error_log($msg,1,email);
continue;
}
$xp = new domxpath($dom);
$xpParam = new domxpath($domParam);
$xpOrb = new domxpath($domOrbites);
$body = explode('.',$target->nodeValue);
$query = "//dataset";
$datasets = $xp->query($query);
if ($datasets->length > 0){
foreach ($datasets as $dataset){
$vi = $dataset->getAttribute('xml:id');
$query = "//PARAM[@vi='$vi']";
$param = $xpParam->query($query);
if($param->length > 0){
$paramID = $param->item(0)->getAttribute('xml:id');
$query = "//orbites[@xml:id='$paramID']";
$orbites = $xpOrb->query($query);
if ($orbites->length > 0) { // && $dataset->getElementsByTagName('target')->item(0)->nodeValue == $body[0]){
if ($dataset->getElementsByTagName('target')->item(0)->nodeValue == $body[0] ){
// $help = $help."<p><b>$sat: </b> ";
$title = $dataset->getElementsByTagName('title')->item(0)->nodeValue;
$start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;
$stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
$help = $help."$title: $start - $stop</p>";
if ($target->nodeValue == 'Ganymede') $help = $help."<p>You can find the Ganymede flyby TimeTable in the <b>Shared Time Tables/OTHER/ganymede_flyby</b>
</p><br/>1996-06-27T06:07:08 - 1996-06-27T06:52:37 45.48 min <br/>
1996-09-06T18:32:44 - 1996-09-06T19:28:22 - 55.63 min <br/>
1997-04-05T06:44:41 - 1997-04-05T07:40:19 - 55.63 min <br/>
1997-05-07T15:36:54 - 1997-05-07T16:22:24 - 45.50 min <br/>
1997-06-26T16:50:00 - 1997-06-26T17:49:56 - 59.93 min <br/>
1997-12-15T09:30:23 - 1997-12-15T10:30:00 - 59.62 min <br/>
2000-05-20T09:40:04 - 2000-05-20T10:40:41 - 60.62 min <br/>
2000-12-28T07:54:41 - 2000-12-28T08:55:21 - 60.67 min <br/>";
}
elseif ($dataset->getElementsByTagName('title')->item(0)->nodeValue == 'ToDo' ||
$dataset->getAttribute('name') == 'orbit'){
// $help = $help."<p><b>$sat: </b> ";
$start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;
$stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
$help = $help.$orbites->item(0)->getAttribute('mission')." $start - $stop</p>";
}
elseif ($dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER1' ||
$dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER2' ||
$dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER3' ||
$dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER4'){
// $help = $help."<p><b>$sat: </b> ";
$start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;
$stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
$help = $help.$orbites->item(0)->getAttribute('param')." $start - $stop</p>";
}
}
}
}
}
}
}
$help = $help."</UL>";
$fileName = HELPPATH."simu/simu".$target->nodeValue;
file_put_contents($fileName, $help);
}
return true;
}
}