Blame view

php/makeOrbitsList.php 2.89 KB
bf74fc2d   Elena.Budnik   IMPEX
1
2
3
4
5
<?php
/*
*  Executable to make Orbits.xml with the description for all Ephemeris parameters 
*  Uses LocalParams.xml and AMDA params descriptions
*/
9c0d113f   Elena.Budnik   IMPEX final
6

f417c762   Elena.Budnik   correcte path
7
		$AMDA_IHM = getenv('AMDA_IHM');
329f027c   Elena.Budnik   updateAmda error-...
8
      error_reporting(E_ERROR);
9c0d113f   Elena.Budnik   IMPEX final
9
      
f417c762   Elena.Budnik   correcte path
10
11
12
13
		if (!isset($AMDA_IHM)) 
			require_once __DIR__."/config.php";      
		else 
			require_once $AMDA_IHM."/php/config.php"; 
bf74fc2d   Elena.Budnik   IMPEX
14
      
f417c762   Elena.Budnik   correcte path
15
		if (!defined('orbitsXml'))
bf74fc2d   Elena.Budnik   IMPEX
16
17
18
19
20
			exit("orbitsXml is not defined in config.php".PHP_EOL);
            
		$pairs = array("-" => "_" );  	
	
		$amdaXml = new DomDocument("1.0");
99ae8744   Benjamin Renard   Use config variab...
21
		$amdaXml->load(LocalData."/LocalParams.xml");
bf74fc2d   Elena.Budnik   IMPEX
22
23
24
		
		$xpath = new DOMXpath($amdaXml);
		
99ae8744   Benjamin Renard   Use config variab...
25
		$amdaParamDir = PARAMS_LOCALDB_DIR;
bf74fc2d   Elena.Budnik   IMPEX
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

		$orbitsXml =  new DomDocument("1.0");
		$orbitsXml->formatOutput = TRUE;
		$orbitsXml->preserveWhiteSpace = FALSE;
		
		$orbitsRoot = $orbitsXml->createElement('orbitesList');
		$orbitsXml->appendChild($orbitsRoot);
		
		$nodesAmda = $xpath->query('//*[@target]');
		
		foreach ($nodesAmda as $node)
		{
			$target = $node->getAttribute('target');
			
			if ( (($node->tagName == 'mission' && $node->getElementsByTagName('observatory')->length == 0) ||
  				 ($node->tagName == 'observatory') ) && $node->getAttribute('name') != $target )
			{
				$instruments =  $node->getElementsByTagName('instrument');
				foreach ($instruments as $ins)
				{
1922ad04   Elena.Budnik   getOrbites()
46
					if (substr($ins->getAttribute('name'),0,9) != 'Ephemeris') continue; // Ephemeris: cruise
bf74fc2d   Elena.Budnik   IMPEX
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
					$parameters = $ins->getElementsByTagName('parameter');
					foreach ($parameters as $parameter)
					{
						if ($parameter->hasAttribute('size') && $parameter->getAttribute('size') == '3')
						{
							$param_file = $amdaParamDir."/".$parameter->getAttribute('xml:id').".xml";
							if (file_exists($param_file))
							{
								$paramXml = simplexml_load_file($param_file);

								$orbitNode = $orbitsXml->createElement('orbites');
								$dsId = strtr($paramXml->info->dataset_id,$pairs);
								$orbitNode->setAttribute('xml:id',$parameter->getAttribute('xml:id'));
								$orbitNode->setAttribute('coordinate_system', $paramXml->info->coordinates_system);
								$orbitNode->setAttribute('units', $paramXml->info->units);
1922ad04   Elena.Budnik   getOrbites()
62
63
64
65
66
67
								
								$name = strtolower($node->getAttribute('name'));
								$name = preg_replace('/\s+/', '', $name);
								$name = str_replace('-', '', $name);
								
								$orbitNode->setAttribute('mission', $name);
bf74fc2d   Elena.Budnik   IMPEX
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
								
								if ( $node->tagName == 'observatory' )
									$orbitNode->setAttribute('missionGroup',$node->parentNode->getAttribute('name'));
									
								$orbitNode->setAttribute('dataset', $dsId);
								$ds = $amdaXml->getElementById($paramXml->info->dataset_id);
								if ($ds->hasAttribute('target'))
									$orbitNode->setAttribute('target', $ds->getAttribute('target'));
								else
									$orbitNode->setAttribute('target', $target);
								
								$orbitsRoot->appendChild($orbitNode);
							}
						}
					}
				}
			}
		}
		
		$orbitsXml->save(orbitsXml);
?>