Blame view

php/RemoteDataCenter/makeOrbitsArgs.php 2.86 KB
bf74fc2d   Elena.Budnik   IMPEX
1
2
3
4
5
6
<?php
/*
*  Executable to make target.json files for IMPEX url_XYZ args
*  is launched AFTER makeProxy and makeOrbitsList
*/
	 
9c0d113f   Elena.Budnik   IMPEX final
7
8
9
	$AMDA_IHM = getenv('AMDA_IHM');
     
	require_once $AMDA_IHM."/php/config.php";
bf74fc2d   Elena.Budnik   IMPEX
10
11
12
13
14
15
16
      
	if (!defined('orbitsXml'))
		exit("orbitsXml is not defined in config.php".PHP_EOL);
		
	if (!defined('SimuTargetsXml'))
		exit('SimuTargetsXml is not defined in config.php'.PHP_EOL);	
		
63f83396   Elena.Budnik   orbit in km for i...
17
18
19
20
21
// 	if (!file_exists(orbitsXml))
// 			exit("ERROR : NO Orbites.xml FILE !!! Run makeOrbitsList.php".PHP_EOL);

	if (!file_exists(orbitsAllXml))
 			exit("ERROR : NO OrbitsAll.xml FILE !!! Run makeOrbitsList.php and makeOrbitsInKm.php".PHP_EOL);
bf74fc2d   Elena.Budnik   IMPEX
22
23
24
25
26
27
			
	if (!file_exists(SimuTargetsXml))
		exit("ERROR : NO TargetsSimu FILE !!! Run makeProxy.php".PHP_EOL);
			
	$targetXml = simplexml_load_file(SimuTargetsXml);
	$orbitsXml = new DomDocument("1.0");
63f83396   Elena.Budnik   orbit in km for i...
28
	$orbitsXml->load(orbitsAllXml);
bf74fc2d   Elena.Budnik   IMPEX
29
30
31
	$xpath = new DOMXpath($orbitsXml);				
				
	$targets = $targetXml->Target;
63f83396   Elena.Budnik   orbit in km for i...
32
	$unitsImpex = "km";
bf74fc2d   Elena.Budnik   IMPEX
33
34
35
36
37
	
	foreach ($targets as $target) 
	{			
		if (file_exists(RemoteData."$target.json"))
			unlink(RemoteData."$target.json");
b21d09b2   Elena.Budnik   mercury coord modifs
38
		 	
bf74fc2d   Elena.Budnik   IMPEX
39
40
41
		$targetMain = $target['TargetMain'];
		$coordImpex = $target['CoordName'];
			
b21d09b2   Elena.Budnik   mercury coord modifs
42
43
44
45
		// Mercury double definition
		if ($coordImpex == "HSM")  $coordImpex = "MSM";
		if ($coordImpex == "MESO") $coordImpex = "MSO";
		
bf74fc2d   Elena.Budnik   IMPEX
46
		// general case 
63f83396   Elena.Budnik   orbit in km for i...
47
		  $params = $xpath->query('//orbites[@target="'.$target.'" and @coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'"]');	
b21d09b2   Elena.Budnik   mercury coord modifs
48
		  
bf74fc2d   Elena.Budnik   IMPEX
49
50
		// case of targetImpex = Jupiter.Magnetosphere; targetAmda = Jupiter
		if ($params->length == 0)
63f83396   Elena.Budnik   orbit in km for i...
51
52
		  	$params = $xpath->query('//orbites[@target="'.$targetMain.'" and @coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'"]');
	
bf74fc2d   Elena.Budnik   IMPEX
53
54
		// case of targetImpex = Ganymede; targetAmda = Jupiter.Ganymede
		if ($params->length == 0)
63f83396   Elena.Budnik   orbit in km for i...
55
			 $params = $xpath->query('//orbites[@coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'" and contains(@target,"'.$target.'")]');	
bf74fc2d   Elena.Budnik   IMPEX
56
57
58
59
60
61
62
63
				 
		if ($params->length > 0) 
		{				 				
			$dsArr = array();
			$misArr = array();
			$misGrpArr = array();
			
			foreach ($params as $param)
63f83396   Elena.Budnik   orbit in km for i...
64
65
66
67
			{		
			   
			 //	if ($param->getAttribute('units') != $unitsImpex) continue;
				
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
89
90
				$dsId = $param->getAttribute('dataset');	
				
				if (!is_array($dsArr[$dsId])) $dsArr[$dsId] = array();
				$dsArr[$dsId][] = $param->getAttribute('xml:id');
				
				$misId = $param->getAttribute('mission');
				if (!is_array($misArr[$misId])) $misArr[$misId] = array();
				$misArr[$misId][$dsId] = $dsArr[$dsId];
				   
				// Mission Group
				if ($param->hasAttribute('missionGroup'))						
					$misGrpId = $param->getAttribute('missionGroup');
				else
					$misGrpId = 'None';
										
				if (!is_array($misGrpArr[$misGrpId])) $misGrpArr[$misGrpId] = array();
				$misGrpArr[$misGrpId][$misId] = $misArr[$misId];
			}
			
			file_put_contents(RemoteData.$target.'.json', json_encode($misGrpArr));
		}  
	}
?>