Changeset 235

Show
Ignore:
Timestamp:
09/17/08 13:06:50
Author:
dan
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scout/trunk/GetLatestData.pl

    r216 r235  
    107107#my $qs_only = @ARGV[0]; 
    108108 
    109 #12/5/05 Payne Seal changed all http://nccoos.unc.edu to http://nemo.isis.unc.edu per Sara Haines 
    110 #April 9, 2008 Jeremy Cothran changed all http://nemo.isis.unc.edu to http://whewell.marine.unc.edu per Jesse Cleary 
    111  
    112 =comment 
    113 if (length($qs_only) <= 0) { 
    114   @dir_urls = ( 
    115     ##'http://nccoos.unc.edu/data/nos/proc_data/latest_v2.0' 
    116     #'http://carocoops.org/~mkanoth/seacoos_netcdf/' 
    117     #,'http://whewell.marine.unc.edu/data/nos/proc_data/latest_v2.0/' 
    118     'http://seacoos.skio.peachnet.edu/proc_data/latest_v2.0' 
    119     ##,'http://nccoos.unc.edu/data/nws_metar/proc_data/latest_v2.0' 
    120     ,'http://whewell.marine.unc.edu/data/nws_metar/proc_data/latest_v2.0/' 
    121     #,'http://trident.baruch.sc.edu/usgs_data' 
    122     #,'http://trident.baruch.sc.edu/storm_surge_data/latest' 
    123     #,'http://trident.baruch.sc.edu/storm_surge_data/netcdf_latest' 
    124     ,'http://seacoos.marine.usf.edu/data/seacoos_rt_v2' 
    125     #,'http://oceanlab.rsmas.miami.edu/ELWX5/v2' 
    126     #,'http://aigeann.ucsc.edu/cimtLatest' 
    127     ##,'http://nccoos.unc.edu/data/nc-coos/latest_v2.0' 
    128     #,'http://nemo.isis.unc.edu/data/nc-coos/latest_v2.0/' #nccoos hf radar 
    129     ##,'http://iwave.rsmas.miami.edu/wera/efs/data' 
    130     #,'http://oceanlab.rsmas.miami.edu/wera' #miami hf radar 
    131     ##,'http://ak.aoos.org/seacoos/codar' 
    132     ,'http://www.cormp.org/data' 
    133     ##'http://www.cormp.org/data' 
    134   ); 
    135 
    136 else { 
    137   @dir_urls = ( 
    138    #'http://trident.baruch.sc.edu/po.daac_data/OVW' 
    139   ); 
    140   $qs_prefix = 'qs_'; 
    141 
    142 =cut 
     109 
    143110 
    144111#DWR v1.1.0.0 
     
    148115{ 
    149116  my $cmd = "rm /home/dramage/log/cdl_0master.log"; 
    150   print( "Remove Log: $cmd\n" ); 
    151   `$cmd`;       
     117#  print( "Remove Log: $cmd\n" ); 
     118#  `$cmd`;       
    152119  #Open up a new log file. 
    153   $cmd = "echo cdl_0master log opened > /home/dramage/log/cdl_0master.log"; 
     120  $cmd = "echo cdl_0master log opened >> /home/dramage/log/cdl_0master.log"; 
    154121  `$cmd`; 
    155122} 
     
    163130  { 
    164131    my $this_dir_url = $URL->string_value();; 
    165      
    166     print "$this_dir_url\n"
     132    print('-------------------------------------------------------------------------------------------------'."\n" ); 
     133    print( "NetCDF Source URL: $this_dir_url\n" )
    167134    my @latest = get_index_match( $this_dir_url, $strFilter ); 
    168135    foreach (@latest)  
     
    170137      my $latest_file = $_; 
    171138      my $strLatestFile; 
    172       if( !MICROSOFT_PLATFORM ) 
    173       { 
    174         $strLatestFile = "$this_dir_url/$latest_file" 
    175       } 
    176       else 
    177       { 
    178         $strLatestFile = "$this_dir_url\\$latest_file" 
    179       } 
     139 
     140      $strLatestFile = "$this_dir_url/$latest_file"; 
     141 
    180142      my ($content_type, $document_length, $modified_time, $expires, $server) = head($strLatestFile); 
    181143       
    182       print "  $latest_file\n     "
     144      print( "File to check against cache: $latest_file\n" )
    183145      my $latest_file_filter = $_; 
    184146      my $latest_file_filter =~ s/-/_/g; 
     
    187149      my $strLogFile; 
    188150      $strSourceFile = "$this_dir_url/$latest_file"; 
     151       
     152      #DWR v1.1.1.0 
     153      #Find the file extension. 
     154      my $iPos = rindex( $latest_file, '.' ); 
     155      my $strFileName = $latest_file; 
     156      if( $iPos != -1 ) 
     157      { 
     158        $strFileName = substr( $latest_file, 0, $iPos ); 
     159      } 
    189160      if( !MICROSOFT_PLATFORM ) 
    190161      { 
     162        #my $strDate    = `date  +%Y%m%d%H%M%S`; 
     163        #chomp( $strDate ); 
     164        #$strFileName   = $strFileName."-$strDate.nc"; 
     165        #$strDestFile   = "$strNetCDFDir/$strFileName"; 
     166         
    191167        $strDestFile   = "$strNetCDFDir/$latest_file"; 
    192         $strLogFile    = "$strFetchLogDir/$latest_file"; 
     168        $strLogFile    = "$strFetchLogDir//$latest_file"; 
    193169      } 
    194170      else 
    195171      { 
     172        #my $strDate    = `\\UnixUtils\\usr\\local\\wbin\\date.exe  +%Y%m%d%H%M%S`; 
     173        #chomp( $strDate ); 
     174        #$strFileName   = $strFileName."-$strDate.nc"; 
     175        #$strDestFile   = "$strNetCDFDir\\$strFileName"; 
     176         
    196177        $strDestFile   = "$strNetCDFDir\\$latest_file"; 
    197178        $strLogFile    = "$strFetchLogDir\\$latest_file"; 
    198179      } 
    199       print( "strDestFile = $strDestFile strLogFile = $strLogFile\n" ); 
     180      #print( "strDestFile = $strDestFile strLogFile = $strLogFile\n" ); 
    200181       
    201182      my $bDownloadFile = 0; 
     
    203184      { 
    204185        my $last_fetch_time = <LAST_FETCH>; 
    205         print 'file last modified on record  = '.scalar localtime($last_fetch_time)."\n     "
     186        print( "\t".'Fetch log file: '.$strLogFile.' last modified on record  = '.scalar localtime($last_fetch_time)."\n" )
    206187        chop($last_fetch_time); 
    207188        if ($modified_time > $last_fetch_time) 
     
    212193      else  
    213194      { 
     195        print( "\tUnable to open Fetch log file: $strLogFile.\n" ); 
    214196        $bDownloadFile = 1; 
    215197      } 
     
    219201        if( is_success($RetVal) ) 
    220202        {         
    221           print "Downloaded: $strSourceFile to $strDestFile"
     203          print( "\tDownloaded: $strSourceFile to $strDestFile\n" )
    222204          if( $bWriteObsKML ) 
    223205          { 
     
    227209        else 
    228210        { 
    229           print "ERROR: Fail Download: $strSourceFile to $strDestFile, Return Code: $RetVal"; 
    230         } 
    231       } 
    232       print "\n     ".'file last modified            = '.scalar localtime($modified_time)."\n"; 
     211          print( "ERROR: Fail Download: $strSourceFile to $strDestFile, Return Code: $RetVal\n" ); 
     212        } 
     213      } 
     214      else 
     215      { 
     216        print( "\tNot downloaded.\n" ); 
     217      } 
     218      print( "\t".'File last modified = '.scalar localtime($modified_time)."\n" ); 
    233219      my $cmd; 
    234220      if( !MICROSOFT_PLATFORM ) 
     
    240226        $cmd = "\\UnixUtils\\usr\\local\\wbin\\touch $strFetchLogDir/$latest_file"; 
    241227      } 
    242       print( "Touch: $cmd\n" ); 
     228      #print( "\tTouch: $cmd\n" ); 
    243229      `$cmd`; 
    244230      if( !MICROSOFT_PLATFORM ) 
     
    251237      } 
    252238      `$cmd`; 
    253       if( $bProcessNetCDF
     239      if( $bDownloadFile
    254240      { 
    255241        if( !MICROSOFT_PLATFORM ) 
     
    258244          #Added the passing of $strLastNTimeStamps onto the command line. 
    259245          $cmd = "cd /home/dramage/netcdf; /usr/bin/perl /home/dramage/netcdf/cdl_0master.pl $strDestFile 1 $strDirForObsKml $strLastNTimeStamps >> /home/dramage/log/cdl_0master.log 2>&1"; 
    260           print( "ObsKML Script: $cmd\n" ); 
     246          print( "\tObsKML Script: $cmd\n" ); 
    261247          `$cmd`;       
    262248        } 
     
    269255} 
    270256if( $bProcessNetCDF ) 
    271 
     257{    
     258  #`cd /home/dramage; /home/dramage/netcdf/DirZip.sh $strDirForObsKml kml` 
     259  my $strDirtoList; 
     260  my @aFeedDirs;  
    272261  if( !MICROSOFT_PLATFORM ) 
    273   { 
    274     `cd /home/dramage; /home/dramage/DirZip.sh $strDirForObsKml kml >> GetLatestData.log 2>&1` 
    275   } 
     262  {  
     263    $strDirtoList = $strDirForObsKml."/*"; 
     264    @aFeedDirs    = `ls -dq $strDirtoList`; 
     265     
     266    #`cd /home/dramage; /home/dramage/netcdf/DirZip.sh $strDirForObsKml kml` 
     267  } 
     268  else 
     269  { 
     270    $strDirtoList = $strDirForObsKml."\\*"; 
     271    @aFeedDirs    = `\\UnixUtils\\usr\\local\\wbin\\ls -dq $strDirtoList`; 
     272  } 
     273  print( "\nNumber of directories to zip: ". @aFeedDirs . "\n" ); 
     274  foreach my $strDir (@aFeedDirs) 
     275  { 
     276    chomp( $strDir ); 
     277       
     278    my $iPos; 
     279    if( !MICROSOFT_PLATFORM ) 
     280    {  
     281      #Get rid of KML files older than 4 hours. 
     282      #print( "\tfind $strDir -maxdepth 1 -cmin +240 -exec rm -f {}\n"); 
     283      #`find $strDir -maxdepth 1 -cmin +240 -exec rm -f {} \;`; 
     284      $iPos = rindex( $strDir, '/' ); 
     285      my $strDirName = $strDir; 
     286      if( $iPos != -1 ) 
     287      { 
     288        $strDirName = substr( $strDir, $iPos+1, length( $strDir ) ); 
     289      } 
     290      my $strZipName = $strDir.'/'.$strDirName.'_latest_obskml.zip'; 
     291      print( "\tRemoving previous zip: $strZipName.\n"); 
     292      `rm $strZipName`; 
     293      #print( "\tZipping: zip -j $strZipName $strDir/*.kml\n" );  
     294      print( "\tcd $strDir ; find -iname \'*.kml\' | zip -j $strZipName -@\n" );  
     295      `cd $strDir ; find -iname '*.kml' | zip -j $strZipName -@`; 
     296       
     297      #`zip -j $strZipName $strDir/*.kml`;        
     298    } 
     299    else 
     300    { 
     301      #Get rid of KML files older than 4 hours. 
     302      #print( "\tfind $strDir -maxdepth 1 -cmin +240 -exec rm -f {}\n"); 
     303      #`\\UnixUtils\\usr\\local\\wbin\\find $strDir -maxdepth 1 -cmin +240 -exec rm -f {} \;`; 
     304      $iPos = rindex( $strDir, '\\' ); 
     305      my $strDirName = $strDir; 
     306      if( $iPos != -1 ) 
     307      { 
     308        $strDirName = substr( $strDir, $iPos+1, length( $strDir ) ); 
     309      } 
     310      my $strZipName = $strDir.'\\'.$strDirName.'_latest_obskml.zip'; 
     311      print( "\tRemoving previous zip: $strZipName.\n"); 
     312      `\\UnixUtils\\usr\\local\\wbin\\rm $strZipName`; 
     313      print( "\tcd $strDir ; \\UnixUtils\\usr\\local\\wbin\\find -iname \'*.kml\' | zip -j $strZipName -@\n" );       
     314      #print( "\tZipping: zip -j $strZipName $strDir\\*.kml\n" );        
     315      `cd $strDir ; \\UnixUtils\\usr\\local\\wbin\\find -iname '*.kml' | zip -j $strZipName -@`; 
     316      #`\\UnixUtils\\usr\\local\\wbin\\zip -j $strZipName $strDir\\*.kml`;        
     317    } 
     318  }   
    276319} 
    277320