sub_cruiseinfo.pl 2.98 KB
sub sub_cruiseinfo {

	# does this cruise already have a mission log?
	if (-e "$folder/LogGen/$name.out") {

		# Open the file for reading
		open(OUT,"$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n")  ;

		# Read header and store in an array
		while (<OUT>) { 
			if ( $_ !~ /\#/) {last;}
			chop($_) ;
			$str = substr $_, 2 ;
			push(@header,$str) ; } 
		close(OUT) ;

		$gpson   = $header[2] ; 
		$gpsport = $header[3] ; 
		$gpsbaud = $header[4] ; 
		$numops  = $header[5] ; 

		# Get the operations  
		for ($ii=0;$ii<$numops;$ii++) {
			push(@ops,$header[6+$ii]) ; } 
			
		$numsts  = $header[6+$numops] ; 

		# Get the stations and their coordinates 
		for ($ii=0;$ii<$numsts;$ii++) {
			@hl = split(/;/,$header[6+$numops+1+$ii]) ;
			push(@sts,$hl[0]) ;
			$stslon{$hl[0]} = $hl[2] ;
			$stslat{$hl[0]} = $hl[1] ;
		} 
		$stslon{"none"} = "NaN" ;
		$stslat{"none"} = "NaN" ;

		$headerstring = "Continuing operations log for $name cruise" ;

		#Close the file handle and open for appending
		close(OUT) ;
		open(OUT,">>$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n")  ;
	
	} else { # this cruise does not already have an output file
	# MANAGE FILE HANDLES 
		# create and open the outfile handle 
		open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n")  ;
		print ">> Enter operations, 		end with CTRL-d		: " ;
		
		# operations to be conducted
		$numops = 0 ;
		while ( <STDIN> ) {
			chop($_) ;
			push(@ops,$_) ;
			print ">> 							: " ;
			$numops++ ;
		}
		print "\n" ;
		
		
		# stations to be visited 
		$numsts = 0 ;
		print ">> Enter stations names, 	end with CTRL-d		: " ;
		while (<STDIN>) {
			chop($_) ;
			push(@sts,$_) ;
			print ">> 							: " ;
			$numsts++ ;
		}
		print "\n" ;


		# Ask for gps and connect if needed
		($gps,$gpson,$gpsport,$gpsbaud) = sub_getgps() ;

		# Manually enter GPS values for stations if no GPS is used
		if (not $gpson) {
			for ($ii=0;$ii<$numsts;$ii++) {
			print ">> Enter  lon;lat of station $sts[$ii] (pm180)		: " ;
				chop($line = <STDIN>) ;
				($stslon{$sts[$ii]},$stslat{$sts[$ii]}) = split(/;/,$line) ;
			}
			$stslon{"none"} = "NaN" ;
			$stslat{"none"} = "NaN" ;
		}
		print "\n\n\n" ;
	
		# print header to outputfile
		print OUT "\# $name\n" ;
		print OUT "\# $folder\n" ;
		print OUT "\# $gpson\n" ;
		print OUT "\# $gpsport\n" ;
		print OUT "\# $gpsbaud\n" ;
		print OUT "\# $numops\n" ;
		for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
		print OUT "\# $numsts\n" ;
		for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii];$stslat{$sts[$ii]};$stslon{$sts[$ii]}\n" ; }
		print OUT "\# 0\n" ;
		$cul = 0 ;	
		@coltitles = ("\#type","latitude","longitude","yyyy-mm-ddTHH:MM:SSZ","value") ;
		printf OUT "%5s;%10s;%10s;%20s;%s\n",@coltitles ;
	
		$headerstring = "Starting operations log for $name cruise" ;
	
	}

	# RETURN NEEDED VALUES
	return (\@ops,\@sts,$gps,$gpson,$numops,$numsts,$headerstring,\%stslat,\%stslon) ;


}

1;