arguments.php 10.4 KB
<?php
/**
 *  arguments.php
 *
 *  @version $Id: arguments.php 2681 2014-11-28 17:08:06Z elena $
 */

/*
 *   info for spectra energies
 *
 */

function getInfo($dataSet, $infoName)
{
	$amda = new AmdaClient();
	$info = $amda->getInfo($dataSet, $infoName);

	return explode(";",$info);
}

/*
 *  special plotting arguments
 *
 */
function addPlottingSettings($option)  {

	$argsXML = new DomDocument('1.0');
	$argsXML->load(SettingsXML);
	$xPath = new domxpath($argsXML);

	if ($option)
	$plotGroups = array($option);
	else
	$plotGroups = array('Color', 'Symbol', 'Scale');

	foreach ($plotGroups as $plotGroup) {
		$group = $xPath->query("//group[@name='".$plotGroup."']");
		$groupChildren = $group->item(0)->getElementsByTagName('value');
		$args = array();
		$number = 0;
		foreach ($groupChildren as $groupChild) {
			if ($plotGroup == "Symbol") $args[] = array("arg" => $number, "value" => $groupChild->nodeValue);
			else  $args[] = array("arg" => $groupChild->nodeValue, "value" => $groupChild->nodeValue);
			$number++;
		}
		$grp[] = array("groupS" => $plotGroup, "args" => $args);
	}

	return $grp;
}


require_once 'config.php';

define('USERWSDIR', USERPATH."/".$_GET['sessionID']."/WS/"); 

$RefFrame = array("GSE", "GSM", "SM");
$OrbitPresentation = array("LINE", "TICKS", "CYL");

$paramID = $_GET['paramID'];
$isPlot = $_GET['application'] == 'plot' ? true : false;

// convert user WS
    if (!$paramID) {
        $paramID = $argv[1];
        $isPlot = true;
    }

 // to correct 'restricted' parameters  
    if (strpos($paramID, restricted) !== false) {
        $paramID = str_replace(restricted,"",$paramID);
    }
//  define('ArgumentsXML', Param.'Args/paramArguments.xml');
define('SettingsXML', Param.'Args/paramPlotSettings.xml');

$noargs = array('success' => false);

// this is WS param => plot settings
if (strncmp(strtolower($paramID), 'ws_', 3) == 0) {
	$grp = addPlottingSettings();
	exit(json_encode($grp));
}
// this is WSD param => plot settings if SIZE = 1
if (strncmp(strtolower($paramID), 'wsd_', 4) == 0) {
    $infoMgr = new ParamsInfoMgr();
    $info = $infoMgr->GetParamInfo($paramID);
 
    if (!$info || $info['success'] == false)
                exit(json_encode($noargs));

    if ($info['infos']['size'] == 1) {
        $grp = addPlottingSettings();
        exit(json_encode($grp)); 
    }
    exit(json_encode($noargs));
}
// this is SIMU param => make param
if ((strncmp(strtolower($paramID), "impex___", 8) == 0 )||(strncmp(strtolower($paramID), "spase___", 8) == 0 )) {
  if ((strncmp(strtolower($paramID), "impex___lesia_", 14) == 0 )||(strncmp(strtolower($paramID), "spase___IMPEX_NumericalOutput_lesia_", 36) == 0 )) {}
  else {
      $mySimuArgsMgr = new SimuArgsMgr();
      $mySimuArgsMgr->init($paramID);
      $grp = $mySimuArgsMgr->makeSimuArgs();
      if ($grp)
       exit(json_encode($grp));
      else exit();
    }
}

// themis_cesr
$objToTest = str_replace("_", " ", $paramID);
if (sscanf($objToTest, "th%s pe%s %s", $X, $mode, $property) == 3){
	switch ($property) {
		case "n" : $grp = addPlottingSettings();
		exit(json_encode($grp));
		case "v" :  foreach ($RefFrame as $frame) $frame_args[] = array("arg" => $frame);
		$grp[] = array("group" => "RefFrame", "args" => $frame_args);
		exit(json_encode($grp));
		case "t" :$grp = addPlottingSettings();
                exit(json_encode($grp)); 
		case "sp" :  $grp = addPlottingSettings();
		$args[] = array("arg" => "spectrogram");
		for ($i = 0; $i < 32; $i++) {
			$args[] = array("arg" => $i+1, "value" => $i+1);
		}
		$grp[] = array("group" => "Channel", "args" => $args);
		exit(json_encode($grp));
	}
} 

