AddLocalVI.php 3.49 KB
<?php

/**
*  @file AddLocalVI.php
*  @version $Id: AddLocalVI.php,v 1.3 2010/10/29 14:03:53 budnik Exp $
*  @brief DD Server Tools: 
*  @arg    
*/

 function makeInfoXml() {

    $xml_dom = new DomDocument("1.0");
    $rootElement = $xml_dom -> createElement("VI");
    $rootElement -> appendChild($xml_dom -> createElement("Mission",mission));
    $rootElement -> appendChild($xml_dom -> createElement("Instrument",instrument));
    $rootElement -> appendChild($xml_dom -> createElement("GlobalStart"));
    $rootElement -> appendChild($xml_dom -> createElement("GlobalStop"));
    $rootElement -> appendChild($xml_dom -> createElement("MinSampling", MinSampling));
    if (MaxSampling > MinSampling)  $rootElement -> appendChild($xml_dom -> createElement("MaxSampling", MaxSampling));
    $rootElement -> appendChild($xml_dom -> createElement("LocalStart"));
    $rootElement -> appendChild($xml_dom -> createElement("LocalStop"));
    $xml_dom -> appendChild($rootElement);
    $xml_dom -> save(brief."_info.xml");
    
}

   require_once 'mgr_ini.php';
   define("CURRDIR",dirname(__FILE__));

/*
*  DEFINITIONS TO FILL
*/
   define("brief", "jedi"); // prefix
   define("ViId", "juno_jedi_i180");
   define("mission", "JUNO");
   define("instrument", "JEDI");
   define("MISSION_DIR", DDBASE."JUNO/");
   define("location", MISSION_DIR."JEDI/I_180");
   define("MinSampling", 2);
   define("MaxSampling", 3); // 0 if constant sampling
/*
*  DO NOT TOUCH
*/
      
   $times = brief."_times.nc";
   $info =  brief."_info.nc";
   $info_xml =  brief."_info.xml";
   $cache = brief."_cache.nc";

   $DDsysDoc = new DomDocument();
   $DDsysDoc->preserveWhiteSpace = false;
   $DDsysDoc->formatOutput = true;
   $DDsysDoc->load(DDBASE.DDsys);
   $dataSet = $DDsysDoc->getElementsByTagName("VI");
/*
*   Check if there is already such VI
*/
   foreach ($dataSet as $theDataSet) 
           if (strcmp($theDataSet->getElementsByTagName("NAME")->item(0)->nodeValue, ViId) == 0) 
            die(ViId." Already Exists!!!\n");
    
    $refNode = $dataSet->item(0);
    $newNode = $DDsysDoc->createElement("VI");
    $name = $newNode->appendChild($DDsysDoc->createElement("NAME",ViId));
    $name->setAttributeNode(new DOMAttr('base', 'LOCAL'));
    $name->setAttributeNode(new DOMAttr('mission', mission));
    $name->setAttributeNode(new DOMAttr('instrument', instrument));

    if (substr(location, -1) !== "/") $newNode->appendChild($DDsysDoc->createElement("LOCATION",location."/")); 
    else $newNode->appendChild($DDsysDoc->createElement("LOCATION",location));

    $newNode->appendChild($DDsysDoc->createElement("TIMES",$times));
    $newNode->appendChild($DDsysDoc->createElement("INFO",$info));
    $newNode->appendChild($DDsysDoc->createElement("CACHE",$cache));

    $newNode = $refNode->parentNode->insertBefore($newNode, $refNode);
         
    $DDsysDoc->save(DDBASE.DDsys);
    system(DDBASEBIN."/makeDDsys");  
          
/*
*   Create Real Stuff
*
*/   

  if (!is_dir(MISSION_DIR)) mkdir(MISSION_DIR);
  if (!is_dir(location)) mkdir(location, 0775, true);
  echo location."\n";
  chdir(location);
   if (!file_exists($times)) system("TimesUpdate -r ".$times." ".brief."_0*.nc");
   if (!file_exists($info_xml)) makeInfoXml();
   if (!file_exists($info)) system("infoLocal2nc ".$info_xml." ".$info);
   if (!file_exists("clean")) {
           copy (DDLIB."/Cash.template", $cache);         
           $SED = "sed 's/NAME/".brief."/g' ".DDLIB."/Clean.template > clean";
           exec($SED);
           exec('chmod ugo+x clean');
    } 
  chdir(CURRDIR);
?>