AddLocalVI.php 2.73 KB
<?php

/**
*  @file AddLocalVI.php
*  @version 
*  @brief DD Server Tools: 
*  @arg    
*/

	if (!function_exists('__autoload')) 
	{
		function __autoload($class_name) {
				require_once $class_name . '.php';
		}
	}

   $shortopts  = "j:";
   $longopts  = array("json:");
   $options = getopt($shortopts, $longopts);
   $json_file = "";
   if (array_key_exists("json",$options)) {
      $json_file = $options["json"];
   }
   else if (array_key_exists("j",$options)) {
      $json_file = $options["j"];
   }
   if (!empty($json_file)) {
      if (!file_exists($json_file)) {
         echo "[ERROR] Cannot find json file: ".$json_file.PHP_EOL;
         exit(1);
      }
      $json_string = file_get_contents($json_file);
      $json_obj = json_decode($json_string);
      if (empty($json_obj)) {
         echo "[ERROR] Cannot decode json data from: ".$json_file.PHP_EOL;
         exit(1);
      }
   }
   
    putenv("LD_LIBRARY_PATH=".getenv("LD_LIBRARY_PATH"));
	putenv("PATH=./:".getenv("DDBASEBIN").":/bin:/usr/bin");
	set_include_path("./:".getenv("DATAMANAGER").":".getenv("REMOTEDATA").":".getenv("CALLEXT")); 

if (!isset($json_obj)) {
/*
*  DEFINITIONS TO FILL
*/
   $brief = "jedi"; // prefix $argv[1]
   $ViId = "juno_jedi_i180"; // $argv[2]
   $mission = "JUNO";  // $argv[3]
   $instrument= "JEDI"; // $argv[4]
   $mission_dir = "JUNO/"; // $argv[5]
   $location = "JEDI/I_180"; // $argv[6]
   $min_sampling = 2;// $argv[7]
   $max_sampling = 3;// $argv[8]  // 0 if constant sampling
   $no_compression = TRUE; // set to FALSE to compress data file
/*
*  DO NOT TOUCH
*/
}
else {
   if (!isset($json_obj->brief) || !isset($json_obj->ViId) || !isset($json_obj->mission) || !isset($json_obj->instrument) ||
       !isset($json_obj->mission_dir) || !isset($json_obj->location) || !isset($json_obj->min_sampling)) {
      echo "[ERROR] Missing some required arguments in json file: ".$json_file.PHP_EOL;
      exit(1);
   }
   $brief = $json_obj->brief;
   $ViId = $json_obj->ViId;
   $mission = $json_obj->mission;
   $instrument = $json_obj->instrument;
   $mission_dir = $json_obj->mission_dir;
   $location = $json_obj->location;
   $min_sampling = $json_obj->min_sampling;
   $max_sampling = isset($json_obj->max_sampling) ? $json_obj->max_sampling : 0;
   $no_compression = isset($json_obj->no_compression) ? $json_obj->no_compression : false;
}
   $base = "LOCAL";
	$baseMgr = new DDBaseMgr();

	if ($baseMgr->viExists($ViId, $base)) die("$ViId Already Exists!!!".PHP_EOL);

	$baseMgr->setViId($ViId);
	$baseMgr->setViInfo($brief);
	$baseMgr->setViParentsInfo($base, $mission, $instrument);
	$baseMgr->setViLocation($mission_dir, $location);
	$baseMgr->setViSampling($min_sampling, $max_sampling);
	$baseMgr->setViNoCompression($no_compression);

	$baseMgr->createVi();
		 
?>