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

sub get_first_data_from_object {

# Use the event log object to get at day and month for old format data
# Argument passed is:
#	$_[0] = jgofs object, e.g. /globec/gb/eventlogs

# In addition the following global hash arrays are available
#	%field_values, where
#		$field_values{"field_name"} = field_value  or
#		$field_values{"cruiseid"} = "AL9701"
# and
#	%projection, where
#		$projection{"field_name_desired"} = desired_field_value or
#		$projection{"inst"} = MOC1

my ( $field_name, @field_names, $field_value, $listgb, $listgb_options, 
	$message0, $message1, $object_spec, %returned_data );


#print STDERR ("#**debug, object=$_[0]\n");

my $inventory_file = "no";  #No inventory file exists for cmarz

#$listgb = "/data5/globec/bin/list ";
$listgb = "/home/bco/dbase-v2/bin/list ";
$listgb_options = "-c -n -b -t ";
$object_spec = "\"$_[0](";

#Create selection criteria
while (($field_name,$field_value) = each %field_values) {
	$object_spec = $object_spec . $field_name . "=" . $field_value . ",";
}

#Create projection criteria
@field_names = keys %projection;
foreach $field_name_desired ( @field_names) {
	$object_spec = $object_spec . $field_name_desired . ",";
}
$object_spec =~ s/(.*),$/$1/;
$object_spec = $object_spec . ")\"";

#print STDERR ("#**debug, list=$listgb\n");
#print STDERR ("#**debug, listgb_options=$listgb_options\n");
#print STDERR ("#**debug, object_spec=$object_spec\n");

$input = $listgb . $listgb_options . $object_spec . "|";

foreach $field_name_desired ( @field_names) {
	$projection{$field_name_desired} = "nd";
}

# return early since can't get data from non-existent cmarz inventory

return if $inventory_file eq "no";

unless ( open EVENTLOG, $input) {
	$message0="Could not open inventory to get cruise type";
	$message1="open=$input, error=$!";
	&sendmessage ($error, $message0, $message1);
	return;
}
# Get desired information
$k = -1;
while (<EVENTLOG>) {
	if ( m/^#/ ) { next; }
	chomp;
#	print STDERR ("#**debug, EVENTLOG=$_\n");
	@returned_data = split /\t/;
	unless (defined $returned_data[0] ) { $returned_data[0]="nd"; }
#	if ($returned_data[0] =~ m/Üd/i ) { $returned_data[0]="nd"; }
	unless ($returned_data[0] =~ m/\w+/ ) { $returned_data[0]="nd"; }
#	print STDERR ("#**debug, returned_data=@returned_data\n");
	if ($#returned_data < $#field_names) { 
		$message0="Could not get data from object $_[0]";
		$message1="Data returned=" . @returned_data;
		&sendmessage ($error, $message0, $message1);
		return;
		}
	foreach $field_name_desired ( @field_names) {
		$k = $k +1;
		$projection{$field_name_desired} = $returned_data[$k];
#		print STDERR ("#**debug, k=$k, ",
#			"projection{$field_name_desired} ",
#			"= $returned_data[$k]\n");
	}
	last;
}
close EVENTLOG;
return;
}
