#!/usr/bin/perl -w

# emolt.pl serves the Jim Manning Emolt data.  
# It is loosely based on the avhrr_level1.pl shell script.

$version = "January 15, 2003, V1.00";

# Original version, V1.00, January 15, 2003

# Robert C. Groman

# Assumptions:
#	1. Script arguments are
#		ARGV[0] - configuration file
#		ARGV[1] - name of project to retrieve
#	2. Location of the DODS server and other required parameters
# are supplied via the configuration file
#	3. Data will be gotten by the wget routine and the data coming from
# the DODS server will look like this:
#	Dataset {
#		Sequence {
#			String TIME_LOCAL;
#			Float64 YRDAY0_LOCAL;
#			Float64 DEPTH_I;
#		} emolt_sensor;
#	} emolt_sensor;
#	---------------------------------------------
#	emolt_sensor.TIME_LOCAL, emolt_sensor.YRDAY0_LOCAL, emolt_sensor.TEMP_I
#	"2000-08-05 19:24:00.0", 217.8083, 52.2
#	"2000-08-05 20:24:00.0", 217.85, 52.3


unshift (@INC, "/data/rgroman/perllib");
require ("read_configuration_file.pl");
require ("sendmessage.pl");


$date = scalar localtime;

($configuration_file, $project) = @ARGV;
#$configuration_file = "/data/jmanning/emolt/data/emolt.config";


$| = 1;
$error = "&x";
$warning = "#";

print STDOUT ("#Program $0 Version: $version\n");
print STDOUT ("#   configuration file is $configuration_file\n");

@required = (
	"DODS_object_name",
	"field_names",
	"DODS_selection_field_name");

&read_configuration_file($configuration_file);

&make_log_entry (">>>>>>>Begin Program=$0",
	"Date of run=$date\tVersion=$version",
	"Configuration file=$configuration_file");
$okay = "yes";

if (exists $config_param{'debug'} and defined $config_param{'debug'}) {
	$debug = $config_param{'debug'};
}
else {
	$debug = 'no';
}
#print STDOUT ("debug=$debug\n");


for ($i=0; $i<=$#required; $i++) {
	unless (exists $config_param{$required[$i]} ) { 
	   $okay="no"; 
	   &sendmessage ($error,
	   	"$required[$i] is missing from configuration ",
	   	"file=$configuration_file");
	   &make_log_entry (
		"$required[$i] is missing from configuration file",
	   	"file=$configuration_file");
	}
	else {
#		print STDOUT (
#			"#  $required[$i]=$config_param{$required[$i]}\n");
		&make_log_entry ("$required[$i]=$config_param{$required[$i]}");
	}
}
if ( $okay eq "no") { 
	&sendmessage ($error,
		"One or more parameters are missing from the configuration file",
		"Cannot continue.");
	&make_log_entry (
		"One or more parameters missing from configuration file=$configuration_file");
	exit;
}

&process_data;

undef $error;
undef $warning;
undef $version;

&make_log_entry ("<<<<<<<End of $0");

exit;

#-------------------------------------------------------

sub process_data {

# Process the Emolt data by forming the correct URL and using wget to
# get the data.  Strip off the leading lines, and the DODS object name
# from the field names then output the field names followed by the data.

my ();

