Changeset 167

Show
Ignore:
Timestamp:
04/07/08 16:22:36
Author:
dan
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scout/branches/cdl_0master.pl

    r165 r167  
    14611461    if( $bWriteSQLFiles ) 
    14621462    { 
    1463     open(STATION_ID_SQLFILE,'>>../sql_in_situ_station_id/in_situ_station_id_'.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'.sql'); 
    1464     print STATION_ID_SQLFILE "-- format_category      = $format_category_value\n"; 
    1465     print STATION_ID_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1466     print STATION_ID_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1467     print STATION_ID_SQLFILE "-- package_code         = $package_code_value\n"; 
    1468     print STATION_ID_SQLFILE "-- title                = $title_value\n"; 
    1469     print STATION_ID_SQLFILE "-- institution          = $institution_value\n"; 
    1470     print STATION_ID_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1471     print STATION_ID_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1472     print STATION_ID_SQLFILE "-- source               = $source_value\n"; 
    1473     print STATION_ID_SQLFILE "-- references           = $references_value\n"; 
    1474     print STATION_ID_SQLFILE "-- contact              = $contact_value\n"; 
    1475     print STATION_ID_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1476     print STATION_ID_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1477     print STATION_ID_SQLFILE "INSERT INTO in_situ_station_id (";  
    1478     print STATION_ID_SQLFILE "station_id,"; 
    1479     print STATION_ID_SQLFILE "title,"; 
    1480     print STATION_ID_SQLFILE "institution,"; 
    1481     print STATION_ID_SQLFILE "institution_url,"; 
    1482     print STATION_ID_SQLFILE "institution_dods_url,"; 
    1483     print STATION_ID_SQLFILE "source,"; 
    1484     print STATION_ID_SQLFILE "refs,"; 
    1485     print STATION_ID_SQLFILE "contact"; 
    1486     print STATION_ID_SQLFILE ") ";  
    1487     print STATION_ID_SQLFILE "VALUES ("; 
    1488     print STATION_ID_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    1489     print STATION_ID_SQLFILE ','.'\''.$title_value.'\''; 
    1490     print STATION_ID_SQLFILE ','.'\''.$institution_value.'\''; 
    1491     print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
    1492     print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
    1493     print STATION_ID_SQLFILE ','.'\''.$source_value.'\''; 
    1494     print STATION_ID_SQLFILE ','.'\''.$references_value.'\''; 
    1495     print STATION_ID_SQLFILE ','.'\''.$contact_value.'\''; 
    1496     print STATION_ID_SQLFILE ");\n"; 
    1497     close(STATION_ID_SQLFILE); 
     1463      open(STATION_ID_SQLFILE,'>>../sql_in_situ_station_id/in_situ_station_id_'.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'.sql'); 
     1464      print STATION_ID_SQLFILE "-- format_category      = $format_category_value\n"; 
     1465      print STATION_ID_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1466      print STATION_ID_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1467      print STATION_ID_SQLFILE "-- package_code         = $package_code_value\n"; 
     1468      print STATION_ID_SQLFILE "-- title                = $title_value\n"; 
     1469      print STATION_ID_SQLFILE "-- institution          = $institution_value\n"; 
     1470      print STATION_ID_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1471      print STATION_ID_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1472      print STATION_ID_SQLFILE "-- source               = $source_value\n"; 
     1473      print STATION_ID_SQLFILE "-- references           = $references_value\n"; 
     1474      print STATION_ID_SQLFILE "-- contact              = $contact_value\n"; 
     1475      print STATION_ID_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1476      print STATION_ID_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1477      print STATION_ID_SQLFILE "INSERT INTO in_situ_station_id (";  
     1478      print STATION_ID_SQLFILE "station_id,"; 
     1479      print STATION_ID_SQLFILE "title,"; 
     1480      print STATION_ID_SQLFILE "institution,"; 
     1481      print STATION_ID_SQLFILE "institution_url,"; 
     1482      print STATION_ID_SQLFILE "institution_dods_url,"; 
     1483      print STATION_ID_SQLFILE "source,"; 
     1484      print STATION_ID_SQLFILE "refs,"; 
     1485      print STATION_ID_SQLFILE "contact"; 
     1486      print STATION_ID_SQLFILE ") ";  
     1487      print STATION_ID_SQLFILE "VALUES ("; 
     1488      print STATION_ID_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1489      print STATION_ID_SQLFILE ','.'\''.$title_value.'\''; 
     1490      print STATION_ID_SQLFILE ','.'\''.$institution_value.'\''; 
     1491      print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1492      print STATION_ID_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1493      print STATION_ID_SQLFILE ','.'\''.$source_value.'\''; 
     1494      print STATION_ID_SQLFILE ','.'\''.$references_value.'\''; 
     1495      print STATION_ID_SQLFILE ','.'\''.$contact_value.'\''; 
     1496      print STATION_ID_SQLFILE ");\n"; 
     1497      close(STATION_ID_SQLFILE); 
     1498    } 
    14981499  } 
    14991500   
     
    15071508  # water_level (water_level) 
    15081509  if ($#water_level > -1) { 
    1509     my $DataVal     = 'NULL'; 
    1510     my $MLLWDataVal = 'NULL'; 
    1511     my $MSLDataVal  = 'NULL'; 
    1512     my $NavD88DataVal = 'NULL'; 
    1513     my $Height = ''; 
    1514     open(WATER_LEVEL_SQLFILE,'>>../sql/water_level_prod_'.$institution_code_value.'_' 
    1515       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    1516     print WATER_LEVEL_SQLFILE "-- format_category      = $format_category_value\n"; 
    1517     print WATER_LEVEL_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1518     print WATER_LEVEL_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1519     print WATER_LEVEL_SQLFILE "-- package_code         = $package_code_value\n"; 
    1520     print WATER_LEVEL_SQLFILE "-- title                = $title_value\n"; 
    1521     print WATER_LEVEL_SQLFILE "-- institution          = $institution_value\n"; 
    1522     print WATER_LEVEL_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1523     print WATER_LEVEL_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1524     print WATER_LEVEL_SQLFILE "-- source               = $source_value\n"; 
    1525     print WATER_LEVEL_SQLFILE "-- references           = $references_value\n"; 
    1526     print WATER_LEVEL_SQLFILE "-- contact              = $contact_value\n"; 
    1527     print WATER_LEVEL_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1528     print WATER_LEVEL_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1529     for my $i (0..$#water_level) { 
    1530       for my $j (0..$#this_water_level_data) { 
    1531         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    1532         $this_time_stamp = $time_formatted_values[$j]; 
    1533         $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)); 
    1534  
    1535         if ($water_level[$i]{'data'}[$j] != $missing_value_value 
    1536           && $water_level[$i]{'data'}[$j] != $Fill_value_value 
    1537           && $this_station_id_top_ts < $this_time_stamp_sec 
    1538           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    1539           print WATER_LEVEL_SQLFILE "INSERT INTO water_level_prod (";  
    1540           print WATER_LEVEL_SQLFILE "station_id,"; 
    1541           print WATER_LEVEL_SQLFILE "time_stamp,";  
    1542           print WATER_LEVEL_SQLFILE "z,"; 
    1543           print WATER_LEVEL_SQLFILE "positive,"; 
    1544           print WATER_LEVEL_SQLFILE "water_level,"; 
    1545           print WATER_LEVEL_SQLFILE "reference,"; 
    1546           print WATER_LEVEL_SQLFILE "reference_to_mllw,"; 
    1547           print WATER_LEVEL_SQLFILE "reference_to_msl,"; 
    1548           print WATER_LEVEL_SQLFILE "reference_to_navd88,"; 
    1549           print WATER_LEVEL_SQLFILE "title,"; 
    1550           print WATER_LEVEL_SQLFILE "institution,"; 
    1551           print WATER_LEVEL_SQLFILE "institution_url,"; 
    1552           print WATER_LEVEL_SQLFILE "institution_dods_url,"; 
    1553           print WATER_LEVEL_SQLFILE "source,"; 
    1554           print WATER_LEVEL_SQLFILE "refs,"; 
    1555           print WATER_LEVEL_SQLFILE "contact,"; 
    1556           print WATER_LEVEL_SQLFILE "the_geom"; 
    1557           print WATER_LEVEL_SQLFILE ") ";  
    1558           print WATER_LEVEL_SQLFILE "VALUES (";  
    1559           print WATER_LEVEL_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    1560           print WATER_LEVEL_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    1561           if ($water_level[$i]{'height'} == $missing_value_value 
    1562             || $water_level[$i]{'height'} == $Fill_value_value) { 
    1563             print WATER_LEVEL_SQLFILE ','.'\'\''; 
     1510    if( $bWriteSQLFiles ) 
     1511    { 
     1512      open(WATER_LEVEL_SQLFILE,'>>../sql/water_level_prod_'.$institution_code_value.'_' 
     1513        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1514      print WATER_LEVEL_SQLFILE "-- format_category      = $format_category_value\n"; 
     1515      print WATER_LEVEL_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1516      print WATER_LEVEL_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1517      print WATER_LEVEL_SQLFILE "-- package_code         = $package_code_value\n"; 
     1518      print WATER_LEVEL_SQLFILE "-- title                = $title_value\n"; 
     1519      print WATER_LEVEL_SQLFILE "-- institution          = $institution_value\n"; 
     1520      print WATER_LEVEL_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1521      print WATER_LEVEL_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1522      print WATER_LEVEL_SQLFILE "-- source               = $source_value\n"; 
     1523      print WATER_LEVEL_SQLFILE "-- references           = $references_value\n"; 
     1524      print WATER_LEVEL_SQLFILE "-- contact              = $contact_value\n"; 
     1525      print WATER_LEVEL_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1526      print WATER_LEVEL_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1527      for my $i (0..$#water_level) { 
     1528        for my $j (0..$#this_water_level_data) { 
     1529          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1530          $this_time_stamp = $time_formatted_values[$j]; 
     1531          $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)); 
     1532 
     1533          if ($water_level[$i]{'data'}[$j] != $missing_value_value 
     1534            && $water_level[$i]{'data'}[$j] != $Fill_value_value 
     1535            && $this_station_id_top_ts < $this_time_stamp_sec 
     1536            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1537            print WATER_LEVEL_SQLFILE "INSERT INTO water_level_prod (";  
     1538            print WATER_LEVEL_SQLFILE "station_id,"; 
     1539            print WATER_LEVEL_SQLFILE "time_stamp,";  
     1540            print WATER_LEVEL_SQLFILE "z,"; 
     1541            print WATER_LEVEL_SQLFILE "positive,"; 
     1542            print WATER_LEVEL_SQLFILE "water_level,"; 
     1543            print WATER_LEVEL_SQLFILE "reference,"; 
     1544            print WATER_LEVEL_SQLFILE "reference_to_mllw,"; 
     1545            print WATER_LEVEL_SQLFILE "reference_to_msl,"; 
     1546            print WATER_LEVEL_SQLFILE "reference_to_navd88,"; 
     1547            print WATER_LEVEL_SQLFILE "title,"; 
     1548            print WATER_LEVEL_SQLFILE "institution,"; 
     1549            print WATER_LEVEL_SQLFILE "institution_url,"; 
     1550            print WATER_LEVEL_SQLFILE "institution_dods_url,"; 
     1551            print WATER_LEVEL_SQLFILE "source,"; 
     1552            print WATER_LEVEL_SQLFILE "refs,"; 
     1553            print WATER_LEVEL_SQLFILE "contact,"; 
     1554            print WATER_LEVEL_SQLFILE "the_geom"; 
     1555            print WATER_LEVEL_SQLFILE ") ";  
     1556            print WATER_LEVEL_SQLFILE "VALUES (";  
     1557            print WATER_LEVEL_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1558            print WATER_LEVEL_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1559            if ($water_level[$i]{'height'} == $missing_value_value 
     1560              || $water_level[$i]{'height'} == $Fill_value_value) { 
     1561              print WATER_LEVEL_SQLFILE ','.'\'\''; 
     1562            } 
     1563            else { 
     1564              $this_val = sprintf("%.2f",$water_level[$i]{'height'}); 
     1565              print WATER_LEVEL_SQLFILE ','.$this_val; 
     1566            } 
     1567            print WATER_LEVEL_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1568            $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
     1569            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1570            print WATER_LEVEL_SQLFILE ','.'\''.$water_level[$i]{'reference'}.'\''; 
     1571             
     1572             
     1573            if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
     1574              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_mllw'}); 
     1575            } 
     1576            else { 
     1577              $this_val = 'NULL'; 
     1578            } 
     1579 
     1580            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1581            if (length $water_level[$i]{'reference_to_msl'} > 0) { 
     1582              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
     1583            } 
     1584            else { 
     1585              $this_val = 'NULL'; 
     1586            } 
     1587 
     1588            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1589            if (length $water_level[$i]{'reference_to_navd88'} > 0) { 
     1590              $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_navd88'}); 
     1591            } 
     1592            else { 
     1593              $this_val = 'NULL'; 
     1594            } 
     1595 
     1596            print WATER_LEVEL_SQLFILE ','.$this_val; 
     1597            print WATER_LEVEL_SQLFILE ','.'\''.$title_value.'\''; 
     1598            print WATER_LEVEL_SQLFILE ','.'\''.$institution_value.'\''; 
     1599            print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1600            print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1601            print WATER_LEVEL_SQLFILE ','.'\''.$source_value.'\''; 
     1602            print WATER_LEVEL_SQLFILE ','.'\''.$references_value.'\''; 
     1603            print WATER_LEVEL_SQLFILE ','.'\''.$contact_value.'\''; 
     1604            print WATER_LEVEL_SQLFILE ",GeometryFromText('POINT(";  
     1605            print WATER_LEVEL_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1606            print WATER_LEVEL_SQLFILE ")',-1));\n"; 
    15641607          } 
    1565           else { 
    1566             $this_val = sprintf("%.2f",$water_level[$i]{'height'}); 
    1567             $Height = $this_val; 
    1568             print WATER_LEVEL_SQLFILE ','.$this_val; 
     1608        } 
     1609         
     1610        print WATER_LEVEL_SQLFILE "\n"; 
     1611      } 
     1612      close(WATER_LEVEL_SQLFILE); 
     1613    } 
     1614    if( $bWriteobsKMLFile ) 
     1615    {        
     1616      my $MLLWDataVal = 'NULL'; 
     1617      my $MSLDataVal  = 'NULL'; 
     1618      my $NavD88DataVal = 'NULL'; 
     1619      my $Height = ''; 
     1620     
     1621      for my $i (0..$#water_level)  
     1622      { 
     1623        for my $j (0..$#this_water_level_data)  
     1624        { 
     1625          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1626          $this_time_stamp = $time_formatted_values[$j]; 
     1627          $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)); 
     1628 
     1629          if ($water_level[$i]{'data'}[$j] != $missing_value_value 
     1630            && $water_level[$i]{'data'}[$j] != $Fill_value_value 
     1631            && $this_station_id_top_ts < $this_time_stamp_sec 
     1632            && $this_time_stamp_sec > $oldest_ok_timestamp)  
     1633            { 
     1634     
     1635              #DWR 4/3/2008 
     1636              if ($water_level[$i]{'height'} != $missing_value_value 
     1637                && $water_level[$i]{'height'} != $Fill_value_value)  
     1638              { 
     1639                $this_val = sprintf("%.2f",$water_level[$i]{'height'}); 
     1640                $Height = $this_val; 
     1641              } 
     1642              $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
     1643               
     1644              $DataVal = $water_level[$i]{'reference'}; 
     1645               
     1646              if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
     1647                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_mllw'}); 
     1648              } 
     1649              else { 
     1650                $this_val = 'NULL'; 
     1651              } 
     1652              $MLLWDataVal = $this_val; 
     1653 
     1654              if (length $water_level[$i]{'reference_to_msl'} > 0) { 
     1655                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
     1656              } 
     1657              else { 
     1658                $this_val = 'NULL'; 
     1659              } 
     1660              $MSLDataVal = $this_val; 
     1661 
     1662              if (length $water_level[$i]{'reference_to_navd88'} > 0) { 
     1663                $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_navd88'}); 
     1664              } 
     1665              else { 
     1666                $this_val = 'NULL'; 
     1667              } 
     1668              #DWR 4/5/2008 
     1669              $NavD88DataVal = $this_val; 
    15691670          } 
    1570           print WATER_LEVEL_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    1571           $this_val = sprintf("%.2f",$water_level[$i]{'data'}[$j]); 
    1572           print WATER_LEVEL_SQLFILE ','.$this_val; 
    1573           print WATER_LEVEL_SQLFILE ','.'\''.$water_level[$i]{'reference'}.'\''; 
    1574            
    1575           #DWR 4/5/2008 
    1576           $DataVal = $water_level[$i]{'reference'}; 
    1577            
    1578           if (length $water_level[$i]{'reference_to_mllw'} > 0) { 
    1579             $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_mllw'}); 
    1580           } 
    1581           else { 
    1582             $this_val = 'NULL'; 
    1583           } 
    1584           #DWR 4/5/2008 
    1585           $MLLWDataVal = $this_val; 
    1586  
    1587           print WATER_LEVEL_SQLFILE ','.$this_val; 
    1588           if (length $water_level[$i]{'reference_to_msl'} > 0) { 
    1589             $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_msl'}); 
    1590           } 
    1591           else { 
    1592             $this_val = 'NULL'; 
    1593           } 
    1594           #DWR 4/5/2008 
    1595           $MSLDataVal = $this_val; 
    1596  
    1597           print WATER_LEVEL_SQLFILE ','.$this_val; 
    1598           if (length $water_level[$i]{'reference_to_navd88'} > 0) { 
    1599             $this_val = sprintf("%.2f",$water_level[$i]{'reference_to_navd88'}); 
    1600           } 
    1601           else { 
    1602             $this_val = 'NULL'; 
    1603           } 
    1604           #DWR 4/5/2008 
    1605           $NavD88DataVal = $this_val; 
    1606  
    1607           print WATER_LEVEL_SQLFILE ','.$this_val; 
    1608           print WATER_LEVEL_SQLFILE ','.'\''.$title_value.'\''; 
    1609           print WATER_LEVEL_SQLFILE ','.'\''.$institution_value.'\''; 
    1610           print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
    1611           print WATER_LEVEL_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
    1612           print WATER_LEVEL_SQLFILE ','.'\''.$source_value.'\''; 
    1613           print WATER_LEVEL_SQLFILE ','.'\''.$references_value.'\''; 
    1614           print WATER_LEVEL_SQLFILE ','.'\''.$contact_value.'\''; 
    1615           print WATER_LEVEL_SQLFILE ",GeometryFromText('POINT(";  
    1616           print WATER_LEVEL_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    1617           print WATER_LEVEL_SQLFILE ")',-1));\n"; 
    1618         } 
    1619         #DWR 4/3/2008 
    1620                   obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
    1621                                                       $time_formatted_values[$j], 
    1622                                                                   $MLLWDataVal, 
    1623                                                       1, 
    1624                                                       $strPlatformID, 
    1625                                                       $Height, 
    1626                                                       'm(MLLW)', 
    1627                                                       $rObsHash ); 
    1628                   obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
    1629                                                       $time_formatted_values[$j], 
    1630                                                                   $MSLDataVal, 
    1631                                                       2, 
    1632                                                       $strPlatformID, 
    1633                                                       $Height, 
    1634                                                       'm(MSL)', 
    1635                                                       $rObsHash ); 
    1636                   obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
    1637                                                       $time_formatted_values[$j], 
    1638                                                                   $NavD88DataVal, 
    1639                                                       3, 
    1640                                                       $strPlatformID, 
    1641                                                       $Height, 
    1642                                                       'm(NAVD88)', 
    1643                                                       $rObsHash ); 
    1644          
    1645       } 
    1646        
    1647       print WATER_LEVEL_SQLFILE "\n"; 
    1648     } 
    1649     close(WATER_LEVEL_SQLFILE); 
     1671          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1672                                            $time_formatted_values[$j], 
     1673                                            $MLLWDataVal, 
     1674                                            1, 
     1675                                            $strPlatformID, 
     1676                                            $Height, 
     1677                                            'm(MLLW)', 
     1678                                            $rObsHash ); 
     1679          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1680                                            $time_formatted_values[$j], 
     1681                                            $MSLDataVal, 
     1682                                            2, 
     1683                                            $strPlatformID, 
     1684                                            $Height, 
     1685                                            'm(MSL)', 
     1686                                            $rObsHash ); 
     1687          obsKMLSubRoutines::KMLAddObsToHash( 'water_level',  
     1688                                            $time_formatted_values[$j], 
     1689                                            $NavD88DataVal, 
     1690                                            3, 
     1691                                            $strPlatformID, 
     1692                                            $Height, 
     1693                                            'm(NAVD88)', 
     1694                                            $rObsHash ); 
     1695      } 
     1696    }             
    16501697  } 
    16511698   
    16521699  # sea_surface_temperature (sst) 
    16531700  if ($#sea_surface_temperature > -1) { 
    1654     open(SST_SQLFILE,'>>../sql/sst_prod_'.$institution_code_value.'_' 
    1655       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    1656     print SST_SQLFILE "-- format_category      = $format_category_value\n"; 
    1657     print SST_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1658     print SST_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1659     print SST_SQLFILE "-- package_code         = $package_code_value\n"; 
    1660     print SST_SQLFILE "-- title                = $title_value\n"; 
    1661     print SST_SQLFILE "-- institution          = $institution_value\n"; 
    1662     print SST_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1663     print SST_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1664     print SST_SQLFILE "-- source               = $source_value\n"; 
    1665     print SST_SQLFILE "-- references           = $references_value\n"; 
    1666     print SST_SQLFILE "-- contact              = $contact_value\n"; 
    1667     print SST_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1668     print SST_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1669      
    1670     my $DataVal = 'NULL'; 
    1671     my $Height = ''; 
    1672     for my $i (0..$#sea_surface_temperature) { 
    1673       for my $j (0..$#this_sea_surface_temperature_data) { 
    1674         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    1675         $this_time_stamp = $time_formatted_values[$j]; 
    1676         $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)); 
     1701    if( $bWriteSQLFiles ) 
     1702    { 
     1703      open(SST_SQLFILE,'>>../sql/sst_prod_'.$institution_code_value.'_' 
     1704        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1705      print SST_SQLFILE "-- format_category      = $format_category_value\n"; 
     1706      print SST_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1707      print SST_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1708      print SST_SQLFILE "-- package_code         = $package_code_value\n"; 
     1709      print SST_SQLFILE "-- title                = $title_value\n"; 
     1710      print SST_SQLFILE "-- institution          = $institution_value\n"; 
     1711      print SST_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1712      print SST_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1713      print SST_SQLFILE "-- source               = $source_value\n"; 
     1714      print SST_SQLFILE "-- references           = $references_value\n"; 
     1715      print SST_SQLFILE "-- contact              = $contact_value\n"; 
     1716      print SST_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1717      print SST_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    16771718       
    1678         if ($sea_surface_temperature[$i]{'data'}[$j] != $missing_value_value 
    1679           && $sea_surface_temperature[$i]{'data'}[$j] != $Fill_value_value 
    1680           && $this_station_id_top_ts < $this_time_stamp_sec 
    1681           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    1682           print SST_SQLFILE "INSERT INTO sst_prod (";  
    1683           print SST_SQLFILE "station_id,"; 
    1684           print SST_SQLFILE "time_stamp,";  
    1685           print SST_SQLFILE "z,"; 
    1686           print SST_SQLFILE "positive,"; 
    1687           print SST_SQLFILE "temperature_celcius,"; 
    1688           print SST_SQLFILE "title,"; 
    1689           print SST_SQLFILE "institution,"; 
    1690           print SST_SQLFILE "institution_url,"; 
    1691           print SST_SQLFILE "institution_dods_url,"; 
    1692           print SST_SQLFILE "source,"; 
    1693           print SST_SQLFILE "refs,"; 
    1694           print SST_SQLFILE "contact,"; 
    1695           print SST_SQLFILE "the_geom"; 
    1696           print SST_SQLFILE ") ";  
    1697           print SST_SQLFILE "VALUES (";  
    1698           print SST_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    1699           print SST_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    1700           if ($sea_surface_temperature[$i]{'height'} == $missing_value_value 
    1701             || $sea_surface_temperature[$i]{'height'} == $Fill_value_value) { 
    1702             print SST_SQLFILE ','.'\'\''; 
     1719      my $DataVal = 'NULL'; 
     1720      my $Height = ''; 
     1721      for my $i (0..$#sea_surface_temperature) { 
     1722        for my $j (0..$#this_sea_surface_temperature_data) { 
     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 ($sea_surface_temperature[$i]{'data'}[$j] != $missing_value_value 
     1728            && $sea_surface_temperature[$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            print SST_SQLFILE "INSERT INTO sst_prod (";  
     1732            print SST_SQLFILE "station_id,"; 
     1733            print SST_SQLFILE "time_stamp,";  
     1734            print SST_SQLFILE "z,"; 
     1735            print SST_SQLFILE "positive,"; 
     1736            print SST_SQLFILE "temperature_celcius,"; 
     1737            print SST_SQLFILE "title,"; 
     1738            print SST_SQLFILE "institution,"; 
     1739            print SST_SQLFILE "institution_url,"; 
     1740            print SST_SQLFILE "institution_dods_url,"; 
     1741            print SST_SQLFILE "source,"; 
     1742            print SST_SQLFILE "refs,"; 
     1743            print SST_SQLFILE "contact,"; 
     1744            print SST_SQLFILE "the_geom"; 
     1745            print SST_SQLFILE ") ";  
     1746            print SST_SQLFILE "VALUES (";  
     1747            print SST_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1748            print SST_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1749            if ($sea_surface_temperature[$i]{'height'} == $missing_value_value 
     1750              || $sea_surface_temperature[$i]{'height'} == $Fill_value_value) { 
     1751              print SST_SQLFILE ','.'\'\''; 
     1752            } 
     1753            else { 
     1754              $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'height'}); 
     1755              print SST_SQLFILE ','.$this_val; 
     1756            } 
     1757 
     1758            print SST_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1759            $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'data'}[$j]); 
     1760             
     1761             
     1762            print SST_SQLFILE ','.$this_val; 
     1763            print SST_SQLFILE ','.'\''.$title_value.'\''; 
     1764            print SST_SQLFILE ','.'\''.$institution_value.'\''; 
     1765            print SST_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1766            print SST_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1767            print SST_SQLFILE ','.'\''.$source_value.'\''; 
     1768            print SST_SQLFILE ','.'\''.$references_value.'\''; 
     1769            print SST_SQLFILE ','.'\''.$contact_value.'\''; 
     1770            print SST_SQLFILE ",GeometryFromText('POINT(";  
     1771            print SST_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1772            print SST_SQLFILE ")',-1));\n"; 
    17031773          } 
    1704           else { 
    1705             $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'height'}); 
    1706             print SST_SQLFILE ','.$this_val; 
     1774           
     1775        } 
     1776        print SST_SQLFILE "\n"; 
     1777      } 
     1778      close(SST_SQLFILE); 
     1779    } 
     1780    #DWR 4/5/2008 
     1781    if( $bWriteobsKMLFile ) 
     1782    { 
     1783      my $DataVal = 'NULL'; 
     1784      my $Height = ''; 
     1785      for my $i (0..$#sea_surface_temperature)  
     1786      { 
     1787        for my $j (0..$#this_sea_surface_temperature_data)  
     1788        { 
     1789          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1790          $this_time_stamp = $time_formatted_values[$j]; 
     1791          $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)); 
     1792         
     1793          if ($sea_surface_temperature[$i]{'data'}[$j] != $missing_value_value 
     1794              && $sea_surface_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1795              && $this_station_id_top_ts < $this_time_stamp_sec 
     1796              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     1797          { 
     1798 
     1799            if ($sea_surface_temperature[$i]{'height'} != $missing_value_value 
     1800              && $sea_surface_temperature[$i]{'height'} != $Fill_value_value)  
     1801            { 
     1802              $Height = sprintf("%.2f",$sea_surface_temperature[$i]{'height'}); 
     1803            } 
     1804            $DataVal = sprintf("%.2f",$sea_surface_temperature[$i]{'data'}[$j]); 
     1805                       
    17071806          } 
    1708           #DWR 4/5/2008 
    1709           $Height = $this_val; 
    1710  
    1711           print SST_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    1712           $this_val = sprintf("%.2f",$sea_surface_temperature[$i]{'data'}[$j]); 
    1713            
    1714           #DWR 4/5/2008 
    1715           $DataVal = $this_val; 
    1716            
    1717           print SST_SQLFILE ','.$this_val; 
    1718           print SST_SQLFILE ','.'\''.$title_value.'\''; 
    1719           print SST_SQLFILE ','.'\''.$institution_value.'\''; 
    1720           print SST_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
    1721           print SST_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
    1722           print SST_SQLFILE ','.'\''.$source_value.'\''; 
    1723           print SST_SQLFILE ','.'\''.$references_value.'\''; 
    1724           print SST_SQLFILE ','.'\''.$contact_value.'\''; 
    1725           print SST_SQLFILE ",GeometryFromText('POINT(";  
    1726           print SST_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    1727           print SST_SQLFILE ")',-1));\n"; 
    1728         } 
    1729         #DWR 4/5/2008 
    1730               my $strUnits; 
    1731               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_temperature[$i]{'units'}, $XMLControlFile ); 
    1732               if( length( $strUnits ) == 0 ) 
    1733               { 
    1734                $strUnits = $sea_surface_temperature[$i]{'units'}; 
    1735               } 
    1736                   obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
    1737                                                       $time_formatted_values[$j], 
    1738                                                                   $DataVal, 
    1739                                                       1, 
    1740                                                       $strPlatformID, 
    1741                                                       $Height, 
    1742                                                       $strUnits, 
    1743                                                       $rObsHash ); 
    1744          
    1745       } 
    1746       print SST_SQLFILE "\n"; 
    1747     } 
    1748     close(SST_SQLFILE); 
    1749   } 
    1750  
     1807          my $strUnits; 
     1808          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_temperature[$i]{'units'}, $XMLControlFile ); 
     1809          if( length( $strUnits ) == 0 ) 
     1810          { 
     1811            $strUnits = $sea_surface_temperature[$i]{'units'}; 
     1812          } 
     1813          obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
     1814                                            $time_formatted_values[$j], 
     1815                                            $DataVal, 
     1816                                            1, 
     1817                                            $strPlatformID, 
     1818                                            $Height, 
     1819                                            $strUnits, 
     1820                                            $rObsHash ); 
     1821        } 
     1822      }                                             
     1823    } 
     1824  } 
    17511825  # sea_bottom_temperature (sbt) 
    17521826  if ($#sea_bottom_temperature > -1) { 
    1753     open(SBT_SQLFILE,'>>../sql/bottom_water_temp_prod_'.$institution_code_value.'_' 
    1754       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    1755     print SBT_SQLFILE "-- format_category      = $format_category_value\n"; 
    1756     print SBT_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1757     print SBT_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1758     print SBT_SQLFILE "-- package_code         = $package_code_value\n"; 
    1759     print SBT_SQLFILE "-- title                = $title_value\n"; 
    1760     print SBT_SQLFILE "-- institution          = $institution_value\n"; 
    1761     print SBT_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1762     print SBT_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1763     print SBT_SQLFILE "-- source               = $source_value\n"; 
    1764     print SBT_SQLFILE "-- references           = $references_value\n"; 
    1765     print SBT_SQLFILE "-- contact              = $contact_value\n"; 
    1766     print SBT_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1767     print SBT_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1768      
     1827    if( $bWriteSQLFiles ) 
     1828    { 
     1829      open(SBT_SQLFILE,'>>../sql/bottom_water_temp_prod_'.$institution_code_value.'_' 
     1830        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1831      print SBT_SQLFILE "-- format_category      = $format_category_value\n"; 
     1832      print SBT_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1833      print SBT_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1834      print SBT_SQLFILE "-- package_code         = $package_code_value\n"; 
     1835      print SBT_SQLFILE "-- title                = $title_value\n"; 
     1836      print SBT_SQLFILE "-- institution          = $institution_value\n"; 
     1837      print SBT_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1838      print SBT_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1839      print SBT_SQLFILE "-- source               = $source_value\n"; 
     1840      print SBT_SQLFILE "-- references           = $references_value\n"; 
     1841      print SBT_SQLFILE "-- contact              = $contact_value\n"; 
     1842      print SBT_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1843      print SBT_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1844       
     1845      for my $i (0..$#sea_bottom_temperature) { 
     1846        for my $j (0..$#this_sea_bottom_temperature_data) { 
     1847          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1848          $this_time_stamp = $time_formatted_values[$j]; 
     1849          $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)); 
     1850         
     1851          if ($sea_bottom_temperature[$i]{'data'}[$j] != $missing_value_value 
     1852            && $sea_bottom_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1853            && $this_station_id_top_ts < $this_time_stamp_sec 
     1854            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1855            print SBT_SQLFILE "INSERT INTO bottom_water_temp_prod (";  
     1856            print SBT_SQLFILE "station_id,"; 
     1857            print SBT_SQLFILE "time_stamp,";  
     1858            print SBT_SQLFILE "z,"; 
     1859            print SBT_SQLFILE "positive,"; 
     1860            print SBT_SQLFILE "temperature_celcius,"; 
     1861            print SBT_SQLFILE "title,"; 
     1862            print SBT_SQLFILE "institution,"; 
     1863            print SBT_SQLFILE "institution_url,"; 
     1864            print SBT_SQLFILE "institution_dods_url,"; 
     1865            print SBT_SQLFILE "source,"; 
     1866            print SBT_SQLFILE "refs,"; 
     1867            print SBT_SQLFILE "contact,"; 
     1868            print SBT_SQLFILE "the_geom"; 
     1869            print SBT_SQLFILE ") ";  
     1870            print SBT_SQLFILE "VALUES (";  
     1871            print SBT_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1872            print SBT_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1873            if ($sea_bottom_temperature[$i]{'height'} == $missing_value_value 
     1874              || $sea_bottom_temperature[$i]{'height'} == $Fill_value_value) { 
     1875              print SBT_SQLFILE ','.'\'\''; 
     1876            } 
     1877            else { 
     1878              $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'height'}); 
     1879              print SBT_SQLFILE ','.$this_val; 
     1880            } 
     1881 
     1882            print SBT_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     1883            $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'data'}[$j]); 
     1884             
     1885             
     1886            print SBT_SQLFILE ','.$this_val; 
     1887            print SBT_SQLFILE ','.'\''.$title_value.'\''; 
     1888            print SBT_SQLFILE ','.'\''.$institution_value.'\''; 
     1889            print SBT_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     1890            print SBT_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     1891            print SBT_SQLFILE ','.'\''.$source_value.'\''; 
     1892            print SBT_SQLFILE ','.'\''.$references_value.'\''; 
     1893            print SBT_SQLFILE ','.'\''.$contact_value.'\''; 
     1894            print SBT_SQLFILE ",GeometryFromText('POINT(";  
     1895            print SBT_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     1896            print SBT_SQLFILE ")',-1));\n"; 
     1897          } 
     1898 
     1899        } 
     1900        print SBT_SQLFILE "\n"; 
     1901      } 
     1902      close(SBT_SQLFILE); 
     1903    } 
    17691904    #DWR 4/5/2008 
    1770     my $DataVal = 'NULL'; 
    1771     my $Height = ''; 
    1772     for my $i (0..$#sea_bottom_temperature) { 
    1773       for my $j (0..$#this_sea_bottom_temperature_data) { 
    1774         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    1775         $this_time_stamp = $time_formatted_values[$j]; 
    1776         $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)); 
    1777        
    1778         if ($sea_bottom_temperature[$i]{'data'}[$j] != $missing_value_value 
    1779           && $sea_bottom_temperature[$i]{'data'}[$j] != $Fill_value_value 
    1780           && $this_station_id_top_ts < $this_time_stamp_sec 
    1781           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    1782           print SBT_SQLFILE "INSERT INTO bottom_water_temp_prod (";  
    1783           print SBT_SQLFILE "station_id,"; 
    1784           print SBT_SQLFILE "time_stamp,";  
    1785           print SBT_SQLFILE "z,"; 
    1786           print SBT_SQLFILE "positive,"; 
    1787           print SBT_SQLFILE "temperature_celcius,"; 
    1788           print SBT_SQLFILE "title,"; 
    1789           print SBT_SQLFILE "institution,"; 
    1790           print SBT_SQLFILE "institution_url,"; 
    1791           print SBT_SQLFILE "institution_dods_url,"; 
    1792           print SBT_SQLFILE "source,"; 
    1793           print SBT_SQLFILE "refs,"; 
    1794           print SBT_SQLFILE "contact,"; 
    1795           print SBT_SQLFILE "the_geom"; 
    1796           print SBT_SQLFILE ") ";  
    1797           print SBT_SQLFILE "VALUES (";  
    1798           print SBT_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    1799           print SBT_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    1800           if ($sea_bottom_temperature[$i]{'height'} == $missing_value_value 
    1801             || $sea_bottom_temperature[$i]{'height'} == $Fill_value_value) { 
    1802             print SBT_SQLFILE ','.'\'\''; 
     1905    if( $bWriteobsKMLFile ) 
     1906    { 
     1907      my $DataVal = 'NULL'; 
     1908      my $Height = ''; 
     1909      for my $i (0..$#sea_bottom_temperature)  
     1910      { 
     1911        for my $j (0..$#sea_bottom_temperature)  
     1912        { 
     1913          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1914          $this_time_stamp = $time_formatted_values[$j]; 
     1915          $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));        
     1916          if ($sea_bottom_temperature[$i]{'data'}[$j] != $missing_value_value 
     1917              && $sea_bottom_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1918              && $this_station_id_top_ts < $this_time_stamp_sec 
     1919              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     1920          { 
     1921 
     1922            if ($sea_bottom_temperature[$i]{'height'} != $missing_value_value 
     1923              && $sea_bottom_temperature[$i]{'height'} != $Fill_value_value)  
     1924            { 
     1925              $Height = sprintf("%.2f",$sea_bottom_temperature[$i]{'height'}); 
     1926            } 
     1927            $DataVal = sprintf("%.2f",$sea_bottom_temperature[$i]{'data'}[$j]); 
     1928                       
    18031929          } 
    1804           else { 
    1805             $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'height'}); 
    1806             print SBT_SQLFILE ','.$this_val; 
     1930          my $strUnits; 
     1931          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_bottom_temperature[$i]{'units'}, $XMLControlFile );         
     1932          if( length( $strUnits ) == 0 ) 
     1933          { 
     1934           $strUnits = $sea_bottom_temperature[$i]{'units'}; 
    18071935          } 
    1808           #DWR 4/5/2008; 
    1809           $DataVal = $this_val; 
    1810  
    1811           print SBT_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    1812           $this_val = sprintf("%.2f",$sea_bottom_temperature[$i]{'data'}[$j]); 
    1813            
    1814           #DWR 4/5/2008; 
    1815           $DataVal = $this_val; 
    1816            
    1817           print SBT_SQLFILE ','.$this_val; 
    1818           print SBT_SQLFILE ','.'\''.$title_value.'\''; 
    1819           print SBT_SQLFILE ','.'\''.$institution_value.'\''; 
    1820           print SBT_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
    1821           print SBT_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
    1822           print SBT_SQLFILE ','.'\''.$source_value.'\''; 
    1823           print SBT_SQLFILE ','.'\''.$references_value.'\''; 
    1824           print SBT_SQLFILE ','.'\''.$contact_value.'\''; 
    1825           print SBT_SQLFILE ",GeometryFromText('POINT(";  
    1826           print SBT_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    1827           print SBT_SQLFILE ")',-1));\n"; 
    1828         } 
    1829         #DWR 4/5/2008 
    1830               my $strUnits; 
    1831               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_bottom_temperature[$i]{'units'}, $XMLControlFile );         
    1832               if( length( $strUnits ) == 0 ) 
    1833               { 
    1834                $strUnits = $sea_bottom_temperature[$i]{'units'}; 
    1835               } 
    1836          
    1837                   obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
    1838                                                       $time_formatted_values[$j], 
    1839                                                                   $DataVal, 
    1840                                                       2, 
    1841                                                       $strPlatformID, 
    1842                                                       $Height, 
    1843                                                       $strUnits, 
    1844                                                       $rObsHash ); 
    1845  
    1846       } 
    1847       print SBT_SQLFILE "\n"; 
    1848     } 
    1849     close(SBT_SQLFILE); 
     1936          obsKMLSubRoutines::KMLAddObsToHash( 'water_temperature',  
     1937                                            $time_formatted_values[$j], 
     1938                                            $DataVal, 
     1939                                            2, 
     1940                                            $strPlatformID, 
     1941                                            $Height, 
     1942                                            $strUnits, 
     1943                                            $rObsHash ); 
     1944        } 
     1945      }                                             
     1946    }     
    18501947  } 
    18511948   
     
    18541951  # the metadata, use the station_id lookup, instead. 
    18551952  if ($#air_temperature > -1) { 
    1856     open(AIR_TEMP_SQLFILE,'>>../sql/air_temperature_prod_'.$institution_code_value.'_' 
    1857       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    1858     print AIR_TEMP_SQLFILE "-- format_category      = $format_category_value\n"; 
    1859     print AIR_TEMP_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1860     print AIR_TEMP_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1861     print AIR_TEMP_SQLFILE "-- package_code         = $package_code_value\n"; 
    1862     print AIR_TEMP_SQLFILE "-- title                = $title_value\n"; 
    1863     print AIR_TEMP_SQLFILE "-- institution          = $institution_value\n"; 
    1864     print AIR_TEMP_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1865     print AIR_TEMP_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1866     print AIR_TEMP_SQLFILE "-- source               = $source_value\n"; 
    1867     print AIR_TEMP_SQLFILE "-- references           = $references_value\n"; 
    1868     print AIR_TEMP_SQLFILE "-- contact              = $contact_value\n"; 
    1869     print AIR_TEMP_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1870     print AIR_TEMP_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1871     for my $i (0..$#air_temperature) { 
    1872       for my $j (0..$#this_air_temperature_data) { 
    1873         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    1874         $this_time_stamp = $time_formatted_values[$j]; 
    1875         $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)); 
    1876  
    1877         my $DataValue = 'NULL'; 
    1878         my $Height    = ''; 
    1879         if ($air_temperature[$i]{'data'}[$j] != $missing_value_value 
    1880           && $air_temperature[$i]{'data'}[$j] != $Fill_value_value 
    1881           && $this_station_id_top_ts < $this_time_stamp_sec 
    1882           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    1883           print AIR_TEMP_SQLFILE "INSERT INTO air_temperature_prod (";  
    1884           print AIR_TEMP_SQLFILE "station_id,"; 
    1885           print AIR_TEMP_SQLFILE "time_stamp,";  
    1886           print AIR_TEMP_SQLFILE "z,"; 
    1887           print AIR_TEMP_SQLFILE "positive,"; 
    1888           print AIR_TEMP_SQLFILE "temperature_celcius,"; 
    1889           print AIR_TEMP_SQLFILE "the_geom"; 
    1890           print AIR_TEMP_SQLFILE ") ";  
    1891           print AIR_TEMP_SQLFILE "VALUES (";  
    1892           print AIR_TEMP_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    1893           print AIR_TEMP_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    1894           if ($air_temperature[$i]{'height'} == $missing_value_value 
    1895             || $air_temperature[$i]{'height'} == $Fill_value_value) { 
    1896             print AIR_TEMP_SQLFILE ',NULL'; 
     1953    #DWR 4/5/2008  
     1954    if( $bWriteSQLFiles ) 
     1955    { 
     1956      open(AIR_TEMP_SQLFILE,'>>../sql/air_temperature_prod_'.$institution_code_value.'_' 
     1957        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     1958      print AIR_TEMP_SQLFILE "-- format_category      = $format_category_value\n"; 
     1959      print AIR_TEMP_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     1960      print AIR_TEMP_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     1961      print AIR_TEMP_SQLFILE "-- package_code         = $package_code_value\n"; 
     1962      print AIR_TEMP_SQLFILE "-- title                = $title_value\n"; 
     1963      print AIR_TEMP_SQLFILE "-- institution          = $institution_value\n"; 
     1964      print AIR_TEMP_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     1965      print AIR_TEMP_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     1966      print AIR_TEMP_SQLFILE "-- source               = $source_value\n"; 
     1967      print AIR_TEMP_SQLFILE "-- references           = $references_value\n"; 
     1968      print AIR_TEMP_SQLFILE "-- contact              = $contact_value\n"; 
     1969      print AIR_TEMP_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     1970      print AIR_TEMP_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     1971      for my $i (0..$#air_temperature) { 
     1972        for my $j (0..$#this_air_temperature_data) { 
     1973          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     1974          $this_time_stamp = $time_formatted_values[$j]; 
     1975          $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)); 
     1976 
     1977          my $DataValue = 'NULL'; 
     1978          my $Height    = ''; 
     1979          if ($air_temperature[$i]{'data'}[$j] != $missing_value_value 
     1980            && $air_temperature[$i]{'data'}[$j] != $Fill_value_value 
     1981            && $this_station_id_top_ts < $this_time_stamp_sec 
     1982            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     1983            print AIR_TEMP_SQLFILE "INSERT INTO air_temperature_prod (";  
     1984            print AIR_TEMP_SQLFILE "station_id,"; 
     1985            print AIR_TEMP_SQLFILE "time_stamp,";  
     1986            print AIR_TEMP_SQLFILE "z,"; 
     1987            print AIR_TEMP_SQLFILE "positive,"; 
     1988            print AIR_TEMP_SQLFILE "temperature_celcius,"; 
     1989            print AIR_TEMP_SQLFILE "the_geom"; 
     1990            print AIR_TEMP_SQLFILE ") ";  
     1991            print AIR_TEMP_SQLFILE "VALUES (";  
     1992            print AIR_TEMP_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     1993            print AIR_TEMP_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     1994            if ($air_temperature[$i]{'height'} == $missing_value_value 
     1995              || $air_temperature[$i]{'height'} == $Fill_value_value) { 
     1996              print AIR_TEMP_SQLFILE ',NULL'; 
     1997            } 
     1998            else { 
     1999              $this_val = sprintf("%.2f",$air_temperature[$i]{'height'}); 
     2000              print AIR_TEMP_SQLFILE ','.$this_val;               
     2001            } 
     2002            print AIR_TEMP_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2003            $this_val = sprintf("%.2f",$air_temperature[$i]{'data'}[$j]); 
     2004            print AIR_TEMP_SQLFILE ','.$this_val; 
     2005            print AIR_TEMP_SQLFILE ",GeometryFromText('POINT(";  
     2006            print AIR_TEMP_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2007            print AIR_TEMP_SQLFILE ")',-1));\n"; 
     2008                        
    18972009          } 
    1898           else { 
    1899             $this_val = sprintf("%.2f",$air_temperature[$i]{'height'}); 
    1900             print AIR_TEMP_SQLFILE ','.$this_val; 
    1901              
    1902             $Height = $this_val; 
     2010        } 
     2011        print AIR_TEMP_SQLFILE "\n"; 
     2012      } 
     2013      close(AIR_TEMP_SQLFILE); 
     2014    } 
     2015    #DWR 4/5/2008 
     2016    if( $bWriteobsKMLFile ) 
     2017    { 
     2018      my $DataVal = 'NULL'; 
     2019      my $Height = ''; 
     2020      for my $i (0..$#air_temperature)  
     2021      { 
     2022        for my $j (0..$#air_temperature)  
     2023        { 
     2024          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2025          $this_time_stamp = $time_formatted_values[$j]; 
     2026          $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)); 
     2027         
     2028          if ($air_temperature[$i]{'data'}[$j] != $missing_value_value 
     2029              && $air_temperature[$i]{'data'}[$j] != $Fill_value_value 
     2030              && $this_station_id_top_ts < $this_time_stamp_sec 
     2031              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2032          { 
     2033 
     2034            if ($air_temperature[$i]{'height'} != $missing_value_value 
     2035              && $air_temperature[$i]{'height'} != $Fill_value_value)  
     2036            { 
     2037              $Height = sprintf("%.2f",$air_temperature[$i]{'height'}); 
     2038            } 
     2039            $DataVal = sprintf("%.2f",$air_temperature[$i]{'data'}[$j]); 
     2040                       
    19032041          } 
    1904           print AIR_TEMP_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    1905           $this_val = sprintf("%.2f",$air_temperature[$i]{'data'}[$j]); 
    1906           print AIR_TEMP_SQLFILE ','.$this_val; 
    1907           print AIR_TEMP_SQLFILE ",GeometryFromText('POINT(";  
    1908           print AIR_TEMP_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    1909           print AIR_TEMP_SQLFILE ")',-1));\n"; 
    1910            
    1911           $DataValue = $this_val; 
    1912            
    1913         } 
    1914               #DWR 4/3/2008 
    1915               my $strUnits; 
    1916               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_bottom_temperature[$i]{'units'}, $XMLControlFile ); 
    1917               if( length( $strUnits ) == 0 ) 
    1918               { 
    1919                $strUnits = $sea_bottom_temperature[$i]{'units'}; 
    1920               } 
    1921                
    1922                           obsKMLSubRoutines::KMLAddObsToHash( 'air_temperature',  
    1923                                                                       $time_formatted_values[$j], 
    1924                                                                     $DataValue, 
    1925                                                               1, 
    1926                                                               $strPlatformID, 
    1927                                                               $Height, 
    1928                                                         $strUnits, 
    1929                                                               $rObsHash ); 
    1930       } 
    1931       print AIR_TEMP_SQLFILE "\n"; 
    1932     } 
    1933     close(AIR_TEMP_SQLFILE); 
     2042          my $strUnits; 
     2043          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $air_temperature[$i]{'units'}, $XMLControlFile );         
     2044          if( length( $strUnits ) == 0 ) 
     2045          { 
     2046           $strUnits = $air_temperature[$i]{'units'}; 
     2047          } 
     2048          obsKMLSubRoutines::KMLAddObsToHash( 'air_temperature',  
     2049                                            $time_formatted_values[$j], 
     2050                                            $DataVal, 
     2051                                            1, 
     2052                                            $strPlatformID, 
     2053                                            $Height, 
     2054                                            $strUnits, 
     2055                                            $rObsHash ); 
     2056        } 
     2057      }                                             
     2058    }         
    19342059  } 
    19352060  
     
    19402065  # Assume that wind_speed controls everything (from_dir, gust, z, normalized) index-wise. 
    19412066  if ($#wind_speed > -1) { 
    1942     open(WIND_SQLFILE,'>>../sql/wind_prod_'.$institution_code_value.'_' 
    1943       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    1944     print WIND_SQLFILE "-- format_category      = $format_category_value\n"; 
    1945     print WIND_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    1946     print WIND_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    1947     print WIND_SQLFILE "-- package_code         = $package_code_value\n"; 
    1948     print WIND_SQLFILE "-- title                = $title_value\n"; 
    1949     print WIND_SQLFILE "-- institution          = $institution_value\n"; 
    1950     print WIND_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    1951     print WIND_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    1952     print WIND_SQLFILE "-- source               = $source_value\n"; 
    1953     print WIND_SQLFILE "-- references           = $references_value\n"; 
    1954     print WIND_SQLFILE "-- contact              = $contact_value\n"; 
    1955     print WIND_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    1956     print WIND_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    1957     for my $i (0..$#wind_speed) { 
    1958       my $j = 0; 
    1959       while ($j <= $#wind_from_direction 
    1960         && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'}) { 
    1961         $j++; 
    1962       } 
    1963       if ($j > $#wind_from_direction) { 
    1964         die "ABORT!  Could not find matching wind_from_direction for $wind_speed[$i]  {'var_name'}.\n"; 
    1965       } 
    1966       else { 
    1967         for my $k (0..$#this_wind_speed_data) { 
    1968           $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    1969           $this_time_stamp = $time_formatted_values[$k]; 
    1970           $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)); 
    1971            
    1972           my $WindSpdDataVal = 'NULL'; 
    1973           my $WindDirDataVal = 'NULL'; 
    1974           my $WindGstDataVal = 'NULL'; 
    1975           my $Height = ''; 
    1976           if ($wind_speed[$i]{'data'}[$k] != $missing_value_value 
    1977             && $wind_speed[$i]{'data'}[$k] != $Fill_value_value 
    1978             && $wind_from_direction[$j]{'data'}[$k] != $missing_value_value 
    1979             && $wind_from_direction[$j]{'data'}[$k] != $Fill_value_value 
    1980             && $this_station_id_top_ts < $this_time_stamp_sec 
    1981             && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    1982             print WIND_SQLFILE "INSERT INTO wind_prod (";  
    1983             print WIND_SQLFILE "station_id,"; 
    1984             print WIND_SQLFILE "time_stamp,";  
    1985             print WIND_SQLFILE "z,"; 
    1986             print WIND_SQLFILE "positive,"; 
    1987             print WIND_SQLFILE "wind_speed,"; 
    1988             print WIND_SQLFILE "wind_gust,"; 
    1989             print WIND_SQLFILE "wind_from_direction,"; 
    1990             print WIND_SQLFILE "can_be_normalized,"; 
    1991             print WIND_SQLFILE "title,"; 
    1992             print WIND_SQLFILE "institution,"; 
    1993             print WIND_SQLFILE "institution_url,"; 
    1994             print WIND_SQLFILE "institution_dods_url,"; 
    1995             print WIND_SQLFILE "source,"; 
    1996             print WIND_SQLFILE "refs,"; 
    1997             print WIND_SQLFILE "contact,"; 
    1998             print WIND_SQLFILE "the_geom"; 
    1999             print WIND_SQLFILE ") ";  
    2000             print WIND_SQLFILE "VALUES (";  
    2001             print WIND_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    2002             print WIND_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; 
    2003             if ($wind_speed[$i]{'height'} == $missing_value_value 
    2004               || $wind_speed[$i]{'height'} == $Fill_value_value) { 
    2005               print WIND_SQLFILE ','.'\'\''; 
    2006             } 
    2007             else { 
    2008               $this_val = sprintf("%.2f",$wind_speed[$i]{'height'}); 
     2067    #dwr 4/5/2008 
     2068    if( $bWriteSQLFiles ) 
     2069    { 
     2070      open(WIND_SQLFILE,'>>../sql/wind_prod_'.$institution_code_value.'_' 
     2071        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2072      print WIND_SQLFILE "-- format_category      = $format_category_value\n"; 
     2073      print WIND_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2074      print WIND_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2075      print WIND_SQLFILE "-- package_code         = $package_code_value\n"; 
     2076      print WIND_SQLFILE "-- title                = $title_value\n"; 
     2077      print WIND_SQLFILE "-- institution          = $institution_value\n"; 
     2078      print WIND_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2079      print WIND_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2080      print WIND_SQLFILE "-- source               = $source_value\n"; 
     2081      print WIND_SQLFILE "-- references           = $references_value\n"; 
     2082      print WIND_SQLFILE "-- contact              = $contact_value\n"; 
     2083      print WIND_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2084      print WIND_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2085      for my $i (0..$#wind_speed) { 
     2086        my $j = 0; 
     2087        while ($j <= $#wind_from_direction 
     2088          && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'}) { 
     2089          $j++; 
     2090        } 
     2091        if ($j > $#wind_from_direction) { 
     2092          die "ABORT!  Could not find matching wind_from_direction for $wind_speed[$i]  {'var_name'}.\n"; 
     2093        } 
     2094        else { 
     2095          for my $k (0..$#this_wind_speed_data) { 
     2096            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2097            $this_time_stamp = $time_formatted_values[$k]; 
     2098            $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)); 
     2099             
     2100            if ($wind_speed[$i]{'data'}[$k] != $missing_value_value 
     2101              && $wind_speed[$i]{'data'}[$k] != $Fill_value_value 
     2102              && $wind_from_direction[$j]{'data'}[$k] != $missing_value_value 
     2103              && $wind_from_direction[$j]{'data'}[$k] != $Fill_value_value 
     2104              && $this_station_id_top_ts < $this_time_stamp_sec 
     2105              && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2106              print WIND_SQLFILE "INSERT INTO wind_prod (";  
     2107              print WIND_SQLFILE "station_id,"; 
     2108              print WIND_SQLFILE "time_stamp,";  
     2109              print WIND_SQLFILE "z,"; 
     2110              print WIND_SQLFILE "positive,"; 
     2111              print WIND_SQLFILE "wind_speed,"; 
     2112              print WIND_SQLFILE "wind_gust,"; 
     2113              print WIND_SQLFILE "wind_from_direction,"; 
     2114              print WIND_SQLFILE "can_be_normalized,"; 
     2115              print WIND_SQLFILE "title,"; 
     2116              print WIND_SQLFILE "institution,"; 
     2117              print WIND_SQLFILE "institution_url,"; 
     2118              print WIND_SQLFILE "institution_dods_url,"; 
     2119              print WIND_SQLFILE "source,"; 
     2120              print WIND_SQLFILE "refs,"; 
     2121              print WIND_SQLFILE "contact,"; 
     2122              print WIND_SQLFILE "the_geom"; 
     2123              print WIND_SQLFILE ") ";  
     2124              print WIND_SQLFILE "VALUES (";  
     2125              print WIND_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2126              print WIND_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$k].'\''; 
     2127              if ($wind_speed[$i]{'height'} == $missing_value_value 
     2128                || $wind_speed[$i]{'height'} == $Fill_value_value) { 
     2129                print WIND_SQLFILE ','.'\'\''; 
     2130              } 
     2131              else { 
     2132                $this_val = sprintf("%.2f",$wind_speed[$i]{'height'}); 
     2133                print WIND_SQLFILE ','.$this_val; 
     2134              } 
     2135 
     2136              print WIND_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2137              $this_val = sprintf("%.2f",$wind_speed[$i]{'data'}[$k]); 
    20092138              print WIND_SQLFILE ','.$this_val; 
    2010             } 
    2011             #DWR 4/5/2008 
    2012             $Height = $this_val; 
    2013  
    2014             print WIND_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    2015             $this_val = sprintf("%.2f",$wind_speed[$i]{'data'}[$k]); 
    2016             print WIND_SQLFILE ','.$this_val; 
    2017  
    2018             #DWR 4/5/2008 
    2019             if( length( $this_val ) > 0 ) 
    2020             { 
    2021               $WindSpdDataVal = $this_val; 
    2022             } 
    2023  
    2024             if ($wind_gust[$j]{'data'}[$k] == $missing_value_value 
    2025               || $wind_gust[$j]{'data'}[$k] == $Fill_value_value 
    2026               || $wind_gust[$j]{'data'}[$k] == '') { 
    2027               print WIND_SQLFILE ',NULL'; 
    2028             } 
    2029             else { 
    2030               $this_val = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     2139 
     2140 
     2141              if ($wind_gust[$j]{'data'}[$k] == $missing_value_value 
     2142                || $wind_gust[$j]{'data'}[$k] == $Fill_value_value 
     2143                || $wind_gust[$j]{'data'}[$k] == '') { 
     2144                print WIND_SQLFILE ',NULL'; 
     2145              } 
     2146              else { 
     2147                $this_val = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     2148                print WIND_SQLFILE ','.$this_val; 
     2149              } 
     2150               
     2151              $this_val = sprintf("%.2f",$wind_from_direction[$j]{'data'}[$k]); 
     2152               
    20312153              print WIND_SQLFILE ','.$this_val; 
    2032               #DWR 4/5/2008 
    2033               $WindGstDataVal = $this_val; 
    2034             } 
     2154              print WIND_SQLFILE ','.'\''.$wind_speed[$i]{'can_be_normalized'}.'\''; 
     2155              print WIND_SQLFILE ','.'\''.$title_value.'\''; 
     2156              print WIND_SQLFILE ','.'\''.$institution_value.'\''; 
     2157              print WIND_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
     2158              print WIND_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
     2159              print WIND_SQLFILE ','.'\''.$source_value.'\''; 
     2160              print WIND_SQLFILE ','.'\''.$references_value.'\''; 
     2161              print WIND_SQLFILE ','.'\''.$contact_value.'\''; 
     2162              print WIND_SQLFILE ",GeometryFromText('POINT(";  
     2163              print WIND_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2164              print WIND_SQLFILE ")',-1));\n"; 
     2165                             
     2166            } 
     2167          } 
     2168        } 
     2169        print WIND_SQLFILE "\n"; 
     2170      } 
     2171      close(WIND_SQLFILE); 
     2172    } 
     2173    #DWR 4/5/2008 
     2174    if( $bWriteobsKMLFile ) 
     2175    { 
     2176      for my $i (0..$#wind_speed)  
     2177      { 
     2178        my $j = 0; 
     2179        while ($j <= $#wind_from_direction 
     2180          && $wind_from_direction[$j]{'height'} != $wind_speed[$i]{'height'})  
     2181          { 
     2182          $j++; 
     2183        } 
     2184        if ($j > $#wind_from_direction)  
     2185        { 
     2186          die "ABORT!  Could not find matching wind_from_direction for $wind_speed[$i]  {'var_name'}.\n"; 
     2187        } 
     2188        else  
     2189        { 
     2190          for my $k (0..$#this_wind_speed_data)  
     2191          { 
     2192            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2193            $this_time_stamp = $time_formatted_values[$k]; 
     2194            $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)); 
    20352195             
    2036             $this_val = sprintf("%.2f",$wind_from_direction[$j]{'data'}[$k]); 
    2037             #DWR 4/5/2008 
    2038             if( length( $this_val ) > 0 ) 
    2039             { 
    2040               $WindDirDataVal = $this_val; 
    2041             } 
    2042              
    2043             print WIND_SQLFILE ','.$this_val; 
    2044             print WIND_SQLFILE ','.'\''.$wind_speed[$i]{'can_be_normalized'}.'\''; 
    2045             print WIND_SQLFILE ','.'\''.$title_value.'\''; 
    2046             print WIND_SQLFILE ','.'\''.$institution_value.'\''; 
    2047             print WIND_SQLFILE ','.'\''.'<a href='.$institution_url_value.' target=  _blank>'.$institution_url_value.'</a>'.'\''; 
    2048             print WIND_SQLFILE ','.'\''.'<a href='.$institution_dods_url_value.' target=  _blank>'.$institution_dods_url_value.'</a>'.'\''; 
    2049             print WIND_SQLFILE ','.'\''.$source_value.'\''; 
    2050             print WIND_SQLFILE ','.'\''.$references_value.'\''; 
    2051             print WIND_SQLFILE ','.'\''.$contact_value.'\''; 
    2052             print WIND_SQLFILE ",GeometryFromText('POINT(";  
    2053             print WIND_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    2054             print WIND_SQLFILE ")',-1));\n"; 
    2055              
    2056           #DWR 4/5/2008 
    2057               my $strUnits; 
    2058               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_speed[$i]{'units'}, $XMLControlFile );         
    2059               if( length( $strUnits ) == 0 ) 
    2060               { 
    2061                $strUnits = $wind_speed[$i]{'units'}; 
    2062               } 
    2063                
    2064                           obsKMLSubRoutines::KMLAddObsToHash( 'wind_speed',  
    2065                                                                       $time_formatted_values[$j], 
    2066                                                                     $WindSpdDataVal, 
    2067                                                               1, 
    2068                                                               $strPlatformID, 
    2069                                                               $Height, 
    2070                                                               $strUnits, 
    2071                                                               $rObsHash ); 
    2072               #DWR 4/3/2008 
    2073               $strUnits = ''; 
    2074               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_from_direction[$i]{'units'}, $XMLControlFile );         
    2075               if( length( $strUnits ) == 0 ) 
    2076               { 
    2077                $strUnits = $wind_from_direction[$i]{'units'}; 
    2078               } 
    2079                           obsKMLSubRoutines::KMLAddObsToHash( 'wind_from_direction',  
    2080                                                                       $time_formatted_values[$j], 
    2081                                                                     $WindDirDataVal, 
    2082                                                               1, 
    2083                                                               $strPlatformID, 
    2084                                                               $Height, 
    2085                                                               $strUnits, 
    2086                                                               $rObsHash ); 
    2087               #DWR 4/3/2008 
    2088               $strUnits = ''; 
    2089               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_gust[$i]{'units'}, $XMLControlFile );         
    2090               if( length( $strUnits ) == 0 ) 
    2091               { 
    2092                $strUnits = $wind_gust[$i]{'units'}; 
    2093               } 
    2094                           obsKMLSubRoutines::KMLAddObsToHash( 'wind_gust',  
    2095                                                                       $time_formatted_values[$j], 
    2096                                                                     $WindGstDataVal, 
    2097                                                               1, 
    2098                                                               $strPlatformID, 
    2099                                                               $Height, 
    2100                                                               $strUnits, 
    2101                                                               $rObsHash ); 
    2102              
     2196            my $WindSpdDataVal = 'NULL'; 
     2197            my $WindDirDataVal = 'NULL'; 
     2198            my $WindGstDataVal = 'NULL'; 
     2199            my $Height = ''; 
     2200            if ($wind_speed[$i]{'data'}[$k] != $missing_value_value 
     2201              && $wind_speed[$i]{'data'}[$k] != $Fill_value_value 
     2202              && $wind_from_direction[$j]{'data'}[$k] != $missing_value_value 
     2203              && $wind_from_direction[$j]{'data'}[$k] != $Fill_value_value 
     2204              && $this_station_id_top_ts < $this_time_stamp_sec 
     2205              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2206              { 
     2207                if ($wind_speed[$i]{'height'} != $missing_value_value 
     2208                  && $wind_speed[$i]{'height'} != $Fill_value_value)  
     2209                { 
     2210                  $Height = sprintf("%.2f",$wind_speed[$i]{'height'}); 
     2211                } 
     2212 
     2213                $this_val = sprintf("%.2f",$wind_speed[$i]{'data'}[$k]); 
     2214                if( length( $this_val ) > 0 ) 
     2215                { 
     2216                  $WindSpdDataVal = $this_val; 
     2217                } 
     2218 
     2219                if ($wind_gust[$j]{'data'}[$k] != $missing_value_value 
     2220                    && $wind_gust[$j]{'data'}[$k] != $Fill_value_value 
     2221                    && $wind_gust[$j]{'data'}[$k] != '')  
     2222                { 
     2223                  $WindGstDataVal = sprintf("%.2f",$wind_gust[$j]{'data'}[$k]); 
     2224                } 
     2225                 
     2226                $this_val = sprintf("%.2f",$wind_from_direction[$j]{'data'}[$k]); 
     2227                #DWR 4/5/2008 
     2228                if( length( $this_val ) > 0 ) 
     2229                { 
     2230                  $WindDirDataVal = $this_val; 
     2231                }               
     2232              } 
     2233              my $strUnits; 
     2234              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_speed[$i]{'units'}, $XMLControlFile );         
     2235              if( length( $strUnits ) == 0 ) 
     2236              { 
     2237               $strUnits = $wind_speed[$i]{'units'}; 
     2238              } 
     2239               
     2240              obsKMLSubRoutines::KMLAddObsToHash( 'wind_speed',  
     2241                                                  $time_formatted_values[$j], 
     2242                                                  $WindSpdDataVal, 
     2243                                                  1, 
     2244                                                  $strPlatformID, 
     2245                                                  $Height, 
     2246                                                  $strUnits, 
     2247                                                  $rObsHash ); 
     2248              $strUnits = ''; 
     2249              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_from_direction[$i]{'units'}, $XMLControlFile );         
     2250              if( length( $strUnits ) == 0 ) 
     2251              { 
     2252               $strUnits = $wind_from_direction[$i]{'units'}; 
     2253              } 
     2254              obsKMLSubRoutines::KMLAddObsToHash( 'wind_from_direction',  
     2255                                                  $time_formatted_values[$j], 
     2256                                                  $WindDirDataVal, 
     2257                                                  1, 
     2258                                                  $strPlatformID, 
     2259                                                  $Height, 
     2260                                                  $strUnits, 
     2261                                                  $rObsHash ); 
     2262              $strUnits = ''; 
     2263              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $wind_gust[$i]{'units'}, $XMLControlFile );         
     2264              if( length( $strUnits ) == 0 ) 
     2265              { 
     2266               $strUnits = $wind_gust[$i]{'units'}; 
     2267              } 
     2268              obsKMLSubRoutines::KMLAddObsToHash( 'wind_gust',  
     2269                                                  $time_formatted_values[$j], 
     2270                                                  $WindGstDataVal, 
     2271                                                  1, 
     2272                                                  $strPlatformID, 
     2273                                                  $Height, 
     2274                                                  $strUnits, 
     2275                                                  $rObsHash ); 
    21032276          } 
    21042277        } 
    2105       } 
    2106       print WIND_SQLFILE "\n"; 
    2107     } 
    2108     close(WIND_SQLFILE); 
     2278      }                                             
     2279    }             
    21092280  } 
    21102281   
     
    21132284  # the metadata, use the station_id lookup, instead. 
    21142285  if ($#air_pressure > -1) { 
    2115     open(AIR_PRESSURE_SQLFILE,'>>../sql/air_pressure_prod_'.$institution_code_value.'_' 
    2116       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    2117     print AIR_PRESSURE_SQLFILE "-- format_category      = $format_category_value\n"; 
    2118     print AIR_PRESSURE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    2119     print AIR_PRESSURE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    2120     print AIR_PRESSURE_SQLFILE "-- package_code         = $package_code_value\n"; 
    2121     print AIR_PRESSURE_SQLFILE "-- title                = $title_value\n"; 
    2122     print AIR_PRESSURE_SQLFILE "-- institution          = $institution_value\n"; 
    2123     print AIR_PRESSURE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    2124     print AIR_PRESSURE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    2125     print AIR_PRESSURE_SQLFILE "-- source               = $source_value\n"; 
    2126     print AIR_PRESSURE_SQLFILE "-- references           = $references_value\n"; 
    2127     print AIR_PRESSURE_SQLFILE "-- contact              = $contact_value\n"; 
    2128     print AIR_PRESSURE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    2129     print AIR_PRESSURE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    2130     for my $i (0..$#air_pressure) { 
    2131       for my $j (0..$#this_air_pressure_data) { 
    2132         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    2133         $this_time_stamp = $time_formatted_values[$j]; 
    2134         $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)); 
    2135          
    2136         my $DataVal = 'NULL'; 
    2137         my $Height = ''; 
    2138         if ($air_pressure[$i]{'data'}[$j] != $missing_value_value 
    2139           && $air_pressure[$i]{'data'}[$j] != $Fill_value_value 
    2140           && $this_station_id_top_ts < $this_time_stamp_sec 
    2141           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    2142           print AIR_PRESSURE_SQLFILE "INSERT INTO air_pressure_prod (";  
    2143           print AIR_PRESSURE_SQLFILE "station_id,"; 
    2144           print AIR_PRESSURE_SQLFILE "time_stamp,";  
    2145           print AIR_PRESSURE_SQLFILE "z,"; 
    2146           print AIR_PRESSURE_SQLFILE "positive,"; 
    2147           print AIR_PRESSURE_SQLFILE "pressure,"; 
    2148           print AIR_PRESSURE_SQLFILE "the_geom"; 
    2149           print AIR_PRESSURE_SQLFILE ") ";  
    2150           print AIR_PRESSURE_SQLFILE "VALUES (";  
    2151           print AIR_PRESSURE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    2152           print AIR_PRESSURE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    2153           if ($air_pressure[$i]{'height'} == $missing_value_value 
    2154             || $air_pressure[$i]{'height'} == $Fill_value_value) { 
    2155             print AIR_PRESSURE_SQLFILE ',NULL'; 
     2286    if( $bWriteSQLFiles ) 
     2287    { 
     2288      open(AIR_PRESSURE_SQLFILE,'>>../sql/air_pressure_prod_'.$institution_code_value.'_' 
     2289        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2290      print AIR_PRESSURE_SQLFILE "-- format_category      = $format_category_value\n"; 
     2291      print AIR_PRESSURE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2292      print AIR_PRESSURE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2293      print AIR_PRESSURE_SQLFILE "-- package_code         = $package_code_value\n"; 
     2294      print AIR_PRESSURE_SQLFILE "-- title                = $title_value\n"; 
     2295      print AIR_PRESSURE_SQLFILE "-- institution          = $institution_value\n"; 
     2296      print AIR_PRESSURE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2297      print AIR_PRESSURE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2298      print AIR_PRESSURE_SQLFILE "-- source               = $source_value\n"; 
     2299      print AIR_PRESSURE_SQLFILE "-- references           = $references_value\n"; 
     2300      print AIR_PRESSURE_SQLFILE "-- contact              = $contact_value\n"; 
     2301      print AIR_PRESSURE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2302      print AIR_PRESSURE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2303      for my $i (0..$#air_pressure) { 
     2304        for my $j (0..$#this_air_pressure_data) { 
     2305          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2306          $this_time_stamp = $time_formatted_values[$j]; 
     2307          $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)); 
     2308           
     2309          if ($air_pressure[$i]{'data'}[$j] != $missing_value_value 
     2310            && $air_pressure[$i]{'data'}[$j] != $Fill_value_value 
     2311            && $this_station_id_top_ts < $this_time_stamp_sec 
     2312            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2313            print AIR_PRESSURE_SQLFILE "INSERT INTO air_pressure_prod (";  
     2314            print AIR_PRESSURE_SQLFILE "station_id,"; 
     2315            print AIR_PRESSURE_SQLFILE "time_stamp,";  
     2316            print AIR_PRESSURE_SQLFILE "z,"; 
     2317            print AIR_PRESSURE_SQLFILE "positive,"; 
     2318            print AIR_PRESSURE_SQLFILE "pressure,"; 
     2319            print AIR_PRESSURE_SQLFILE "the_geom"; 
     2320            print AIR_PRESSURE_SQLFILE ") ";  
     2321            print AIR_PRESSURE_SQLFILE "VALUES (";  
     2322            print AIR_PRESSURE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2323            print AIR_PRESSURE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2324            if ($air_pressure[$i]{'height'} == $missing_value_value 
     2325              || $air_pressure[$i]{'height'} == $Fill_value_value) { 
     2326              print AIR_PRESSURE_SQLFILE ',NULL'; 
     2327            } 
     2328            else { 
     2329              $this_val = sprintf("%.2f",$air_pressure[$i]{'height'}); 
     2330              print AIR_PRESSURE_SQLFILE ','.$this_val; 
     2331            } 
     2332             
     2333            print AIR_PRESSURE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2334            $this_val = sprintf("%.2f",$air_pressure[$i]{'data'}[$j]); 
     2335             
     2336            print AIR_PRESSURE_SQLFILE ','.$this_val; 
     2337            print AIR_PRESSURE_SQLFILE ",GeometryFromText('POINT(";  
     2338            print AIR_PRESSURE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2339            print AIR_PRESSURE_SQLFILE ")',-1));\n"; 
    21562340          } 
    2157           else { 
    2158             $this_val = sprintf("%.2f",$air_pressure[$i]{'height'}); 
    2159             print AIR_PRESSURE_SQLFILE ','.$this_val; 
     2341           
     2342        } 
     2343        print AIR_PRESSURE_SQLFILE "\n"; 
     2344      } 
     2345      close(AIR_PRESSURE_SQLFILE); 
     2346    } 
     2347    #DWR 4/5/2008 
     2348    if( $bWriteobsKMLFile ) 
     2349    { 
     2350      my $DataVal = 'NULL'; 
     2351      my $Height = ''; 
     2352      for my $i (0..$#air_pressure)  
     2353      { 
     2354        for my $j (0..$#this_air_pressure_data)  
     2355        { 
     2356          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2357          $this_time_stamp = $time_formatted_values[$j]; 
     2358          $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)); 
     2359           
     2360          my $DataVal = 'NULL'; 
     2361          my $Height = ''; 
     2362          if ($air_pressure[$i]{'data'}[$j] != $missing_value_value 
     2363            && $air_pressure[$i]{'data'}[$j] != $Fill_value_value 
     2364            && $this_station_id_top_ts < $this_time_stamp_sec 
     2365            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2366            if ($air_pressure[$i]{'height'} != $missing_value_value 
     2367              && $air_pressure[$i]{'height'} != $Fill_value_value)  
     2368            { 
     2369              $Height = sprintf("%.2f",$air_pressure[$i]{'height'}); 
     2370            } 
     2371            $DataVal = sprintf("%.2f",$air_pressure[$i]{'data'}[$j]); 
     2372          }            
     2373          #DWR 4/3/2008 
     2374          my $strUnits; 
     2375          $strUnits = obsKMLSubRoutines::UnitsStringConversion( $air_pressure[$i]{'units'}, $XMLControlFile );  
     2376          if( length( $strUnits ) == 0 ) 
     2377          { 
     2378           $strUnits =  $air_pressure[$i]{'units'}; 
    21602379          } 
    2161           #DWR 4/5/2008 
    2162           $Height = $this_val; 
    2163            
    2164           print AIR_PRESSURE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    2165           $this_val = sprintf("%.2f",$air_pressure[$i]{'data'}[$j]); 
    2166           #DWR 4/5/2008 
    2167           $DataVal = $this_val; 
    2168            
    2169           print AIR_PRESSURE_SQLFILE ','.$this_val; 
    2170           print AIR_PRESSURE_SQLFILE ",GeometryFromText('POINT(";  
    2171           print AIR_PRESSURE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    2172           print AIR_PRESSURE_SQLFILE ")',-1));\n"; 
    2173         } 
    2174               #DWR 4/3/2008 
    2175             my $strUnits; 
    2176               $strUnits = obsKMLSubRoutines::UnitsStringConversion( $air_pressure[$i]{'units'}, $XMLControlFile );  
    2177               if( length( $strUnits ) == 0 ) 
    2178               { 
    2179                $strUnits =  $air_pressure[$i]{'units'}; 
    2180               } 
    2181                       
    2182                           obsKMLSubRoutines::KMLAddObsToHash( 'air_pressure',  
    2183                                                               $time_formatted_values[$j], 
    2184                                                                     $DataVal, 
    2185                                                               1, 
    2186                                                               $strPlatformID, 
    2187                                                               $Height, 
    2188                                                               $strUnits, 
    2189                                                               $rObsHash ); 
    2190          
    2191       } 
    2192       print AIR_PRESSURE_SQLFILE "\n"; 
    2193     } 
    2194     close(AIR_PRESSURE_SQLFILE); 
     2380                  
     2381          obsKMLSubRoutines::KMLAddObsToHash( 'air_pressure',  
     2382                                              $time_formatted_values[$j], 
     2383                                              $DataVal, 
     2384                                              1, 
     2385                                              $strPlatformID, 
     2386                                              $Height, 
     2387                                              $strUnits, 
     2388                                              $rObsHash ); 
     2389        } 
     2390      }                                             
     2391    }         
    21952392  } 
    21962393   
     
    21992396  # the metadata, use the station_id lookup, instead. 
    22002397  if ($#salinity > -1) { 
    2201     open(SALINITY_SQLFILE,'>>../sql/salinity_prod_'.$institution_code_value.'_' 
    2202       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    2203     print SALINITY_SQLFILE "-- format_category      = $format_category_value\n"; 
    2204     print SALINITY_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    2205     print SALINITY_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    2206     print SALINITY_SQLFILE "-- package_code         = $package_code_value\n"; 
    2207     print SALINITY_SQLFILE "-- title                = $title_value\n"; 
    2208     print SALINITY_SQLFILE "-- institution          = $institution_value\n"; 
    2209     print SALINITY_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    2210     print SALINITY_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    2211     print SALINITY_SQLFILE "-- source               = $source_value\n"; 
    2212     print SALINITY_SQLFILE "-- references           = $references_value\n"; 
    2213     print SALINITY_SQLFILE "-- contact              = $contact_value\n"; 
    2214     print SALINITY_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    2215     print SALINITY_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    2216     for my $i (0..$#salinity) { 
    2217       for my $j (0..$#this_salinity_data) { 
    2218         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    2219         $this_time_stamp = $time_formatted_values[$j]; 
    2220         $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)); 
    2221          
    2222         my $DataVal = 'NULL'; 
    2223         my $Height = ''; 
    2224               print "debug: $salinity[$i]{'data'}[$k]\n";             
    2225         if ($salinity[$i]{'data'}[$j] != $missing_value_value 
    2226           && $salinity[$i]{'data'}[$j] != $Fill_value_value 
    2227           && $this_station_id_top_ts < $this_time_stamp_sec 
    2228           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    2229           print SALINITY_SQLFILE "INSERT INTO salinity_prod (";  
    2230           print SALINITY_SQLFILE "station_id,"; 
    2231           print SALINITY_SQLFILE "time_stamp,";  
    2232           print SALINITY_SQLFILE "z,"; 
    2233           print SALINITY_SQLFILE "positive,"; 
    2234           print SALINITY_SQLFILE "salinity,"; 
    2235           print SALINITY_SQLFILE "the_geom"; 
    2236           print SALINITY_SQLFILE ") ";  
    2237           print SALINITY_SQLFILE "VALUES (";  
    2238           print SALINITY_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    2239           print SALINITY_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    2240           if ($salinity[$i]{'height'} == $missing_value_value 
    2241             || $salinity[$i]{'height'} == $Fill_value_value) { 
    2242             print SALINITY_SQLFILE ',NULL'; 
     2398    if( $bWriteSQLFiles ) 
     2399    { 
     2400      open(SALINITY_SQLFILE,'>>../sql/salinity_prod_'.$institution_code_value.'_' 
     2401        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2402      print SALINITY_SQLFILE "-- format_category      = $format_category_value\n"; 
     2403      print SALINITY_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2404      print SALINITY_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2405      print SALINITY_SQLFILE "-- package_code         = $package_code_value\n"; 
     2406      print SALINITY_SQLFILE "-- title                = $title_value\n"; 
     2407      print SALINITY_SQLFILE "-- institution          = $institution_value\n"; 
     2408      print SALINITY_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2409      print SALINITY_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2410      print SALINITY_SQLFILE "-- source               = $source_value\n"; 
     2411      print SALINITY_SQLFILE "-- references           = $references_value\n"; 
     2412      print SALINITY_SQLFILE "-- contact              = $contact_value\n"; 
     2413      print SALINITY_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2414      print SALINITY_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2415      for my $i (0..$#salinity) { 
     2416        for my $j (0..$#this_salinity_data) { 
     2417          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2418          $this_time_stamp = $time_formatted_values[$j]; 
     2419          $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)); 
     2420           
     2421          #print "debug: $salinity[$i]{'data'}[$k]\n";             
     2422          if ($salinity[$i]{'data'}[$j] != $missing_value_value 
     2423            && $salinity[$i]{'data'}[$j] != $Fill_value_value 
     2424            && $this_station_id_top_ts < $this_time_stamp_sec 
     2425            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2426            print SALINITY_SQLFILE "INSERT INTO salinity_prod (";  
     2427            print SALINITY_SQLFILE "station_id,"; 
     2428            print SALINITY_SQLFILE "time_stamp,";  
     2429            print SALINITY_SQLFILE "z,"; 
     2430            print SALINITY_SQLFILE "positive,"; 
     2431            print SALINITY_SQLFILE "salinity,"; 
     2432            print SALINITY_SQLFILE "the_geom"; 
     2433            print SALINITY_SQLFILE ") ";  
     2434            print SALINITY_SQLFILE "VALUES (";  
     2435            print SALINITY_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2436            print SALINITY_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2437            if ($salinity[$i]{'height'} == $missing_value_value 
     2438              || $salinity[$i]{'height'} == $Fill_value_value) { 
     2439              print SALINITY_SQLFILE ',NULL'; 
     2440            } 
     2441            else { 
     2442              $this_val = sprintf("%.2f",$salinity[$i]{'height'}); 
     2443              print SALINITY_SQLFILE ','.$this_val; 
     2444            } 
     2445             
     2446            print SALINITY_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2447            $this_val = sprintf("%.2f",$salinity[$i]{'data'}[$j]); 
     2448             
     2449            print SALINITY_SQLFILE ','.$this_val; 
     2450            print SALINITY_SQLFILE ",GeometryFromText('POINT(";  
     2451            print SALINITY_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2452            print SALINITY_SQLFILE ")',-1));\n"; 
     2453          }           
     2454        } 
     2455        print SALINITY_SQLFILE "\n"; 
     2456      } 
     2457      close(SALINITY_SQLFILE); 
     2458    } 
     2459    #DWR 4/5/2008 
     2460    if( $bWriteobsKMLFile ) 
     2461    { 
     2462      my $DataVal = 'NULL'; 
     2463      my $Height = ''; 
     2464      for my $i (0..$#salinity)  
     2465      { 
     2466        for my $j (0..$#this_salinity_data)  
     2467        { 
     2468          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2469          $this_time_stamp = $time_formatted_values[$j]; 
     2470          $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)); 
     2471           
     2472          my $DataVal = 'NULL'; 
     2473          my $Height = ''; 
     2474          if ($salinity[$i]{'data'}[$j] != $missing_value_value 
     2475              && $salinity[$i]{'data'}[$j] != $Fill_value_value 
     2476              && $this_station_id_top_ts < $this_time_stamp_sec 
     2477              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2478          { 
     2479            if ($salinity[$i]{'height'} != $missing_value_value 
     2480              && $salinity[$i]{'height'} != $Fill_value_value)  
     2481            { 
     2482              $Height = sprintf("%.2f",$salinity[$i]{'height'}); 
     2483            } 
     2484            $DataVal = sprintf("%.2f",$salinity[$i]{'data'}[$j]); 
     2485          }            
     2486          my $strUnits; 
     2487          if( lc( $salinity[$i]{'units'} ) eq 'ppt' ) 
     2488          { 
     2489            $strUnits =  'psu';         
    22432490          } 
    2244           else { 
    2245             $this_val = sprintf("%.2f",$salinity[$i]{'height'}); 
    2246             print SALINITY_SQLFILE ','.$this_val
     2491          if( length( $strUnits ) == 0 ) 
     2492          { 
     2493           $strUnits = $salinity[$i]{'units'}
    22472494          } 
    2248           #DWR 4/5/2008; 
    2249           $Height = $this_val; 
    22502495           
    2251           print SALINITY_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    2252           $this_val = sprintf("%.2f",$salinity[$i]{'data'}[$j]); 
    2253           #DWR 4/5/2008; 
    2254           $DataVal = $this_val; 
    2255            
    2256           print SALINITY_SQLFILE ','.$this_val; 
    2257           print SALINITY_SQLFILE ",GeometryFromText('POINT(";  
    2258           print SALINITY_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    2259           print SALINITY_SQLFILE ")',-1));\n"; 
    2260         } 
    2261               #DWR 4/3/2008 
    2262             my $strUnits; 
    2263             if( lc( $salinity[$i]{'units'} ) eq 'ppt' ) 
    2264             { 
    2265               $strUnits =  'psu';         
    2266             } 
    2267               if( length( $strUnits ) == 0 ) 
    2268               { 
    2269                $strUnits = $salinity[$i]{'units'}; 
    2270               } 
    2271                
    2272                           obsKMLSubRoutines::KMLAddObsToHash( 'salinity',  
    2273                                                               $time_formatted_values[$j], 
    2274                                                                     $DataVal, 
    2275                                                               1, 
    2276                                                               $strPlatformID, 
    2277                                                               $Height, 
    2278                                                               $strUnits, 
    2279                                                               $rObsHash ); 
    2280          
    2281       } 
    2282       print SALINITY_SQLFILE "\n"; 
    2283     } 
    2284     close(SALINITY_SQLFILE); 
     2496          obsKMLSubRoutines::KMLAddObsToHash( 'salinity',  
     2497                                              $time_formatted_values[$j], 
     2498                                              $DataVal, 
     2499                                              1, 
     2500                                              $strPlatformID, 
     2501                                              $Height, 
     2502                                              $strUnits, 
     2503                                              $rObsHash ); 
     2504        } 
     2505      }                                             
     2506    }             
    22852507  } 
    22862508   
     
    22902512    # Assume that sea_surface_eastward_current controls everything index-wise. 
    22912513    if ($#sea_surface_eastward_current > -1) { 
     2514    if( $bWriteSQLFiles ) 
     2515    { 
    22922516      open(CURRENT_IN_SITU_SQLFILE,'>>../sql/current_in_situ_prod_'.$institution_code_value.'_' 
    22932517        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     
    23192543            $this_time_stamp = $time_formatted_values[$k]; 
    23202544            $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)); 
    2321              
    2322             #DWR 4/5/2008 
    2323             my $ECurrentDataVal = 'NULL'; 
    2324             my $NCurrentDataVal = 'NULL'; 
    2325             my $Height = '';             
    2326              
     2545                         
    23272546            #print "debug: $sea_surface_eastward_current[$i]{'data'}[$k]\n";             
    23282547            if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value 
     
    23522571                $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'}); 
    23532572                print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
    2354                 #DWR 4/5/2008 
    2355                 $Height = $this_val; 
    23562573                 
    23572574              } 
    23582575              print CURRENT_IN_SITU_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    23592576              $this_val = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); 
    2360               #DWR 4/5/2008 
    2361               $ECurrentDataVal = $this_val; 
    23622577               
    23632578              print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
    23642579              $this_val = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); 
    2365               #DWR 4/5/2008 
    2366               $NCurrentDataVal = $this_val; 
    23672580 
    23682581              print CURRENT_IN_SITU_SQLFILE ','.$this_val; 
     
    23722585              print CURRENT_IN_SITU_SQLFILE ")',-1));\n"; 
    23732586            } 
    2374               #DWR 4/3/2008 
     2587             
     2588          } 
     2589        } 
     2590        print CURRENT_IN_SITU_SQLFILE "\n"; 
     2591      } 
     2592      close(CURRENT_IN_SITU_SQLFILE); 
     2593    } 
     2594    #DWR 4/5/2008 
     2595    if( $bWriteobsKMLFile ) 
     2596    { 
     2597      for my $i (0..$#sea_surface_eastward_current)  
     2598      { 
     2599        my $j = 0; 
     2600        while ($j <= $#sea_surface_northward_current 
     2601              && $sea_surface_northward_current[$j]{'height'} != $sea_surface_eastward_current[$i]{'height'})  
     2602        { 
     2603          $j++; 
     2604        } 
     2605        if ($j > $#sea_surface_northward_current)  
     2606        { 
     2607          die "ABORT!  Could not find matching sea_surface_northward_current for $sea_surface_eastward_current[$i]  {'var_name'}.\n"; 
     2608        } 
     2609        else  
     2610        { 
     2611          for my $k (0..$#this_sea_surface_eastward_current_data)  
     2612          { 
     2613            $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2614            $this_time_stamp = $time_formatted_values[$k]; 
     2615            $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)); 
     2616             
     2617            my $ECurrentDataVal = 'NULL'; 
     2618            my $NCurrentDataVal = 'NULL'; 
     2619            my $Height = '';             
     2620             
     2621            if ($sea_surface_eastward_current[$i]{'data'}[$k] != $missing_value_value 
     2622                && $sea_surface_eastward_current[$i]{'data'}[$k] != $Fill_value_value 
     2623                && $sea_surface_northward_current[$j]{'data'}[$k] != $missing_value_value 
     2624                && $sea_surface_northward_current[$j]{'data'}[$k] != $Fill_value_value 
     2625                && $this_station_id_top_ts < $this_time_stamp_sec 
     2626                && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2627            { 
     2628              if ($sea_surface_eastward_current[$i]{'height'} != $missing_value_value 
     2629                  && $sea_surface_eastward_current[$i]{'height'} != $Fill_value_value)  
     2630              { 
     2631                $Height = sprintf("%.2f",$sea_surface_eastward_current[$i]{'height'});                 
     2632              } 
     2633              $ECurrentDataVal = sprintf("%.2f",$sea_surface_eastward_current[$i]{'data'}[$k]); 
     2634               
     2635              $NCurrentDataVal = sprintf("%.2f",$sea_surface_northward_current[$j]{'data'}[$k]); 
     2636 
     2637            } 
    23752638            my $strUnits; 
    23762639              $strUnits = obsKMLSubRoutines::UnitsStringConversion( $sea_surface_eastward_current[$i]{'units'}, $XMLControlFile );         
     
    24022665                                                              $strUnits, 
    24032666                                                              $rObsHash ); 
    2404              
    2405           } 
    2406         } 
    2407         print CURRENT_IN_SITU_SQLFILE "\n"; 
    2408       } 
    2409       close(CURRENT_IN_SITU_SQLFILE); 
     2667        } 
     2668      }                                             
     2669    }                   
    24102670  } 
    24112671   
     
    24152675  # the metadata, use the station_id lookup, instead. 
    24162676  if ($#significant_wave_height > -1) { 
    2417     open(WAVE_SQLFILE,'>>../sql/wave_in_situ_prod_'.$institution_code_value.'_' 
    2418       .$platform_code_value.'_'.$package_code_value.'.sql'); 
    2419     print WAVE_SQLFILE "-- format_category      = $format_category_value\n"; 
    2420     print WAVE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
    2421     print WAVE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
    2422     print WAVE_SQLFILE "-- package_code         = $package_code_value\n"; 
    2423     print WAVE_SQLFILE "-- title                = $title_value\n"; 
    2424     print WAVE_SQLFILE "-- institution          = $institution_value\n"; 
    2425     print WAVE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
    2426     print WAVE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
    2427     print WAVE_SQLFILE "-- source               = $source_value\n"; 
    2428     print WAVE_SQLFILE "-- references           = $references_value\n"; 
    2429     print WAVE_SQLFILE "-- contact              = $contact_value\n"; 
    2430     print WAVE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
    2431     print WAVE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
    2432     for my $i (0..$#significant_wave_height) { 
    2433       for my $j (0..$#this_significant_wave_height_data) { 
    2434         $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
    2435         $this_time_stamp = $time_formatted_values[$j]; 
    2436         $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)); 
     2677    if( $bWriteSQLFiles ) 
     2678    { 
     2679      open(WAVE_SQLFILE,'>>../sql/wave_in_situ_prod_'.$institution_code_value.'_' 
     2680        .$platform_code_value.'_'.$package_code_value.'.sql'); 
     2681      print WAVE_SQLFILE "-- format_category      = $format_category_value\n"; 
     2682      print WAVE_SQLFILE "-- institution_code     = $institution_code_value\n"; 
     2683      print WAVE_SQLFILE "-- platform_code        = $platform_code_value\n"; 
     2684      print WAVE_SQLFILE "-- package_code         = $package_code_value\n"; 
     2685      print WAVE_SQLFILE "-- title                = $title_value\n"; 
     2686      print WAVE_SQLFILE "-- institution          = $institution_value\n"; 
     2687      print WAVE_SQLFILE "-- institution_url      = $institution_url_value\n"; 
     2688      print WAVE_SQLFILE "-- institution_dods_url = $institution_dods_url_value\n"; 
     2689      print WAVE_SQLFILE "-- source               = $source_value\n"; 
     2690      print WAVE_SQLFILE "-- references           = $references_value\n"; 
     2691      print WAVE_SQLFILE "-- contact              = $contact_value\n"; 
     2692      print WAVE_SQLFILE "-- missing_value        = $missing_value_value\n"; 
     2693      print WAVE_SQLFILE "-- _FillValue           = $Fill_value_value\n"; 
     2694      for my $i (0..$#significant_wave_height) { 
     2695        for my $j (0..$#this_significant_wave_height_data) { 
     2696          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2697          $this_time_stamp = $time_formatted_values[$j]; 
     2698          $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)); 
     2699           
     2700          my $DomWaveDataVal = 'NULL'; 
     2701          my $SigWaveHgtDataVal = 'NULL'; 
     2702          my $Height = ''; 
     2703           
     2704          if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
     2705            && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
     2706            && $this_station_id_top_ts < $this_time_stamp_sec 
     2707            && $this_time_stamp_sec > $oldest_ok_timestamp) { 
     2708            print WAVE_SQLFILE "INSERT INTO wave_in_situ_prod (";  
     2709            print WAVE_SQLFILE "station_id,"; 
     2710            print WAVE_SQLFILE "time_stamp,";  
     2711            print WAVE_SQLFILE "z,"; 
     2712            print WAVE_SQLFILE "positive,"; 
     2713            print WAVE_SQLFILE "significant_wave_height,"; 
     2714            print WAVE_SQLFILE "dominant_wave_period,"; 
     2715            print WAVE_SQLFILE "the_geom"; 
     2716            print WAVE_SQLFILE ") ";  
     2717            print WAVE_SQLFILE "VALUES (";  
     2718            print WAVE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
     2719            print WAVE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
     2720            if ($significant_wave_height[$i]{'height'} == $missing_value_value 
     2721              || $significant_wave_height[$i]{'height'} == $Fill_value_value) { 
     2722              print WAVE_SQLFILE ',NULL'; 
     2723            } 
     2724            else { 
     2725              $this_val = sprintf("%.2f",$significant_wave_height[$i]{'height'}); 
     2726              print WAVE_SQLFILE ','.$this_val; 
     2727 
     2728              #DWR 4/5/2008 
     2729              $Height = $this_val; 
     2730            } 
     2731            print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2732            if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
     2733              || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
     2734              || $significant_wave_height[$i]{'data'}[$j] == '') { 
     2735              print WAVE_SQLFILE ',NULL'; 
     2736            } 
     2737            else { 
     2738              $this_val = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
     2739              print WAVE_SQLFILE ','.$this_val; 
     2740              #DWR 4/5/2008 
     2741              $SigWaveHgtDataVal = $this_val; 
     2742            } 
     2743            if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
     2744              || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
     2745              || $dominant_wave_period[$i]{'data'}[$j] == '') { 
     2746              print WAVE_SQLFILE ',NULL'; 
     2747            } 
     2748            else { 
     2749              $this_val = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
     2750              print WAVE_SQLFILE ','.$this_val; 
     2751              #DWR 4/5/2008 
     2752              $DomWaveDataVal = $this_val; 
     2753            } 
     2754            print WAVE_SQLFILE ",GeometryFromText('POINT(";  
     2755            print WAVE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
     2756            print WAVE_SQLFILE ")',-1));\n"; 
     2757          } 
     2758        } 
     2759        print WAVE_SQLFILE "\n"; 
     2760        #DWR 4/3/2008 
     2761        my $strUnits; 
     2762        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $dominant_wave_period[$i]{'units'}, $XMLControlFile );       
     2763        if( length( $strUnits ) == 0 ) 
     2764        { 
     2765           $strUnits = $dominant_wave_period[$i]{'units'}; 
     2766        } 
     2767           
     2768        obsKMLSubRoutines::KMLAddObsToHash( 'dominant_wave_period',  
     2769                                            $time_formatted_values[$j], 
     2770                                            $DomWaveDataVal, 
     2771                                            1, 
     2772                                            $strPlatformID, 
     2773                                            $Height, 
     2774                                            $strUnits, 
     2775                                            $rObsHash ); 
     2776        $strUnits = ''; 
     2777        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $significant_wave_height[$i]{'units'}, $XMLControlFile );         
     2778        if( length( $strUnits ) == 0 ) 
     2779        { 
     2780           $strUnits = $significant_wave_height[$i]{'units'}; 
     2781        } 
     2782        obsKMLSubRoutines::KMLAddObsToHash( 'significant_wave_height',  
     2783                                            $time_formatted_values[$j], 
     2784                                            $SigWaveHgtDataVal, 
     2785                                            1, 
     2786                                            $strPlatformID, 
     2787                                            $Height, 
     2788                                            $strUnits, 
     2789                                            $rObsHash ); 
    24372790         
    2438         my $DomWaveDataVal = 'NULL'; 
    2439         my $SigWaveHgtDataVal = 'NULL'; 
    2440         my $Height = ''; 
     2791      } 
     2792      close(WAVE_SQLFILE); 
     2793    } 
     2794    #DWR 4/5/2008 
     2795    if( $bWriteobsKMLFile ) 
     2796    { 
     2797      for my $i (0..$#significant_wave_height)  
     2798      { 
     2799        for my $j (0..$#this_significant_wave_height_data)  
     2800        { 
     2801          $this_station_id = $institution_code_value.'_'.$platform_code_value.'_'.$package_code_value; 
     2802          $this_time_stamp = $time_formatted_values[$j]; 
     2803          $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)); 
     2804           
     2805          my $DomWaveDataVal = 'NULL'; 
     2806          my $SigWaveHgtDataVal = 'NULL'; 
     2807          my $Height = ''; 
     2808           
     2809          if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
     2810              && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
     2811              && $this_station_id_top_ts < $this_time_stamp_sec 
     2812              && $this_time_stamp_sec > $oldest_ok_timestamp)  
     2813          { 
     2814            if ($significant_wave_height[$i]{'height'} != $missing_value_value 
     2815                && $significant_wave_height[$i]{'height'} != $Fill_value_value) 
     2816            { 
     2817              $Height = sprintf("%.2f",$significant_wave_height[$i]{'height'}); 
     2818            } 
     2819            print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
     2820            if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
     2821                || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
     2822                || $significant_wave_height[$i]{'data'}[$j] == '')  
     2823            { 
     2824              $SigWaveHgtDataVal = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
     2825            } 
     2826            if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
     2827              || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
     2828              || $dominant_wave_period[$i]{'data'}[$j] == '')  
     2829            { 
     2830              $DomWaveDataVal = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
     2831            } 
     2832          } 
     2833        } 
     2834        my $strUnits; 
     2835        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $dominant_wave_period[$i]{'units'}, $XMLControlFile );       
     2836        if( length( $strUnits ) == 0 ) 
     2837        { 
     2838           $strUnits = $dominant_wave_period[$i]{'units'}; 
     2839        } 
     2840           
     2841        obsKMLSubRoutines::KMLAddObsToHash( 'dominant_wave_period',  
     2842                                            $time_formatted_values[$j], 
     2843                                            $DomWaveDataVal, 
     2844                                            1, 
     2845                                            $strPlatformID, 
     2846                                            $Height, 
     2847                                            $strUnits, 
     2848                                            $rObsHash ); 
     2849        $strUnits = ''; 
     2850        $strUnits = obsKMLSubRoutines::UnitsStringConversion( $significant_wave_height[$i]{'units'}, $XMLControlFile );         
     2851        if( length( $strUnits ) == 0 ) 
     2852        { 
     2853           $strUnits = $significant_wave_height[$i]{'units'}; 
     2854        } 
     2855        obsKMLSubRoutines::KMLAddObsToHash( 'significant_wave_height',  
     2856                                            $time_formatted_values[$j], 
     2857                                            $SigWaveHgtDataVal, 
     2858                                            1, 
     2859                                            $strPlatformID, 
     2860                                            $Height, 
     2861                                            $strUnits, 
     2862                                            $rObsHash ); 
    24412863         
    2442         if ($significant_wave_height[$i]{'data'}[$j] != $missing_value_value 
    2443           && $significant_wave_height[$i]{'data'}[$j] != $Fill_value_value 
    2444           && $this_station_id_top_ts < $this_time_stamp_sec 
    2445           && $this_time_stamp_sec > $oldest_ok_timestamp) { 
    2446           print WAVE_SQLFILE "INSERT INTO wave_in_situ_prod (";  
    2447           print WAVE_SQLFILE "station_id,"; 
    2448           print WAVE_SQLFILE "time_stamp,";  
    2449           print WAVE_SQLFILE "z,"; 
    2450           print WAVE_SQLFILE "positive,"; 
    2451           print WAVE_SQLFILE "significant_wave_height,"; 
    2452           print WAVE_SQLFILE "dominant_wave_period,"; 
    2453           print WAVE_SQLFILE "the_geom"; 
    2454           print WAVE_SQLFILE ") ";  
    2455           print WAVE_SQLFILE "VALUES (";  
    2456           print WAVE_SQLFILE   '\''.$institution_code_value.'_'.$platform_code_value.'_'.$package_code_value.'\''; 
    2457           print WAVE_SQLFILE ','.'timestamp without time zone \''.$time_formatted_values[$j].'\''; 
    2458           if ($significant_wave_height[$i]{'height'} == $missing_value_value 
    2459             || $significant_wave_height[$i]{'height'} == $Fill_value_value) { 
    2460             print WAVE_SQLFILE ',NULL'; 
    2461           } 
    2462           else { 
    2463             $this_val = sprintf("%.2f",$significant_wave_height[$i]{'height'}); 
    2464             print WAVE_SQLFILE ','.$this_val; 
    2465  
    2466             #DWR 4/5/2008 
    2467             $Height = $this_val; 
    2468           } 
    2469           print WAVE_SQLFILE ','.'\''.$height_var{'positive'}.'\''; 
    2470           if ($significant_wave_height[$i]{'data'}[$j] == $missing_value_value 
    2471             || $significant_wave_height[$i]{'data'}[$j] == $Fill_value_value 
    2472             || $significant_wave_height[$i]{'data'}[$j] == '') { 
    2473             print WAVE_SQLFILE ',NULL'; 
    2474           } 
    2475           else { 
    2476             $this_val = sprintf("%.2f",$significant_wave_height[$i]{'data'}[$j]); 
    2477             print WAVE_SQLFILE ','.$this_val; 
    2478             #DWR 4/5/2008 
    2479             $SigWaveHgtDataVal = $this_val; 
    2480           } 
    2481           if ($dominant_wave_period[$i]{'data'}[$j] == $missing_value_value 
    2482             || $dominant_wave_period[$i]{'data'}[$j] == $Fill_value_value 
    2483             || $dominant_wave_period[$i]{'data'}[$j] == '') { 
    2484             print WAVE_SQLFILE ',NULL'; 
    2485           } 
    2486           else { 
    2487             $this_val = sprintf("%.2f",$dominant_wave_period[$i]{'data'}[$j]); 
    2488             print WAVE_SQLFILE ','.$this_val; 
    2489             #DWR 4/5/2008 
    2490             $DomWaveDataVal = $this_val; 
    2491           } 
    2492           print WAVE_SQLFILE ",GeometryFromText('POINT(";  
    2493           print WAVE_SQLFILE $longitude_value[0].' '.$latitude_value[0];  
    2494           print WAVE_SQLFILE ")',-1));\n"; 
    2495         } 
    2496       } 
    2497       print WAVE_SQLFILE "\n"; 
    2498       #DWR 4/3/2008 
    2499             my $strUnits; 
    2500       $strUnits = obsKMLSubRoutines::UnitsStringConversion( $dominant_wave_period[$i]{'units'}, $XMLControlFile );       
    2501       if( length( $strUnits ) == 0 ) 
    2502       { 
    2503                $strUnits = $dominant_wave_period[$i]{'units'}; 
    2504       } 
    2505          
    2506                   obsKMLSubRoutines::KMLAddObsToHash( 'dominant_wave_period',  
    2507                                                 $time_formatted_values[$j], 
    2508                                                             $DomWaveDataVal, 
    2509                                                       1, 
    2510                                                       $strPlatformID, 
    2511                                                       $Height, 
    2512                                                       $strUnits, 
    2513                                                       $rObsHash ); 
    2514             $strUnits = ''; 
    2515       $strUnits = obsKMLSubRoutines::UnitsStringConversion( $significant_wave_height[$i]{'units'}, $XMLControlFile );         
    2516       if( length( $strUnits ) == 0 ) 
    2517       { 
    2518                $strUnits = $significant_wave_height[$i]{'units'}; 
    2519       } 
    2520                   obsKMLSubRoutines::KMLAddObsToHash( 'significant_wave_height',  
    2521                                                 $time_formatted_values[$j], 
    2522                                                             $SigWaveHgtDataVal, 
    2523                                                       1, 
    2524                                                       $strPlatformID, 
    2525                                                       $Height, 
    2526                                                       $strUnits, 
    2527                                                       $rObsHash ); 
    2528        
    2529     } 
    2530     close(WAVE_SQLFILE); 
     2864      } 
     2865    }                     
    25312866  }   
    25322867  my $strXMLPath = '';