// Remote Data 
//TODO add method of paramInfoMgr class 
 $nameXml = RemoteData."PARAMS/".$paramID.".xml";
 $isRemote = file_exists($nameXml); 
 if ($isRemote) {
      $infoDom = new DomDocument("1.0");
      if (!$infoDom->load($nameXml))
                                exit();  
      $size = $infoDom->getElementsByTagName('DIMENSION')->item(0)->nodeValue;
      if ($size == 1) {
                $grp = addPlottingSettings();
                exit(json_encode($grp)); 
         }

       $dispay_type = $infoDom->getElementsByTagName('DISPLAY_TYPE')->item(0)->nodeValue;
       
       exit();
 }

 
$infoMgr = new ParamsInfoMgr();
$info = $infoMgr->GetParamInfo($paramID);
 
if (sscanf($paramID,"%[^'('](%d:%d)",$par,$cstart,$cstop) == 3)
{
	$isComponent = false;
}
else if (sscanf($paramID,"%[^'('](%d)",$par,$cstart) == 2)
{
	$isComponent = true;
}
else {
	$par = $paramID;
	$isComponent = false;
}

if (!$info['success'] && $isComponent) {
	// component
	$size = 1;
}
else {
	$codeinfo = $info['codeinfos'];
	$ddinfo = $info['ddinfos'];
	$size = $codeinfo ? $codeinfo['size'] : $ddinfo['parameter']['size'];
	$display_type = $ddinfo['parameter']['display_type'];
	$validmin =  $codeinfo ? $codeinfo['validmin'] : -1;
}

switch ($size) {
	// scalar - so color + symbol for all
	case 1 :
		$grp = addPlottingSettings();
		break;
	case 3 :
		// component
		if ($isComponent) $grp = addPlottingSettings();
		if ($validmin === "0") $grp = addPlottingSettings('Scale');

		if ($codeinfo && $codeinfo['frame'] && strtolower($codeinfo['frame']) == 'gse') {
			foreach ($RefFrame as $frame) $frame_args[] = array("arg" => $frame);
			$grp[] = array("group" => "RefFrame", "args" => $frame_args);
		}

		if ($codeinfo && $codeinfo['plottype'] && strtolower($codeinfo['plottype']) == 'orbit' && !$isComponent) {
			foreach ($OrbitPresentation as $frame) $type_args[] = array("arg" => $frame);
			$grp[] = array("group" => "OrbitPresentation", "args" => $type_args);
		}

		if ($ddinfo && $ddinfo['parameter']['display_type'] && $ddinfo['parameter']['display_type'] == 'orbit' && !$isComponent) {
			foreach ($OrbitPresentation as $frame) $type_args[] = array("arg" => $frame);
			$grp[] = array("group" => "OrbitPresentation", "args" => $type_args);
		}

		break;

	default:
		if ($display_type == 'spectrogram' || $display_type == 'stack_plot') {
			if ($isPlot) $args[] = array("arg" => $display_type);

	//		  error_log( $ddinfo['dataset']['id']." ".$codeinfo['energychannel'].PHP_EOL,1, email);
			$info = getInfo($ddinfo['dataset']['id'],$codeinfo['energychannel']);
			$args_bckgrd[] = array("arg" => "0", "value" => "none");
			for ($i = 0; $i < $size; $i++) {
				$args[] = array("arg" => strval($i+1), "value" => $info[$i]);
				$args_bckgrd[] = array("arg" => strval($i+1), "value" => $info[$i]);
			}
			// automatic generated args - simple case
			if ($isPlot) $grp = addPlottingSettings();
			$grp[] = array("group" => "Channel", "args" => $args);

			if ($display_type == 'spectrogram' && $isPlot)
			{
				$grp[] = array("group" => "backgrdChan", "args" => $args_bckgrd);
				$grp[] = array("group" => "backgrdVal", "args" => array("value" => "0"));
				$grp[] = array("group" => "minCount", "args" => array("value" => "0"));
				$grp[] = array("group" => "maxCount", "args" => array("value" => "0"));			
			}
		}

}


