makeOrbitsInKm.php
4.15 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
<?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');
$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 = DATAPATH."newKernelDDBase";
$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 = '$'.$paramXml->get->vi['name'].'*'.$scale[$units];
}
else if (strpos($process, '/RADIUS') > 0)
{
$newProcess = substr($process,0,strpos($process, '/RADIUS'));
if ($newProcess == '$'.$paramXml->get->vi['name']) $newProcess = '';
}
else
{
$newProcess = $process."/".$scale[$units];
}
$newId = $id."_km";
$new_param_file = $amdaParamDir."/".$newId.".xml";
$newXML = new SimpleXMLElement("<param></param>");
$newXML->addAttribute('xml:id', $newId);
$newInfo = $newXML->addChild('info');
$newInfo->addChild('name', $paramXml->info->name);
$newInfo->addChild('short_name', $paramXml->info->name);
$newInfo->addChild('components', $paramXml->info->components);
$newInfo->addChild('units', 'km');
$newInfo->addChild('coordinates_system', $paramXml->info->coordinates_system);
$newInfo->addChild('tensor_order', $paramXml->info->tensor_order);
$newInfo->addChild('si_conversion', 1.e3);
//TODO scale fill value
$newInfo->addChild('fill_value', $paramXml->info->fill_value);
$newInfo->addChild('ucd', $paramXml->info->ucd);
$newInfo->addChild('dataset_id', $paramXml->info->dataset_id);
$newGet = $newXML->addChild('get');
$newVi = $newXML->addChild('vi');
$newVi->addAttribute('name', $paramXml->get->vi['name']);
$newParam = $newVi->addChild('baseParam');
$newParam->addAttribute('name', $paramXml->get->vi->baseParam['name']);
$newXML->addChild('process',$newProcess);
$newXML->addChild('output');
$newXML->asXML($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');
?>