#!/usr/bin/perl use strict; =comment This program assumes creates a netcdf file to be pulled by the seacoos data loader/aggregation scripts =cut use DBI; use Config::IniFiles; use Math::Trig; my ($cfg, $db_name, $db_user, $db_passwd); my ($sql, $sth); my ($dbh_wls, $dbh_buoy); my $qc_flag; $cfg = new Config::IniFiles( -file => "./processBuoys.ini" ); $db_name = $cfg->val('DB_WLS', 'db_name'); $db_user = $cfg->val('DB_WLS', 'db_user'); $db_passwd = $cfg->val('DB_WLS', 'db_passwd'); #establish database connection $dbh_wls = DBI->connect ( "dbi:Pg:dbname=$db_name", $db_user, $db_passwd); if ( !defined $dbh_wls ) { die "Cannot connect to database!\n"; } $db_name = $cfg->val('DB', 'db_name'); $db_user = $cfg->val('DB', 'db_user'); $db_passwd = $cfg->val('DB', 'db_passwd'); #establish database connection $dbh_buoy = DBI->connect ( "dbi:Pg:dbname=$db_name", $db_user, $db_passwd); if ( !defined $dbh_buoy ) { die "Cannot connect to database!\n"; } my $platform_id = $ARGV[0]; my $measurement_date = $ARGV[1]; my $platform_ref; my ($netcdf_header, $netcdf_final); my $file_ref; my $content; my $record_created = 0; print $platform_id."\n"; print $measurement_date."\n"; my $measurement_date_query; if ($measurement_date eq 'latest') { $measurement_date_query = 'order by desc limit 1'; } else { $measurement_date_query = "and = '$measurement_date'"; } if (($platform_id eq 'buoy2') || ($platform_id eq 'buoy4') || ($platform_id eq 'buoy6') || ($platform_id eq 'buoy5') || ($platform_id eq 'buoy7')) { $record_created = 1; if ($platform_id eq 'buoy2') { $platform_ref = 'cc_buoy2'; $file_ref = 'FRP2_buoy'; $netcdf_header = './netcdf/FRP2_header.txt'; $netcdf_final = './netcdf/FRP2_final.txt'; } if ($platform_id eq 'buoy4') { $platform_ref = 'cc_buoy4'; $file_ref = 'CAP2_buoy'; $netcdf_header = './netcdf/CAP2_header.txt'; $netcdf_final = './netcdf/CAP2_final.txt'; } if ($platform_id eq 'buoy6') { $platform_ref = 'cc_buoy6'; $file_ref = 'SUN2_buoy'; $netcdf_header = './netcdf/SUN2_header.txt'; $netcdf_final = './netcdf/SUN2_final.txt'; } if ($platform_id eq 'buoy5') { $platform_ref = 'cc_buoy5'; $file_ref = 'CAP3_buoy'; $netcdf_header = './netcdf/CAP3_header.txt'; $netcdf_final = './netcdf/CAP3_final.txt'; } if ($platform_id eq 'buoy7') { $platform_ref = 'cc_buoy7'; $file_ref = 'SUN3_buoy'; $netcdf_header = './netcdf/SUN3_header.txt'; $netcdf_final = './netcdf/SUN3_final.txt'; } open (NETCDF_FILE, ">$netcdf_final"); $content = `cat $netcdf_header`; #depth $sql = qq{ SELECT pcat_pressure, FROM $platform_id where 1=1 $measurement_date_query }; $sql =~ s//measurement_date/g; #print $sql."\n"; $sth = $dbh_buoy->prepare( $sql ); $sth->execute(); my $depth; ($depth,$measurement_date) = $sth->fetchrow_array; $sth->finish; my $time_sec = `date --date='$measurement_date +0000' +%s`; chomp($time_sec); $content =~ s//$measurement_date/g; $content =~ s/