Changeset 253

Show
Ignore:
Timestamp:
08/14/09 09:19:29
Author:
dan
Message:

--

Files:

Legend:

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

    r252 r253  
    44 
    55 
     6use constant USE_DEBUG_PRINTS => 1; 
     7 
    68sub samos_moving_point 
    79{ 
     
    1517  # Open the netCDF file 
    1618 
    17   $ncid = NetCDF::open($ncFilename, NetCDF::READ); 
     19  my $ncid = NetCDF::open($ncFilename, 0); 
    1820  if($ncid < 0) 
    1921  { 
     
    2325  # 
    2426  # General file query 
    25   $inquire = NetCDF::inquire($ncid,$ndims,$nvars,$natts,$recdim); 
     27  my( $ndims,$nvars,$natts,$recdim ); 
     28  my $inquire = NetCDF::inquire($ncid,$ndims,$nvars,$natts,$recdim); 
    2629  if( $inquire < 0 ) 
    2730  { 
     
    4447  #Create the platform handle 
    4548  my $id='None'; 
    46   $attget = NetCDF::attget($ncid,NetCDF::GLOBAL,'ID',\$id); 
     49  my $attget = NetCDF::attget($ncid,NetCDF::GLOBAL,'ID',\$id); 
    4750  if( $attget < 0 ) 
    4851  { 
    4952    print( "No ID provided in file.\n" ); 
    5053  } 
    51   #my $strPlatformID = "samos.$id.ship"; 
    52   my $strPlatformID = $id; 
    53    
    54   $institution_url_value = 'http://samos.coaps.fsu.edu/html/data.php'; 
     54  my $strPlatformID = "samos.$id.ship"; 
     55  #my $strPlatformID = $id; 
     56   
     57  my $institution_url_value = 'http://samos.coaps.fsu.edu/html/data.php'; 
    5558   
    5659  my @KMLTimeStamp; 
     
    6770                       ); 
    6871   
    69   for ($i = 0; $i < $nvars; $i++)  
    70   { 
    71     my $this_var_name; 
     72  my $this_var_name; 
     73  my $timeCnt = 0; 
     74  for (my $i = 0; $i < $nvars; $i++)  
     75  { 
    7276    my $this_var_type; 
    7377    my $this_var_dims; 
     
    121125          $rTime = \%VariableHash; 
    122126           
    123           $iTimeCnt = %$rTime->{'var_name'}{$this_var_name}{'dim_name'}{'time'}{'dim_size'}; 
     127          $timeCnt = %$rTime->{'var_name'}{$this_var_name}{'dim_name'}{'time'}{'dim_size'}; 
    124128          my $strUnits = %$rTime->{'var_name'}{$this_var_name}{'units'};          
    125129          my @Data = %$rTime->{'var_name'}{$this_var_name}{'data'}; 
    126130          my $iDataSize = @{$Data[0]}; 
    127           if( $iTimeCnt != $iDataSize ) 
     131          if( $timeCnt != $iDataSize ) 
    128132          { 
    129             die( "ABORT! Time Dimension: $iTimeCnt does not match the data count: $iDataSize!\n"); 
     133            die( "ABORT! Time Dimension: $timeCnt does not match the data count: $iDataSize!\n"); 
    130134          } 
    131135        } 
     
    152156    #If we have more entries in the time_values array, let's set the starting index at the spot in the array which    
    153157    #will get us to the first of the N time stamps. 
    154     print( "iTimeCnt: $iTimeCnt iLastNTimeStamps: $iLastNTimeStamps\n" ); 
    155     if( $iTimeCnt > $iLastNTimeStamps ) 
    156     { 
    157       $iStartingNdx = $iTimeCnt - $iLastNTimeStamps; 
     158    print( "iTimeCnt: $timeCnt iLastNTimeStamps: $iLastNTimeStamps\n" ); 
     159    if( $timeCnt > $iLastNTimeStamps ) 
     160    { 
     161      $iStartingNdx = $timeCnt - $iLastNTimeStamps; 
    158162      if( USE_DEBUG_PRINTS ) 
    159163      { 
    160         print( "moving_point()::Printing Last: $iLastNTimeStamps out of $iTimeCnt entries. Starting Index: $iStartingNdx. $ncid\n" ); 
    161       } 
    162     } 
    163     elsif( $iLastNTimeStamps > $iTimeCnt ) 
    164     { 
    165       print( "moving_point()::iLastNTimeStamps: $iLastNTimeStamps is greater than total number of times in file. Resetting to iLastNTimeStamps to $iTimeCnt\n" ); 
    166       $iLastNTimeStamps = $iTimeCnt; 
    167     } 
    168   } 
     164        print( "moving_point()::Printing Last: $iLastNTimeStamps out of $timeCnt entries. Starting Index: $iStartingNdx. $ncid\n" ); 
     165      } 
     166    } 
     167    elsif( $iLastNTimeStamps > $timeCnt ) 
     168    { 
     169      print( "moving_point()::iLastNTimeStamps: $iLastNTimeStamps is greater than total number of times in file. Resetting to iLastNTimeStamps to $timeCnt\n" ); 
     170      $iLastNTimeStamps = $timeCnt; 
     171    } 
     172  } 
     173  my %ObsHash; 
    169174  # write data to file(s) 
    170   my %TimeRef = %{$time[0]}; 
    171175  my $iVarCnt = @vars; 
    172176  if( $bWriteobsKMLFile ) 
     
    174178    #TIme is always the outer loop. Each measurement is taken at a specific time.  
    175179    my $iTimeNdx = $iStartingNdx; 
    176     for( ; $iTimeNdx < $iTimeCnt; $iTimeNdx++ ) 
    177     { 
    178       $strTimeVal = getDateTimeFromEpoch( $rTime, $iTimeNdx ); 
     180    for( ; $iTimeNdx < $timeCnt; $iTimeNdx++ ) 
     181    { 
     182      my $strTimeVal = getDateTimeFromEpoch( $rTime, $iTimeNdx ); 
    179183      my( $LatVal, $LonVal ); 
    180184      netcdfFuncs::ncGetLatLong( $rLat, $rLong, $iTimeNdx, \$LatVal, \$LonVal ); 
     
    233237      #Add the $strDate which gives us a unique file name. Some providers don't uniquely name the netcdf files, so to prevent overwritting of my 
    234238      #kml, I add the time. 
    235       $strXMLPath = "$strObsKMLFilePath/$strFileName.kml"
     239      $strXMLPath = $strObsKMLFilePath . $strFileName . '.kml'
    236240      print( "XMLFilePath: $strXMLPath\n" ); 
    237241      obsKMLSubRoutines::BuildKMLFile( \%ObsHash, $strXMLPath ); 
     
    289293  my @Data = $refVarData->{'var_name'}{$strVarName}{'data'};  
    290294  #Get "missing value" value. 
    291   my $missingVal = $refVarHash->{'var_name'}{$strVarName}{'missing_value'}; 
     295  my $missingVal = $refVarData->{'var_name'}{$strVarName}{'missing_value'}; 
    292296   
    293297  my $iStartNdx = $iDataNdx; 
     
    303307    else 
    304308    { 
    305       $Val = NULL
     309      $Val = 'NULL'
    306310    } 
    307311    my $iSOrder = 1; 
    308     $obsName = convertToXeniaObsName( $strVarName ); 
     312    my $obsName = convertToXeniaObsName( $strVarName ); 
    309313    netcdfFuncs::ncOutputData( $strPlatformID, 
    310314                $obsName,