Changeset 251

Show
Ignore:
Timestamp:
05/21/09 16:03:39
Author:
dan
Message:

Sub: KMLAddObsToHash, KMLAddObsList
Changes: In the observation hash, the sorder is now a hash key and not simply a value. This allows us to have the same sensor at the same elevation, and we can distinguish them by the sorder.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • obskml/trunk/General/obsKMLSubRoutines.pm

    r248 r251  
    11####################################################################################################### 
    22#Revisions 
     3#Rev: 1.2.0.0 
     4#Author: DWR 
     5#Sub: KMLAddObsToHash, KMLAddObsList 
     6#Changes: In the observation hash, the sorder is now a hash key and not simply a value. This allows us to have the same sensor 
     7# at the same elevation, and we can distinguish them by the sorder. 
    38#Rev: 1.1.0.0 
    49#Author: DWR 
     
    229234  return( $iFoundItems ); 
    230235} 
     236####################################################################################################### 
     237#Subroutine: GetConversionUnits 
     238#Given a unit of one measurement system, this subroutine will return the equivalent unit from the  
     239# specified system. IE if you have "m" in the metric system and want the equivalent in the Imperial system. 
     240####################################################################################################### 
     241sub GetConversionUnits #($strCurrentUnits, $strDesiredUOMSystem ) 
     242{ 
     243  my ( $strCurrentUnits, $strDesiredUOMSystem ) = @_; 
     244  if( $strDesiredUOMSystem eq 'en' ) 
     245  { 
     246    if( $strCurrentUnits eq 'm' ) 
     247    { 
     248      return( 'ft' ); 
     249    } 
     250    elsif( $strCurrentUnits eq  'm_s-1' ) 
     251    { 
     252      return( 'mph' ); 
     253    } 
     254    elsif( $strCurrentUnits eq 'celsius' ) 
     255    { 
     256      return( 'fahrenheit' ); 
     257    } 
     258    elsif( $strCurrentUnits eq 'cm_s-1' ) 
     259    { 
     260      return( 'mph' ); 
     261    } 
     262    elsif( $strCurrentUnits eq 'mph' ) 
     263    { 
     264      return( 'knots' ); 
     265    } 
     266  } 
     267  else 
     268  { 
     269  } 
     270  return('') 
     271} 
    231272 
    232273####################################################################################################### 
     
    328369{ 
    329370  my ( $strPlatformID, $strPlatformURL, $Latitude, $Longitude, $rObsHash ) = @_; 
    330  
    331371  $rObsHash->{PlatformID}{$strPlatformID}{Latitude}     = $Latitude; 
    332372  $rObsHash->{PlatformID}{$strPlatformID}{Longitude}    = $Longitude; 
    333   $rObsHash->{PlatformID}{$strPlatformID}{PlatformURL}  = $strPlatformURL; 
    334    
     373  $rObsHash->{PlatformID}{$strPlatformID}{PlatformURL}  = $strPlatformURL;     
    335374} 
    336375####################################################################################################### 
     
    398437{ 
    399438  my ( $strObsName, $strDate, $Value, $SensorSOrder, $strPlatformID, $ObsElevation, $strUnits, $rObsHash ) = @_; 
    400   print( "KMLAddObsToHash:: Obs: $strObsName Date: $strDate Val: $Value SORder: $SensorSOrder Platform: $strPlatformID Elev: $ObsElevation Units: $strUnits\n" ); 
     439  print( "KMLAddObsToHash::Adding Obs: $strObsName Date: $strDate Val: $Value SORder: $SensorSOrder Platform: $strPlatformID Elev: $ObsElevation Units: $strUnits Lat: $rObsHash->{PlatformID}{$strPlatformID}{Latitude} Long: $rObsHash->{PlatformID}{$strPlatformID}{Longitude}\n" ); 
    401440  my $QCLevel = $QCLEVEL_DATANOTEVALD; 
    402   $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{uomType} = $strUnits; 
    403   $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{sorder}  = $SensorSOrder; 
     441  #DWR v1.2.0.0 Use the sorder as a has key, not just a value. 
     442  $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{sorder}{$SensorSOrder}{obsType}{$strObsName}{uomType} = $strUnits; 
     443  #$rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{sorder}  = $SensorSOrder;   
    404444  if( $Value ne 'NULL') 
    405445  { 
    406     $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{value} = $Value; 
     446    #$rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{value} = $Value; 
     447    #DWR v1.2.0.0 Use the sorder as a has key. 
     448    $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{sorder}{$SensorSOrder}{obsType}{$strObsName}{value} = $Value; 
    407449  } 
    408450  else 
     
    410452    $QCLevel = $QCLEVEL_DATAMISSING; 
    411453  } 
    412   $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{QCLevel} = $QCLevel;   
    413 
    414  
    415 ####################################################################################################### 
     454  #$rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{obsType}{$strObsName}{QCLevel} = $QCLevel;   
     455  #DWR v1.2.0.0 Use the sorder as a has key. 
     456  $rObsHash->{PlatformID}{$strPlatformID}{TimeStamp}{$strDate}{elev}{$ObsElevation}{sorder}{$SensorSOrder}{obsType}{$strObsName}{QCLevel} = $QCLevel;   
     457
     458 
     459                                     
     460###################################################################################################### 
    416461#Subroutine: BuildKMLFile 
    417462# Given a hash and a filename, this set of subroutines will build an obsKML file. 
     
    539584  my $Latitude =  $hObsList->{PlatformID}{$strPlatformID}{Latitude};        
    540585  my $Longitude =  $hObsList->{PlatformID}{$strPlatformID}{Longitude};        
    541    
    542586  KMLAddLatLong( $Doc, $Placemark, $Latitude, $Longitude ); 
    543587  KMLAddTimeStamp( $Doc, $Placemark, $Date ); 
     
    620664  foreach my $Elev ( reverse sort { $a <=> $b } keys %{$hObsList->{elev}} )   
    621665  { 
    622     foreach my $ObsType ( sort keys %{$hObsList->{elev}{$Elev}{obsType}} ) 
    623     { 
    624        
    625       #Create the obs child tag. 
    626       my $Obs = $Doc->createElement( 'obs'); 
    627  
    628       #my $strVal = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value}; 
    629       #my $strUOM = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType}; 
    630       #Add all the data for the obs. 
    631       AddChild( $Doc, $Obs, 'obsType', $ObsType ); 
    632       AddChild( $Doc, $Obs, 'value', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value} ); 
    633       AddChild( $Doc, $Obs, 'uomType', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType} ); 
    634       AddChild( $Doc, $Obs, 'elev', $Elev ); 
    635       AddChild( $Doc, $Obs, 'sorder', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{sorder} ); 
    636       if( exists $hObsList->{elev}{$Elev}{obsType}{$ObsType}{QCLevel} ) 
     666    #foreach my $ObsType ( sort keys %{$hObsList->{elev}{$Elev}{obsType}} ) 
     667    foreach my $SensorSOrder ( sort keys %{$hObsList->{elev}{$Elev}{sorder}} ) 
     668    {    
     669      foreach my $ObsType ( sort keys %{$hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}} ) 
    637670      { 
    638         my $QCLevel = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{QCLevel}; 
    639         AddChild( $Doc, $Obs, 'QCLevel', $QCLevel ); 
     671        #Create the obs child tag. 
     672        my $Obs = $Doc->createElement( 'obs'); 
     673 
     674        #my $strVal = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value}; 
     675        #my $strUOM = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType}; 
     676        #Add all the data for the obs. 
     677        AddChild( $Doc, $Obs, 'obsType', $ObsType ); 
     678         
     679        #DWR v1.2.0.0 Use the sorder as a has key. 
     680        #AddChild( $Doc, $Obs, 'value', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value} ); 
     681        AddChild( $Doc, $Obs, 'value', $hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{value} );         
     682        #AddChild( $Doc, $Obs, 'uomType', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType} ); 
     683        AddChild( $Doc, $Obs, 'uomType', $hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{uomType} ); 
     684        AddChild( $Doc, $Obs, 'elev', $Elev ); 
     685        #DWR v1.2.0.0 Use the sorder as a has key. 
     686        #AddChild( $Doc, $Obs, 'sorder', $hObsList->{elev}{$Elev}{obsType}{$ObsType}{sorder} ); 
     687        AddChild( $Doc, $Obs, 'sorder', $SensorSOrder ); 
     688        #DWR v1.2.0.0 Use the sorder as a has key. 
     689        #if( exists $hObsList->{elev}{$Elev}{obsType}{$ObsType}{QCLevel} ) 
     690        if( exists $hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{QCLevel} ) 
     691        { 
     692          #my $QCLevel = $hObsList->{elev}{$Elev}{obsType}{$ObsType}{QCLevel}; 
     693          my $QCLevel = $hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{QCLevel}; 
     694          AddChild( $Doc, $Obs, 'QCLevel', $QCLevel ); 
     695        } 
     696        #Add the child tag to the parent, ObsList. 
     697        $ObsList->appendChild( $Obs ); 
     698        #print( "obsType: $ObsType value: $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value} uomType: $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType}\n" ); 
     699        #DWR v1.1.0.0 
     700        #Each obs has its own row with the observation type, value, and units of measurement. 
     701        #DWR v1.2.0.0 Use the sorder as a has key. 
     702        $$strDescription = $$strDescription."<tr><td>$ObsType</td><td>$hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{value}</td><td>$hObsList->{elev}{$Elev}{sorder}{$SensorSOrder}{obsType}{$ObsType}{uomType}</td></tr>"; 
     703        #print( "KMLAddObsList::strDescription: $$strDescription\n" ); 
    640704      } 
    641       #Add the child tag to the parent, ObsList. 
    642       $ObsList->appendChild( $Obs ); 
    643       #print( "obsType: $ObsType value: $hObsList->{elev}{$Elev}{obsType}{$ObsType}{value} uomType: $hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType}\n" ); 
    644       #DWR v1.1.0.0 
    645       #Each obs has its own row with the observation type, value, and units of measurement. 
    646       $$strDescription = $$strDescription."<tr><td>$ObsType</td><td>$hObsList->{elev}{$Elev}{obsType}{$ObsType}{value}</td><td>$hObsList->{elev}{$Elev}{obsType}{$ObsType}{uomType}</td></tr>"; 
    647       #print( "KMLAddObsList::strDescription: $$strDescription\n" ); 
    648705    } 
    649706  }