PostProcessing.php 8.5 KB
<?php
/**
 * @class PostProcessing
 * @version $Id: PostProcessing.php 2806 2015-03-02 15:31:05Z natacha $
 *
 *
 */

  class PostProcessing  {
  
  private  $myParamsInfoMgr, $contentDom;
  protected $xmlName, $rootTag = 'orbitesList', $objTagName = 'orbites';
  protected $attributes = array('name' => '', 'type' => '', 'mission' => '', 
                                'units' => '','time_resolution' => '', 'fillval' => '',
                                'coordinate_system' => '', 'label' => '');
  
  function __construct() {
                             
                $this->myParamsInfoMgr =  new ParamsInfoMgr();	
	        $this->xmlName = orbitesXml;
		if (file_exists($this->xmlName)) unlink($this->xmlName);
	        $this->contentDom = new DomDocument("1.0");
                $this->contentDom->preserveWhiteSpace = false;
                $this->contentDom->formatOutput = true;          
		$this->createDom();
		$this->xp = new domxpath($this->contentDom);
 
	}

	protected function createDom() {
                $rootElement = $this->contentDom->createElement('orbitesList');		
                $this->contentDom->appendChild($rootElement);
		$this->contentDom->save($this->xmlName);
        }
	
/*
* Add Orbites in Orbites.xml
*/      
 	protected function addOrbites($obj) {
              
                $objList = $this->contentDom->documentElement; 		
                $newObj = $this->contentDom->createElement($this->objTagName);
                $newObj->setAttribute('xml:id',$this->id);
                $obj_arr = (array)$obj;
                foreach ($obj_arr as $key => $value) {
                	if ($key != 'xml:id') $newObj->setAttribute($key, $value);
                }
                $objList -> appendChild($newObj);       

                $this->contentDom->save($this->xmlName);
      }

  /*****************************************************************
         *                           PUBLIC FUNCTIONS
*****************************************************************/   	
	 
	public function createOrbites() {
	
	    $parametresXml = new DomDocument();
	    
	    if (file_exists(paramXml)) {
		    $parametresXml -> load(paramXml);
		    $xpath = new DOMXpath($parametresXml);
		    
		    $parametres = $xpath->query("//PARAM[@type='orbit']");

		    if (!is_null($parametres)) {
		      foreach ($parametres as $parametre) {
			   
			   $paramInfo = $this->myParamsInfoMgr->GetDDInfoFromParameterID($parametre->getAttribute('xml:id'));	      
			   $mission =  $paramInfo['submission']['id'];
			   if ($mission == '') $mission =  $paramInfo['mission_id'];
 			   
			   echo $parametre->getAttribute('xml:id')." was generated....".$mission.PHP_EOL;
			   
			   if ($mission != '') {   
			    $obj = (object)array(
				"param"   => $parametre->getAttribute('xml:id'),
				"name"	=> $parametre->getAttribute('name'),
				"type"    => $parametre->getAttribute('type'),
				"mission" => strtoupper($mission),
				"units"   => $parametre->getElementsByTagName('UNITS')->item(0)->nodeValue,
				"time_resolution" => $parametre->getElementsByTagName('TIME_RESOLUTION')->item(0)->nodeValue, 
				"fillval" => $parametre->getElementsByTagName('FILLVAL')->item(0)->nodeValue,
				"coordinate_system" => $parametre->getElementsByTagName('COORDINATE_SYSTEM')->item(0)->nodeValue, 
				"label" => $parametre->getElementsByTagName('LABEL_I')->item(0)->nodeValue
			      );
			      $this->id = $obj->param;
                              $this -> addOrbites($obj); 
			  }
		      }
		      
		   }
		   else {
		      return array('success' => false, 'message' => "Local param file is empty"); 		   
		   }
	    }
	    else {
		echo  "Local param file doesn't exist ".paramXml.PHP_EOL;
		return array('success' => false, 'message' => "Local param file doesn't exist"); 
	    }	    
	}
	
	public function createOrbitesInfoFiles($locBases){

	  $domTargets = new DomDocument();
	  if (!$domTargets->load(targetsSimu)) {
	      $msg = "Cannot load file ".targetsSimu.PHP_EOL;
	      if (!$this->updateOnly) error_log($msg,1,email);
	      continue;
	  }

	  $targets = $domTargets->getElementsByTagName('target');

	  foreach ($targets as $target) {
	  $help = "<h2> ".$target->nodeValue." </b></a></h2><UL><br/><br/><li><b>Orbits of satellites :</b><br/><br/>";  
	  foreach ($locBases as $locBase)
		{		
                      if (strpos($locBase->getAttribute('targets'),$target->nodeValue) !== FALSE){
			$sat = $locBase->nodeValue;
echo "Loc Base is $sat & target is ".$target->nodeValue.PHP_EOL;                        			
			$domName = LocalData."DD_".$sat.".xml";
			$domParamName = LocalDataParam.$sat.".xml";
			$help = $help."<p><b>$sat: </b> <br/>";
			$dom = new DomDocument();
			if (!$dom->load($domName)) {
				  $msg = "Cannot load file ".$domName.PHP_EOL;
				  print_r($msg);
				  if (!$this->updateOnly) error_log($msg,1,email);
				  continue;
			  }
			  $domParam = new DomDocument();
			if (!$domParam->load($domParamName)) {
				  $msg = "Cannot load file ".$domParamName.PHP_EOL;
				  print_r($msg);
				  if (!$this->updateOnly) error_log($msg,1,email);
				  continue;
			  }
			$domOrbites = new DomDocument();
			if (!$domOrbites->load(orbitesXml)) {
				  $msg = "Cannot load file ".orbitesXml.PHP_EOL;
				  print_r($msg);
				  if (!$this->updateOnly) error_log($msg,1,email);
				  continue;
			  }
			  $xp = new domxpath($dom);
			  $xpParam = new domxpath($domParam); 
			  $xpOrb = new domxpath($domOrbites); 

			  $body = explode('.',$target->nodeValue);
			  $query = "//dataset";   
			  $datasets = $xp->query($query);
			  if ($datasets->length > 0){
			    foreach ($datasets as $dataset){
			      $vi = $dataset->getAttribute('xml:id'); 
			      $query = "//PARAM[@vi='$vi']";
			      $param = $xpParam->query($query);
			      if($param->length > 0){
				$paramID = $param->item(0)->getAttribute('xml:id');
				$query = "//orbites[@xml:id='$paramID']";
			
				$orbites = $xpOrb->query($query);
				
				if ($orbites->length > 0) { // && $dataset->getElementsByTagName('target')->item(0)->nodeValue == $body[0]){
				 
				 if ($dataset->getElementsByTagName('target')->item(0)->nodeValue == $body[0] ){
// 				      $help = $help."<p><b>$sat: </b> ";
				      $title = $dataset->getElementsByTagName('title')->item(0)->nodeValue;
				      $start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;
				      $stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
     
				      $help = $help."$title: $start   -   $stop</p>"; 
				      if ($target->nodeValue == 'Ganymede') $help = $help."<p>You can find the Ganymede flyby TimeTable in the <b>Shared Time Tables/OTHER/ganymede_flyby</b>
				      </p><br/>1996-06-27T06:07:08  -  1996-06-27T06:52:37  45.48 min   <br/>
1996-09-06T18:32:44  -  1996-09-06T19:28:22  -  55.63 min   <br/>
1997-04-05T06:44:41  -  1997-04-05T07:40:19  -  55.63 min   <br/>
1997-05-07T15:36:54  -  1997-05-07T16:22:24  -  45.50 min   <br/>
1997-06-26T16:50:00  -  1997-06-26T17:49:56  -  59.93 min   <br/>
1997-12-15T09:30:23  -  1997-12-15T10:30:00  -  59.62 min   <br/>
2000-05-20T09:40:04  -  2000-05-20T10:40:41  -  60.62 min   <br/>
2000-12-28T07:54:41  -  2000-12-28T08:55:21  -  60.67 min   <br/>";
				  }
				  elseif ($dataset->getElementsByTagName('title')->item(0)->nodeValue == 'ToDo' ||
				  $dataset->getAttribute('name') == 'orbit'){
// 				      $help = $help."<p><b>$sat: </b> ";
				      $start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;   
				      $stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
				      $help = $help.$orbites->item(0)->getAttribute('mission')." $start   -   $stop</p>"; 
				  }
				  elseif ($dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER1' ||
					  $dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER2' ||
					  $dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER3' ||
					  $dataset->getElementsByTagName('title')->item(0)->nodeValue == 'CLUSTER4'){
// 				      $help = $help."<p><b>$sat: </b> ";
				      $start = $dataset->getElementsByTagName('dataStart')->item(0)->nodeValue;   
				      $stop = $dataset->getElementsByTagName('dataStop')->item(0)->nodeValue;
				      $help = $help.$orbites->item(0)->getAttribute('param')." $start   -   $stop</p>"; 
				  }
				
				}
			      }
			    }
			  }
                      }
                      }
                      $help = $help."</UL>";                       
                      $fileName = HELPPATH."simu/simu".$target->nodeValue;                      
		file_put_contents($fileName, $help);
		}
		return true;
	
	}
  }