$paramArgsFile = Param.'Args/'.$par.'.xml';
if (!file_exists($paramArgsFile)) exit(json_encode($grp));


$grp = array();

// specific parameter settings if exists

$paramXML = new DomDocument('1.0');
 
$paramXML->load($paramArgsFile);
// arguments
$specialArgs = $paramXML->getElementsByTagName('specialArgs');
$paramArgs = $paramXML->getElementsByTagName('args');
 
if ($specialArgs->length > 0) {
	//spectra => tables
	$specialGroups = $specialArgs->item(0)->getElementsByTagName('group');

	if ($specialGroups->length > 0) {

        foreach ($specialGroups as $spGroup) {

	  $group = $spGroup->getAttribute('name');
	  if (!$isPlot && $group == 'anode' && $specialGroups->length > 1)
                            continue;
	  $groupType = $spGroup->getAttribute('type');
	  $units = $spGroup->getAttribute('units');

	  if ($groupType != 'multi') {
	  	$argMax =  $spGroup->getAttribute('number');
	  	$argAll = $spGroup->getElementsByTagName('value');

	  	$args = array();

	  	if ($argAll->length > 0) {
	  		if ($group == 'anode')  $args[] = array("arg" => 'all', "value" => "all");

	  		for  ($i = 0; $i < $argAll->length; $i++) {                            
                            $args[] = array("arg" => $i+1, "value" => $argAll->item($i)->nodeValue);
	  		}
	  	}
	  	// create manually
	  	else {
	  		if ($group == 'anode')  $args[] = array("arg" => 'all');
	  		for ($i = 0; $i < $argMax; $i++) {
		    $args[] = array("arg" => $i+1);
	  		}
	  	}
	  	// energy or angle (3D)
	  	$groupType = $group == "energy" ? "groupE" : "group";
	  	$grp[] = array($groupType => $group, "units" => $units, "args" => $args);
	  }
	  //variable time table
	  else {
	  	$args = array();
	  	 
	  	$args[] = array("arg" => 'energyMin', "value" => $spGroup->getAttribute('emin'));
	  	$args[] = array("arg" => 'energyMax', "value" => $spGroup->getAttribute('emax'));

	  	$grp[] = array("groupEmulti" => $group, "units" => $units, "args" => $args);
	  }
		}

	}
}

if ($paramArgs->length > 0) {
	// special args
	$argSpecial =  $paramArgs->item(0)->getElementsByTagName('group');

	if ($argSpecial->length > 0) {
		foreach ($argSpecial as $group) {
			if (!$isPlot && $group->getAttribute('name') == 'elevationAsTime') continue;
			$args = array();
			$groupChildren = $group->getElementsByTagName('value');
			if ($groupChildren->length > 0) {
				$hasArgs = $group->getAttribute('args');
				$num = 0;
				$N_args = $groupChildren->length;
				foreach ($groupChildren as $child) {
					$num++;
					if ($hasArgs) {
						if ($hasArgs != 'reverse')  {
                                                        $argValue = $child->nodeValue;
                                                        if (!$isPlot && $argValue == 'spectrogram') $argValue = 'all';
                                                        $args[] = array("arg" => $num, "value" => $argValue);
						}
                                                else {                                                       
							$args[] = array("arg" => $N_args - $num, "value" => $child->nodeValue);
						}
					}
					else {
                                            $args[] = array("arg" => $child->nodeValue, "value" => $child->nodeValue);
                                         }
				}
			} // create manually
			else {
				$args[] = array("arg" => "all");
				$argMax = $group->getAttribute('number');
				for ($i = 0; $i < $argMax; $i++) {
					$args[] = array("arg" => $i+1);
				}
			}
			$grp[] = array("group" => $group->getAttribute('name'), "units" =>  $group->getAttribute('units'), "args" => $args);
	  }
	}
      
      }
     
  exit(json_encode($grp));

?>