Changeset 257

Show
Ignore:
Timestamp:
05/25/10 15:16:14
Author:
dan
Message:

Added relative_humidity and chl_concentration to the variables for processing.

Files:

Legend:

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

    r250 r257  
    268268        push @dominant_wave_period, {%this_dominant_wave_period}; 
    269269      } 
     270      #DWR 5/25/2010 
     271      # push all relative_humidity's onto a stack 
     272      elsif ($this_standard_name =~ /^relative_humidity$/) { 
     273        %this_relative_humidity = ( 
     274          var_name => $this_var_name, 
     275          var_id   => $i, 
     276          dim_id   => $this_var_dimid[0], 
     277          height   => '', 
     278          units    => ''        
     279        ); 
     280        push @relative_humidity, {%this_relative_humidity}; 
     281      } 
     282      #DWR 5/25/2010 
     283      # push all relative_humidity's onto a stack 
     284      elsif ($this_standard_name =~ /^chl_concentration$/) { 
     285        %this_chl_concentration = ( 
     286          var_name => $this_var_name, 
     287          var_id   => $i, 
     288          dim_id   => $this_var_dimid[0], 
     289          height   => '', 
     290          units    => ''        
     291        ); 
     292        push @chl_concentration, {%this_chl_concentration}; 
     293      } 
     294       
    270295    } 
    271296  } 
     
    13231348    } 
    13241349  } 
     1350   
     1351  #DWR 5/25/1010 
     1352  # relative_humidity's 
     1353  @this_relative_humidity_data = ''; 
     1354  for $i (0..$#relative_humidity) { 
     1355    # this variable's dimension better be time 
     1356    if ($relative_humidity[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1357      die "ABORT!  $relative_humidity[$i]{'var_name'} has wrong time dimension.\n"; 
     1358    } 
     1359    else { 
     1360      # get all the variable goodies 
     1361      $varget = NetCDF::varget($ncid, $relative_humidity[$i]{'var_id'}, 
     1362        (0), $time_dim{'dim_size'}, \@this_relative_humidity_data); 
     1363      if ($varget < 0) {die "ABORT! Cannot get $relative_humidity[$i]{'var_name'} data.\n";} 
     1364      # get all the attributes for this variable 
     1365      my $name    = ''; 
     1366      my $nc_type = ''; 
     1367      my $ndims   = ''; 
     1368      my @dimids  = ''; 
     1369      my $natts   = ''; 
     1370       
     1371      #DWR 4/5/2008 
     1372      my $units_value = ''; 
     1373      my $attget = NetCDF::attget($ncid, $relative_humidity[$i]{'var_id'}, 'units', \$units_value); 
     1374      if ($attget < 0)  
     1375      { 
     1376       die "ABORT! $relative_humidity[$i]{'var_name'} has no units.\n"; 
     1377      } 
     1378      $relative_humidity[$i]{'units'} = $units_value; 
     1379       
     1380      # we need to loop through the attributes, so find out how many there are 
     1381      my $varinq = NetCDF::varinq($ncid, $relative_humidity[$i]{'var_id'}, 
     1382        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1383      if ($varinq < 0) {die "ABORT! Cannot get $relative_humidity[$i]{'var_name'}   attributes.\n";} 
     1384      for my $k (0..$natts-1) { 
     1385        # find out about each attribute 
     1386        my $this_attname = ''; 
     1387        my $attname = NetCDF::attname($ncid, $relative_humidity[$i]{'var_id'}, $k,   \$this_attname); 
     1388        if ($attname < 0) {die "ABORT! Cannot get $relative_humidity[$i]{'var_name'} $k   attribute.\n";} 
     1389        # is this a height? 
     1390        if ($this_attname eq $height_dim{'dim_name'}) { 
     1391          my $attval = ''; 
     1392          my $attget = NetCDF::attget($ncid, $relative_humidity[$i]{'var_id'}, $this_attname,   \$attval); 
     1393          if ($attget < 0) {die "ABORT!  Cannot get $relative_humidity[$i]{'var_name'} $k   attribute.\n";} 
     1394          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1395          $relative_humidity[$i]{'height'} = $attval; 
     1396        }; 
     1397      } 
     1398      # if we didn't have an height attribute, assign the global one to this var 
     1399      if ($relative_humidity[$i]{'height'} == '') { 
     1400        $relative_humidity[$i]{'height'} = $height_value[0]; 
     1401      } 
     1402      for my $j (0..$#this_relative_humidity_data) { 
     1403        push @{$relative_humidity[$i]{'data'}}, $this_relative_humidity_data[$j]; 
     1404      } 
     1405    } 
     1406  } 
     1407  #DWR 5/25/1010 
     1408  # chl_concentration's 
     1409  @this_chl_concentration_data = ''; 
     1410  for $i (0..$#chl_concentration) { 
     1411    # this variable's dimension better be time 
     1412    if ($chl_concentration[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1413      die "ABORT!  $chl_concentration[$i]{'var_name'} has wrong time dimension.\n"; 
     1414    } 
     1415    else { 
     1416      # get all the variable goodies 
     1417      $varget = NetCDF::varget($ncid, $chl_concentration[$i]{'var_id'}, 
     1418        (0), $time_dim{'dim_size'}, \@this_chl_concentration_data); 
     1419      if ($varget < 0) {die "ABORT! Cannot get $chl_concentration[$i]{'var_name'} data.\n";} 
     1420      # get all the attributes for this variable 
     1421      my $name    = ''; 
     1422      my $nc_type = ''; 
     1423      my $ndims   = ''; 
     1424      my @dimids  = ''; 
     1425      my $natts   = ''; 
     1426       
     1427      #DWR 4/5/2008 
     1428      my $units_value = ''; 
     1429      my $attget = NetCDF::attget($ncid, $chl_concentration[$i]{'var_id'}, 'units', \$units_value); 
     1430      if ($attget < 0)  
     1431      { 
     1432       die "ABORT! $chl_concentration[$i]{'var_name'} has no units.\n"; 
     1433      } 
     1434      $chl_concentration[$i]{'units'} = $units_value; 
     1435       
     1436      # we need to loop through the attributes, so find out how many there are 
     1437      my $varinq = NetCDF::varinq($ncid, $chl_concentration[$i]{'var_id'}, 
     1438        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1439      if ($varinq < 0) {die "ABORT! Cannot get $chl_concentration[$i]{'var_name'}   attributes.\n";} 
     1440      for my $k (0..$natts-1) { 
     1441        # find out about each attribute 
     1442        my $this_attname = ''; 
     1443        my $attname = NetCDF::attname($ncid, $chl_concentration[$i]{'var_id'}, $k,   \$this_attname); 
     1444        if ($attname < 0) {die "ABORT! Cannot get $chl_concentration[$i]{'var_name'} $k   attribute.\n";} 
     1445        # is this a height? 
     1446        if ($this_attname eq $height_dim{'dim_name'}) { 
     1447          my $attval = ''; 
     1448          my $attget = NetCDF::attget($ncid, $chl_concentration[$i]{'var_id'}, $this_attname,   \$attval); 
     1449          if ($attget < 0) {die "ABORT!  Cannot get $chl_concentration[$i]{'var_name'} $k   attribute.\n";} 
     1450          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1451          $chl_concentration[$i]{'height'} = $attval; 
     1452        }; 
     1453      } 
     1454      # if we didn't have an height attribute, assign the global one to this var 
     1455      if ($chl_concentration[$i]{'height'} == '') { 
     1456        $chl_concentration[$i]{'height'} = $height_value[0]; 
     1457      } 
     1458      for my $j (0..$#this_chl_concentration_data) { 
     1459        push @{$chl_concentration[$i]{'data'}}, $this_chl_concentration_data[$j]; 
     1460      } 
     1461    } 
     1462  } 
     1463   
    13251464   
    13261465  # 
     
    28162955    }                     
    28172956  } 
     2957   
     2958  #DWR 5/25/2010 
     2959  # relative_humidity 
     2960  # Going to do this right this time.  Instead of populating each row w/ all 
     2961  # the metadata, use the station_id lookup, instead. 
     2962  if ($#relative_humidity > -1) { 
     2963    #DWR 4/5/2008 
     2964    if( $bWriteobsKMLFile ) 
     2965    { 
     2966      my $DataVal = 'NULL'; 
     2967      my $Height = ''; 
     2968      for my $i (0..$#relative_humidity)  
     2969      { 
     2970        for my $j ($iStartingNdx..$#this_relative_humidity_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2971        #for my $j (0..$#relative_humidity)  
     2972        { 
     2973          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2974          $this_time_stamp = $time_formatted_values[$j]; 
     2975          $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); 
     2976          if( $this_time_stamp_sec > $oldest_ok_timestamp ) 
     2977          {         
     2978            if ($relative_humidity[$i]{'data'}[$j] != $missing_value_value 
     2979                && $relative_humidity[$i]{'data'}[$j] != $Fill_value_value 
     2980                && $this_station_id_top_ts < $this_time_stamp_sec 
     2981                )  
     2982            { 
     2983 
     2984              if ($relative_humidity[$i]{'height'} != $missing_value_value 
     2985                && $relative_humidity[$i]{'height'} != $Fill_value_value)  
     2986              { 
     2987                $Height = sprintf("%.2f",$relative_humidity[$i]{'height'}); 
     2988              } 
     2989              $DataVal = sprintf("%.2f",$relative_humidity[$i]{'data'}[$j]); 
     2990                         
     2991            } 
     2992            my $strUnits; 
     2993            $strUnits = obsKMLSubRoutines::UnitsStringConversion( $relative_humidity[$i]{'units'}, $XMLControlFile );         
     2994            if( length( $strUnits ) == 0 ) 
     2995            { 
     2996              #DWR v1.1.0.0 
     2997              #Make sure we don't have any unprintable characters.             
     2998              $strUnits = obsKMLSubRoutines::CleanString( $relative_humidity[$i]{'units'} );   
     2999              
     3000            } 
     3001            obsKMLSubRoutines::KMLAddObsToHash( 'relative_humidity',  
     3002                                              $KMLTimeStamp[$j], 
     3003                                              $DataVal, 
     3004                                              1, 
     3005                                              $strPlatformID, 
     3006                                              $Height, 
     3007                                              $strUnits, 
     3008                                              $rObsHash ); 
     3009          }                                                 
     3010        } 
     3011      }                                             
     3012    }         
     3013  } 
     3014  #DWR 5/25/2010 
     3015  # relative_humidity 
     3016  # Going to do this right this time.  Instead of populating each row w/ all 
     3017  # the metadata, use the station_id lookup, instead. 
     3018  if ($#chl_concentration > -1) { 
     3019    #DWR 4/5/2008 
     3020    if( $bWriteobsKMLFile ) 
     3021    { 
     3022      my $DataVal = 'NULL'; 
     3023      my $Height = ''; 
     3024      for my $i (0..$#chl_concentration)  
     3025      { 
     3026        for my $j ($iStartingNdx..$#this_chl_concentration_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     3027        #for my $j (0..$#chl_concentration)  
     3028        { 
     3029          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     3030          $this_time_stamp = $time_formatted_values[$j]; 
     3031          $this_time_stamp_sec = timelocal(substr($this_time_stamp,17,2),substr($this_time_stamp,14,2),substr($this_time_stamp,11,2),substr($this_time_stamp,8,2),(substr($this_time_stamp,5,2)-1),substr($this_time_stamp,0,4)); 
     3032          if( $this_time_stamp_sec > $oldest_ok_timestamp ) 
     3033          {         
     3034            if ($chl_concentration[$i]{'data'}[$j] != $missing_value_value 
     3035                && $chl_concentration[$i]{'data'}[$j] != $Fill_value_value 
     3036                && $this_station_id_top_ts < $this_time_stamp_sec 
     3037                )  
     3038            { 
     3039 
     3040              if ($chl_concentration[$i]{'height'} != $missing_value_value 
     3041                && $chl_concentration[$i]{'height'} != $Fill_value_value)  
     3042              { 
     3043                $Height = sprintf("%.2f",$chl_concentration[$i]{'height'}); 
     3044              } 
     3045              $DataVal = sprintf("%.2f",$chl_concentration[$i]{'data'}[$j]); 
     3046                         
     3047            } 
     3048            my $strUnits; 
     3049            $strUnits = obsKMLSubRoutines::UnitsStringConversion( $chl_concentration[$i]{'units'}, $XMLControlFile );         
     3050            if( length( $strUnits ) == 0 ) 
     3051            { 
     3052              #DWR v1.1.0.0 
     3053              #Make sure we don't have any unprintable characters.             
     3054              $strUnits = obsKMLSubRoutines::CleanString( $chl_concentration[$i]{'units'} );   
     3055              
     3056            } 
     3057            obsKMLSubRoutines::KMLAddObsToHash( 'chlorophyll',  
     3058                                              $KMLTimeStamp[$j], 
     3059                                              $DataVal, 
     3060                                              1, 
     3061                                              $strPlatformID, 
     3062                                              $Height, 
     3063                                              $strUnits, 
     3064                                              $rObsHash ); 
     3065          }                                                 
     3066        } 
     3067      }                                             
     3068    }         
     3069  } 
     3070   
     3071   
     3072   
    28183073  #DWR 4/5/2008 
    28193074  if( $bWriteobsKMLFile )