makeOrbitsArgs.php 2.81 KB
<?php
/*
*  Executable to make target.json files for IMPEX url_XYZ args
*  is launched AFTER makeProxy and makeOrbitsList
*/
	 
	$AMDA_IHM = getenv('AMDA_IHM');
     
	require_once $AMDA_IHM."/php/config.php";
      
	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);	
		
// 	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);
			
	if (!file_exists(SimuTargetsXml))
		exit("ERROR : NO TargetsSimu FILE !!! Run makeProxy.php".PHP_EOL);
			
	$targetXml = simplexml_load_file(SimuTargetsXml);
	$orbitsXml = new DomDocument("1.0");
	$orbitsXml->load(orbitsAllXml);
	$xpath = new DOMXpath($orbitsXml);				
				
	$targets = $targetXml->Target;
	$unitsImpex = "km";
	
	foreach ($targets as $target) 
	{			
		if (file_exists(RemoteData."$target.json"))
			unlink(RemoteData."$target.json");
			
		$targetMain = $target['TargetMain'];
		$coordImpex = $target['CoordName'];
			
		// Mecrury double definition
		if ($coordImpex == "HSM") $coordImpex == "MSM";
		 
		// general case 
		  $params = $xpath->query('//orbites[@target="'.$target.'" and @coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'"]');	
	 
		// case of targetImpex = Jupiter.Magnetosphere; targetAmda = Jupiter
		if ($params->length == 0)
		  	$params = $xpath->query('//orbites[@target="'.$targetMain.'" and @coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'"]');
	
		// case of targetImpex = Ganymede; targetAmda = Jupiter.Ganymede
		if ($params->length == 0)
			 $params = $xpath->query('//orbites[@coordinate_system="'.$coordImpex.'" and @units="'.$unitsImpex.'" and contains(@target,"'.$target.'")]');	
				 
		if ($params->length > 0) 
		{				 				
			$dsArr = array();
			$misArr = array();
			$misGrpArr = array();
			
			foreach ($params as $param)
			{		
			   
			 //	if ($param->getAttribute('units') != $unitsImpex) continue;
				
				$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));
		}  
	}
?>