Changeset 232

Show
Ignore:
Timestamp:
08/26/08 09:04:08
Author:
dan
Message:

--

Files:

Legend:

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

    r209 r232  
    11sub fixed_point() { 
     2 
    23 
    34  # top timestamp 
     
    842843      for my $j (0..$#this_wind_gust_data) { 
    843844        push @{$wind_gust[$i]{'data'}}, $this_wind_gust_data[$j]; 
     845        print( "$this_wind_gust_data $j: $this_wind_gust_data[$j] wind_gust $i: $wind_gust[$i]{'data'} \n" ); 
    844846      } 
    845847    } 
     
    943945       
    944946      #DWR 4/5/2008 
    945       $air_pressure[$i]{'units'} = $units_value; 
     947      #DWR v1.1.1.0 
     948      #Hardcode millibras string since the conversion below on the data is hardcoded and does not come from UDUNITS. 
     949      $air_pressure[$i]{'units'} = "millibar"; 
    946950       
    947951      # we need to loop through the attributes, so find out how many there are 
     
    972976        #also canceling conversion if air_pressure > 900 
    973977        #print "$this_air_pressure_data[$j]\n"; 
    974         if ($this_air_pressure_data[$j] == $missing_value_value || $this_air_pressure_data[$j] == $Fill_value_value || $this_air_pressure_data[$j] > 900) { $this_slope = 1; $this_intercept = 0; } else { $this_slope = 1000; $this_intercept = 0;}  
     978        if ($this_air_pressure_data[$j] == $missing_value_value || $this_air_pressure_data[$j] == $Fill_value_value || $this_air_pressure_data[$j] > 900)  
     979        {  
     980          $this_slope = 1; $this_intercept = 0; 
     981        } else 
     982        {  
     983          $this_slope = 1000; $this_intercept = 0; 
     984        }  
    975985print STATION_ID_SQLFILE "-- this_air_pressure_data[j]=".$this_air_pressure_data[$j]." missing_value_value=".$missing_value_value." Fill_value_value=".$Fill_value_value."\n"; 
    976986        push @{$air_pressure[$i]{'data'}}, 
     
    10511061      $varget = NetCDF::varget($ncid, $sea_surface_eastward_current[$i]{'var_id'}, 
    10521062        (0), $time_dim{'dim_size'}, \@this_sea_surface_eastward_current_data); 
     1063 
    10531064      if ($varget < 0) {die "ABORT! Cannot get $sea_surface_eastward_current[$i]{'var_name'} data.\n";} 
    10541065      # get all the attributes for this variable 
     
    10721083 
    10731084      #DWR 4/5/2008 
    1074       $sea_surface_eastward_current[$i]{'units'} = $units_value
     1085      $sea_surface_eastward_current[$i]{'units'} = 'm_s-1'
    10751086 
    10761087      # we need to loop through the attributes, so find out how many there are 
     
    10981109      # add a NULL where missing value 
    10991110      for my $j (0..$#this_sea_surface_eastward_current_data) { 
    1100       #cancel out conversion operation if missing value 
    1101       if ($this_sea_surface_eastward_current_data[$j] == $missing_value_value || $this_sea_surface_eastward_current_data[$j] == $Fill_value_value) { $this_slope = 1; $this_intercept = 0; } 
     1111      #cancel out conversion operation if missing value 
     1112      if ($this_sea_surface_eastward_current_data[$j] == $missing_value_value || $this_sea_surface_eastward_current_data[$j] == $Fill_value_value) { $this_slope = 1; $this_intercept = 0; } 
    11021113        push @{$sea_surface_eastward_current[$i]{'data'}}, 
    11031114          ($this_sea_surface_eastward_current_data[$j] * $this_slope + $this_intercept); 
     
    14911502                $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
    14921503                 
    1493                 $DataVal = $water_level[$i]{'reference'}
     1504                $DataVal = $this_val
    14941505                 
    14951506                if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
     
    14991510                  $this_val = 'NULL'; 
    15001511                } 
    1501                 $MLLWDataVal = $this_val; 
    1502  
     1512                $MLLWDataVal = $DataVal + $this_val; 
     1513=comment 
    15031514                if (length $water_level[$i]{'reference_to_msl'} > 0) { 
    15041515                  $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
     
    15171528                #DWR 4/5/2008 
    15181529                $NavD88DataVal = $this_val; 
     1530=cut                 
    15191531            } 
    15201532            obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     
    15261538                                              'm(MLLW)', 
    15271539                                              $rObsHash ); 
     1540=comment 
    15281541            obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
    15291542                                              $KMLTimeStamp[$j], 
     
    15421555                                              'm(NAVD88)', 
    15431556                                              $rObsHash ); 
     1557=cut                                               
    15441558          }                                                       
    15451559        } 
     
    20082022 
    20092023              if ($wind_gust[$j]{'data'}[$k] == $missing_value_value 
    2010                 || $wind_gust[$j]{'data'}[$k] == $Fill_value_value 
    2011                 || $wind_gust[$j]{'data'}[$k] == '') { 
     2024                || $wind_gust[$j]{'data'}[$k] == $Fill_value_value ) 
     2025                #|| $wind_gust[$j]{'data'}[$k] == '') DWR v1.1.2.0 
     2026              { 
    20122027                print WIND_SQLFILE ',NULL'; 
    20132028              } 
     
    20892104 
    20902105                  if ($wind_gust[$j]{'data'}[$k] != $missing_value_value 
    2091                       && $wind_gust[$j]{'data'}[$k] != $Fill_value_value 
    2092                       && $wind_gust[$j]{'data'}[$k] != '')  
     2106                      && $wind_gust[$j]{'data'}[$k] != $Fill_value_value ) 
     2107                      #&& $wind_gust[$j]{'data'}[$k] != '') DWR v1.1.2.0 
    20932108                  { 
    20942109                    $WindGstDataVal = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     
    23722387            }            
    23732388            my $strUnits; 
     2389            #DWR v1.1.1.0 
     2390            #Added UnitsStringConversionfucntion. 
     2391            $strUnits = obsKMLSubRoutines::UnitsStringConversion( $salinity[$i]{'units'}, $XMLControlFile );  
     2392             
    23742393            if( lc( $salinity[$i]{'units'} ) eq 'ppt' ) 
    23752394            { 
     
    25102529              my $ECurrentDataVal = 'NULL'; 
    25112530              my $NCurrentDataVal = 'NULL'; 
    2512               my $Height = '';             
     2531              my @VectorDataVal; 
     2532              my $Height = '';      
     2533              my $strUnits; 
     2534              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_eastward_current[$i]{'units'}, $XMLControlFile );         
     2535              if( length( $strUnits ) == 0 ) 
     2536              { 
     2537                #DWR v1.1.0.0 
     2538                #Make sure we don't have any unprintable characters.             
     2539                $strUnits = obsKMLSubRoutines::CleanString( $sea_surface_eastward_current[$i]{'units'} );                  
     2540              } 
     2541 
    25132542              if( $this_time_stamp_sec > $oldest_ok_timestamp ) 
    25142543              {              
     
    25242553                  { 
    25252554                    $Height = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'});                 
    2526                   } 
     2555                  }  
    25272556                  $ECurrentDataVal = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); 
    25282557                   
    25292558                  $NCurrentDataVal = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); 
    2530  
     2559                  @VectorDataVal = get_mag_and_dir( $ECurrentDataVal, $NCurrentDataVal, 1 ); 
    25312560                } 
    2532                 my $strUnits; 
    2533                 $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_eastward_current[$i]{'units'}, $XMLControlFile );         
    2534                 if( length( $strUnits ) == 0 ) 
    2535                 { 
    2536                   #DWR v1.1.0.0 
    2537                   #Make sure we don't have any unprintable characters.             
    2538                   $strUnits = obsKMLSubRoutines::CleanString( $sea_surface_eastward_current[$i]{'units'} );                  
    2539                 } 
    2540                  
    2541                 obsKMLSubRoutines::KMLAddObsToHash( 'eastward_current',  
     2561                obsKMLSubRoutines::KMLAddObsToHash( 'current_to_direction',  
    25422562                                                    $KMLTimeStamp[$k], 
    2543                                                     $ECurrentDataVal
     2563                                                    @VectorDataVal[1]
    25442564                                                    1, 
    25452565                                                    $strPlatformID, 
    25462566                                                    $Height, 
    2547                                                     $strUnits, 
     2567                                                    'degrees_true', 
     2568                                                    $rObsHash ); 
     2569 
     2570 
     2571                obsKMLSubRoutines::KMLAddObsToHash( 'current_speed',  
     2572                                                    $KMLTimeStamp[$k], 
     2573                                                    @VectorDataVal[0], 
     2574                                                    1, 
     2575                                                    $strPlatformID, 
     2576                                                    $Height, 
     2577                                                    'm_s-1', 
    25482578                                                    $rObsHash ); 
    25492579                $strUnits = ''; 
     
    26312661            print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    26322662            if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
    2633               || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
    2634               || $significant_wave_height[$i]{'data'}[$j] == '') { 
     2663              || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value ) 
     2664              #|| $significant_wave_height[$i]{'data'}[$j] == '') DWR v1.1.2.0 
     2665            { 
    26352666              print WAVE_SQLFILE ',NULL'; 
    26362667            } 
     
    26422673            } 
    26432674            if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
    2644               || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
    2645               || $dominant_wave_period[$i]{'data'}[$j] == '') { 
     2675              || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value ) 
     2676              #|| $dominant_wave_period[$i]{'data'}[$j] == '') DWR v1.1.2.0 
     2677            { 
    26462678              print WAVE_SQLFILE ',NULL'; 
    26472679            } 
     
    26892721              } 
    26902722              if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
    2691                   && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
    2692                   && $significant_wave_height[$i]{'data'}[$j] != '')  
     2723                  && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value ) 
     2724                  #&& $significant_wave_height[$i]{'data'}[$j] != '')  DWR v1.1.2.0 
    26932725              { 
    26942726                $SigWaveHgtDataVal = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
    26952727              } 
    26962728              if ($dominant_wave_period[$i]{'data'}[$j] != $missing_value_value 
    2697                 && $dominant_wave_period[$i]{'data'}[$j] != $Fill_value_value 
    2698                 && $dominant_wave_period[$i]{'data'}[$j] != '')  
     2729                && $dominant_wave_period[$i]{'data'}[$j] != $Fill_value_value ) 
     2730                #&& $dominant_wave_period[$i]{'data'}[$j] != '') DWR v1.1.2.0 
    26992731              { 
    27002732                $DomWaveDataVal = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
     
    27492781       
    27502782      my $strXMLPath;  
    2751       #my $strDate = `date  +%Y-%m-%dT%H-%M-%S`; 
     2783      #my $strDate = `date  +%H%M%S`; 
    27522784      #chomp( $strDate );       
    2753       $strXMLPath = "$strObsKMLFilePath/$this_station_id"; 
    2754       $strXMLPath = $strXMLPath . '_latest.kml'; 
     2785      my @aSrcFileParts = split( /\//, $net_cdf_file ); 
     2786      my $strSrcFileName = @aSrcFileParts[-1]; 
     2787      #Break the filename and extension apart. 
     2788      #print( "$strSrcFileName\n" ); 
     2789      my $iPos = rindex( $strSrcFileName, '.' ); 
     2790      my $strFileName = $strSrcFileName; 
     2791      if( $iPos != -1 ) 
     2792      { 
     2793        $strFileName = substr( $strSrcFileName, 0, $iPos ); 
     2794      } 
     2795      #print( "$strFileName\n" ); 
     2796       
     2797      #$strXMLPath = "$strObsKMLFilePath/$this_station_id"; 
     2798      #DWR v1.1.1.0 
     2799      #Use the source netcdf filename. 
     2800      #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 
     2801      #kml, I add the time. 
     2802      $strXMLPath = "$strObsKMLFilePath/$strFileName.kml"; 
     2803      #$strXMLPath = $strXMLPath . '_latest.kml'; 
    27552804      print( "XMLFilePath: $strXMLPath\n" ); 
    27562805      obsKMLSubRoutines::BuildKMLFile( \%ObsHash, $strXMLPath ); 
     
    27672816  } 
    27682817} 
     2818 
     2819sub get_mag_and_dir { 
     2820 
     2821my ($x, $y, $scale) = @_; 
     2822my ($mag,$angle); 
     2823 
     2824$mag = sprintf("%d",$scale*sqrt($x*$x+$y*$y)); 
     2825#print "$mag\n"; 
     2826 
     2827$angle = atan2($y,$x); 
     2828$angle = sprintf("%d",180/3.1416*$angle); 
     2829$angle = 90 - $angle; 
     2830#only return positive degrees 
     2831if ($angle < 0)  
     2832{  
     2833  $angle = 360 + $angle;  
     2834} 
     2835 
     2836my @result = ($mag, $angle); 
     2837 
     2838return (@result); 
     2839 
     2840}