getDataSKR.php 2.64 KB
<?php
/**
*  @file  getDataSKR.php 
*  @brief DD_Server tools <br> Gets Data from SKR
* 
*   @arg  remDataSetID  ddVIdir StartTime StopTime  
*   @arg Env Vars:  $DDBASE $DDBASEBIN \n
*   @arg Executables: skr2nc(DECODERS) TimesUpdate TimesUpdateNoData clean
*
*
*  @todo  General getData.php(dataBaseID)
*  @version  $Id:   $
*  @date 20 june 2008
*/
   
//  Args
  $id    =  $argv[1];
  $ViDir  = $argv[2];
  $Start =  $argv[3];
  $Stop  =  $argv[4];

// Env variables
  $DDBASEBIN = getenv("DDBASEBIN");
  $DDBASE = getenv("DDBASE");
  $MAX_NAME_LENGTH = 31;

//  SKR STUFF
   
   $url = "http://rpwsTeam:KronoS04@www.lesia.obspm.fr/kronos/"
   
// Open STDERR stream
               $STDERR = fopen("php://stderr","w");

//  Lock VI directory for Updating
//  Stamp -> this directory is being updated
    $LockName = $ViDir."/LOCK";
    touch($LockName);
  
fprintf($STDERR,$ViDir." is LOCKED\n");         
// Send - Receive query              
    $url  .= http_build_query($args); 
    $fileList = new DOMDocument();
    $fileList->load($url);
    $Files = $fileList->getElementsByTagName("url");

                fprintf($STDERR,  "FILES RETURN ". $Files->length."\n");
    
// Clean VI directory 
    system("cd ".$ViDir."; clean");            
    if ($Files->length  > 0) {            
       for ($i = 0; $i < $Files->length; $i++) {

          copy($ViDir."/header.nc","temp.nc");
          $fileName_ = explode("//",$Files->item($i)->nodeValue);
          $fileName = $fileName_[0].$passwd.$fileName_[1];        
          $fileArr = split("/",$fileName); 
// Copy URL file to DD_Server dir
            copy($fileName, $fileArr[count($fileArr)-1]);
// Convert ascii TAB to nc using header.nc
            system($DDBASEBIN."/ascii2nc ".$fileArr[count($fileArr)-1]); 
                fprintf($STDERR, "FILE $i TRANSLATED  \n");
             unlink($fileArr[count($fileArr)-1]);
            $ncFile = name2DD($fileArr[count($fileArr)-1]);  
// Truncate file if it is too long  
            $ncFileTrue = ($strLength = strlen($ncFile)) > $MAX_NAME_LENGTH ?   
              "t".substr(substr($ncFile, 0, $strLength-3), $strLength-$MAX_NAME_LENGTH+1, $MAX_NAME_LENGTH-4).".nc" : $ncFile;
// Move nc file to VIdir                        
             rename("temp.nc", $ViDir."/".$ncFileTrue); 

// Updates VI time info 
             system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdate -u ".strtolower($id)."_times.nc ".$ncFileTrue);
      } 
           fprintf($STDERR, "TIMES IS UPDATED \n");
    }

        system("cd ".$ViDir."; ".$DDBASEBIN."/TimesUpdateNoData ".strtolower($id)."_times.nc ".$argv[3]." ".$argv[4]);
// Unlock VI dir
      unlink($LockName);
      fprintf($STDERR, "UNLOCK \n");
?>