makeOrbitsInKm.php
4.79 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
<?php
/*
* Executable to make dynamically internal ephemeris params in km
*
*/
$scale = array('AU'=>'ASTRONOMICAL_UNIT','Rme'=>'RADIUS_MERCURY','Rv'=>'RADIUS_VENUS','Re'=>'RADIUS_EARTH','Rma'=>'RADIUS_MARS','Rm'=>'RADIUS_MARS',
'Rj'=>'RADIUS_JUPITER','Rs'=>'RADIUS_SATURN','Ru'=>'RADIUS_URANUS','Rn' =>'RADIUS_NEPTUNE',
'Rga'=>'RADIUS_GANYMEDE','Rg'=>'RADIUS_GANYMEDE');
$tr = array(':' => '_');
$AMDA_IHM = getenv('AMDA_IHM');
if (!isset($AMDA_IHM))
require_once __DIR__."/config.php";
else
require_once $AMDA_IHM."/php/config.php";
if (!defined('orbitsXml'))
exit("orbitsXml is not defined in config.php".PHP_EOL);
if (!file_exists(orbitsXml))
exit("No orbitsXml file".PHP_EOL);
$amdaParamDir = PARAMS_LOCALDB_DIR;
$dom = new DomDocument("1.0");
$dom->load(orbitsXml);
$orbits = $dom->getElementsByTagName("orbites");
$domKm = new DomDocument("1.0");
$domKm->formatOutput = TRUE;
$domKm->preserveWhiteSpace = FALSE;
$rootKm = $domKm->createElement('orbitesList');
$domKm->appendChild($rootKm);
Header('Content-type: text/xml');
foreach ($orbits as $orbit)
{
$id = $orbit->getAttribute('xml:id');
$units = $orbit->getAttribute('units');
if ($units != 'km') // add orbital parameter in km
{
$param_file = $amdaParamDir."/".$id.".xml";
if (file_exists($param_file))
{
$paramXml = simplexml_load_file($param_file);
$process = $paramXml->process;
if ($process == "")
{
$newProcess = '$'.strtr($paramXml->get->vi['name'], $tr).'_'.$paramXml->get->vi->baseParam['name'].'*'.$scale[$units];
}
else if (strpos($process, '/RADIUS') > 0)
{
$newProcess = substr($process,0,strpos($process, '/RADIUS'));
if ($newProcess == '$'.strtr($paramXml->get->vi['name'], $tr)) $newProcess = '';
}
else
{
$newProcess = $process."/".$scale[$units];
}
$newId = $id."_km";
$new_param_file = $amdaParamDir."/".$newId.".xml";
$newDom = new DomDocument("1.0");
$newXML = $newDom->createElement("param");
$newDom->appendChild($newXML);
$newXML->setAttribute("xml:id", $newId);
$newInfo = $newDom->createElement('info');
$newInfo->appendChild($newDom->createElement('name', $paramXml->info->name));
$newInfo->appendChild($newDom->createElement('short_name', $paramXml->info->name));
$newInfo->appendChild($newDom->createElement('components', $paramXml->info->components));
$newInfo->appendChild($newDom->createElement('units', 'km'));
$newInfo->appendChild($newDom->createElement('coordinates_system', $paramXml->info->coordinates_system));
$newInfo->appendChild($newDom->createElement('tensor_order', $paramXml->info->tensor_order));
$newInfo->appendChild($newDom->createElement('si_conversion', 1.e3));
//TODO scale fill value
$newInfo->appendChild($newDom->createElement('fill_value', $paramXml->info->fill_value));
$newInfo->appendChild($newDom->createElement('ucd', $paramXml->info->ucd));
$newInfo->appendChild($newDom->createElement('dataset_id', $paramXml->info->dataset_id));
$newXML->appendChild($newInfo);
$newGet = $newDom->createElement('get');
$newXML->appendChild($newGet);
$newVi = $newDom->createElement('vi');
$newVi->setAttribute('name', $paramXml->get->vi['name']);
$newGet->appendChild($newVi);
$newParam = $newDom->createElement('baseParam');
$newParam->setAttribute('name', $paramXml->get->vi->baseParam['name']);
$newVi->appendChild($newParam);
$newXML->appendChild($newDom->createElement('process',$newProcess));
$newXML->appendChild($newDom->createElement('output'));
$newDom->save($new_param_file);
$newOrbit = $domKm->createElement('orbites');
$newOrbit->setAttribute('xml:id', $newId);
$newOrbit->setAttribute('coordinate_system', $paramXml->info->coordinates_system);
$newOrbit->setAttribute('units','km');
$newOrbit->setAttribute('mission', $orbit->getAttribute('mission'));
if ($orbit->hasAttribute('missionGroup'))
$newOrbit->setAttribute('missionGroup', $orbit->getAttribute('missionGroup'));
$newOrbit->setAttribute('dataset', $orbit->getAttribute('dataset'));
$newOrbit->setAttribute('target', $orbit->getAttribute('target'));
$rootKm->appendChild($newOrbit);
}
}
}
$domKm->save(LocalData.'OrbitsInternal.xml');
if (file_exists(LocalData.'OrbitsAll.xml'))
unlink(LocalData.'OrbitsAll.xml');
// Merge internal orbits and open orbits
$orbitsInternal = $rootKm->getElementsByTagName('orbites');
foreach ($orbitsInternal as $orbitInternal)
{
$dom->documentElement->appendChild($dom->importNode($orbitInternal));
}
$dom->save(LocalData.'OrbitsAll.xml');
?>