Blame view

php/makeOrbitsInKm.php 4.79 KB
f223812e   Elena.Budnik   make orbits in km
1
2
3
4
5
6
7
8
<?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');
9ac23b1f   Elena.Budnik   bug in xyz_km gen...
9
10
11
						
		$tr = array(':' => '_');
		
f223812e   Elena.Budnik   make orbits in km
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
		$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 == "")
					{						
9ac23b1f   Elena.Budnik   bug in xyz_km gen...
56
						$newProcess = '$'.strtr($paramXml->get->vi['name'], $tr).'_'.$paramXml->get->vi->baseParam['name'].'*'.$scale[$units];						
f223812e   Elena.Budnik   make orbits in km
57
58
59
60
					}
					else if (strpos($process, '/RADIUS') > 0)
					{   
						$newProcess = substr($process,0,strpos($process, '/RADIUS'));					  
9ac23b1f   Elena.Budnik   bug in xyz_km gen...
61
						if ($newProcess == '$'.strtr($paramXml->get->vi['name'], $tr)) $newProcess = '';
f223812e   Elena.Budnik   make orbits in km
62
63
64
65
66
67
68
69
					}
					else
					{
						$newProcess = $process."/".$scale[$units];
					}
					
					$newId = $id."_km";
					$new_param_file =  $amdaParamDir."/".$newId.".xml";
6a3bb8f6   Elena.Budnik   DomDocument, simp...
70
71
72
73
74
75
76
77
78
79
80
81
					$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));
f223812e   Elena.Budnik   make orbits in km
82
					//TODO scale fill value
6a3bb8f6   Elena.Budnik   DomDocument, simp...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
					$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); 	
f223812e   Elena.Budnik   make orbits in km
98
		
005bea96   Elena.Budnik   corr in orbInKm
99
					$newOrbit = $domKm->createElement('orbites');
f223812e   Elena.Budnik   make orbits in km
100
					$newOrbit->setAttribute('xml:id', $newId);
58c45979   Elena.Budnik   coordinate_system
101
					$newOrbit->setAttribute('coordinate_system', $paramXml->info->coordinates_system);
f223812e   Elena.Budnik   make orbits in km
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
					$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	
005bea96   Elena.Budnik   corr in orbInKm
119
		$orbitsInternal = $rootKm->getElementsByTagName('orbites');
f223812e   Elena.Budnik   make orbits in km
120
121
122
123
124
125
126
127
128
		foreach ($orbitsInternal as $orbitInternal)
		{
			$dom->documentElement->appendChild($dom->importNode($orbitInternal));
		}
		
		$dom->save(LocalData.'OrbitsAll.xml');
?>