Changeset 201

Show
Ignore:
Timestamp:
06/03/08 15:48:51
Author:
dan
Message:

Added the ability to select last N times from the netcdf files when generating obskml files.
Does not apply currently to the construction of the SQL files.

Files:

Legend:

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

    r193 r201  
    99 
    1010#Get the minute so we know when we are at the top of the hour, we can delete the last hours .zip file. 
     11=comment 
    1112my $Minute; 
    1213if( !MICROSOFT_PLATFORM ) 
     
    1819  $Minute = `\\UnixUtils\\usr\\local\\wbin\\date %M`; 
    1920} 
    20  
     21=cut 
    2122my %CommandLineOptions; 
    2223GetOptions( \%CommandLineOptions, 
     
    2627            "Delete:s",             #Optional. If we are converting to obsKML and want to get rid of the netcdfs afterwards, set this to yes. 
    2728            "DownloadDir:s",        #Optional. Directory to store the downloaded netcdf files in. Default is ./latest_netcdf_files. 
    28             "FetchLogDir:s"         #Optional. Directory for log files we use to determine what the new netcdf files are to download. Default is ./fetch_logs. 
     29            "FetchLogDir:s",        #Optional. Directory for log files we use to determine what the new netcdf files are to download. Default is ./fetch_logs. 
     30            "UseLastNTimeStamps:s"  #Optional. Integer representing the last N time entries to use when converting the data to obsKML. DWR v1.1.0.0 6/2/2008 
    2931             ); 
    3032 
    3133my $strURLControlFile  = $CommandLineOptions{"URLControlFile"};  
    32 my $strFilter          = $CommandLineOptions{"FileFilter"}; 
     34my $strFilter          = $CommandLineOptions{"FileFilter"}; 
    3335my $strDirForObsKml    = $CommandLineOptions{"DirForObsKml"};  
    3436my $strDelete          = $CommandLineOptions{"DeleteFiles"};  
    3537my $strNetCDFDir       = $CommandLineOptions{"NetCDFDir"}; 
    3638my $strFetchLogDir     = $CommandLineOptions{"FetchLogDir"}; 
     39my $strLastNTimeStamps   = $CommandLineOptions{"UseLastNTimeStamps"}; #DWR v1.1.0.0 6/2/2008 
    3740if( length( $strURLControlFile ) == 0 ) 
    3841{ 
     
    4447              "--Delete specifies we delete the netcdf files after we write the ObsKML files. This is an optional argument.\n". 
    4548              "--DownloadDir is the directory to store the downloaded files. Optional, default is ./latest_netcdf_files.\n". 
    46               "--FetchLogDir is the directory were the file time stamps are stored. The script uses these files to determine which files are really the latest. Optional, default is ./fetch_logs.\n" ); 
     49              "--FetchLogDir is the directory were the file time stamps are stored. The script uses these files to determine which files are really the latest. Optional, default is ./fetch_logs.\n". 
     50              "--UseLastNTimeStamps Integer representing the last N time entries to use when converting the data to obsKML. Optional.\n" ); 
    4751} 
    4852if( length( $strNetCDFDir) == 0 ) 
     
    8690} 
    8791 
    88 print( "Command Line Options: strURLControlFile = $strURLControlFile strFilter = $strFilter strDirForObsKml = $strDirForObsKml strDelete = $strDelete strNetCDFDir = $strNetCDFDir strFetchLogDir = $strFetchLogDir\n" ); 
    89  
    9092my $bWriteObsKML = 0; 
    9193if( length( $strDirForObsKml ) != 0 ) 
     
    9395  $bWriteObsKML = 1; 
    9496} 
     97 
     98#DWR v1.1.0.0 6/2/2008 
     99if( length( $strLastNTimeStamps ) == 0 ) 
     100{ 
     101  $strLastNTimeStamps = 0; 
     102} 
     103 
     104print( "Command Line Options: strURLControlFile = $strURLControlFile strFilter = $strFilter strDirForObsKml = $strDirForObsKml strDelete = $strDelete strNetCDFDir = $strNetCDFDir strFetchLogDir = $strFetchLogDir UseLastNTimeStamps = $strLastNTimeStamps\n" ); 
     105 
    95106# qs needs its own individual cycle 
    96107#my $qs_only = @ARGV[0]; 
     
    131142=cut 
    132143 
     144#DWR v1.1.0.0 
     145#Remove the conversion log. We do this since the log gets concatenated every run, so it will get huge fast. 
     146#We just keep the log of the last run. 
     147if( !MICROSOFT_PLATFORM ) 
     148{ 
     149  my $cmd = "rm /home/dramage/log/cdl_0master.log"; 
     150  print( "Remove Log: $cmd\n" ); 
     151  `$cmd`;       
     152  #Open up a new log file. 
     153  $cmd = "echo cdl_0master log opened > /home/dramage/log/cdl_0master.log"; 
     154  `$cmd`; 
     155} 
     156 
    133157my $bProcessNetCDF = 0; 
    134158my $XMLObj = XML::LibXML->new->parse_file($strURLControlFile); 
     
    231255        if( !MICROSOFT_PLATFORM ) 
    232256        { 
    233           $cmd = "cd /home/dramage/netcdf; /usr/bin/perl /home/dramage/netcdf/cdl_0master.pl $strDestFile 2 $strDirForObsKml > /home/dramage/log/cdl_0master.log 2>&1"; 
     257          #DWR v1.1.0.0 6/2/2008  
     258          #Added the passing of $strLastNTimeStamps onto the command line. 
     259          $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"; 
    234260          print( "ObsKML Script: $cmd\n" ); 
    235261          `$cmd`;       
  • scout/trunk/cdl_0master.pl

    r190 r201  
    11############################################################################### 
    22# Revisions 
     3# REv: 1.1.0.0 
     4# Author: DWR 
     5# Date: 6/2/2008 
     6# Changes: Optional. Added command line argument LastNTimeStamps to allow the use of only the last N time stamps 
     7# of the data. 
    38# Author: DWR 
    49# Date: 4/18/2008 
     
    3035use obsKMLSubRoutines; 
    3136 
     37use constant USE_DEBUG_PRINTS => 1; 
     38 
    3239#DWR 4/7/2008 Added constants for use with ARGV[1] to tell us what file(s) to write. 
    3340use constant { 
     
    6875my $FileCreationOption = 0; 
    6976my $strObsKMLFilePath; 
     77my $iLastNTimeStamps = 0; 
    7078if( @ARGV == 0 ) 
    7179{ 
     
    7381       "Parameter 0 is the netcdf filename to process.\n". 
    7482       "Parameter 1 is an optional parameter. Valid values are: 0 Write only SQL files, 1 Write only obsKML file, or 2 Write both SQL files and obsKML file. Default value is 0.\n". 
    75        "Parameter 2 is the directory where the obsKML file is stored. If not provided the default directory is the current directory.\n" ); 
     83       "Parameter 2 is the directory where the obsKML file is stored. If not provided the default directory is the current directory.\n". 
     84       "Parameter 3 is the optional number of last N time stamps to use.\n"  
     85     ); 
    7686} 
    7787if( @ARGV > 1 ) 
     
    91101    $strObsKMLFilePath = @ARGV[2]; 
    92102  } 
     103  if( @ARGV >= 4 ) 
     104  { 
     105    $iLastNTimeStamps = @ARGV[3]; 
     106  } 
    93107} 
     108print( "Processing: $net_cdf_file---------------------------------------------------------------------------------------------------------\n" ); 
     109print( "Command Line Args: net_cdf_file: $net_cdf_file FileType=$FileCreationOption ObsKMLPath=$strObsKMLFilePath LastNTimes=$iLastNTimeStamps\n" ); 
    94110# 
    95111# Turn off fatal error aborts.  We need to allow some attributes to error out w/o crashing. 
     
    211227  }  
    212228  # Added parameters $FileCreationOption and $strObsKMLFilePath. 
    213   fixed_point($this_station_id_top_ts, $FileCreationOption, $strObsKMLDir ); 
     229  #DWR v1.1.0.0 6/2/2008 
     230  #Added use of $iLastNTimeStamps. 
     231  $iLastNTimeStamps = 4; 
     232#  fixed_point_1($this_station_id_top_ts, $FileCreationOption, $strObsKMLDir, $iLastNTimeStamps ); 
     233  fixed_point($this_station_id_top_ts, $FileCreationOption, $strObsKMLDir, $iLastNTimeStamps ); 
    214234} 
    215235elsif ($format_category_value eq 'moving-point-2D') { 
     
    225245  fixed_map(); 
    226246} 
    227  
     247=comment 
     248sub fixed_point_1 () { 
     249 
     250  # top timestamp 
     251  $this_station_id_top_ts = $_[0]; 
     252  #DWR 4/7/2008 
     253  my $FileCreationOptions = $_[1]; 
     254  my $strObsKMLFilePath = $_[2]; 
     255  #DWR v1.1.0.0 6/2/2008 
     256  my $iLastNTimeStamps  = $_[3]; 
     257   
     258  print( "fixed_point::args: this_station_id_top_ts: $this_station_id_top_ts FileCreationOptions: $FileCreationOptions strObsKMLFilePath: $strObsKMLFilePath iLastNTimeStamps: $iLastNTimeStamps\n"); 
     259  my $bWriteSQLFiles = 1; 
     260  my $bWriteobsKMLFile = 0; 
     261  if( $FileCreationOptions == WRITEKMLONLY ) 
     262  { 
     263   $bWriteSQLFiles = 0; 
     264   $bWriteobsKMLFile = 1; 
     265  } 
     266  elsif( $FileCreationOptions == WRITEBOTH ) 
     267  { 
     268   $bWriteobsKMLFile = 1;    
     269  } 
     270   
     271  #DWR 4/5/2008 
     272  #The XML file that has our obsKML units conversion. WE use it here to convert the units string names from the netcdf 
     273  #file into the strings we use in the obsKML and then in our database. 
     274  my $strUnitsXMLFilename; 
     275  $strUnitsXMLFilename = './UnitsConversion.xml'; 
     276  my $XMLControlFile = XML::LibXML->new->parse_file("$strUnitsXMLFilename"); 
     277   
     278  # 
     279  # Loop through variables looking for standard_name's 
     280   
     281  my $this_var_name = ''; 
     282  my $this_var_type = ''; 
     283  my $this_var_dims = ''; 
     284  my @this_var_dimid = ''; 
     285  my $this_var_natts = ''; 
     286  my $this_standard_name = ''; 
     287  my $j = 0; 
     288   
     289  for ($i = 0; $i < $nvars; $i++) { 
     290    my $varinq = NetCDF::varinq($ncid, $i, \$this_var_name,  
     291      \$this_var_type, \$this_var_dims, \@this_var_dimid, \$this_var_natts); 
     292    if ($varinq < 0) {die "ABORT!  Cannot get to variables.\n";} 
     293    my $attget = NetCDF::attget($ncid, $i, 'standard_name', \$this_standard_name); 
     294    if (substr($this_standard_name,length($this_standard_name)-1) eq chr(0))   {chop($this_standard_name);} 
     295    if ($attget >= 0) { 
     296      if ($this_standard_name =~ /^time$/) { 
     297        %time_dim = ( 
     298          ref_var_name => $this_var_name, 
     299          ref_var_id   => $i, 
     300          dim_id       => '', 
     301          dim_name     => '', 
     302          dim_size     => '' 
     303        ); 
     304        if ($this_var_dims != 1) {die "ABORT! Time has incorrect number of dimensions.\n";} 
     305        %time_var = ( 
     306          var_name => $this_var_name, 
     307          var_id   => $i, 
     308          dim_id   => $this_var_dimid[0] 
     309        ); 
     310      } 
     311      elsif ($this_standard_name =~ /^longitude$/) { 
     312        %longitude_dim = ( 
     313          ref_var_name => $this_var_name, 
     314          ref_var_id   => $i, 
     315          dim_id       => '', 
     316          dim_name     => '', 
     317          dim_size     => '' 
     318        ); 
     319        if ($this_var_dims != 1) {die "ABORT! Longitude has incorrect number of dimensions.\n";} 
     320        %longitude_var = ( 
     321          var_name => $this_var_name, 
     322          var_id   => $i, 
     323          dim_id   => $this_var_dimid[0] 
     324        ); 
     325      } 
     326      elsif ($this_standard_name =~ /^latitude$/) { 
     327        %latitude_dim = ( 
     328          ref_var_name => $this_var_name, 
     329          ref_var_id   => $i, 
     330          dim_id       => '', 
     331          dim_name     => '', 
     332          dim_size     => '' 
     333        ); 
     334        if ($this_var_dims != 1) {die "ABORT! Latitude has incorrect number of dimensions.\n";} 
     335        %latitude_var = ( 
     336          var_name => $this_var_name, 
     337          var_id   => $i, 
     338          dim_id   => $this_var_dimid[0] 
     339        ); 
     340      } 
     341      elsif ($this_standard_name =~ /^height$/) { 
     342        %height_dim = ( 
     343          ref_var_name => $this_var_name, 
     344          ref_var_id   => $i, 
     345          dim_id       => '', 
     346          dim_name     => '', 
     347          dim_size     => '' 
     348        ); 
     349        if ($this_var_dims != 1) {die "ABORT! Height has incorrect number of dimensions.\n";} 
     350        %height_var = ( 
     351          var_name => $this_var_name, 
     352          var_id   => $i, 
     353          dim_id   => $this_var_dimid[0], 
     354          positive => '' 
     355        ); 
     356      } 
     357      # push all water_level's onto a stack 
     358      elsif ($this_standard_name =~ /^water_level$/) { 
     359        %this_water_level = ( 
     360          var_name => $this_var_name, 
     361          var_id   => $i, 
     362          dim_id   => $this_var_dimid[0], 
     363          height   => '', 
     364          reference         => '', 
     365          reference_to_mllw => '', 
     366          reference_to_msl  => '', 
     367          reference_to_navd88  => '', 
     368          units => ''       #DWR 4/5/2008 
     369        ); 
     370        push @water_level, {%this_water_level}; 
     371      } 
     372      # push all sea_surface_temperature's onto a stack 
     373      elsif ($this_standard_name =~ /^sea_surface_temperature$/) { 
     374        %this_sea_surface_temperature = ( 
     375          var_name => $this_var_name, 
     376          var_id   => $i, 
     377          dim_id   => $this_var_dimid[0], 
     378          height   => '', 
     379          units => ''       #DWR 4/5/2008 
     380        ); 
     381        push @sea_surface_temperature, {%this_sea_surface_temperature}; 
     382      } 
     383      # push all bottom_water_temp's onto a stack 
     384      elsif ($this_standard_name =~ /^sea_bottom_temperature$/) { 
     385        %this_sea_bottom_temperature = ( 
     386          var_name => $this_var_name, 
     387          var_id   => $i, 
     388          dim_id   => $this_var_dimid[0], 
     389          height   => '', 
     390          units    => ''       #DWR 4/5/2008 
     391        ); 
     392        push @sea_bottom_temperature, {%this_sea_bottom_temperature}; 
     393      } 
     394      # push all air_temperature's onto a stack 
     395      elsif ($this_standard_name =~ /^air_temperature$/) { 
     396        %this_air_temperature = ( 
     397          var_name => $this_var_name, 
     398          var_id   => $i, 
     399          dim_id   => $this_var_dimid[0], 
     400          height   => '', 
     401          units    => ''       #DWR 4/5/2008 
     402        ); 
     403        push @air_temperature, {%this_air_temperature}; 
     404      } 
     405      # push all wind_speed's onto a stack 
     406      elsif ($this_standard_name =~ /^wind_speed$/) { 
     407        %this_wind_speed = ( 
     408          var_name          => $this_var_name, 
     409          var_id            => $i, 
     410          dim_id            => $this_var_dimid[0], 
     411          height            => '', 
     412          can_be_normalized => '', 
     413          units             => ''       #DWR 4/5/2008 
     414        ); 
     415        push @wind_speed, {%this_wind_speed}; 
     416      } 
     417      # push all wind_gust's onto a stack 
     418      elsif ($this_standard_name =~ /^wind_gust$/) { 
     419        %this_wind_gust = ( 
     420          var_name          => $this_var_name, 
     421          var_id            => $i, 
     422          dim_id            => $this_var_dimid[0], 
     423          height            => '', 
     424          can_be_normalized => '', 
     425          units             => ''       #DWR 4/5/2008 
     426        ); 
     427        push @wind_gust, {%this_wind_gust}; 
     428      } 
     429      # push all wind_from_direction's onto a stack 
     430      elsif ($this_standard_name =~ /^wind_from_direction$/) { 
     431        %this_wind_from_direction = ( 
     432          var_name => $this_var_name, 
     433          var_id            => $i, 
     434          dim_id            => $this_var_dimid[0], 
     435          height            => '', 
     436          can_be_normalized => '', 
     437          units             => ''       #DWR 4/5/2008 
     438           
     439        ); 
     440        push @wind_from_direction, {%this_wind_from_direction}; 
     441      } 
     442      # push all air_pressure's onto a stack 
     443      elsif ($this_standard_name =~ /^air_pressure$/) { 
     444        %this_air_pressure = ( 
     445          var_name => $this_var_name, 
     446          var_id   => $i, 
     447          dim_id   => $this_var_dimid[0], 
     448          height   => '', 
     449          units    => ''       #DWR 4/5/2008 
     450        ); 
     451        push @air_pressure, {%this_air_pressure}; 
     452      } 
     453      # push all salinity's onto a stack 
     454      elsif ($this_standard_name =~ /^salinity$/) { 
     455        %this_salinity = ( 
     456          var_name => $this_var_name, 
     457          var_id   => $i, 
     458          dim_id   => $this_var_dimid[0], 
     459          height   => '', 
     460          units    => ''       #DWR 4/5/2008 
     461        ); 
     462        push @salinity, {%this_salinity}; 
     463      } 
     464      # push all sea_surface_eastward_current's onto a stack 
     465      elsif ($this_standard_name =~ /^sea_surface_eastward_current$/) { 
     466        %this_sea_surface_eastward_current = ( 
     467          var_name          => $this_var_name, 
     468          var_id            => $i, 
     469          dim_id            => $this_var_dimid[0], 
     470          height            => '', 
     471          units             => ''       #DWR 4/5/2008 
     472        ); 
     473        push @sea_surface_eastward_current, {%this_sea_surface_eastward_current}; 
     474      } 
     475      # push all sea_surface_northward_current's onto a stack 
     476      elsif ($this_standard_name =~ /^sea_surface_northward_current$/) { 
     477        %this_sea_surface_northward_current = ( 
     478          var_name          => $this_var_name, 
     479          var_id            => $i, 
     480          dim_id            => $this_var_dimid[0], 
     481          height            => '', 
     482          units             => ''       #DWR 4/5/2008 
     483        ); 
     484        push @sea_surface_northward_current, {%this_sea_surface_northward_current}; 
     485      } 
     486      # push all significant_wave_height's onto a stack 
     487      elsif ($this_standard_name =~ /^significant_wave_height$/) { 
     488        %this_significant_wave_height = ( 
     489          var_name          => $this_var_name, 
     490          var_id            => $i, 
     491          dim_id            => $this_var_dimid[0], 
     492          height            => '', 
     493          units             => ''       #DWR 4/5/2008 
     494        ); 
     495        push @significant_wave_height, {%this_significant_wave_height}; 
     496      } 
     497      # push all dominant_wave_period's onto a stack 
     498      elsif ($this_standard_name =~ /^dominant_wave_period$/) { 
     499        %this_dominant_wave_period = ( 
     500          var_name          => $this_var_name, 
     501          var_id            => $i, 
     502          dim_id            => $this_var_dimid[0], 
     503          height            => '', 
     504          units             => ''       #DWR 4/5/2008 
     505        ); 
     506        push @dominant_wave_period, {%this_dominant_wave_period}; 
     507      } 
     508    } 
     509  } 
     510   
     511  # 
     512  # Required dimensions:  time, longitude, latitude, height 
     513  # Find out names through the variables. 
     514  # Abort if all are not found. 
     515   
     516  if (length($time_dim{'ref_var_name'}) < 1) { 
     517    $err .= "ABORT! No time dimension ref. found via variable.\n"; 
     518  } 
     519  if (length($longitude_dim{'ref_var_name'}) < 1) { 
     520    $err .= "ABORT! No longitude dimension ref. found via variable.\n"; 
     521  } 
     522  if (length($latitude_dim{'ref_var_name'}) < 1) { 
     523    $err .= "ABORT! No latitude dimension ref. found via variable.\n"; 
     524  } 
     525  if (length($height_dim{'ref_var_name'}) < 1) { 
     526    $err .= "ABORT! No height dimension ref. found via variable.\n"; 
     527  }  
     528  if (length $err > 0) { 
     529    die $err; 
     530  } 
     531 
     532  # 
     533  # Get the dimensions and their sizes. 
     534   
     535  # time 
     536  { 
     537    my $this_dim_size = ''; 
     538    my $this_dim_name = ''; 
     539    my $this_dim_id = NetCDF::dimid($ncid,$time_dim{'ref_var_name'}); 
     540    my $diminq = NetCDF::diminq($ncid,$this_dim_id,\$this_dim_name,\$this_dim_size); 
     541    if ($diminq >= 0) { 
     542      $time_dim{'dim_id'}   = $this_dim_id; 
     543      $time_dim{'dim_name'} = $this_dim_name; 
     544      $time_dim{'dim_size'} = $this_dim_size; 
     545    } 
     546    else { 
     547      die "ABORT! Error $diminq getting time dimension.\n"; 
     548    } 
     549  #  print "time dim_name [$time_dim{'dim_name'}] dim_size [$time_dim{'dim_size'}]\n"; 
     550  } 
     551   
     552  # longitude 
     553  { 
     554    my $this_dim_size = ''; 
     555    my $this_dim_name = ''; 
     556    my $this_dim_id = NetCDF::dimid($ncid,$longitude_dim{'ref_var_name'}); 
     557    my $diminq = NetCDF::diminq($ncid,$this_dim_id,\$this_dim_name,\$this_dim_size); 
     558    if ($diminq >= 0) { 
     559      $longitude_dim{'dim_id'}   = $this_dim_id; 
     560      $longitude_dim{'dim_name'} = $this_dim_name; 
     561      $longitude_dim{'dim_size'} = $this_dim_size; 
     562    } 
     563    else { 
     564      die "ABORT! Error $diminq getting longitude dimension.\n"; 
     565    } 
     566  #  print "longitude dim_name [$longitude_dim{'dim_name'}] dim_size [$longitude_dim{'dim_size'}]  \n"; 
     567  } 
     568   
     569  # latitude 
     570  { 
     571    my $this_dim_size = ''; 
     572    my $this_dim_name = ''; 
     573    my $this_dim_id = NetCDF::dimid($ncid,$latitude_dim{'ref_var_name'}); 
     574    my $diminq = NetCDF::diminq($ncid,$this_dim_id,\$this_dim_name,\$this_dim_size); 
     575    if ($diminq >= 0) { 
     576      $latitude_dim{'dim_id'}   = $this_dim_id; 
     577      $latitude_dim{'dim_name'} = $this_dim_name; 
     578      $latitude_dim{'dim_size'} = $this_dim_size; 
     579    } 
     580    else { 
     581      die "ABORT! Error $diminq getting latitude dimension.\n"; 
     582    } 
     583  #  print "latitude dim_name [$latitude_dim{'dim_name'}] dim_size [$latitude_dim{'dim_size'}]\n"; 
     584  } 
     585   
     586  # height 
     587  { 
     588    my $this_dim_size = ''; 
     589    my $this_dim_name = ''; 
     590    my $this_dim_id = NetCDF::dimid($ncid,$height_dim{'ref_var_name'}); 
     591    my $diminq = NetCDF::diminq($ncid,$this_dim_id,\$this_dim_name,\$this_dim_size); 
     592    if ($diminq >= 0) { 
     593      $height_dim{'dim_id'}   = $this_dim_id; 
     594      $height_dim{'dim_name'} = $this_dim_name; 
     595      $height_dim{'dim_size'} = $this_dim_size; 
     596    } 
     597    else { 
     598      die "ABORT! Error $diminq getting height dimension.\n"; 
     599    } 
     600  #  print "height dim_name [$height_dim{'dim_name'}] dim_size [$height_dim{'dim_size'}]\n"; 
     601  } 
     602   
     603  # 
     604  # Check to make sure that the required variables have 
     605  # the correct dimensions listed, e.g. time(time), longitude(longitude), etc. 
     606   
     607  # time 
     608  if ($time_var{'dim_id'} != $time_dim{'dim_id'}) { 
     609    die "ABORT! Time variable does not have correct time dimension.\n"; 
     610  } 
     611  # longitude 
     612  if ($longitude_var{'dim_id'} != $longitude_dim{'dim_id'}) { 
     613    die "ABORT! Longitude variable does not have correct longitude dimension.\n"; 
     614  } 
     615  # latitude 
     616  if ($latitude_var{'dim_id'} != $latitude_dim{'dim_id'}) { 
     617    die "ABORT! Latitude variable does not have correct latitude dimension.\n"; 
     618  } 
     619  # height 
     620  if ($height_var{'dim_id'} != $height_dim{'dim_id'}) { 
     621    die "ABORT! Height variable does not have correct height dimension.\n"; 
     622  } 
     623  
     624  # 
     625  # Get the data of the required elements. 
     626  @time_values           = ''; 
     627  @time_formatted_values = ''; 
     628  @longitude_value       = ''; 
     629  @latitude_value        = ''; 
     630  @height_value          = ''; 
     631  my $positive_value     = ''; 
     632   
     633  # time 
     634  # get all the values 
     635  my $units_value = ''; 
     636  my $varget = NetCDF::varget($ncid, $time_var{'var_id'}, (0), $time_dim{'dim_size'},   \@time_values); 
     637  if ($varget < 0) {die "ABORT! Cannot get time values.\n";} 
     638  #DWR v1.1.0.0 
     639  #If we using the last N times, let's populate the array. 
     640   my $iStartingNdx = 0; 
     641  if( $iLastNTimeStamps > 0 ) 
     642  { 
     643    #If we have more entries in the time_values array, let's set the starting index at the spot in the array which    
     644    #will get us to the first of the N time stamps. 
     645    my $iTimeCnt = @time_values; 
     646    print( "iTimeCnt: $iTimeCnt iLastNTimeStamps: $iLastNTimeStamps\n" ); 
     647    if( $iTimeCnt > $iLastNTimeStamps ) 
     648    { 
     649      $iStartingNdx = $iTimeCnt - $iLastNTimeStamps; 
     650      if( USE_DEBUG_PRINTS ) 
     651      { 
     652        print( "fixed_point()::Printing Last: $iLastNTimeStamps out of $iTimeCnt entries. Starting Index: $iStartingNdx. $ncid\n" ); 
     653      } 
     654    } 
     655  } 
     656  # get the units 
     657  my $attget = NetCDF::attget($ncid, $time_var{'var_id'}, 'units', \$units_value); 
     658  if ($attget < 0) {die "ABORT! $time_var{'var_name'} has no units.\n";} 
     659  if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     660  my $base_time = UDUNITS::scan($units_value) 
     661    || die "ABORT! Error with $time_var{'var_name'} units.\n"; 
     662  $base_time->istime() 
     663    || die "ABORT! Invalid units for $time_var{'var_name'}.\n"; 
     664   
     665  my @KMLTimeStamp; 
     666  # format the time values for database insertion (no timezone right now) 
     667  for my $i (0..$#time_values) { 
     668    # convert the time value to new value based on the time units 
     669    my $this_time_value = $base_time->valtocal($time_values[$i],  
     670      $base_year, $base_month, $base_day, $base_hour, $base_minute, $base_second) == 0 
     671      || die "ABORT! Invalid units for $time_var{'var_name'}.\n"; 
     672    $time_formatted_values[$i] = $base_year.'-' 
     673      .sprintf("%02d",$base_month).'-' 
     674      .sprintf("%02d",$base_day).' ' 
     675      .sprintf("%02d",$base_hour).':' 
     676      .sprintf("%02d",$base_minute).':' 
     677      .sprintf("%02d",$base_second); 
     678     #DWR 4/16/2008 
     679     #KML tag <TimeStamp><when> requires the date to be formatted in a YYYY-MM-DDThh:mm:ss format 
     680     $KMLTimeStamp[$i] = $base_year.'-' 
     681      .sprintf("%02d",$base_month).'-' 
     682      .sprintf("%02d",$base_day).'T' 
     683      .sprintf("%02d",$base_hour).':' 
     684      .sprintf("%02d",$base_minute).':' 
     685      .sprintf("%02d",$base_second); 
     686 
     687  } 
     688   
     689  # longitude (scalar) 
     690  $varget = NetCDF::varget($ncid, $longitude_var{'var_id'}, (0), (1), \@longitude_value); 
     691  if ($varget < 0) {die "ABORT! Cannot get longitude value.\n";} 
     692   
     693  # latitude (scalar) 
     694  $varget = NetCDF::varget($ncid, $latitude_var{'var_id'}, (0), (1), \@latitude_value); 
     695  if ($varget < 0) {die "ABORT! Cannot get latitude value.\n";} 
     696   
     697  # height 
     698  #   if count(height) == 1 then this is for all variables 
     699  #   Otherwise, we can ignore the z values passed as parameters and need 
     700  #   to look at each variable's attributes 
     701  if ($height_dim{'dim_size'} == 1) { 
     702    $varget = NetCDF::varget($ncid, $height_var{'var_id'}, (0), (1), \@height_value); 
     703    if ($varget < 0) {die "ABORT! Cannot get height value.\n";} 
     704  } 
     705  # get the positive attribute 
     706  $attget = NetCDF::attget($ncid, $height_var{'var_id'}, 'positive', \$positive_value); 
     707  if (substr($positive_value,length($positive_value)-1) eq chr(0)) {chop($positive_value);} 
     708  $height_var{'positive'} = $positive_value; 
     709 
     710  # water_level's 
     711  @this_water_level_data = ''; 
     712  for $i (0..$#water_level) { 
     713    # this variable's dimension better be time 
     714    if ($water_level[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     715      die "ABORT!  $water_level[$i]{'var_name'} has wrong time dimension.\n"; 
     716    } 
     717    else { 
     718      # get all the variable goodies 
     719      $varget = NetCDF::varget($ncid, $water_level[$i]{'var_id'}, 
     720        (0), $time_dim{'dim_size'}, \@this_water_level_data); 
     721      if ($varget < 0) {die "ABORT! Cannot get $water_level[$i]{'var_name'} data.\n";} 
     722      # get all the attributes for this variable 
     723      my $name    = ''; 
     724      my $nc_type = ''; 
     725      my $ndims   = ''; 
     726      my @dimids  = ''; 
     727      my $natts   = ''; 
     728 
     729      #DWR 4/5/2008 
     730      my $units_value = ''; 
     731      my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, 'units', \$units_value); 
     732      if ($attget < 0)  
     733      { 
     734       die "ABORT! $water_level[$i]{'var_name'} has no units.\n"; 
     735      } 
     736      $water_level[$i]{'units'} = $units_value; 
     737      # we need to loop through the attributes, so find out how many there are 
     738      my $varinq = NetCDF::varinq($ncid, $water_level[$i]{'var_id'}, 
     739        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     740      if ($varinq < 0) {die "ABORT! Cannot get $water_level[$i]{'var_name'} attributes.\n";} 
     741      for my $k (0..$natts-1) { 
     742        # find out about each attribute 
     743        my $this_attname = ''; 
     744        my $attname = NetCDF::attname($ncid, $water_level[$i]{'var_id'}, $k, \$this_attname); 
     745        if ($attname < 0) {die "ABORT! Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     746        # is this a height? 
     747        if ($this_attname eq $height_dim{'dim_name'}) { 
     748          my $attval = ''; 
     749          my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, $this_attname, \$attval); 
     750          if ($attget < 0) {die "ABORT!  Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     751          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     752          $water_level[$i]{'height'} = $attval; 
     753        } 
     754        elsif ($this_attname =~ /^reference$/) { 
     755          my $attval = ''; 
     756          my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, $this_attname, \$attval); 
     757          if ($attget < 0) {die "ABORT!  Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     758          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     759          $water_level[$i]{'reference'} = $attval; 
     760        } 
     761        elsif ($this_attname =~ /^reference_to_MLLW$/) { 
     762          my $attval = ''; 
     763          my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, $this_attname, \$attval); 
     764          if ($attget < 0) {die "ABORT!  Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     765          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     766          $water_level[$i]{'reference_to_mllw'} = $attval; 
     767        } 
     768        elsif ($this_attname =~ /^reference_to_MSL$/) { 
     769          my $attval = ''; 
     770          my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, $this_attname, \$attval); 
     771          if ($attget < 0) {die "ABORT!  Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     772          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     773          $water_level[$i]{'reference_to_msl'} = $attval; 
     774        } 
     775        elsif ($this_attname =~ /^reference_to_NAVD88$/) { 
     776          my $attval = ''; 
     777          my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, $this_attname, \$attval); 
     778          if ($attget < 0) {die "ABORT!  Cannot get $water_level[$i]{'var_name'} $k attribute.\n";} 
     779          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     780          $water_level[$i]{'reference_to_navd88'} = $attval; 
     781        }; 
     782      } 
     783      # if we didn't have an height attribute, assign the global one to this var 
     784      if ($water_level[$i]{'height'} == '') { 
     785        $water_level[$i]{'height'} = $height_value[0]; 
     786      } 
     787      for my $j (0..$#this_water_level_data) { 
     788        push @{$water_level[$i]{'data'}}, $this_water_level_data[$j]; 
     789      } 
     790    } 
     791  } 
     792   
     793  # sea_surface_temperature's 
     794  @this_sea_surface_temperature_data = ''; 
     795  for $i (0..$#sea_surface_temperature) { 
     796    # this variable's dimension better be time 
     797    if ($sea_surface_temperature[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     798      die "ABORT!  $sea_surface_temperature[$i]{'var_name'} has wrong time dimension.\n"; 
     799    } 
     800    else { 
     801      # get all the variable goodies 
     802      $varget = NetCDF::varget($ncid, $sea_surface_temperature[$i]{'var_id'}, 
     803        (0), $time_dim{'dim_size'}, \@this_sea_surface_temperature_data); 
     804      if ($varget < 0) {die "ABORT! Cannot get $sea_surface_temperature[$i]{'var_name'} data.\n";} 
     805      # get all the attributes for this variable 
     806      my $name    = ''; 
     807      my $nc_type = ''; 
     808      my $ndims   = ''; 
     809      my @dimids  = ''; 
     810      my $natts   = ''; 
     811 
     812      #DWR 4/5/2008 
     813      my $units_value = ''; 
     814      my $attget = NetCDF::attget($ncid, $sea_surface_temperature[$i]{'var_id'}, 'units', \$units_value); 
     815      if ($attget < 0)  
     816      { 
     817       die "ABORT! $sea_surface_temperature[$i]{'var_name'} has no units.\n"; 
     818      } 
     819      $sea_surface_temperature[$i]{'units'} = $units_value; 
     820       
     821      # we need to loop through the attributes, so find out how many there are 
     822      my $varinq = NetCDF::varinq($ncid, $sea_surface_temperature[$i]{'var_id'}, 
     823        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     824      if ($varinq < 0) {die "ABORT! Cannot get $sea_surface_temperature[$i]{'var_name'}   attributes.\n";} 
     825      for my $k (0..$natts-1) { 
     826        # find out about each attribute 
     827        my $this_attname = ''; 
     828        my $attname = NetCDF::attname($ncid, $sea_surface_temperature[$i]{'var_id'}, $k,   \$this_attname); 
     829        if ($attname < 0) {die "ABORT! Cannot get $sea_surface_temperature[$i]{'var_name'} $k   attribute.\n";} 
     830        # is this a height? 
     831        if ($this_attname eq $height_dim{'dim_name'}) { 
     832          my $attval = ''; 
     833          my $attget = NetCDF::attget($ncid, $sea_surface_temperature[$i]{'var_id'}, $this_attname,   \$attval); 
     834          if ($attget < 0) {die "ABORT!  Cannot get $sea_surface_temperature[$i]{'var_name'} $k   attribute.\n";} 
     835          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     836          $sea_surface_temperature[$i]{'height'} = $attval; 
     837        }; 
     838      } 
     839      # if we didn't have an height attribute, assign the global one to this var 
     840      if ($sea_surface_temperature[$i]{'height'} == '') { 
     841        $sea_surface_temperature[$i]{'height'} = $height_value[0]; 
     842      } 
     843      for my $j (0..$#this_sea_surface_temperature_data) { 
     844        push @{$sea_surface_temperature[$i]{'data'}}, $this_sea_surface_temperature_data[$j]; 
     845      } 
     846    } 
     847  } 
     848 
     849  # sea_bottom_temperature's 
     850  @this_sea_bottom_temperature_data = ''; 
     851  for $i (0..$#sea_bottom_temperature) { 
     852    # this variable's dimension better be time 
     853    if ($sea_bottom_temperature[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     854      die "ABORT!  $sea_bottom_temperature[$i]{'var_name'} has wrong time dimension.\n"; 
     855    } 
     856    else { 
     857      # get all the variable goodies 
     858      $varget = NetCDF::varget($ncid, $sea_bottom_temperature[$i]{'var_id'}, 
     859        (0), $time_dim{'dim_size'}, \@this_sea_bottom_temperature_data); 
     860      if ($varget < 0) {die "ABORT! Cannot get $sea_bottom_temperature[$i]{'var_name'} data.\n";} 
     861      # get all the attributes for this variable 
     862      my $name    = ''; 
     863      my $nc_type = ''; 
     864      my $ndims   = ''; 
     865      my @dimids  = ''; 
     866      my $natts   = ''; 
     867 
     868      #DWR 4/5/2008 
     869      my $units_value = ''; 
     870      my $attget = NetCDF::attget($ncid, $sea_bottom_temperature[$i]{'var_id'}, 'units', \$units_value); 
     871      if ($attget < 0)  
     872      { 
     873       die "ABORT! $sea_bottom_temperature[$i]{'var_name'} has no units.\n"; 
     874      } 
     875      $sea_bottom_temperature[$i]{'units'} = $units_value; 
     876 
     877      # we need to loop through the attributes, so find out how many there are 
     878      my $varinq = NetCDF::varinq($ncid, $sea_bottom_temperature[$i]{'var_id'}, 
     879        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     880      if ($varinq < 0) {die "ABORT! Cannot get $sea_bottom_temperature[$i]{'var_name'}   attributes.\n";} 
     881      for my $k (0..$natts-1) { 
     882        # find out about each attribute 
     883        my $this_attname = ''; 
     884        my $attname = NetCDF::attname($ncid, $sea_bottom_temperature[$i]{'var_id'}, $k,   \$this_attname); 
     885        if ($attname < 0) {die "ABORT! Cannot get $sea_bottom_temperature[$i]{'var_name'} $k   attribute.\n";} 
     886        # is this a height? 
     887        if ($this_attname eq $height_dim{'dim_name'}) { 
     888          my $attval = ''; 
     889          my $attget = NetCDF::attget($ncid, $sea_bottom_temperature[$i]{'var_id'}, $this_attname,   \$attval); 
     890          if ($attget < 0) {die "ABORT!  Cannot get $sea_bottom_temperature[$i]{'var_name'} $k   attribute.\n";} 
     891          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     892          $sea_bottom_temperature[$i]{'height'} = $attval; 
     893        }; 
     894      } 
     895      # if we didn't have an height attribute, assign the global one to this var 
     896      if ($sea_bottom_temperature[$i]{'height'} == '') { 
     897        $sea_bottom_temperature[$i]{'height'} = $height_value[0]; 
     898      } 
     899      for my $j (0..$#this_sea_bottom_temperature_data) { 
     900        push @{$sea_bottom_temperature[$i]{'data'}}, $this_sea_bottom_temperature_data[$j]; 
     901      } 
     902    } 
     903  } 
     904 
     905  # air_temperature's 
     906  @this_air_temperature_data = ''; 
     907  for $i (0..$#air_temperature) { 
     908    # this variable's dimension better be time 
     909    if ($air_temperature[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     910      die "ABORT!  $air_temperature[$i]{'var_name'} has wrong time dimension.\n"; 
     911    } 
     912    else { 
     913      # get all the variable goodies 
     914      $varget = NetCDF::varget($ncid, $air_temperature[$i]{'var_id'}, 
     915        (0), $time_dim{'dim_size'}, \@this_air_temperature_data); 
     916      if ($varget < 0) {die "ABORT! Cannot get $air_temperature[$i]{'var_name'} data.\n";} 
     917      # get all the attributes for this variable 
     918      my $name    = ''; 
     919      my $nc_type = ''; 
     920      my $ndims   = ''; 
     921      my @dimids  = ''; 
     922      my $natts   = ''; 
     923       
     924      #DWR 4/5/2008 
     925      my $units_value = ''; 
     926      my $attget = NetCDF::attget($ncid, $air_temperature[$i]{'var_id'}, 'units', \$units_value); 
     927      if ($attget < 0)  
     928      { 
     929       die "ABORT! $air_temperature[$i]{'var_name'} has no units.\n"; 
     930      } 
     931      $air_temperature[$i]{'units'} = $units_value; 
     932       
     933      # we need to loop through the attributes, so find out how many there are 
     934      my $varinq = NetCDF::varinq($ncid, $air_temperature[$i]{'var_id'}, 
     935        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     936      if ($varinq < 0) {die "ABORT! Cannot get $air_temperature[$i]{'var_name'}   attributes.\n";} 
     937      for my $k (0..$natts-1) { 
     938        # find out about each attribute 
     939        my $this_attname = ''; 
     940        my $attname = NetCDF::attname($ncid, $air_temperature[$i]{'var_id'}, $k,   \$this_attname); 
     941        if ($attname < 0) {die "ABORT! Cannot get $air_temperature[$i]{'var_name'} $k   attribute.\n";} 
     942        # is this a height? 
     943        if ($this_attname eq $height_dim{'dim_name'}) { 
     944          my $attval = ''; 
     945          my $attget = NetCDF::attget($ncid, $air_temperature[$i]{'var_id'}, $this_attname,   \$attval); 
     946          if ($attget < 0) {die "ABORT!  Cannot get $air_temperature[$i]{'var_name'} $k   attribute.\n";} 
     947          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     948          $air_temperature[$i]{'height'} = $attval; 
     949        }; 
     950      } 
     951      # if we didn't have an height attribute, assign the global one to this var 
     952      if ($air_temperature[$i]{'height'} == '') { 
     953        $air_temperature[$i]{'height'} = $height_value[0]; 
     954      } 
     955      for my $j (0..$#this_air_temperature_data) { 
     956        push @{$air_temperature[$i]{'data'}}, $this_air_temperature_data[$j]; 
     957      } 
     958    } 
     959  } 
     960 
     961  # wind_speed's 
     962  @this_wind_speed_data = ''; 
     963  for $i (0..$#wind_speed) { 
     964    # this variable's dimension better be time 
     965    if ($wind_speed[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     966      die "ABORT!  $wind_speed[$i]{'var_name'} has wrong time dimension.\n"; 
     967    } 
     968    else { 
     969      # get all the variable goodies 
     970      $varget = NetCDF::varget($ncid, $wind_speed[$i]{'var_id'}, 
     971        (0), $time_dim{'dim_size'}, \@this_wind_speed_data); 
     972      if ($varget < 0) {die "ABORT! Cannot get $wind_speed[$i]{'var_name'} data.\n";} 
     973      # get all the attributes for this variable 
     974      my $name    = ''; 
     975      my $nc_type = ''; 
     976      my $ndims   = ''; 
     977      my @dimids  = ''; 
     978      my $natts   = ''; 
     979 
     980      #DWR 4/5/2008 
     981      my $units_value = ''; 
     982      my $attget = NetCDF::attget($ncid, $wind_speed[$i]{'var_id'}, 'units', \$units_value); 
     983      if ($attget < 0)  
     984      { 
     985       die "ABORT! $wind_speed[$i]{'var_name'} has no units.\n"; 
     986      } 
     987      $wind_speed[$i]{'units'} = $units_value; 
     988       
     989       
     990      # we need to loop through the attributes, so find out how many there are 
     991      my $varinq = NetCDF::varinq($ncid, $wind_speed[$i]{'var_id'}, 
     992        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     993      if ($varinq < 0) {die "ABORT! Cannot get $wind_speed[$i]{'var_name'} attributes.\n";} 
     994      for my $k (0..$natts-1) { 
     995        # find out about each attribute 
     996        my $this_attname = ''; 
     997        my $attname = NetCDF::attname($ncid, $wind_speed[$i]{'var_id'}, $k, \$this_attname); 
     998        if ($attname < 0) {die "ABORT! Cannot get $wind_speed[$i]{'var_name'} $k attribute.\n";} 
     999        # is this a height? 
     1000        if ($this_attname eq $height_dim{'dim_name'}) { 
     1001          my $attval = ''; 
     1002          my $attget = NetCDF::attget($ncid, $wind_speed[$i]{'var_id'}, $this_attname, \$attval); 
     1003          if ($attget < 0) {die "ABORT!  Cannot get $wind_speed[$i]{'var_name'} $k attribute.\n";} 
     1004          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1005          $wind_speed[$i]{'height'} = $attval; 
     1006        } 
     1007        elsif ($this_attname eq 'can_be_normalized') { 
     1008          my $attval = ''; 
     1009          my $attget = NetCDF::attget($ncid, $wind_speed[$i]{'var_id'}, $this_attname, \$attval); 
     1010          if ($attget < 0) {die "ABORT!  Cannot get $wind_speed[$i]{'var_name'} $k attribute.\n";} 
     1011          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1012          $wind_speed[$i]{'can_be_normalized'} = $attval; 
     1013        } 
     1014      } 
     1015      # if we didn't have an height attribute, assign the global one to this var 
     1016      if ($wind_speed[$i]{'height'} == '') { 
     1017        $wind_speed[$i]{'height'} = $height_value[0]; 
     1018      } 
     1019      # add a NULL where missing value 
     1020      for my $j (0..$#this_wind_speed_data) { 
     1021        push @{$wind_speed[$i]{'data'}}, $this_wind_speed_data[$j]; 
     1022      } 
     1023    } 
     1024  } 
     1025   
     1026  # wind_gust's 
     1027  @this_wind_gust_data = ''; 
     1028  for $i (0..$#wind_gust) { 
     1029    # this variable's dimension better be time 
     1030    if ($wind_gust[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1031      die "ABORT!  $wind_gust[$i]{'var_name'} has wrong time dimension.\n"; 
     1032    } 
     1033    else { 
     1034      # get all the variable goodies 
     1035      $varget = NetCDF::varget($ncid, $wind_gust[$i]{'var_id'}, 
     1036        (0), $time_dim{'dim_size'}, \@this_wind_gust_data); 
     1037      if ($varget < 0) {die "ABORT! Cannot get $wind_gust[$i]{'var_name'} data.\n";} 
     1038      # get all the attributes for this variable 
     1039      my $name    = ''; 
     1040      my $nc_type = ''; 
     1041      my $ndims   = ''; 
     1042      my @dimids  = ''; 
     1043      my $natts   = ''; 
     1044       
     1045      #DWR 4/5/2008 
     1046      my $units_value = ''; 
     1047      my $attget = NetCDF::attget($ncid, $wind_gust[$i]{'var_id'}, 'units', \$units_value); 
     1048      if ($attget < 0)  
     1049      { 
     1050       die "ABORT! $wind_gust[$i]{'var_name'} has no units.\n"; 
     1051      } 
     1052      $wind_gust[$i]{'units'} = $units_value; 
     1053 
     1054       
     1055      # we need to loop through the attributes, so find out how many there are 
     1056      my $varinq = NetCDF::varinq($ncid, $wind_gust[$i]{'var_id'}, 
     1057        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1058      if ($varinq < 0) {die "ABORT! Cannot get $wind_gust[$i]{'var_name'} attributes.\n";} 
     1059      for my $k (0..$natts-1) { 
     1060        # find out about each attribute 
     1061        my $this_attname = ''; 
     1062        my $attname = NetCDF::attname($ncid, $wind_gust[$i]{'var_id'}, $k, \$this_attname); 
     1063        if ($attname < 0) {die "ABORT! Cannot get $wind_gust[$i]{'var_name'} $k attribute.\n";} 
     1064        # is this a height? 
     1065        if ($this_attname eq $height_dim{'dim_name'}) { 
     1066          my $attval = ''; 
     1067          my $attget = NetCDF::attget($ncid, $wind_gust[$i]{'var_id'}, $this_attname, \$attval); 
     1068          if ($attget < 0) {die "ABORT!  Cannot get $wind_gust[$i]{'var_name'} $k attribute.\n";} 
     1069          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1070          $wind_gust[$i]{'height'} = $attval; 
     1071        } 
     1072        elsif ($this_attname eq 'can_be_normalized') { 
     1073          my $attval = ''; 
     1074          my $attget = NetCDF::attget($ncid, $wind_gust[$i]{'var_id'}, $this_attname, \$attval); 
     1075          if ($attget < 0) {die "ABORT!  Cannot get $wind_gust[$i]{'var_name'} $k attribute.\n";} 
     1076          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1077          $wind_gust[$i]{'can_be_normalized'} = $attval; 
     1078        } 
     1079      } 
     1080      # if we didn't have an height attribute, assign the global one to this var 
     1081      if ($wind_gust[$i]{'height'} == '') { 
     1082        $wind_gust[$i]{'height'} = $height_value[0]; 
     1083      } 
     1084      # add a NULL where missing value 
     1085      for my $j (0..$#this_wind_gust_data) { 
     1086        push @{$wind_gust[$i]{'data'}}, $this_wind_gust_data[$j]; 
     1087      } 
     1088    } 
     1089  } 
     1090   
     1091  # wind_from_direction's 
     1092  @this_wind_from_direction_data = ''; 
     1093  for $i (0..$#wind_from_direction) { 
     1094    # this variable's dimension better be time 
     1095    if ($wind_from_direction[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1096      die "ABORT!  $wind_from_direction[$i]{'var_name'} has wrong time dimension.\n"; 
     1097    } 
     1098    else { 
     1099      
     1100      #DWR 4/5/2008 
     1101      my $units_value = ''; 
     1102      my $attget = NetCDF::attget($ncid, $wind_from_direction[$i]{'var_id'}, 'units', \$units_value); 
     1103      if ($attget < 0)  
     1104      { 
     1105       die "ABORT! $wind_from_direction[$i]{'var_name'} has no units.\n"; 
     1106      } 
     1107      $wind_from_direction[$i]{'units'} = $units_value; 
     1108      
     1109      # get all the variable goodies 
     1110      $varget = NetCDF::varget($ncid, $wind_from_direction[$i]{'var_id'}, 
     1111        (0), $time_dim{'dim_size'}, \@this_wind_from_direction_data); 
     1112      if ($varget < 0) {die "ABORT! Cannot get $wind_from_direction[$i]{'var_name'} data.\n";} 
     1113      # get all the attributes for this variable 
     1114      my $name    = ''; 
     1115      my $nc_type = ''; 
     1116      my $ndims   = ''; 
     1117      my @dimids  = ''; 
     1118      my $natts   = ''; 
     1119      # we need to loop through the attributes, so find out how many there are 
     1120      my $varinq = NetCDF::varinq($ncid, $wind_from_direction[$i]{'var_id'}, 
     1121        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1122      if ($varinq < 0) {die "ABORT! Cannot get $wind_from_direction[$i]{'var_name'} attributes.\n";} 
     1123      for my $k (0..$natts-1) { 
     1124        # find out about each attribute 
     1125        my $this_attname = ''; 
     1126        my $attname = NetCDF::attname($ncid, $wind_from_direction[$i]{'var_id'}, $k,   \$this_attname); 
     1127        if ($attname < 0) {die "ABORT! Cannot get $wind_from_direction[$i]{'var_name'} $k   attribute.\n";} 
     1128        # is this a height? 
     1129        if ($this_attname eq $height_dim{'dim_name'}) { 
     1130          my $attval = ''; 
     1131          my $attget = NetCDF::attget($ncid, $wind_from_direction[$i]{'var_id'}, $this_attname,   \$attval); 
     1132          if ($attget < 0) {die "ABORT!  Cannot get $wind_from_direction[$i]{'var_name'} $k   attribute.\n";} 
     1133          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1134          $wind_from_direction[$i]{'height'} = $attval; 
     1135        } 
     1136        elsif ($this_attname eq 'can_be_normalized') { 
     1137          my $attval = ''; 
     1138          my $attget = NetCDF::attget($ncid, $wind_speed[$i]{'var_id'}, $this_attname, \$attval); 
     1139          if ($attget < 0) {die "ABORT!  Cannot get $wind_speed[$i]{'var_name'} $k attribute.\n";} 
     1140          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1141          $wind_from_direction[$i]{'can_be_normalized'} = $attval; 
     1142        } 
     1143      } 
     1144      # if we didn't have an height attribute, assign the global one to this var 
     1145      if ($wind_from_direction[$i]{'height'} == '') { 
     1146        $wind_from_direction[$i]{'height'} = $height_value[0]; 
     1147      } 
     1148      # add a NULL where missing value 
     1149      for my $j (0..$#this_wind_from_direction_data) { 
     1150        push @{$wind_from_direction[$i]{'data'}}, $this_wind_from_direction_data[$j]; 
     1151      } 
     1152    } 
     1153  } 
     1154   
     1155  # air_pressure's 
     1156  @this_air_pressure_data = ''; 
     1157  for $i (0..$#air_pressure) { 
     1158    # this variable's dimension better be time 
     1159    if ($air_pressure[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1160      die "ABORT!  $air_pressure[$i]{'var_name'} has wrong time dimension.\n"; 
     1161    } 
     1162    else { 
     1163          
     1164      # get all the variable goodies 
     1165      $varget = NetCDF::varget($ncid, $air_pressure[$i]{'var_id'}, 
     1166        (0), $time_dim{'dim_size'}, \@this_air_pressure_data); 
     1167      if ($varget < 0) {die "ABORT! Cannot get $air_pressure[$i]{'var_name'} data.\n";} 
     1168      # get all the attributes for this variable 
     1169      my $name    = ''; 
     1170      my $nc_type = ''; 
     1171      my $ndims   = ''; 
     1172      my @dimids  = ''; 
     1173      my $natts   = ''; 
     1174       
     1175      # check for units 
     1176      my $units_value    = ''; 
     1177      my $this_slope     = ''; 
     1178      my $this_intercept = ''; 
     1179      my $attget = NetCDF::attget($ncid, $air_pressure[$i]{'var_id'}, 'units', \$units_value); 
     1180      if ($attget < 0) {die "ABORT! $air_pressure[$i]{'var_name'} has no units.\n";} 
     1181      if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     1182      my $base_units = UDUNITS::scan($units_value) 
     1183        || die "ABORT! Error with $air_pressure[$i]{'var_name'} units.\n"; 
     1184      my $dest_units = UDUNITS::scan('bar'); 
     1185      $base_units->convert($dest_units,$this_slope,$this_intercept); 
     1186       
     1187      #DWR 4/5/2008 
     1188      $air_pressure[$i]{'units'} = $units_value; 
     1189       
     1190      # we need to loop through the attributes, so find out how many there are 
     1191      my $varinq = NetCDF::varinq($ncid, $air_pressure[$i]{'var_id'}, 
     1192        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1193      if ($varinq < 0) {die "ABORT! Cannot get $air_pressure[$i]{'var_name'}   attributes.\n";} 
     1194      for my $k (0..$natts-1) { 
     1195        # find out about each attribute 
     1196        my $this_attname = ''; 
     1197        my $attname = NetCDF::attname($ncid, $air_pressure[$i]{'var_id'}, $k,   \$this_attname); 
     1198        if ($attname < 0) {die "ABORT! Cannot get $air_pressure[$i]{'var_name'} $k   attribute.\n";} 
     1199        # is this a height? 
     1200        if ($this_attname eq $height_dim{'dim_name'}) { 
     1201          my $attval = ''; 
     1202          my $attget = NetCDF::attget($ncid, $air_pressure[$i]{'var_id'}, $this_attname, \$attval); 
     1203          if ($attget < 0) {die "ABORT!  Cannot get $air_pressure[$i]{'var_name'} $k   attribute.\n";} 
     1204          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1205          $air_pressure[$i]{'height'} = $attval; 
     1206        }; 
     1207      } 
     1208      # if we didn't have an height attribute, assign the global one to this var 
     1209      if ($air_pressure[$i]{'height'} == '') { 
     1210        $air_pressure[$i]{'height'} = $height_value[0]; 
     1211      } 
     1212      for my $j (0..$#this_air_pressure_data) { 
     1213        # target is millibars 
     1214        #cancel out conversion operation if missing value 
     1215        #also canceling conversion if air_pressure > 900 
     1216        #print "$this_air_pressure_data[$j]\n"; 
     1217        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;}  
     1218print 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"; 
     1219        push @{$air_pressure[$i]{'data'}}, 
     1220          ($this_air_pressure_data[$j] * $this_slope + $this_intercept); 
     1221        #print "$this_air_pressure_data[$j] * $this_slope + $this_intercept)\n"; 
     1222        #$test_val = ($this_air_pressure_data[$j] * $this_slope + $this_intercept); 
     1223        #print "$test_val\n"; 
     1224      } 
     1225    } 
     1226  } 
     1227   
     1228  # salinity's 
     1229  @this_salinity_data = ''; 
     1230  for $i (0..$#salinity) { 
     1231    # this variable's dimension better be time 
     1232    if ($salinity[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1233      die "ABORT!  $salinity[$i]{'var_name'} has wrong time dimension.\n"; 
     1234    } 
     1235    else { 
     1236      
     1237      #DWR 4/5/2008 
     1238      my $units_value = ''; 
     1239      my $attget = NetCDF::attget($ncid, $salinity[$i]{'var_id'}, 'units', \$units_value); 
     1240      if ($attget < 0)  
     1241      { 
     1242       die "ABORT! $salinity[$i]{'var_name'} has no units.\n"; 
     1243      } 
     1244      $salinity[$i]{'units'} = $units_value; 
     1245      
     1246      # get all the variable goodies 
     1247      $varget = NetCDF::varget($ncid, $salinity[$i]{'var_id'}, 
     1248        (0), $time_dim{'dim_size'}, \@this_salinity_data); 
     1249      if ($varget < 0) {die "ABORT! Cannot get $salinity[$i]{'var_name'} data.\n";} 
     1250      # get all the attributes for this variable 
     1251      my $name    = ''; 
     1252      my $nc_type = ''; 
     1253      my $ndims   = ''; 
     1254      my @dimids  = ''; 
     1255      my $natts   = ''; 
     1256       
     1257      # we need to loop through the attributes, so find out how many there are 
     1258      my $varinq = NetCDF::varinq($ncid, $salinity[$i]{'var_id'}, 
     1259        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1260      if ($varinq < 0) {die "ABORT! Cannot get $salinity[$i]{'var_name'}   attributes.\n";} 
     1261      for my $k (0..$natts-1) { 
     1262        # find out about each attribute 
     1263        my $this_attname = ''; 
     1264        my $attname = NetCDF::attname($ncid, $salinity[$i]{'var_id'}, $k,   \$this_attname); 
     1265        if ($attname < 0) {die "ABORT! Cannot get $salinity[$i]{'var_name'} $k   attribute.\n";} 
     1266        # is this a height? 
     1267        if ($this_attname eq $height_dim{'dim_name'}) { 
     1268          my $attval = ''; 
     1269          my $attget = NetCDF::attget($ncid, $salinity[$i]{'var_id'}, $this_attname, \$attval); 
     1270          if ($attget < 0) {die "ABORT!  Cannot get $salinity[$i]{'var_name'} $k   attribute.\n";} 
     1271          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1272          $salinity[$i]{'height'} = $attval; 
     1273        }; 
     1274      } 
     1275      # if we didn't have an height attribute, assign the global one to this var 
     1276      if ($salinity[$i]{'height'} == '') { 
     1277        $salinity[$i]{'height'} = $height_value[0]; 
     1278      } 
     1279      for my $j (0..$#this_salinity_data) { 
     1280        push @{$salinity[$i]{'data'}}, $this_salinity_data[$j]; 
     1281      } 
     1282    } 
     1283  } 
     1284   
     1285  # sea_surface_eastward_current's 
     1286  @this_sea_surface_eastward_current_data = ''; 
     1287  for $i (0..$#sea_surface_eastward_current) { 
     1288    # this variable's dimension better be time 
     1289    if ($sea_surface_eastward_current[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1290      die "ABORT!  $sea_surface_eastward_current[$i]{'var_name'} has wrong time dimension.\n"; 
     1291    } 
     1292    else {              
     1293      # get all the variable goodies 
     1294      $varget = NetCDF::varget($ncid, $sea_surface_eastward_current[$i]{'var_id'}, 
     1295        (0), $time_dim{'dim_size'}, \@this_sea_surface_eastward_current_data); 
     1296      if ($varget < 0) {die "ABORT! Cannot get $sea_surface_eastward_current[$i]{'var_name'} data.\n";} 
     1297      # get all the attributes for this variable 
     1298      my $name    = ''; 
     1299      my $nc_type = ''; 
     1300      my $ndims   = ''; 
     1301      my @dimids  = ''; 
     1302      my $natts   = ''; 
     1303       
     1304      # check for units 
     1305      my $units_value    = ''; 
     1306      my $this_slope     = ''; 
     1307      my $this_intercept = ''; 
     1308      my $attget = NetCDF::attget($ncid, $sea_surface_eastward_current[$i]{'var_id'}, 'units', \$units_value); 
     1309      if ($attget < 0) {die "ABORT! $sea_surface_eastward_current[$i]{'var_name'} has no units.\n";} 
     1310      if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     1311      my $base_units = UDUNITS::scan($units_value) 
     1312        || die "ABORT! Error with $sea_surface_eastward_current[$i]{'var_name'} units.\n"; 
     1313      my $dest_units = UDUNITS::scan('m s-1'); 
     1314      $base_units->convert($dest_units,$this_slope,$this_intercept); 
     1315 
     1316      #DWR 4/5/2008 
     1317      $sea_surface_eastward_current[$i]{'units'} = $units_value; 
     1318 
     1319      # we need to loop through the attributes, so find out how many there are 
     1320      my $varinq = NetCDF::varinq($ncid, $sea_surface_eastward_current[$i]{'var_id'}, 
     1321        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1322      if ($varinq < 0) {die "ABORT! Cannot get $sea_surface_eastward_current[$i]{'var_name'} attributes.\n";} 
     1323      for my $k (0..$natts-1) { 
     1324        # find out about each attribute 
     1325        my $this_attname = ''; 
     1326        my $attname = NetCDF::attname($ncid, $sea_surface_eastward_current[$i]{'var_id'}, $k, \$this_attname); 
     1327        if ($attname < 0) {die "ABORT! Cannot get $sea_surface_eastward_current[$i]{'var_name'} $k attribute.\n";} 
     1328        # is this a height? 
     1329        if ($this_attname eq $height_dim{'dim_name'}) { 
     1330          my $attval = ''; 
     1331          my $attget = NetCDF::attget($ncid, $sea_surface_eastward_current[$i]{'var_id'}, $this_attname, \$attval); 
     1332          if ($attget < 0) {die "ABORT!  Cannot get $sea_surface_eastward_current[$i]{'var_name'} $k attribute.\n";} 
     1333          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1334          $sea_surface_eastward_current[$i]{'height'} = $attval; 
     1335        } 
     1336      } 
     1337      # if we didn't have an height attribute, assign the global one to this var 
     1338      if ($sea_surface_eastward_current[$i]{'height'} == '') { 
     1339        $sea_surface_eastward_current[$i]{'height'} = $height_value[0]; 
     1340      } 
     1341      # add a NULL where missing value 
     1342      for my $j (0..$#this_sea_surface_eastward_current_data) { 
     1343        #cancel out conversion operation if missing value 
     1344        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; } 
     1345        push @{$sea_surface_eastward_current[$i]{'data'}}, 
     1346          ($this_sea_surface_eastward_current_data[$j] * $this_slope + $this_intercept); 
     1347      } 
     1348    } 
     1349  } 
     1350   
     1351  # sea_surface_northward_current's 
     1352  @this_sea_surface_northward_current_data = ''; 
     1353  for $i (0..$#sea_surface_northward_current) { 
     1354    # this variable's dimension better be time 
     1355    if ($sea_surface_northward_current[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1356      die "ABORT!  $sea_surface_northward_current[$i]{'var_name'} has wrong time dimension.\n"; 
     1357    } 
     1358    else { 
     1359          
     1360      # get all the variable goodies 
     1361      $varget = NetCDF::varget($ncid, $sea_surface_northward_current[$i]{'var_id'}, 
     1362        (0), $time_dim{'dim_size'}, \@this_sea_surface_northward_current_data); 
     1363      if ($varget < 0) {die "ABORT! Cannot get $sea_surface_northward_current[$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      # check for units 
     1372      my $units_value    = ''; 
     1373      my $this_slope     = ''; 
     1374      my $this_intercept = ''; 
     1375      my $attget = NetCDF::attget($ncid, $sea_surface_northward_current[$i]{'var_id'}, 'units', \$units_value); 
     1376      if ($attget < 0) {die "ABORT! $sea_surface_northward_current[$i]{'var_name'} has no units.\n";} 
     1377      if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     1378      my $base_units = UDUNITS::scan($units_value) 
     1379        || die "ABORT! Error with $sea_surface_northward_current[$i]{'var_name'} units.\n"; 
     1380      my $dest_units = UDUNITS::scan('m s-1'); 
     1381      $base_units->convert($dest_units,$this_slope,$this_intercept); 
     1382      #DWR 4/5/2008 
     1383      $sea_surface_northward_current[$i]{'units'} = $units_value; 
     1384       
     1385      # we need to loop through the attributes, so find out how many there are 
     1386      my $varinq = NetCDF::varinq($ncid, $sea_surface_northward_current[$i]{'var_id'}, 
     1387        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1388      if ($varinq < 0) {die "ABORT! Cannot get $sea_surface_northward_current[$i]{'var_name'} attributes.\n";} 
     1389      for my $k (0..$natts-1) { 
     1390        # find out about each attribute 
     1391        my $this_attname = ''; 
     1392        my $attname = NetCDF::attname($ncid, $sea_surface_northward_current[$i]{'var_id'}, $k, \$this_attname); 
     1393        if ($attname < 0) {die "ABORT! Cannot get $sea_surface_northward_current[$i]{'var_name'} $k attribute.\n";} 
     1394        # is this a height? 
     1395        if ($this_attname eq $height_dim{'dim_name'}) { 
     1396          my $attval = ''; 
     1397          my $attget = NetCDF::attget($ncid, $sea_surface_northward_current[$i]{'var_id'}, $this_attname, \$attval); 
     1398          if ($attget < 0) {die "ABORT!  Cannot get $sea_surface_northward_current[$i]{'var_name'} $k attribute.\n";} 
     1399          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1400          $sea_surface_northward_current[$i]{'height'} = $attval; 
     1401        } 
     1402      } 
     1403      # if we didn't have an height attribute, assign the global one to this var 
     1404      if ($sea_surface_northward_current[$i]{'height'} == '') { 
     1405        $sea_surface_northward_current[$i]{'height'} = $height_value[0]; 
     1406      } 
     1407      # add a NULL where missing value 
     1408      for my $j (0..$#this_sea_surface_northward_current_data) { 
     1409        #cancel out conversion operation if missing value 
     1410        if ($this_sea_surface_northward_current_data[$j] == $missing_value_value || $this_sea_surface_northward_current_data[$j] == $Fill_value_value) { $this_slope = 1; $this_intercept = 0; } 
     1411        push @{$sea_surface_northward_current[$i]{'data'}}, 
     1412          ($this_sea_surface_northward_current_data[$j] * $this_slope + $this_intercept); 
     1413      } 
     1414    } 
     1415  } 
     1416   
     1417  # significant_wave_height's 
     1418  @this_significant_wave_height_data = ''; 
     1419  for $i (0..$#significant_wave_height) { 
     1420    # this variable's dimension better be time 
     1421    if ($significant_wave_height[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1422      die "ABORT!  $significant_wave_height[$i]{'var_name'} has wrong time dimension.\n"; 
     1423    } 
     1424    else { 
     1425           
     1426      # get all the variable goodies 
     1427      $varget = NetCDF::varget($ncid, $significant_wave_height[$i]{'var_id'}, 
     1428        (0), $time_dim{'dim_size'}, \@this_significant_wave_height_data); 
     1429      if ($varget < 0) {die "ABORT! Cannot get $significant_wave_height[$i]{'var_name'} data.\n";} 
     1430      # get all the attributes for this variable 
     1431      my $name    = ''; 
     1432      my $nc_type = ''; 
     1433      my $ndims   = ''; 
     1434      my @dimids  = ''; 
     1435      my $natts   = ''; 
     1436       
     1437      # check for units 
     1438      my $units_value    = ''; 
     1439      my $this_slope     = ''; 
     1440      my $this_intercept = ''; 
     1441      my $attget = NetCDF::attget($ncid, $significant_wave_height[$i]{'var_id'}, 'units', \$units_value); 
     1442      if ($attget < 0) {die "ABORT! $significant_wave_height[$i]{'var_name'} has no units.\n";} 
     1443      if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     1444      my $base_units = UDUNITS::scan($units_value) 
     1445        || die "ABORT! Error with $significant_wave_height[$i]{'var_name'} units.\n"; 
     1446      my $dest_units = UDUNITS::scan('m'); 
     1447      $base_units->convert($dest_units,$this_slope,$this_intercept); 
     1448      #DWR 4/5/2008 
     1449      $significant_wave_height[$i]{'units'} = $units_value; 
     1450       
     1451      # we need to loop through the attributes, so find out how many there are 
     1452      my $varinq = NetCDF::varinq($ncid, $significant_wave_height[$i]{'var_id'}, 
     1453        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1454      if ($varinq < 0) {die "ABORT! Cannot get $significant_wave_height[$i]{'var_name'} attributes.\n";} 
     1455      for my $k (0..$natts-1) { 
     1456        # find out about each attribute 
     1457        my $this_attname = ''; 
     1458        my $attname = NetCDF::attname($ncid, $significant_wave_height[$i]{'var_id'}, $k, \$this_attname); 
     1459        if ($attname < 0) {die "ABORT! Cannot get $significant_wave_height[$i]{'var_name'} $k attribute.\n";} 
     1460        # is this a height? 
     1461        if ($this_attname eq $height_dim{'dim_name'}) { 
     1462          my $attval = ''; 
     1463          my $attget = NetCDF::attget($ncid, $significant_wave_height[$i]{'var_id'}, $this_attname, \$attval); 
     1464          if ($attget < 0) {die "ABORT!  Cannot get $significant_wave_height[$i]{'var_name'} $k attribute.\n";} 
     1465          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1466          $significant_wave_height[$i]{'height'} = $attval; 
     1467        } 
     1468      } 
     1469      # if we didn't have an height attribute, assign the global one to this var 
     1470      if (length $significant_wave_height[$i]{'height'} <= 0) { 
     1471        $significant_wave_height[$i]{'height'} = $height_value[0]; 
     1472      } 
     1473      # add a NULL where missing value 
     1474      for my $j (0..$#this_significant_wave_height_data) { 
     1475        #cancel out conversion operation if missing value 
     1476        if ($this_significant_wave_height_data[$j] == $missing_value_value || $this_significant_wave_height_data[$j] == $Fill_value_value) { $this_slope = 1; $this_intercept = 0; } 
     1477        push @{$significant_wave_height[$i]{'data'}}, 
     1478          ($this_significant_wave_height_data[$j] * $this_slope + $this_intercept); 
     1479      } 
     1480    } 
     1481  } 
     1482   
     1483  # dominant_wave_period's 
     1484  @this_dominant_wave_period_data = ''; 
     1485  for $i (0..$#dominant_wave_period) { 
     1486    # this variable's dimension better be time 
     1487    if ($dominant_wave_period[$i]{'dim_id'} != $time_dim{'dim_id'}) { 
     1488      die "ABORT!  $dominant_wave_period[$i]{'var_name'} has wrong time dimension.\n"; 
     1489    } 
     1490    else { 
     1491           
     1492      # get all the variable goodies 
     1493      $varget = NetCDF::varget($ncid, $dominant_wave_period[$i]{'var_id'}, 
     1494        (0), $time_dim{'dim_size'}, \@this_dominant_wave_period_data); 
     1495      if ($varget < 0) {die "ABORT! Cannot get $dominant_wave_period[$i]{'var_name'} data.\n";} 
     1496      # get all the attributes for this variable 
     1497      my $name    = ''; 
     1498      my $nc_type = ''; 
     1499      my $ndims   = ''; 
     1500      my @dimids  = ''; 
     1501      my $natts   = ''; 
     1502       
     1503      # check for units 
     1504      my $units_value    = ''; 
     1505      my $this_slope     = ''; 
     1506      my $this_intercept = ''; 
     1507      my $attget = NetCDF::attget($ncid, $dominant_wave_period[$i]{'var_id'}, 'units', \$units_value); 
     1508      if ($attget < 0) {die "ABORT! $dominant_wave_period[$i]{'var_name'} has no units.\n";} 
     1509      if (substr($units_value,length($units_value)-1) eq chr(0)) {chop($units_value);} 
     1510      my $base_units = UDUNITS::scan($units_value) 
     1511        || die "ABORT! Error with $dominant_wave_period[$i]{'var_name'} units.\n"; 
     1512      my $dest_units = UDUNITS::scan('second'); 
     1513      $base_units->convert($dest_units,$this_slope,$this_intercept); 
     1514      #DWR 4/5/2008 
     1515      $dominant_wave_period[$i]{'units'} = $units_value; 
     1516       
     1517      # we need to loop through the attributes, so find out how many there are 
     1518      my $varinq = NetCDF::varinq($ncid, $dominant_wave_period[$i]{'var_id'}, 
     1519        \$name, \$nc_type, $ndims, \@dimids, \$natts); 
     1520      if ($varinq < 0) {die "ABORT! Cannot get $dominant_wave_period[$i]{'var_name'} attributes.\n";} 
     1521      for my $k (0..$natts-1) { 
     1522        # find out about each attribute 
     1523        my $this_attname = ''; 
     1524        my $attname = NetCDF::attname($ncid, $dominant_wave_period[$i]{'var_id'}, $k, \$this_attname); 
     1525        if ($attname < 0) {die "ABORT! Cannot get $dominant_wave_period[$i]{'var_name'} $k attribute.\n";} 
     1526        # is this a height? 
     1527        if ($this_attname eq $height_dim{'dim_name'}) { 
     1528          my $attval = ''; 
     1529          my $attget = NetCDF::attget($ncid, $dominant_wave_period[$i]{'var_id'}, $this_attname, \$attval); 
     1530          if ($attget < 0) {die "ABORT!  Cannot get $dominant_wave_period[$i]{'var_name'} $k attribute.\n";} 
     1531          if (substr($attval,length($attval)-1) eq chr(0)) {chop($attval);} 
     1532          $dominant_wave_period[$i]{'height'} = $attval; 
     1533        } 
     1534      } 
     1535      # if we didn't have an height attribute, assign the global one to this var 
     1536      if (length $dominant_wave_period[$i]{'height'} <= 0) { 
     1537        $dominant_wave_period[$i]{'height'} = $height_value[0]; 
     1538      } 
     1539      # add a NULL where missing value 
     1540      for my $j (0..$#this_dominant_wave_period_data) { 
     1541        #cancel out conversion operation if missing value 
     1542        if ($this_dominant_wave_period_data[$j] == $missing_value_value || $this_dominant_wave_period_data[$j] == $Fill_value_value) { $this_slope = 1; $this_intercept = 0; } 
     1543        push @{$dominant_wave_period[$i]{'data'}}, 
     1544          ($this_dominant_wave_period_data[$j] * $this_slope + $this_intercept); 
     1545      } 
     1546    } 
     1547  } 
     1548   
     1549  # 
     1550  # write data to file(s) 
     1551 
     1552  # station_id 
     1553  $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1554  # 6/15/05 < changed to <= in next line by payne; when timestamp file doesn't exist (station has never been reported) 
     1555  # $this_station_id_top_ts has an empty value, which wasn't properly triggering the code to run, 
     1556  # so new stations weren't being created. 
     1557  if ($this_station_id_top_ts <= 0) { 
     1558    if( $bWriteSQLFiles ) 
     1559    { 
     1560      open(STATION_ID_SQLFILE,'>>../sql_in_situ_station_id/in_situ_station_id_'.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'.sql'); 
     1561      print STATION_ID_SQLFILE "-- format_category      = $format_category_value\n"; 
     1562      print STATION_ID_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1563      print STATION_ID_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1564      print STATION_ID_SQLFILE "-- package_code         = $package_code_value\n"; 
     1565      print STATION_ID_SQLFILE "-- title                = $title_value\n"; 
     1566      print STATION_ID_SQLFILE "-- institution          = $institution_value\n"; 
     1567      print STATION_ID_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1568      print STATION_ID_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1569      print STATION_ID_SQLFILE "-- source               = $source_value\n"; 
     1570      print STATION_ID_SQLFILE "-- references           = $references_value\n"; 
     1571      print STATION_ID_SQLFILE "-- contact              = $contact_value\n"; 
     1572      print STATION_ID_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1573      print STATION_ID_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1574      print STATION_ID_SQLFILE "INSERT INTO in_situ_station_id (";  
     1575      print STATION_ID_SQLFILE "station_id,"; 
     1576      print STATION_ID_SQLFILE "title,"; 
     1577      print STATION_ID_SQLFILE "institution,"; 
     1578      print STATION_ID_SQLFILE "institution_url,"; 
     1579      print STATION_ID_SQLFILE "institution_dods_url,"; 
     1580      print STATION_ID_SQLFILE "source,"; 
     1581      print STATION_ID_SQLFILE "refs,"; 
     1582      print STATION_ID_SQLFILE "contact"; 
     1583      print STATION_ID_SQLFILE ") ";  
     1584      print STATION_ID_SQLFILE "VALUES ("; 
     1585      print STATION_ID_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1586      print STATION_ID_SQLFILE ','.'\''.$title_value.'\''; 
     1587      print STATION_ID_SQLFILE ','.'\''.$institution_value.'\''; 
     1588      print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1589      print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1590      print STATION_ID_SQLFILE ','.'\''.$source_value.'\''; 
     1591      print STATION_ID_SQLFILE ','.'\''.$references_value.'\''; 
     1592      print STATION_ID_SQLFILE ','.'\''.$contact_value.'\''; 
     1593      print STATION_ID_SQLFILE ");\n"; 
     1594      close(STATION_ID_SQLFILE); 
     1595    } 
     1596  } 
     1597   
     1598  #DWR 4/5/2008 
     1599  #Implemented code to write the obsKML files.  
     1600  my %ObsHash; 
     1601  my $rObsHash = \%ObsHash; 
     1602  my $strPlatformID = $institution_code_value.'.'.$platform_code_value.'.'.$package_code_value; 
     1603  obsKMLSubRoutines::KMLAddPlatformHashEntry( $strPlatformID, $institution_url_value, $latitude_value[0], $longitude_value[0], $rObsHash ); 
     1604   
     1605  # water_level (water_level) 
     1606  if ($#water_level > -1) 
     1607  { 
     1608    if( $bWriteSQLFiles ) 
     1609    { 
     1610      open(WATER_LEVEL_SQLFILE,'>>../sql/water_level_prod_'.$institution_code_value.'_' 
     1611        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1612      print WATER_LEVEL_SQLFILE "-- format_category      = $format_category_value\n"; 
     1613      print WATER_LEVEL_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1614      print WATER_LEVEL_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1615      print WATER_LEVEL_SQLFILE "-- package_code         = $package_code_value\n"; 
     1616      print WATER_LEVEL_SQLFILE "-- title                = $title_value\n"; 
     1617      print WATER_LEVEL_SQLFILE "-- institution          = $institution_value\n"; 
     1618      print WATER_LEVEL_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1619      print WATER_LEVEL_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1620      print WATER_LEVEL_SQLFILE "-- source               = $source_value\n"; 
     1621      print WATER_LEVEL_SQLFILE "-- references           = $references_value\n"; 
     1622      print WATER_LEVEL_SQLFILE "-- contact              = $contact_value\n"; 
     1623      print WATER_LEVEL_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1624      print WATER_LEVEL_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1625      for my $i (0..$#water_level) { 
     1626        for my $j (0..$#this_water_level_data) { 
     1627          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1628          $this_time_stamp = $time_formatted_values[$j]; 
     1629          $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)); 
     1630 
     1631          if ($water_level[$i]{'data'}[$j] != $missing_value_value 
     1632            && $water_level[$i]{'data'}[$j] != $Fill_value_value 
     1633            && $this_station_id_top_ts < $this_time_stamp_sec 
     1634            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1635            print WATER_LEVEL_SQLFILE "INSERT INTO water_level_prod (";  
     1636            print WATER_LEVEL_SQLFILE "station_id,"; 
     1637            print WATER_LEVEL_SQLFILE "time_stamp,";  
     1638            print WATER_LEVEL_SQLFILE "z,"; 
     1639            print WATER_LEVEL_SQLFILE "positive,"; 
     1640            print WATER_LEVEL_SQLFILE "water_level,"; 
     1641            print WATER_LEVEL_SQLFILE "reference,"; 
     1642            print WATER_LEVEL_SQLFILE "reference_to_mllw,"; 
     1643            print WATER_LEVEL_SQLFILE "reference_to_msl,"; 
     1644            print WATER_LEVEL_SQLFILE "reference_to_navd88,"; 
     1645            print WATER_LEVEL_SQLFILE "title,"; 
     1646            print WATER_LEVEL_SQLFILE "institution,"; 
     1647            print WATER_LEVEL_SQLFILE "institution_url,"; 
     1648            print WATER_LEVEL_SQLFILE "institution_dods_url,"; 
     1649            print WATER_LEVEL_SQLFILE "source,"; 
     1650            print WATER_LEVEL_SQLFILE "refs,"; 
     1651            print WATER_LEVEL_SQLFILE "contact,"; 
     1652            print WATER_LEVEL_SQLFILE "the_geom"; 
     1653            print WATER_LEVEL_SQLFILE ") ";  
     1654            print WATER_LEVEL_SQLFILE "VALUES (";  
     1655            print WATER_LEVEL_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1656            print WATER_LEVEL_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1657            if ($water_level[$i]{'height'} == $missing_value_value 
     1658              || $water_level[$i]{'height'} == $Fill_value_value) { 
     1659              print WATER_LEVEL_SQLFILE ','.'\'\''; 
     1660            } 
     1661            else { 
     1662              $this_val = sprintf("%.2f",$water_level[$i]{'height'}); 
     1663              print WATER_LEVEL_SQLFILE ','.$this_val; 
     1664            } 
     1665            print WATER_LEVEL_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1666            $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
     1667            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1668            print WATER_LEVEL_SQLFILE ','.'\''.$water_level[$i]{'reference'}.'\''; 
     1669             
     1670             
     1671            if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
     1672              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_mllw'}); 
     1673            } 
     1674            else { 
     1675              $this_val = 'NULL'; 
     1676            } 
     1677 
     1678            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1679            if (length $water_level[$i]{'reference_to_msl'} > 0) { 
     1680              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
     1681            } 
     1682            else { 
     1683              $this_val = 'NULL'; 
     1684            } 
     1685 
     1686            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1687            if (length $water_level[$i]{'reference_to_navd88'} > 0) { 
     1688              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_navd88'}); 
     1689            } 
     1690            else { 
     1691              $this_val = 'NULL'; 
     1692            } 
     1693 
     1694            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1695            print WATER_LEVEL_SQLFILE ','.'\''.$title_value.'\''; 
     1696            print WATER_LEVEL_SQLFILE ','.'\''.$institution_value.'\''; 
     1697            print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1698            print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1699            print WATER_LEVEL_SQLFILE ','.'\''.$source_value.'\''; 
     1700            print WATER_LEVEL_SQLFILE ','.'\''.$references_value.'\''; 
     1701            print WATER_LEVEL_SQLFILE ','.'\''.$contact_value.'\''; 
     1702            print WATER_LEVEL_SQLFILE ",GeometryFromText('POINT(";  
     1703            print WATER_LEVEL_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1704            print WATER_LEVEL_SQLFILE ")',-1));\n"; 
     1705          } 
     1706        } 
     1707         
     1708        print WATER_LEVEL_SQLFILE "\n"; 
     1709      } 
     1710      close(WATER_LEVEL_SQLFILE); 
     1711    } 
     1712    if( $bWriteobsKMLFile ) 
     1713    {        
     1714      my $MLLWDataVal = 'NULL'; 
     1715      my $MSLDataVal  = 'NULL'; 
     1716      my $NavD88DataVal = 'NULL'; 
     1717      my $Height = ''; 
     1718      for my $i (0..$#water_level)  
     1719      { 
     1720        for my $j ($iStartingNdx..$#this_water_level_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1721        #for my $j (0..$#this_water_level_data)  
     1722        { 
     1723          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1724          $this_time_stamp = $time_formatted_values[$j]; 
     1725          $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)); 
     1726 
     1727          if ($water_level[$i]{'data'}[$j] != $missing_value_value 
     1728            && $water_level[$i]{'data'}[$j] != $Fill_value_value 
     1729            && $this_station_id_top_ts < $this_time_stamp_sec 
     1730            && $this_time_stamp_sec > $oldest_ok_timestamp)  
     1731            { 
     1732     
     1733              #DWR 4/3/2008 
     1734              if ($water_level[$i]{'height'} != $missing_value_value 
     1735                && $water_level[$i]{'height'} != $Fill_value_value)  
     1736              { 
     1737                $this_val = sprintf("%.2f",$water_level[$i]{'height'}); 
     1738                $Height = $this_val; 
     1739              } 
     1740              $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
     1741               
     1742              $DataVal = $water_level[$i]{'reference'}; 
     1743               
     1744              if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
     1745                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_mllw'}); 
     1746              } 
     1747              else { 
     1748                $this_val = 'NULL'; 
     1749              } 
     1750              $MLLWDataVal = $this_val; 
     1751 
     1752              if (length $water_level[$i]{'reference_to_msl'} > 0) { 
     1753                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
     1754              } 
     1755              else { 
     1756                $this_val = 'NULL'; 
     1757              } 
     1758              $MSLDataVal = $this_val; 
     1759 
     1760              if (length $water_level[$i]{'reference_to_navd88'} > 0) { 
     1761                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_navd88'}); 
     1762              } 
     1763              else { 
     1764                $this_val = 'NULL'; 
     1765              } 
     1766              #DWR 4/5/2008 
     1767              $NavD88DataVal = $this_val; 
     1768          } 
     1769          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1770                                            $KMLTimeStamp[$j], 
     1771                                            $MLLWDataVal, 
     1772                                            1, 
     1773                                            $strPlatformID, 
     1774                                            $Height, 
     1775                                            'm(MLLW)', 
     1776                                            $rObsHash ); 
     1777          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1778                                            $KMLTimeStamp[$j], 
     1779                                            $MSLDataVal, 
     1780                                            2, 
     1781                                            $strPlatformID, 
     1782                                            $Height, 
     1783                                            'm(MSL)', 
     1784                                            $rObsHash ); 
     1785          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1786                                            $KMLTimeStamp[$j], 
     1787                                            $NavD88DataVal, 
     1788                                            3, 
     1789                                            $strPlatformID, 
     1790                                            $Height, 
     1791                                            'm(NAVD88)', 
     1792                                            $rObsHash ); 
     1793        } 
     1794      }             
     1795    } 
     1796  } 
     1797  # sea_surface_temperature (sst) 
     1798  if ($#sea_surface_temperature > -1) { 
     1799    if( $bWriteSQLFiles ) 
     1800    { 
     1801      open(SST_SQLFILE,'>>../sql/sst_prod_'.$institution_code_value.'_' 
     1802        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1803      print SST_SQLFILE "-- format_category      = $format_category_value\n"; 
     1804      print SST_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1805      print SST_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1806      print SST_SQLFILE "-- package_code         = $package_code_value\n"; 
     1807      print SST_SQLFILE "-- title                = $title_value\n"; 
     1808      print SST_SQLFILE "-- institution          = $institution_value\n"; 
     1809      print SST_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1810      print SST_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1811      print SST_SQLFILE "-- source               = $source_value\n"; 
     1812      print SST_SQLFILE "-- references           = $references_value\n"; 
     1813      print SST_SQLFILE "-- contact              = $contact_value\n"; 
     1814      print SST_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1815      print SST_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1816       
     1817      my $DataVal = 'NULL'; 
     1818      my $Height = ''; 
     1819      for my $i (0..$#sea_surface_temperature) { 
     1820        for my $j (0..$#this_sea_surface_temperature_data) { 
     1821          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1822          $this_time_stamp = $time_formatted_values[$j]; 
     1823          $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)); 
     1824         
     1825          if ($sea_surface_temperature[$i]{'data'}[$j] != $missing_value_value 
     1826            && $sea_surface_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1827            && $this_station_id_top_ts < $this_time_stamp_sec 
     1828            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1829            print SST_SQLFILE "INSERT INTO sst_prod (";  
     1830            print SST_SQLFILE "station_id,"; 
     1831            print SST_SQLFILE "time_stamp,";  
     1832            print SST_SQLFILE "z,"; 
     1833            print SST_SQLFILE "positive,"; 
     1834            print SST_SQLFILE "temperature_celcius,"; 
     1835            print SST_SQLFILE "title,"; 
     1836            print SST_SQLFILE "institution,"; 
     1837            print SST_SQLFILE "institution_url,"; 
     1838            print SST_SQLFILE "institution_dods_url,"; 
     1839            print SST_SQLFILE "source,"; 
     1840            print SST_SQLFILE "refs,"; 
     1841            print SST_SQLFILE "contact,"; 
     1842            print SST_SQLFILE "the_geom"; 
     1843            print SST_SQLFILE ") ";  
     1844            print SST_SQLFILE "VALUES (";  
     1845            print SST_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1846            print SST_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1847            if ($sea_surface_temperature[$i]{'height'} == $missing_value_value 
     1848              || $sea_surface_temperature[$i]{'height'} == $Fill_value_value) { 
     1849              print SST_SQLFILE ','.'\'\''; 
     1850            } 
     1851            else { 
     1852              $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'height'}); 
     1853              print SST_SQLFILE ','.$this_val; 
     1854            } 
     1855 
     1856            print SST_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1857            $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'data'}[$j]); 
     1858             
     1859             
     1860            print SST_SQLFILE ','.$this_val; 
     1861            print SST_SQLFILE ','.'\''.$title_value.'\''; 
     1862            print SST_SQLFILE ','.'\''.$institution_value.'\''; 
     1863            print SST_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1864            print SST_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1865            print SST_SQLFILE ','.'\''.$source_value.'\''; 
     1866            print SST_SQLFILE ','.'\''.$references_value.'\''; 
     1867            print SST_SQLFILE ','.'\''.$contact_value.'\''; 
     1868            print SST_SQLFILE ",GeometryFromText('POINT(";  
     1869            print SST_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1870            print SST_SQLFILE ")',-1));\n"; 
     1871          } 
     1872           
     1873        } 
     1874        print SST_SQLFILE "\n"; 
     1875      } 
     1876      close(SST_SQLFILE); 
     1877    } 
     1878    #DWR 4/5/2008 
     1879    if( $bWriteobsKMLFile ) 
     1880    { 
     1881      my $DataVal = 'NULL'; 
     1882      my $Height = ''; 
     1883       
     1884      for my $i (0..$#sea_surface_temperature)  
     1885      { 
     1886        for my $j ($iStartingNdx..$#this_sea_surface_temperature_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1887        #for my $j (0..$#this_sea_surface_temperature_data)  
     1888        { 
     1889          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1890          $this_time_stamp = $time_formatted_values[$j]; 
     1891          $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)); 
     1892         
     1893          if ($sea_surface_temperature[$i]{'data'}[$j] != $missing_value_value 
     1894              && $sea_surface_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1895              && $this_station_id_top_ts < $this_time_stamp_sec 
     1896              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     1897          { 
     1898 
     1899            if ($sea_surface_temperature[$i]{'height'} != $missing_value_value 
     1900              && $sea_surface_temperature[$i]{'height'} != $Fill_value_value)  
     1901            { 
     1902              $Height = sprintf("%.2f",$sea_surface_temperature[$i]{'height'}); 
     1903            } 
     1904            $DataVal = sprintf("%.2f",$sea_surface_temperature[$i]{'data'}[$j]); 
     1905                       
     1906          } 
     1907          my $strUnits; 
     1908          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_temperature[$i]{'units'}, $XMLControlFile ); 
     1909          if( length( $strUnits ) == 0 ) 
     1910          { 
     1911            $strUnits = $sea_surface_temperature[$i]{'units'}; 
     1912          } 
     1913          obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
     1914                                            $KMLTimeStamp[$j], 
     1915                                            $DataVal, 
     1916                                            1, 
     1917                                            $strPlatformID, 
     1918                                            $Height, 
     1919                                            $strUnits, 
     1920                                            $rObsHash ); 
     1921        } 
     1922      }                                             
     1923    } 
     1924  } 
     1925  # sea_bottom_temperature (sbt) 
     1926  if ($#sea_bottom_temperature > -1) { 
     1927    if( $bWriteSQLFiles ) 
     1928    { 
     1929      open(SBT_SQLFILE,'>>../sql/bottom_water_temp_prod_'.$institution_code_value.'_' 
     1930        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1931      print SBT_SQLFILE "-- format_category      = $format_category_value\n"; 
     1932      print SBT_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1933      print SBT_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1934      print SBT_SQLFILE "-- package_code         = $package_code_value\n"; 
     1935      print SBT_SQLFILE "-- title                = $title_value\n"; 
     1936      print SBT_SQLFILE "-- institution          = $institution_value\n"; 
     1937      print SBT_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1938      print SBT_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1939      print SBT_SQLFILE "-- source               = $source_value\n"; 
     1940      print SBT_SQLFILE "-- references           = $references_value\n"; 
     1941      print SBT_SQLFILE "-- contact              = $contact_value\n"; 
     1942      print SBT_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1943      print SBT_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1944       
     1945      for my $i (0..$#sea_bottom_temperature) { 
     1946        for my $j (0..$#this_sea_bottom_temperature_data) { 
     1947          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1948          $this_time_stamp = $time_formatted_values[$j]; 
     1949          $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)); 
     1950         
     1951          if ($sea_bottom_temperature[$i]{'data'}[$j] != $missing_value_value 
     1952            && $sea_bottom_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1953            && $this_station_id_top_ts < $this_time_stamp_sec 
     1954            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1955            print SBT_SQLFILE "INSERT INTO bottom_water_temp_prod (";  
     1956            print SBT_SQLFILE "station_id,"; 
     1957            print SBT_SQLFILE "time_stamp,";  
     1958            print SBT_SQLFILE "z,"; 
     1959            print SBT_SQLFILE "positive,"; 
     1960            print SBT_SQLFILE "temperature_celcius,"; 
     1961            print SBT_SQLFILE "title,"; 
     1962            print SBT_SQLFILE "institution,"; 
     1963            print SBT_SQLFILE "institution_url,"; 
     1964            print SBT_SQLFILE "institution_dods_url,"; 
     1965            print SBT_SQLFILE "source,"; 
     1966            print SBT_SQLFILE "refs,"; 
     1967            print SBT_SQLFILE "contact,"; 
     1968            print SBT_SQLFILE "the_geom"; 
     1969            print SBT_SQLFILE ") ";  
     1970            print SBT_SQLFILE "VALUES (";  
     1971            print SBT_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1972            print SBT_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1973            if ($sea_bottom_temperature[$i]{'height'} == $missing_value_value 
     1974              || $sea_bottom_temperature[$i]{'height'} == $Fill_value_value) { 
     1975              print SBT_SQLFILE ','.'\'\''; 
     1976            } 
     1977            else { 
     1978              $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'height'}); 
     1979              print SBT_SQLFILE ','.$this_val; 
     1980            } 
     1981 
     1982            print SBT_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1983            $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'data'}[$j]); 
     1984             
     1985             
     1986            print SBT_SQLFILE ','.$this_val; 
     1987            print SBT_SQLFILE ','.'\''.$title_value.'\''; 
     1988            print SBT_SQLFILE ','.'\''.$institution_value.'\''; 
     1989            print SBT_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1990            print SBT_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1991            print SBT_SQLFILE ','.'\''.$source_value.'\''; 
     1992            print SBT_SQLFILE ','.'\''.$references_value.'\''; 
     1993            print SBT_SQLFILE ','.'\''.$contact_value.'\''; 
     1994            print SBT_SQLFILE ",GeometryFromText('POINT(";  
     1995            print SBT_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1996            print SBT_SQLFILE ")',-1));\n"; 
     1997          } 
     1998 
     1999        } 
     2000        print SBT_SQLFILE "\n"; 
     2001      } 
     2002      close(SBT_SQLFILE); 
     2003    } 
     2004    #DWR 4/5/2008 
     2005    if( $bWriteobsKMLFile ) 
     2006    { 
     2007      my $DataVal = 'NULL'; 
     2008      my $Height = ''; 
     2009      for my $i (0..$#sea_bottom_temperature)  
     2010      { 
     2011        for my $j ($iStartingNdx..$#sea_bottom_temperature)       #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2012        #for my $j (0..$#sea_bottom_temperature)  
     2013        { 
     2014          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2015          $this_time_stamp = $time_formatted_values[$j]; 
     2016          $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));        
     2017          if ($sea_bottom_temperature[$i]{'data'}[$j] != $missing_value_value 
     2018              && $sea_bottom_temperature[$i]{'data'}[$j] != $Fill_value_value 
     2019              && $this_station_id_top_ts < $this_time_stamp_sec 
     2020              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2021          { 
     2022 
     2023            if ($sea_bottom_temperature[$i]{'height'} != $missing_value_value 
     2024              && $sea_bottom_temperature[$i]{'height'} != $Fill_value_value)  
     2025            { 
     2026              $Height = sprintf("%.2f",$sea_bottom_temperature[$i]{'height'}); 
     2027            } 
     2028            $DataVal = sprintf("%.2f",$sea_bottom_temperature[$i]{'data'}[$j]); 
     2029                       
     2030          } 
     2031          my $strUnits; 
     2032          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_bottom_temperature[$i]{'units'}, $XMLControlFile );         
     2033          if( length( $strUnits ) == 0 ) 
     2034          { 
     2035           $strUnits = $sea_bottom_temperature[$i]{'units'}; 
     2036          } 
     2037          obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
     2038                                            $KMLTimeStamp[$j], 
     2039                                            $DataVal, 
     2040                                            2, 
     2041                                            $strPlatformID, 
     2042                                            $Height, 
     2043                                            $strUnits, 
     2044                                            $rObsHash ); 
     2045        } 
     2046      }                                             
     2047    }     
     2048  } 
     2049   
     2050  # air_temperature 
     2051  # Going to do this right this time.  Instead of populating each row w/ all 
     2052  # the metadata, use the station_id lookup, instead. 
     2053  if ($#air_temperature > -1) { 
     2054    #DWR 4/5/2008  
     2055    if( $bWriteSQLFiles ) 
     2056    { 
     2057      open(AIR_TEMP_SQLFILE,'>>../sql/air_temperature_prod_'.$institution_code_value.'_' 
     2058        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2059      print AIR_TEMP_SQLFILE "-- format_category      = $format_category_value\n"; 
     2060      print AIR_TEMP_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2061      print AIR_TEMP_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2062      print AIR_TEMP_SQLFILE "-- package_code         = $package_code_value\n"; 
     2063      print AIR_TEMP_SQLFILE "-- title                = $title_value\n"; 
     2064      print AIR_TEMP_SQLFILE "-- institution          = $institution_value\n"; 
     2065      print AIR_TEMP_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2066      print AIR_TEMP_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2067      print AIR_TEMP_SQLFILE "-- source               = $source_value\n"; 
     2068      print AIR_TEMP_SQLFILE "-- references           = $references_value\n"; 
     2069      print AIR_TEMP_SQLFILE "-- contact              = $contact_value\n"; 
     2070      print AIR_TEMP_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2071      print AIR_TEMP_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2072      for my $i (0..$#air_temperature) { 
     2073        for my $j (0..$#this_air_temperature_data) { 
     2074          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2075          $this_time_stamp = $time_formatted_values[$j]; 
     2076          $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)); 
     2077 
     2078          my $DataValue = 'NULL'; 
     2079          my $Height    = ''; 
     2080          if ($air_temperature[$i]{'data'}[$j] != $missing_value_value 
     2081            && $air_temperature[$i]{'data'}[$j] != $Fill_value_value 
     2082            && $this_station_id_top_ts < $this_time_stamp_sec 
     2083            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2084            print AIR_TEMP_SQLFILE "INSERT INTO air_temperature_prod (";  
     2085            print AIR_TEMP_SQLFILE "station_id,"; 
     2086            print AIR_TEMP_SQLFILE "time_stamp,";  
     2087            print AIR_TEMP_SQLFILE "z,"; 
     2088            print AIR_TEMP_SQLFILE "positive,"; 
     2089            print AIR_TEMP_SQLFILE "temperature_celcius,"; 
     2090            print AIR_TEMP_SQLFILE "the_geom"; 
     2091            print AIR_TEMP_SQLFILE ") ";  
     2092            print AIR_TEMP_SQLFILE "VALUES (";  
     2093            print AIR_TEMP_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2094            print AIR_TEMP_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2095            if ($air_temperature[$i]{'height'} == $missing_value_value 
     2096              || $air_temperature[$i]{'height'} == $Fill_value_value) { 
     2097              print AIR_TEMP_SQLFILE ',NULL'; 
     2098            } 
     2099            else { 
     2100              $this_val = sprintf("%.2f",$air_temperature[$i]{'height'}); 
     2101              print AIR_TEMP_SQLFILE ','.$this_val;               
     2102            } 
     2103            print AIR_TEMP_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2104            $this_val = sprintf("%.2f",$air_temperature[$i]{'data'}[$j]); 
     2105            print AIR_TEMP_SQLFILE ','.$this_val; 
     2106            print AIR_TEMP_SQLFILE ",GeometryFromText('POINT(";  
     2107            print AIR_TEMP_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2108            print AIR_TEMP_SQLFILE ")',-1));\n"; 
     2109                        
     2110          } 
     2111        } 
     2112        print AIR_TEMP_SQLFILE "\n"; 
     2113      } 
     2114      close(AIR_TEMP_SQLFILE); 
     2115    } 
     2116    #DWR 4/5/2008 
     2117    if( $bWriteobsKMLFile ) 
     2118    { 
     2119      my $DataVal = 'NULL'; 
     2120      my $Height = ''; 
     2121      for my $i (0..$#air_temperature)  
     2122      { 
     2123        for my $j ($iStartingNdx..$#air_temperature) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2124        #for my $j (0..$#air_temperature)  
     2125        { 
     2126          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2127          $this_time_stamp = $time_formatted_values[$j]; 
     2128          $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)); 
     2129         
     2130          if ($air_temperature[$i]{'data'}[$j] != $missing_value_value 
     2131              && $air_temperature[$i]{'data'}[$j] != $Fill_value_value 
     2132              && $this_station_id_top_ts < $this_time_stamp_sec 
     2133              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2134          { 
     2135 
     2136            if ($air_temperature[$i]{'height'} != $missing_value_value 
     2137              && $air_temperature[$i]{'height'} != $Fill_value_value)  
     2138            { 
     2139              $Height = sprintf("%.2f",$air_temperature[$i]{'height'}); 
     2140            } 
     2141            $DataVal = sprintf("%.2f",$air_temperature[$i]{'data'}[$j]); 
     2142                       
     2143          } 
     2144          my $strUnits; 
     2145          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $air_temperature[$i]{'units'}, $XMLControlFile );         
     2146          if( length( $strUnits ) == 0 ) 
     2147          { 
     2148           $strUnits = $air_temperature[$i]{'units'}; 
     2149          } 
     2150          obsKMLSubRoutines::KMLAddObsToHash( 'air_temperature',  
     2151                                            $KMLTimeStamp[$j], 
     2152                                            $DataVal, 
     2153                                            1, 
     2154                                            $strPlatformID, 
     2155                                            $Height, 
     2156                                            $strUnits, 
     2157                                            $rObsHash ); 
     2158        } 
     2159      }                                             
     2160    }         
     2161  } 
     2162  
     2163 
     2164  # wind_speed and wind_gust and wind_from_direction 
     2165  # Start w/ wind_speed and then look through the wind_from_direction to find its 
     2166  # pair by looking at the heights.  This index will also define the gust. 
     2167  # Assume that wind_speed controls everything (from_dir, gust, z, normalized) index-wise. 
     2168  if ($#wind_speed > -1) { 
     2169    #dwr 4/5/2008 
     2170    if( $bWriteSQLFiles ) 
     2171    { 
     2172      open(WIND_SQLFILE,'>>../sql/wind_prod_'.$institution_code_value.'_' 
     2173        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2174      print WIND_SQLFILE "-- format_category      = $format_category_value\n"; 
     2175      print WIND_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2176      print WIND_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2177      print WIND_SQLFILE "-- package_code         = $package_code_value\n"; 
     2178      print WIND_SQLFILE "-- title                = $title_value\n"; 
     2179      print WIND_SQLFILE "-- institution          = $institution_value\n"; 
     2180      print WIND_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2181      print WIND_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2182      print WIND_SQLFILE "-- source               = $source_value\n"; 
     2183      print WIND_SQLFILE "-- references           = $references_value\n"; 
     2184      print WIND_SQLFILE "-- contact              = $contact_value\n"; 
     2185      print WIND_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2186      print WIND_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2187      for my $i (0..$#wind_speed) { 
     2188        my $j = 0; 
     2189        while ($j <= $#wind_from_direction 
     2190          && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'}) { 
     2191          $j++; 
     2192        } 
     2193        if ($j > $#wind_from_direction) { 
     2194          die "ABORT!  Could not find matching wind_from_direction for $wind_speed[$i]  {'var_name'}.\n"; 
     2195        } 
     2196        else { 
     2197          for my $k (0..$#this_wind_speed_data) { 
     2198            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2199            $this_time_stamp = $time_formatted_values[$k]; 
     2200            $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)); 
     2201             
     2202            if ($wind_speed[$i]{'data'}[$k] != $missing_value_value 
     2203              && $wind_speed[$i]{'data'}[$k] != $Fill_value_value 
     2204              && $wind_from_direction[$j]{'data'}[$k] != $missing_value_value 
     2205              && $wind_from_direction[$j]{'data'}[$k] != $Fill_value_value 
     2206              && $this_station_id_top_ts < $this_time_stamp_sec 
     2207              && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2208              print WIND_SQLFILE "INSERT INTO wind_prod (";  
     2209              print WIND_SQLFILE "station_id,"; 
     2210              print WIND_SQLFILE "time_stamp,";  
     2211              print WIND_SQLFILE "z,"; 
     2212              print WIND_SQLFILE "positive,"; 
     2213              print WIND_SQLFILE "wind_speed,"; 
     2214              print WIND_SQLFILE "wind_gust,"; 
     2215              print WIND_SQLFILE "wind_from_direction,"; 
     2216              print WIND_SQLFILE "can_be_normalized,"; 
     2217              print WIND_SQLFILE "title,"; 
     2218              print WIND_SQLFILE "institution,"; 
     2219              print WIND_SQLFILE "institution_url,"; 
     2220              print WIND_SQLFILE "institution_dods_url,"; 
     2221              print WIND_SQLFILE "source,"; 
     2222              print WIND_SQLFILE "refs,"; 
     2223              print WIND_SQLFILE "contact,"; 
     2224              print WIND_SQLFILE "the_geom"; 
     2225              print WIND_SQLFILE ") ";  
     2226              print WIND_SQLFILE "VALUES (";  
     2227              print WIND_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2228              print WIND_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; 
     2229              if ($wind_speed[$i]{'height'} == $missing_value_value 
     2230                || $wind_speed[$i]{'height'} == $Fill_value_value) { 
     2231                print WIND_SQLFILE ','.'\'\''; 
     2232              } 
     2233              else { 
     2234                $this_val = sprintf("%.2f",$wind_speed[$i]{'height'}); 
     2235                print WIND_SQLFILE ','.$this_val; 
     2236              } 
     2237 
     2238              print WIND_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2239              $this_val = sprintf("%.2f",$wind_speed[$i]{'data'}[$k]); 
     2240              print WIND_SQLFILE ','.$this_val; 
     2241 
     2242 
     2243              if ($wind_gust[$j]{'data'}[$k] == $missing_value_value 
     2244                || $wind_gust[$j]{'data'}[$k] == $Fill_value_value 
     2245                || $wind_gust[$j]{'data'}[$k] == '') { 
     2246                print WIND_SQLFILE ',NULL'; 
     2247              } 
     2248              else { 
     2249                $this_val = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     2250                print WIND_SQLFILE ','.$this_val; 
     2251              } 
     2252               
     2253              $this_val = sprintf("%.2f",$wind_from_direction[$j]{'data'}[$k]); 
     2254               
     2255              print WIND_SQLFILE ','.$this_val; 
     2256              print WIND_SQLFILE ','.'\''.$wind_speed[$i]{'can_be_normalized'}.'\''; 
     2257              print WIND_SQLFILE ','.'\''.$title_value.'\''; 
     2258              print WIND_SQLFILE ','.'\''.$institution_value.'\''; 
     2259              print WIND_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     2260              print WIND_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     2261              print WIND_SQLFILE ','.'\''.$source_value.'\''; 
     2262              print WIND_SQLFILE ','.'\''.$references_value.'\''; 
     2263              print WIND_SQLFILE ','.'\''.$contact_value.'\''; 
     2264              print WIND_SQLFILE ",GeometryFromText('POINT(";  
     2265              print WIND_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2266              print WIND_SQLFILE ")',-1));\n"; 
     2267                             
     2268            } 
     2269          } 
     2270        } 
     2271        print WIND_SQLFILE "\n"; 
     2272      } 
     2273      close(WIND_SQLFILE); 
     2274    } 
     2275    #DWR 4/5/2008 
     2276    if( $bWriteobsKMLFile ) 
     2277    { 
     2278      for my $i (0..$#wind_speed)  
     2279      { 
     2280        my $j = 0; 
     2281        while ($j <= $#wind_from_direction 
     2282          && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'})  
     2283        { 
     2284          $j++; 
     2285        } 
     2286        if ($j > $#wind_from_direction)  
     2287        { 
     2288          die "ABORT!  Could not find matching wind_from_direction for $wind_speed[$i]  {'var_name'}.\n"; 
     2289        } 
     2290        else  
     2291        { 
     2292          for my $k ($iStartingNdx..$#this_wind_speed_data)  
     2293          #for my $k (0..$#this_wind_speed_data)  
     2294          { 
     2295            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2296            $this_time_stamp = $time_formatted_values[$k]; 
     2297            $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)); 
     2298             
     2299            my $WindSpdDataVal = 'NULL'; 
     2300            my $WindDirDataVal = 'NULL'; 
     2301            my $WindGstDataVal = 'NULL'; 
     2302            my $Height = ''; 
     2303            if ($wind_speed[$i]{'data'}[$k] != $missing_value_value 
     2304              && $wind_speed[$i]{'data'}[$k] != $Fill_value_value 
     2305              && $wind_from_direction[$j]{'data'}[$k] != $missing_value_value 
     2306              && $wind_from_direction[$j]{'data'}[$k] != $Fill_value_value 
     2307              && $this_station_id_top_ts < $this_time_stamp_sec 
     2308              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2309              { 
     2310                if ($wind_speed[$i]{'height'} != $missing_value_value 
     2311                  && $wind_speed[$i]{'height'} != $Fill_value_value)  
     2312                { 
     2313                  $Height = sprintf("%.2f",$wind_speed[$i]{'height'}); 
     2314                } 
     2315 
     2316                $this_val = sprintf("%.2f",$wind_speed[$i]{'data'}[$k]); 
     2317                if( length( $this_val ) > 0 ) 
     2318                { 
     2319                  $WindSpdDataVal = $this_val; 
     2320                } 
     2321 
     2322                if ($wind_gust[$j]{'data'}[$k] != $missing_value_value 
     2323                    && $wind_gust[$j]{'data'}[$k] != $Fill_value_value 
     2324                    && $wind_gust[$j]{'data'}[$k] != '')  
     2325                { 
     2326                  $WindGstDataVal = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     2327                } 
     2328                 
     2329                $this_val = sprintf("%.2f",$wind_from_direction[$j]{'data'}[$k]); 
     2330                #DWR 4/5/2008 
     2331                if( length( $this_val ) > 0 ) 
     2332                { 
     2333                  $WindDirDataVal = $this_val; 
     2334                }               
     2335              } 
     2336              my $strUnits; 
     2337              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_speed[$i]{'units'}, $XMLControlFile );         
     2338              if( length( $strUnits ) == 0 ) 
     2339              { 
     2340               $strUnits = $wind_speed[$i]{'units'}; 
     2341              } 
     2342               
     2343              obsKMLSubRoutines::KMLAddObsToHash( 'wind_speed',  
     2344                                                  $KMLTimeStamp[$j], 
     2345                                                  $WindSpdDataVal, 
     2346                                                  1, 
     2347                                                  $strPlatformID, 
     2348                                                  $Height, 
     2349                                                  $strUnits, 
     2350                                                  $rObsHash ); 
     2351              $strUnits = ''; 
     2352              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_from_direction[$i]{'units'}, $XMLControlFile );         
     2353              if( length( $strUnits ) == 0 ) 
     2354              { 
     2355               $strUnits = $wind_from_direction[$i]{'units'}; 
     2356              } 
     2357              obsKMLSubRoutines::KMLAddObsToHash( 'wind_from_direction',  
     2358                                                  $KMLTimeStamp[$j], 
     2359                                                  $WindDirDataVal, 
     2360                                                  1, 
     2361                                                  $strPlatformID, 
     2362                                                  $Height, 
     2363                                                  $strUnits, 
     2364                                                  $rObsHash ); 
     2365              $strUnits = ''; 
     2366              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_gust[$i]{'units'}, $XMLControlFile );         
     2367              if( length( $strUnits ) == 0 ) 
     2368              { 
     2369               $strUnits = $wind_gust[$i]{'units'}; 
     2370              } 
     2371              obsKMLSubRoutines::KMLAddObsToHash( 'wind_gust',  
     2372                                                  $KMLTimeStamp[$j], 
     2373                                                  $WindGstDataVal, 
     2374                                                  1, 
     2375                                                  $strPlatformID, 
     2376                                                  $Height, 
     2377                                                  $strUnits, 
     2378                                                  $rObsHash ); 
     2379          } 
     2380        } 
     2381      }                                             
     2382    }             
     2383  } 
     2384   
     2385  # air_pressure 
     2386  # Going to do this right this time.  Instead of populating each row w/ all 
     2387  # the metadata, use the station_id lookup, instead. 
     2388  if ($#air_pressure > -1) { 
     2389    if( $bWriteSQLFiles ) 
     2390    { 
     2391      open(AIR_PRESSURE_SQLFILE,'>>../sql/air_pressure_prod_'.$institution_code_value.'_' 
     2392        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2393      print AIR_PRESSURE_SQLFILE "-- format_category      = $format_category_value\n"; 
     2394      print AIR_PRESSURE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2395      print AIR_PRESSURE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2396      print AIR_PRESSURE_SQLFILE "-- package_code         = $package_code_value\n"; 
     2397      print AIR_PRESSURE_SQLFILE "-- title                = $title_value\n"; 
     2398      print AIR_PRESSURE_SQLFILE "-- institution          = $institution_value\n"; 
     2399      print AIR_PRESSURE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2400      print AIR_PRESSURE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2401      print AIR_PRESSURE_SQLFILE "-- source               = $source_value\n"; 
     2402      print AIR_PRESSURE_SQLFILE "-- references           = $references_value\n"; 
     2403      print AIR_PRESSURE_SQLFILE "-- contact              = $contact_value\n"; 
     2404      print AIR_PRESSURE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2405      print AIR_PRESSURE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2406      for my $i (0..$#air_pressure) { 
     2407        for my $j (0..$#this_air_pressure_data) { 
     2408          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2409          $this_time_stamp = $time_formatted_values[$j]; 
     2410          $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)); 
     2411           
     2412          if ($air_pressure[$i]{'data'}[$j] != $missing_value_value 
     2413            && $air_pressure[$i]{'data'}[$j] != $Fill_value_value 
     2414            && $this_station_id_top_ts < $this_time_stamp_sec 
     2415            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2416            print AIR_PRESSURE_SQLFILE "INSERT INTO air_pressure_prod (";  
     2417            print AIR_PRESSURE_SQLFILE "station_id,"; 
     2418            print AIR_PRESSURE_SQLFILE "time_stamp,";  
     2419            print AIR_PRESSURE_SQLFILE "z,"; 
     2420            print AIR_PRESSURE_SQLFILE "positive,"; 
     2421            print AIR_PRESSURE_SQLFILE "pressure,"; 
     2422            print AIR_PRESSURE_SQLFILE "the_geom"; 
     2423            print AIR_PRESSURE_SQLFILE ") ";  
     2424            print AIR_PRESSURE_SQLFILE "VALUES (";  
     2425            print AIR_PRESSURE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2426            print AIR_PRESSURE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2427            if ($air_pressure[$i]{'height'} == $missing_value_value 
     2428              || $air_pressure[$i]{'height'} == $Fill_value_value) { 
     2429              print AIR_PRESSURE_SQLFILE ',NULL'; 
     2430            } 
     2431            else { 
     2432              $this_val = sprintf("%.2f",$air_pressure[$i]{'height'}); 
     2433              print AIR_PRESSURE_SQLFILE ','.$this_val; 
     2434            } 
     2435             
     2436            print AIR_PRESSURE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2437            $this_val = sprintf("%.2f",$air_pressure[$i]{'data'}[$j]); 
     2438             
     2439            print AIR_PRESSURE_SQLFILE ','.$this_val; 
     2440            print AIR_PRESSURE_SQLFILE ",GeometryFromText('POINT(";  
     2441            print AIR_PRESSURE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2442            print AIR_PRESSURE_SQLFILE ")',-1));\n"; 
     2443          } 
     2444           
     2445        } 
     2446        print AIR_PRESSURE_SQLFILE "\n"; 
     2447      } 
     2448      close(AIR_PRESSURE_SQLFILE); 
     2449    } 
     2450    #DWR 4/5/2008 
     2451    if( $bWriteobsKMLFile ) 
     2452    { 
     2453      my $DataVal = 'NULL'; 
     2454      my $Height = ''; 
     2455      for my $i (0..$#air_pressure)  
     2456      { 
     2457        for my $j ($iStartingNdx..$#this_air_pressure_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2458        #for my $j (0..$#this_air_pressure_data)  
     2459        { 
     2460          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2461          $this_time_stamp = $time_formatted_values[$j]; 
     2462          $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)); 
     2463           
     2464          my $DataVal = 'NULL'; 
     2465          my $Height = ''; 
     2466          if ($air_pressure[$i]{'data'}[$j] != $missing_value_value 
     2467            && $air_pressure[$i]{'data'}[$j] != $Fill_value_value 
     2468            && $this_station_id_top_ts < $this_time_stamp_sec 
     2469            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2470            if ($air_pressure[$i]{'height'} != $missing_value_value 
     2471              && $air_pressure[$i]{'height'} != $Fill_value_value)  
     2472            { 
     2473              $Height = sprintf("%.2f",$air_pressure[$i]{'height'}); 
     2474            } 
     2475            $DataVal = sprintf("%.2f",$air_pressure[$i]{'data'}[$j]); 
     2476          }            
     2477          #DWR 4/3/2008 
     2478          my $strUnits; 
     2479          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $air_pressure[$i]{'units'}, $XMLControlFile );  
     2480          if( length( $strUnits ) == 0 ) 
     2481          { 
     2482           $strUnits =  $air_pressure[$i]{'units'}; 
     2483          } 
     2484          obsKMLSubRoutines::KMLAddObsToHash( 'air_pressure',  
     2485                                              $KMLTimeStamp[$j], 
     2486                                              $DataVal, 
     2487                                              1, 
     2488                                              $strPlatformID, 
     2489                                              $Height, 
     2490                                              $strUnits, 
     2491                                              $rObsHash ); 
     2492        } 
     2493      }                                             
     2494    }         
     2495  } 
     2496   
     2497  # salinity 
     2498  # Going to do this right this time.  Instead of populating each row w/ all 
     2499  # the metadata, use the station_id lookup, instead. 
     2500  if ($#salinity > -1) { 
     2501    if( $bWriteSQLFiles ) 
     2502    { 
     2503      open(SALINITY_SQLFILE,'>>../sql/salinity_prod_'.$institution_code_value.'_' 
     2504        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2505      print SALINITY_SQLFILE "-- format_category      = $format_category_value\n"; 
     2506      print SALINITY_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2507      print SALINITY_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2508      print SALINITY_SQLFILE "-- package_code         = $package_code_value\n"; 
     2509      print SALINITY_SQLFILE "-- title                = $title_value\n"; 
     2510      print SALINITY_SQLFILE "-- institution          = $institution_value\n"; 
     2511      print SALINITY_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2512      print SALINITY_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2513      print SALINITY_SQLFILE "-- source               = $source_value\n"; 
     2514      print SALINITY_SQLFILE "-- references           = $references_value\n"; 
     2515      print SALINITY_SQLFILE "-- contact              = $contact_value\n"; 
     2516      print SALINITY_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2517      print SALINITY_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2518      for my $i (0..$#salinity) { 
     2519        for my $j (0..$#this_salinity_data) { 
     2520          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2521          $this_time_stamp = $time_formatted_values[$j]; 
     2522          $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)); 
     2523           
     2524          #print "debug: $salinity[$i]{'data'}[$k]\n";             
     2525          if ($salinity[$i]{'data'}[$j] != $missing_value_value 
     2526            && $salinity[$i]{'data'}[$j] != $Fill_value_value 
     2527            && $this_station_id_top_ts < $this_time_stamp_sec 
     2528            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2529            print SALINITY_SQLFILE "INSERT INTO salinity_prod (";  
     2530            print SALINITY_SQLFILE "station_id,"; 
     2531            print SALINITY_SQLFILE "time_stamp,";  
     2532            print SALINITY_SQLFILE "z,"; 
     2533            print SALINITY_SQLFILE "positive,"; 
     2534            print SALINITY_SQLFILE "salinity,"; 
     2535            print SALINITY_SQLFILE "the_geom"; 
     2536            print SALINITY_SQLFILE ") ";  
     2537            print SALINITY_SQLFILE "VALUES (";  
     2538            print SALINITY_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2539            print SALINITY_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2540            if ($salinity[$i]{'height'} == $missing_value_value 
     2541              || $salinity[$i]{'height'} == $Fill_value_value) { 
     2542              print SALINITY_SQLFILE ',NULL'; 
     2543            } 
     2544            else { 
     2545              $this_val = sprintf("%.2f",$salinity[$i]{'height'}); 
     2546              print SALINITY_SQLFILE ','.$this_val; 
     2547            } 
     2548             
     2549            print SALINITY_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2550            $this_val = sprintf("%.2f",$salinity[$i]{'data'}[$j]); 
     2551             
     2552            print SALINITY_SQLFILE ','.$this_val; 
     2553            print SALINITY_SQLFILE ",GeometryFromText('POINT(";  
     2554            print SALINITY_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2555            print SALINITY_SQLFILE ")',-1));\n"; 
     2556          }           
     2557        } 
     2558        print SALINITY_SQLFILE "\n"; 
     2559      } 
     2560      close(SALINITY_SQLFILE); 
     2561    } 
     2562    #DWR 4/5/2008 
     2563    if( $bWriteobsKMLFile ) 
     2564    { 
     2565      my $DataVal = 'NULL'; 
     2566      my $Height = ''; 
     2567      for my $i (0..$#salinity)  
     2568      { 
     2569        for my $j ($iStartingNdx..$#this_salinity_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2570        #for my $j (0..$#this_salinity_data)  
     2571        { 
     2572          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2573          $this_time_stamp = $time_formatted_values[$j]; 
     2574          $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)); 
     2575           
     2576          my $DataVal = 'NULL'; 
     2577          my $Height = ''; 
     2578          if ($salinity[$i]{'data'}[$j] != $missing_value_value 
     2579              && $salinity[$i]{'data'}[$j] != $Fill_value_value 
     2580              && $this_station_id_top_ts < $this_time_stamp_sec 
     2581              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2582          { 
     2583            if ($salinity[$i]{'height'} != $missing_value_value 
     2584              && $salinity[$i]{'height'} != $Fill_value_value)  
     2585            { 
     2586              $Height = sprintf("%.2f",$salinity[$i]{'height'}); 
     2587            } 
     2588            $DataVal = sprintf("%.2f",$salinity[$i]{'data'}[$j]); 
     2589          }            
     2590          my $strUnits; 
     2591          if( lc( $salinity[$i]{'units'} ) eq 'ppt' ) 
     2592          { 
     2593            $strUnits =  'psu';         
     2594          } 
     2595          if( length( $strUnits ) == 0 ) 
     2596          { 
     2597           $strUnits = $salinity[$i]{'units'}; 
     2598          } 
     2599           
     2600          obsKMLSubRoutines::KMLAddObsToHash( 'salinity',  
     2601                                              $KMLTimeStamp[$j], 
     2602                                              $DataVal, 
     2603                                              1, 
     2604                                              $strPlatformID, 
     2605                                              $Height, 
     2606                                              $strUnits, 
     2607                                              $rObsHash ); 
     2608        } 
     2609      }                                             
     2610    }             
     2611  } 
     2612   
     2613    # sea_surface_eastward_current and sea_surface_northward_current 
     2614    # Start w/ sea_surface_eastward_current and then look through the sea_surface_northward_current 
     2615    # to find its pair by looking at the heights.  (This is overkill for sea_surface_currents. 
     2616    # Assume that sea_surface_eastward_current controls everything index-wise. 
     2617    if ($#sea_surface_eastward_current > -1)  
     2618    { 
     2619      if( $bWriteSQLFiles ) 
     2620      { 
     2621        open(CURRENT_IN_SITU_SQLFILE,'>>../sql/current_in_situ_prod_'.$institution_code_value.'_' 
     2622          .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2623        print CURRENT_IN_SITU_SQLFILE "-- format_category      = $format_category_value\n"; 
     2624        print CURRENT_IN_SITU_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2625        print CURRENT_IN_SITU_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2626        print CURRENT_IN_SITU_SQLFILE "-- package_code         = $package_code_value\n"; 
     2627        print CURRENT_IN_SITU_SQLFILE "-- title                = $title_value\n"; 
     2628        print CURRENT_IN_SITU_SQLFILE "-- institution          = $institution_value\n"; 
     2629        print CURRENT_IN_SITU_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2630        print CURRENT_IN_SITU_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2631        print CURRENT_IN_SITU_SQLFILE "-- source               = $source_value\n"; 
     2632        print CURRENT_IN_SITU_SQLFILE "-- references           = $references_value\n"; 
     2633        print CURRENT_IN_SITU_SQLFILE "-- contact              = $contact_value\n"; 
     2634        print CURRENT_IN_SITU_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2635        print CURRENT_IN_SITU_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2636        for my $i (0..$#sea_surface_eastward_current) { 
     2637          my $j = 0; 
     2638          while ($j <= $#sea_surface_northward_current 
     2639            && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'}) { 
     2640            $j++; 
     2641          } 
     2642          if ($j > $#sea_surface_northward_current) { 
     2643            die "ABORT!  Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i]  {'var_name'}.\n"; 
     2644          } 
     2645          else { 
     2646            for my $k (0..$#this_sea_surface_eastward_current_data) { 
     2647              $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2648              $this_time_stamp = $time_formatted_values[$k]; 
     2649              $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)); 
     2650                           
     2651        #print "debug: $sea_surface_eastward_current[$i]{'data'}[$k]\n";             
     2652              if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value 
     2653                && $sea_surface_eastward_current[$i]{'data'}[$k] != $Fill_value_value 
     2654                && $sea_surface_northward_current[$j]{'data'}[$k] != $missing_value_value 
     2655                && $sea_surface_northward_current[$j]{'data'}[$k] != $Fill_value_value 
     2656                && $this_station_id_top_ts < $this_time_stamp_sec 
     2657                && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2658                print CURRENT_IN_SITU_SQLFILE "INSERT INTO current_in_situ_prod (";  
     2659                print CURRENT_IN_SITU_SQLFILE "station_id,"; 
     2660                print CURRENT_IN_SITU_SQLFILE "time_stamp,";  
     2661                print CURRENT_IN_SITU_SQLFILE "z,"; 
     2662                print CURRENT_IN_SITU_SQLFILE "positive,"; 
     2663                print CURRENT_IN_SITU_SQLFILE "eastward_current,"; 
     2664                print CURRENT_IN_SITU_SQLFILE "northward_current,"; 
     2665                print CURRENT_IN_SITU_SQLFILE "surface_or_bottom,"; 
     2666                print CURRENT_IN_SITU_SQLFILE "the_geom"; 
     2667                print CURRENT_IN_SITU_SQLFILE ") ";  
     2668                print CURRENT_IN_SITU_SQLFILE "VALUES (";  
     2669                print CURRENT_IN_SITU_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2670                print CURRENT_IN_SITU_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; 
     2671                if ($sea_surface_eastward_current[$i]{'height'} == $missing_value_value 
     2672                  || $sea_surface_eastward_current[$i]{'height'} == $Fill_value_value) { 
     2673                  print CURRENT_IN_SITU_SQLFILE ','.'\'\''; 
     2674                } 
     2675                else { 
     2676                  $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'}); 
     2677                  print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
     2678                   
     2679                } 
     2680                print CURRENT_IN_SITU_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2681                $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); 
     2682                 
     2683                print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
     2684                $this_val = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); 
     2685 
     2686                print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
     2687                print CURRENT_IN_SITU_SQLFILE ','.'\'surface\''; 
     2688                print CURRENT_IN_SITU_SQLFILE ",GeometryFromText('POINT(";  
     2689                print CURRENT_IN_SITU_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2690                print CURRENT_IN_SITU_SQLFILE ")',-1));\n"; 
     2691              } 
     2692               
     2693            } 
     2694          } 
     2695          print CURRENT_IN_SITU_SQLFILE "\n"; 
     2696        } 
     2697        close(CURRENT_IN_SITU_SQLFILE); 
     2698      } 
     2699      #DWR 4/5/2008 
     2700      if( $bWriteobsKMLFile ) 
     2701      { 
     2702        for my $i (0..$#sea_surface_eastward_current)  
     2703        { 
     2704          my $j = 0; 
     2705          while ($j <= $#sea_surface_northward_current 
     2706                && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'})  
     2707          { 
     2708            $j++; 
     2709          } 
     2710          if ($j > $#sea_surface_northward_current)  
     2711          { 
     2712            die "ABORT!  Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i]  {'var_name'}.\n"; 
     2713          } 
     2714          else  
     2715          { 
     2716             
     2717            for my $k ($iStartingNdx..$#this_sea_surface_eastward_current_data)  #DWR v1.1.0.0 
     2718            #for my $k (0..$#this_sea_surface_eastward_current_data)  
     2719            { 
     2720              $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2721              $this_time_stamp = $time_formatted_values[$k]; 
     2722              $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)); 
     2723               
     2724              my $ECurrentDataVal = 'NULL'; 
     2725              my $NCurrentDataVal = 'NULL'; 
     2726              my $Height = '';             
     2727               
     2728              if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value 
     2729                  && $sea_surface_eastward_current[$i]{'data'}[$k] != $Fill_value_value 
     2730                  && $sea_surface_northward_current[$j]{'data'}[$k] != $missing_value_value 
     2731                  && $sea_surface_northward_current[$j]{'data'}[$k] != $Fill_value_value 
     2732                  && $this_station_id_top_ts < $this_time_stamp_sec 
     2733                  && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2734              { 
     2735                if ($sea_surface_eastward_current[$i]{'height'} != $missing_value_value 
     2736                    && $sea_surface_eastward_current[$i]{'height'} != $Fill_value_value)  
     2737                { 
     2738                  $Height = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'});                 
     2739                } 
     2740                $ECurrentDataVal = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); 
     2741                 
     2742                $NCurrentDataVal = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); 
     2743 
     2744              } 
     2745              my $strUnits; 
     2746              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_eastward_current[$i]{'units'}, $XMLControlFile );         
     2747              if( length( $strUnits ) == 0 ) 
     2748              { 
     2749               $strUnits = $sea_surface_eastward_current[$i]{'units'}; 
     2750              } 
     2751               
     2752              obsKMLSubRoutines::KMLAddObsToHash( 'eastward_current',  
     2753                                                  $KMLTimeStamp[$j], 
     2754                                                  $ECurrentDataVal, 
     2755                                                  1, 
     2756                                                  $strPlatformID, 
     2757                                                  $Height, 
     2758                                                  $strUnits, 
     2759                                                  $rObsHash ); 
     2760              $strUnits = ''; 
     2761              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_northward_current[$i]{'units'}, $XMLControlFile );         
     2762              if( length( $strUnits ) == 0 ) 
     2763              { 
     2764               $strUnits = $sea_surface_northward_current[$i]{'units'}; 
     2765              } 
     2766              obsKMLSubRoutines::KMLAddObsToHash( 'northward_current',  
     2767                                                  $KMLTimeStamp[$j], 
     2768                                                  $NCurrentDataVal, 
     2769                                                  1, 
     2770                                                  $strPlatformID, 
     2771                                                  $Height, 
     2772                                                  $strUnits, 
     2773                                                  $rObsHash ); 
     2774          } 
     2775        }                                             
     2776      }                   
     2777    } 
     2778  } 
     2779   
     2780  # significant_wave_height and dominant_wave_period (assume they come as pairs -- 
     2781  # wave_height calls the shots over period 
     2782  # Going to do this right this time.  Instead of populating each row w/ all 
     2783  # the metadata, use the station_id lookup, instead. 
     2784  if ($#significant_wave_height > -1) { 
     2785    if( $bWriteSQLFiles ) 
     2786    { 
     2787      open(WAVE_SQLFILE,'>>../sql/wave_in_situ_prod_'.$institution_code_value.'_' 
     2788        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2789      print WAVE_SQLFILE "-- format_category      = $format_category_value\n"; 
     2790      print WAVE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2791      print WAVE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2792      print WAVE_SQLFILE "-- package_code         = $package_code_value\n"; 
     2793      print WAVE_SQLFILE "-- title                = $title_value\n"; 
     2794      print WAVE_SQLFILE "-- institution          = $institution_value\n"; 
     2795      print WAVE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2796      print WAVE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2797      print WAVE_SQLFILE "-- source               = $source_value\n"; 
     2798      print WAVE_SQLFILE "-- references           = $references_value\n"; 
     2799      print WAVE_SQLFILE "-- contact              = $contact_value\n"; 
     2800      print WAVE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2801      print WAVE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2802      for my $i (0..$#significant_wave_height) { 
     2803        for my $j (0..$#this_significant_wave_height_data) { 
     2804          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2805          $this_time_stamp = $time_formatted_values[$j]; 
     2806          $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)); 
     2807           
     2808          my $DomWaveDataVal = 'NULL'; 
     2809          my $SigWaveHgtDataVal = 'NULL'; 
     2810          my $Height = ''; 
     2811           
     2812          if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
     2813            && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
     2814            && $this_station_id_top_ts < $this_time_stamp_sec 
     2815            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2816            print WAVE_SQLFILE "INSERT INTO wave_in_situ_prod (";  
     2817            print WAVE_SQLFILE "station_id,"; 
     2818            print WAVE_SQLFILE "time_stamp,";  
     2819            print WAVE_SQLFILE "z,"; 
     2820            print WAVE_SQLFILE "positive,"; 
     2821            print WAVE_SQLFILE "significant_wave_height,"; 
     2822            print WAVE_SQLFILE "dominant_wave_period,"; 
     2823            print WAVE_SQLFILE "the_geom"; 
     2824            print WAVE_SQLFILE ") ";  
     2825            print WAVE_SQLFILE "VALUES (";  
     2826            print WAVE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2827            print WAVE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2828            if ($significant_wave_height[$i]{'height'} == $missing_value_value 
     2829              || $significant_wave_height[$i]{'height'} == $Fill_value_value) { 
     2830              print WAVE_SQLFILE ',NULL'; 
     2831            } 
     2832            else { 
     2833              $this_val = sprintf("%.2f",$significant_wave_height[$i]{'height'}); 
     2834              print WAVE_SQLFILE ','.$this_val; 
     2835 
     2836              #DWR 4/5/2008 
     2837              $Height = $this_val; 
     2838            } 
     2839            print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2840            if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
     2841              || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
     2842              || $significant_wave_height[$i]{'data'}[$j] == '') { 
     2843              print WAVE_SQLFILE ',NULL'; 
     2844            } 
     2845            else { 
     2846              $this_val = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
     2847              print WAVE_SQLFILE ','.$this_val; 
     2848              #DWR 4/5/2008 
     2849              $SigWaveHgtDataVal = $this_val; 
     2850            } 
     2851            if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
     2852              || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
     2853              || $dominant_wave_period[$i]{'data'}[$j] == '') { 
     2854              print WAVE_SQLFILE ',NULL'; 
     2855            } 
     2856            else { 
     2857              $this_val = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
     2858              print WAVE_SQLFILE ','.$this_val; 
     2859              #DWR 4/5/2008 
     2860              $DomWaveDataVal = $this_val; 
     2861            } 
     2862            print WAVE_SQLFILE ",GeometryFromText('POINT(";  
     2863            print WAVE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2864            print WAVE_SQLFILE ")',-1));\n"; 
     2865          } 
     2866        } 
     2867        print WAVE_SQLFILE "\n"; 
     2868        #DWR 4/3/2008 
     2869        my $strUnits; 
     2870        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $dominant_wave_period[$i]{'units'}, $XMLControlFile );       
     2871        if( length( $strUnits ) == 0 ) 
     2872        { 
     2873           $strUnits = $dominant_wave_period[$i]{'units'}; 
     2874        } 
     2875           
     2876        obsKMLSubRoutines::KMLAddObsToHash( 'dominant_wave_period',  
     2877                                            $KMLTimeStamp[$j], 
     2878                                            $DomWaveDataVal, 
     2879                                            1, 
     2880                                            $strPlatformID, 
     2881                                            $Height, 
     2882                                            $strUnits, 
     2883                                            $rObsHash ); 
     2884        $strUnits = ''; 
     2885        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $significant_wave_height[$i]{'units'}, $XMLControlFile );         
     2886        if( length( $strUnits ) == 0 ) 
     2887        { 
     2888           $strUnits = $significant_wave_height[$i]{'units'}; 
     2889        } 
     2890        obsKMLSubRoutines::KMLAddObsToHash( 'significant_wave_height',  
     2891                                            $KMLTimeStamp[$j], 
     2892                                            $SigWaveHgtDataVal, 
     2893                                            1, 
     2894                                            $strPlatformID, 
     2895                                            $Height, 
     2896                                            $strUnits, 
     2897                                            $rObsHash ); 
     2898         
     2899      } 
     2900      close(WAVE_SQLFILE); 
     2901    } 
     2902    #DWR 4/5/2008 
     2903    if( $bWriteobsKMLFile ) 
     2904    { 
     2905      for my $i (0..$#significant_wave_height)  
     2906      { 
     2907        for my $j ($iStartingNdx..$#this_significant_wave_height_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2908        #for my $j (0..$#this_significant_wave_height_data)  
     2909        { 
     2910          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2911          $this_time_stamp = $time_formatted_values[$j]; 
     2912          $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)); 
     2913           
     2914          my $DomWaveDataVal = 'NULL'; 
     2915          my $SigWaveHgtDataVal = 'NULL'; 
     2916          my $Height = ''; 
     2917           
     2918          if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
     2919              && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
     2920              && $this_station_id_top_ts < $this_time_stamp_sec 
     2921              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2922          { 
     2923            if ($significant_wave_height[$i]{'height'} != $missing_value_value 
     2924                && $significant_wave_height[$i]{'height'} != $Fill_value_value) 
     2925            { 
     2926              $Height = sprintf("%.2f",$significant_wave_height[$i]{'height'}); 
     2927            } 
     2928            print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2929            if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
     2930                || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
     2931                || $significant_wave_height[$i]{'data'}[$j] == '')  
     2932            { 
     2933              $SigWaveHgtDataVal = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
     2934            } 
     2935            if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
     2936              || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
     2937              || $dominant_wave_period[$i]{'data'}[$j] == '')  
     2938            { 
     2939              $DomWaveDataVal = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
     2940            } 
     2941          } 
     2942        } 
     2943        my $strUnits; 
     2944        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $dominant_wave_period[$i]{'units'}, $XMLControlFile );       
     2945        if( length( $strUnits ) == 0 ) 
     2946        { 
     2947           $strUnits = $dominant_wave_period[$i]{'units'}; 
     2948        } 
     2949           
     2950        obsKMLSubRoutines::KMLAddObsToHash( 'dominant_wave_period',  
     2951                                            $KMLTimeStamp[$j], 
     2952                                            $DomWaveDataVal, 
     2953                                            1, 
     2954                                            $strPlatformID, 
     2955                                            $Height, 
     2956                                            $strUnits, 
     2957                                            $rObsHash ); 
     2958        $strUnits = ''; 
     2959        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $significant_wave_height[$i]{'units'}, $XMLControlFile );         
     2960        if( length( $strUnits ) == 0 ) 
     2961        { 
     2962           $strUnits = $significant_wave_height[$i]{'units'}; 
     2963        } 
     2964        obsKMLSubRoutines::KMLAddObsToHash( 'significant_wave_height',  
     2965                                            $KMLTimeStamp[$j], 
     2966                                            $SigWaveHgtDataVal, 
     2967                                            1, 
     2968                                            $strPlatformID, 
     2969                                            $Height, 
     2970                                            $strUnits, 
     2971                                            $rObsHash ); 
     2972         
     2973      } 
     2974    }                     
     2975  } 
     2976  #DWR 4/5/2008 
     2977  if( $bWriteobsKMLFile ) 
     2978  { 
     2979    my $strXMLPath;  
     2980    #my $strDate = `date  +%Y-%m-%dT%H-%M-%S`; 
     2981    #chomp( $strDate );       
     2982    $strXMLPath = "$strObsKMLFilePath/$this_station_id"; 
     2983    $strXMLPath = $strXMLPath . '_latest.kml'; 
     2984    print( "XMLFilePath: $strXMLPath\n" ); 
     2985    obsKMLSubRoutines::BuildKMLFile( \%ObsHash, $strXMLPath ); 
     2986  } 
     2987
     2988=cut 
  • scout/trunk/cdl_fixed_point.pl

    r194 r201  
    1 #!/bin/perl 
    2  
    3 sub fixed_point () { 
     1sub fixed_point() { 
    42 
    53  # top timestamp 
     
    86  my $FileCreationOptions = $_[1]; 
    97  my $strObsKMLFilePath = $_[2]; 
    10    
     8  #DWR v1.1.0.0 6/2/2008 
     9  my $iLastNTimeStamps  = $_[3]; 
     10   
     11  #print( "fixed_point::args: this_station_id_top_ts: $this_station_id_top_ts FileCreationOptions: $FileCreationOptions strObsKMLFilePath: $strObsKMLFilePath iLastNTimeStamps: $iLastNTimeStamps\n"); 
    1112  my $bWriteSQLFiles = 1; 
    1213  my $bWriteobsKMLFile = 0; 
     
    388389  my $varget = NetCDF::varget($ncid, $time_var{'var_id'}, (0), $time_dim{'dim_size'},   \@time_values); 
    389390  if ($varget < 0) {die "ABORT! Cannot get time values.\n";} 
     391  #DWR v1.1.0.0 
     392  #If we using the last N times, let's populate the array. 
     393   my $iStartingNdx = 0; 
     394  if( $iLastNTimeStamps > 0 ) 
     395  { 
     396    #If we have more entries in the time_values array, let's set the starting index at the spot in the array which    
     397    #will get us to the first of the N time stamps. 
     398    my $iTimeCnt = @time_values; 
     399    if( $iTimeCnt > $iLastNTimeStamps ) 
     400    { 
     401      $iStartingNdx = $iTimeCnt - $iLastNTimeStamps; 
     402      if( USE_DEBUG_PRINTS ) 
     403      { 
     404        print( "fixed_point()::Printing Last: $iLastNTimeStamps out of $iTimeCnt entries. Starting Index: $iStartingNdx. $ncid\n" ); 
     405      } 
     406    } 
     407  } 
    390408  # get the units 
    391409  my $attget = NetCDF::attget($ncid, $time_var{'var_id'}, 'units', \$units_value); 
     
    418436      .sprintf("%02d",$base_minute).':' 
    419437      .sprintf("%02d",$base_second); 
     438 
    420439  } 
    421440   
     
    462481      #DWR 4/5/2008 
    463482      my $units_value = ''; 
    464       my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, \$units_value); 
     483      my $attget = NetCDF::attget($ncid, $water_level[$i]{'var_id'}, 'units', \$units_value); 
    465484      if ($attget < 0)  
    466485      { 
     
    468487      } 
    469488      $water_level[$i]{'units'} = $units_value; 
    470        
    471489      # we need to loop through the attributes, so find out how many there are 
    472490      my $varinq = NetCDF::varinq($ncid, $water_level[$i]{'var_id'}, 
     
    14501468      my $NavD88DataVal = 'NULL'; 
    14511469      my $Height = ''; 
    1452      
    14531470      for my $i (0..$#water_level)  
    14541471      { 
    1455         for my $j (0..$#this_water_level_data)  
     1472        for my $j ($iStartingNdx..$#this_water_level_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1473        #for my $j (0..$#this_water_level_data)  
    14561474        { 
    14571475          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    16151633      my $DataVal = 'NULL'; 
    16161634      my $Height = ''; 
     1635       
    16171636      for my $i (0..$#sea_surface_temperature)  
    16181637      { 
    1619         for my $j (0..$#this_sea_surface_temperature_data)  
     1638        for my $j ($iStartingNdx..$#this_sea_surface_temperature_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1639        #for my $j (0..$#this_sea_surface_temperature_data)  
    16201640        { 
    16211641          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    17411761      for my $i (0..$#sea_bottom_temperature)  
    17421762      { 
    1743         for my $j (0..$#sea_bottom_temperature)  
     1763        for my $j ($iStartingNdx..$#sea_bottom_temperature)       #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1764        #for my $j (0..$#sea_bottom_temperature)  
    17441765        { 
    17451766          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    18521873      for my $i (0..$#air_temperature)  
    18531874      { 
    1854         for my $j (0..$#air_temperature)  
     1875        for my $j ($iStartingNdx..$#air_temperature) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     1876        #for my $j (0..$#air_temperature)  
    18551877        { 
    18561878          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    20112033        while ($j <= $#wind_from_direction 
    20122034          && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'})  
    2013          
     2035       
    20142036          $j++; 
    20152037        } 
     
    20202042        else  
    20212043        { 
    2022           for my $k (0..$#this_wind_speed_data)  
     2044          for my $k ($iStartingNdx..$#this_wind_speed_data)  
     2045          #for my $k (0..$#this_wind_speed_data)  
    20232046          { 
    20242047            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    21842207      for my $i (0..$#air_pressure)  
    21852208      { 
    2186         for my $j (0..$#this_air_pressure_data)  
     2209        for my $j ($iStartingNdx..$#this_air_pressure_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2210        #for my $j (0..$#this_air_pressure_data)  
    21872211        { 
    21882212          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    22952319      for my $i (0..$#salinity)  
    22962320      { 
    2297         for my $j (0..$#this_salinity_data)  
     2321        for my $j ($iStartingNdx..$#this_salinity_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2322        #for my $j (0..$#this_salinity_data)  
    22982323        { 
    22992324          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    24412466          else  
    24422467          { 
    2443             for my $k (0..$#this_sea_surface_eastward_current_data)  
     2468             
     2469            for my $k ($iStartingNdx..$#this_sea_surface_eastward_current_data)  #DWR v1.1.0.0 
     2470            #for my $k (0..$#this_sea_surface_eastward_current_data)  
    24442471            { 
    24452472              $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     
    26302657      for my $i (0..$#significant_wave_height)  
    26312658      { 
    2632         for my $j (0..$#this_significant_wave_height_data)  
     2659        for my $j ($iStartingNdx..$#this_significant_wave_height_data) #DWR v1.1.0.0 Starting index now set to $iStartingNdx 
     2660        #for my $j (0..$#this_significant_wave_height_data)  
    26332661        { 
    26342662          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value;