getDataTHEMIS.php 5.22 KB
<?php
/**
*  @file  getDataTHEMIS.php 
*  @version $Id: getDataTHEMIS.php,v 1.7 2010/01/11 18:16:46 budnik Exp $
*  @brief DD_Server tools <br> Gets Data from  /THEMIS_B1  (NFS)
* 
*   @arg   remDataSetID  ddVIdir StartTime StopTime \n
*   Env Vars:  $DDBASE $DDBASEBIN \n
*   Executables: [DataSet]2nc(DECODERS) TimesUpdate TimesUpdateNoData clean
*
*
*  @todo  General getData.php(dataBaseID) 
*/

  
   
// Open STDERR stream
  $STDERR = fopen("php://stderr","w");
 
//  Args
   $id    =  $argv[1];  
  
   $ViDir  = $argv[2];
   $Start =  $argv[3];  
   $Stop  =  $argv[4];  
//  NFS direcory  
   define('ThemisDir', '/THEMIS_B1/themisdata/');
   define('DataSetDir', ThemisDir.strtr($id,"_","/"));
// Env variables
   define('DDBASEBIN', getenv("DDBASEBIN"));
   define('DDBASE', getenv("DDBASE"));

  

   $arr = explode("/", $ViDir);
   $instrument = $arr[5];
   $mission = $arr[4];
   $mode = strpos($arr[6],"_") === false ? $arr[6] : substr($arr[6],0,4);
   
   
   switch ($mode) {
      case "psif" :
      case "psef" :
      case "peif" : 
      case "peef" :  
      case "peim" :
      case "peem" :
      case "h"    :
      case "l"    : 
                   $realDir =  DDBASE."/".$mission."/".$instrument."/".$arr[6]."/";
                   system("cd  $realDir ; ./clean");
                   touch($realDir."/LOCK");
fprintf($STDERR,$realDir." is LOCKED\n");                        
                   break; 
      case "peir" :
      case "peer" :
      case "peib" :
      case "peeb" :                   
                  $dirAdd = array("/sp", "/mom");
                  $fileAdd = array("s", "");
                  $realDir =   DDBASE."/".$mission."/".$instrument."/".$mode."/";
                  for ($n = 0; $n < 2; $n++) {  
                       $theDir =  $realDir.$dirAdd[$n];                                        
                       system("cd  $theDir ; ./clean ");
                       touch($theDir."/LOCK");
fprintf($STDERR,$theDir." is LOCKED\n");                           
                  }
                  break;                   
            }
   

    switch ($mode) {
      case "peif" : 
      case "peef" :  
                   $program = DDBASEBIN."/themis_esafull2nc ";
                   break;
      case "peim" :
      case "peem" : 
                   $program = DDBASEBIN."/themis_esamom2nc ";
                   break;
      case "peir" :
      case "peer" :
      case "peib" :
      case "peeb" : 
                   $program = DDBASEBIN."/themis_esa2nc ";  
                   break; 
      case "psif" : 
      case "psef" :  
                   $program = DDBASEBIN."/themis_sst2nc ";
                   break;
      case "h"   : 
      case "l"   :
                   $program = DDBASEBIN."/themis_fgm2nc ";  
                   break;    
      }
//   fprintf($STDERR, "REALDIR ".$realDir." \n");
 
// Which files 
    $currTime = strtotime($Start);
    $stopTime = strtotime($Stop);

    $currTime -= 3600.0;

    while ($currTime <= $stopTime) {
        $fileName = DataSetDir."/".date('Y', $currTime)."/".$id."_".date('Ymd', $currTime)."_v01.cdf";
 
        if (file_exists($fileName)) {             
            system($program." ".$fileName." ".$mission." ".$mode);
            fprintf($STDERR, "FILE  $fileName is TRANSLATED  \n");
          
        }
        else {
            fprintf($STDERR,"NO SUCH FILE  $fileName \n");
        }
        $currTime += 24*60*60;
   }        
 

     switch ($mode) {
                case "psif" : 
                case "psef" : 
                case "peif" : 
                case "peef" :  
                case "peim" :
                case "peem" : 
                            system("mv ".$mode."[0-9]*.nc $realDir");
                            system("cd  $realDir ;".DDBASEBIN."/TimesUpdate -u ".$mode."_times.nc ".$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData ".$mode."_times.nc ".$argv[3]." ".$argv[4]); 
                            unlink($realDir."/LOCK");
                            break; 
                case "peir" :
                case "peer" :
                case "peib" :
                case "peeb" :                   
                             for ($n = 0; $n < 2; $n++) {  
                                 $theDir =  $realDir.$dirAdd[$n];                                                                
                                 system("mv ".$fileAdd[$n].$mode."[0-9]*.nc  $theDir");
                                 system("cd  $theDir ;".DDBASEBIN."/TimesUpdate -u ".$mode."_times.nc ".$fileAdd[$n].$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData ".$mode."_times.nc ".$argv[3]." ".$argv[4]);                    
                                 unlink($theDir."/LOCK");
                               }  
                             break; 
                  case "h" :
                  case "l" : 
                            system("mv fgm".$mode."[0-9]*.nc $realDir");
                            system("cd  $realDir ;".DDBASEBIN."/TimesUpdate -u fgm".$mode."_times.nc fgm".$mode."[0-9]*.nc; ".DDBASEBIN."/TimesUpdateNoData fgm".$mode."_times.nc ".$argv[3]." ".$argv[4]); 
                            unlink($realDir."/LOCK");
                            break;  
                        } 
 
 fprintf($STDERR, "TIMES IS UPDATED \n");

 fprintf($STDERR, "UNLOCK \n");
?>