#!/usr/bin/perl use strict; use XML::LibXML; my $gearth_dir = '/var/www/html/gearth'; #opening this lookup file once for later use in sub my $xp_units = XML::LibXML->new->parse_file('./units.xml'); my $xp_style = XML::LibXML->new->parse_file('./style.xml'); my $kmz_time = `date +%y%m%d%H%M`; my $kmz_time_day = '20'.substr($kmz_time,0,2).'_'.substr($kmz_time,2,2).'_'.substr($kmz_time,4,2); #$kmz_time_day = '2006_10_17'; #manually set for testing open (KML_FILE,">$gearth_dir/archive_kmz/day_$kmz_time_day.kml"); my $kml_content .= <<"END_OF_FILE"; Ocean Observing Platform Data $kmz_time_day OOSTechKML Please email jeremy.cothran\@gmail.com regarding questions or comments on this kml product or sharing/registering your observation data using these tools.]]> END_OF_FILE $kml_content .= ""; my @obs_types = qw(air_pressure_at_sea_level air_temperature direction_of_sea_water_velocity sea_bottom_temperature sea_water_salinity sea_water_speed sea_water_temperature significant_height_of_wind_and_swell_waves water_level wind_from_direction wind_gust wind_speed wind_wave_period); my @operators = qw(carocoops cormp nccoos ndbc nos nws skio um usf); foreach my $obs_type (@obs_types) { $kml_content .= "$obs_type0\n"; my $uom; foreach my $unit ($xp_units->findnodes('//unit_list[@id="seacoos"]/parameter[@id="'.$obs_type.'"]')) { $uom = $unit->findvalue("uom"); } #must convert below to int, otherwise errors out on pass to subroutines and improper type handline my $range_high = int($xp_style->findvalue("//$obs_type/range_high")); #print "range_high:$range_high\n"; my $range_low = int($xp_style->findvalue("//$obs_type/range_low")); #print "range_low:$range_low\n"; my $yellow_range = 'yellow = below '.int(unit_convert($obs_type,$range_low)); my $orange_range = 'orange = above '.int(unit_convert($obs_type,$range_high)); my $color_span = ($range_high - $range_low)/3; my $blue_range = 'blue = '.int(unit_convert($obs_type,$range_low)).' to '.int(unit_convert($obs_type,$range_low+$color_span)); my $green_range = 'green = '.int(unit_convert($obs_type,$range_low+$color_span)).' to '.int(unit_convert($obs_type,$range_low+$color_span*2)); my $red_range = 'red = '.int(unit_convert($obs_type,$range_low+$color_span*2)).' to '.int(unit_convert($obs_type,$range_high)); $kml_content .= "The following color ranges apply to this observation
Unit of measure: $uom
$yellow_range
$blue_range
$green_range
$red_range
$orange_range
"; foreach my $operator (@operators) { #checking to see if files are present for the obs&operator, different filetimes as sometimes the system misses hours depending on load if ((-e "$gearth_dir/archive_kmz/temp/$obs_type\_$operator\_$kmz_time_day\_04") || (-e "$gearth_dir/archive_kmz/temp/$obs_type\_$operator\_$kmz_time_day\_16")) { #print "$obs_type:$operator\n"; $kml_content .= "$operator0\n"; foreach my $hour (0..23) { my $hour_label = substr("00".$hour, -2); $kml_content .= `cat $gearth_dir/archive_kmz/temp/$obs_type\_$operator\_$kmz_time_day\_$hour_label`; } $kml_content .= ""; } } #foreach $operator $kml_content .= "
"; } #foreach $obs_types $kml_content .= "
"; print KML_FILE $kml_content; close KML_FILE; `cd $gearth_dir/archive_kmz; rm -f day_$kmz_time_day.kmz; zip day_$kmz_time_day.kmz day_$kmz_time_day.kml`; exit 0; sub unit_convert { #this sub takes $parameter_id, $parameter_value and uses an xml lookup to convert them to another unit of measure my ($parameter_id, $parameter_value) = @_; #print "$parameter_id $parameter_value\n"; my $string; #don't build table string if null parameter value if ($parameter_value eq 'NULL') { return $string; } my $conversion; foreach my $unit ($xp_units->findnodes('//unit_list[@id="seacoos"]/parameter[@id="'.$parameter_id.'"]')) { $conversion = $unit->find('conversion_pure'); if (!($conversion)) { $conversion = $unit->find('conversion'); } } $conversion =~ s/var1/$parameter_value/g; $conversion = eval $conversion; $string = $conversion; #print "$string\n"; return $string; }