getDataVEXGRAZ.php 2.09 KB
<?php

/**
*  @file getDataVEXGRAZ.php 
*  @version $Id: getDataVEXGRAZ.php,v 1.4 2009/08/26 09:32:56 budnik Exp $ 
*  @brief DD_Server tools <br> Gets Data from VEXGRAZ
* 
*   @arg remDataSetID  ddVIdir StartTime StopTime
*   Env Vars:  $DDBASE $DDBASEBIN \n
*   Executables: ascii2nc(DECODERS) TimesUpdate TimesUpdateNoData clean
*
*/

 require_once 'ddserver_ini.php';
 require_once 'vexgraz_ini.php';
 
 function name2DD($fileName) { 
 
  $ncName = prefix.substr($fileName,3,11).".nc"; 
 
   return $ncName;
}

/*
*  Args
*/

  $id    =  $argv[1];
  $ViDir  = $argv[2];
  $Start =  $argv[3];
  $Stop  =  $argv[4];
 
/*
*  Lock VI directory for Updating
*  Stamp -> this directory is being updated
*/  
    $LockName = $ViDir."/LOCK";
    touch($LockName); 
    fprintf(STDERR,$ViDir." is LOCKED \n");

    
/*
*    Clean VI directory 
*/
     system("cd ".$ViDir."; ./clean"); 

/*
*       SPASE Web Service getDatasetUrl()
*/ 
     $mySpaseDataAccess = new DataAccessSpase(); 

     $urlArray = $mySpaseDataAccess->getDatasetUrl($id, $Start, $Stop);
 
     if ($urlArray !== "NODATA") 
      foreach ($urlArray as $theUrl)  {

           copy($ViDir."/header.nc","temp.nc");
           $fileArr = split("/",$theUrl); 
           $fileName = $fileArr[count($fileArr)-1];
/*
*     Copy URL file to DD_Server dir and 
*     Convert ascii TAB to nc using header.nc
*/
           copy($theUrl, $fileName);
           system(DDBASEBIN."/ascii2nc ".$fileName." 1"); 
           fprintf(STDERR, "FILE $theUrl TRANSLATED  \n");
           unlink($fileName);
           $ncFile = name2DD($fileName);
/*
*       Move new nc file to VIdir
*/
             rename("temp.nc", $ViDir."/".$ncFile); 

/*
*        Updates VI time info 
*/
             system("cd ".$ViDir."; ".DDBASEBIN."/TimesUpdate -u ".prefix."_times.nc ".$ncFile);
       
            fprintf(STDERR, "TIMES IS UPDATED \n");
       }
/*
*     Fill NODATA times in VI time info
*/ 
        system("cd ".$ViDir."; ".DDBASEBIN."/TimesUpdateNoData ".prefix."_times.nc ".$argv[3]." ".$argv[4]);
/*
*    Unlock VI dir
*/
      unlink($LockName);
      fprintf(STDERR, "UNLOCK \n");
?>