#!/vol/local/perl
# check inventory of tar archives on seedis.census.gov,
# against list tarinfo.txt of files transferred in dec96
# create missing.txt = list of tar archives missing in seedis

# http://parep2.lbl.gov/mdocs/census/tar2seedis/missing.pl
# $MDOCS/census/tar2seedis/missing.pl

# setenv $MDOCS /CEDRCD/data1/merrill/docs
# on cedr: $MDOCS = /data9/old/parep2/merrill/docs
# on parep2: $MDOCS = /a/cedr/data9/old/parep2/merrill/docs

# example:
#	rlogin parep2 -l merrill
#	cd $MDOCS/census/tar2seedis
#	missing.pl >missing.txt

# tapes that were supposedly transferred in dec96
#INFILE1 = 'tarinfo.txt' ;
# inventory of tar files on seedis.census.gov
#INFILE2 = 'inventory/tarfiles.txt' ;

open (INFILE1, 'tarinfo.txt') ;
open (INFILE2, 'inventory/tarfiles.txt') ;

# store inventory completely
while (<INFILE2>)
		{
		($seq,$file,$size,$date,$time) = split("\t",$_);
		# extract 5-digit tape number from file name
		$tape2 = substr ($file, 19, 5) ;
		# print $tape2 . "\n";
		# stored associative arrays indexed by tape number
		$seqs{$tape2}=$seq;
		$files{$tape2}=$file;
		$sizes{$tape2}=$size; # blocks in seedis
		$dates{$tape2}=$date;
		$times{$tape2}=$time;
		}
close INFILE2 ;

# now cycle through tarinfo.txt (tapes supposedly transferred)
while (<INFILE1>)
		{
		($status,$tape1,$name,$msstape,$owner,$byte1,$month,$day,$year,
			$dummy,$format) = split(" ",$_);
		# status = 7: ftp supposedly completed
		# status = 8: untar supposedly done
		if ($status eq '7' || $status eq '8')
			{
			# byte1 = bytes expected (from tarinfo.txt
			$byte2 = 512*$sizes{$tape1}; # bytes in seedis
			$byte3 = $byte1 - $byte2 ;   # bytes missing 
			# print the tapes missing on seedis
			if ($byte3 > 0)
				{
				print $tape1 . ' ' . $name . 
				' ' . $seqs{$tape1} . 
				' ' . $format . 
				' ' . $byte1 . 
				' ' . $byte2 .
				' ' . $byte3 .
				"\n" ;
				}
			}
		}
close INFILE1 ;