White space analyzer.pl
Jump to navigation
Jump to search
#!/usr/bin/perl use strict; use warnings; # traverses a tree and reports on how holey the images are within # takes directory as input # produces output file with statistics my $imageCoverage_path = "~/src/wndchrm_utilities/image_coverage/imageCoverage"; my $source_dir = shift; my $full_coverage_list = shift; my $i; my @file_list; my $file; my @dir_list; my $dir; my $dir_name; @dir_list = split( "\n", `find $source_dir -d 1 -type d` ); my $tile_scheme = 4; my $retval; my $image_tally_str; my @image_tally; my $total; my $full_coverage = $tile_scheme * $tile_scheme; my $full_coverage_minus = $full_coverage - 1; open( FILE, ">$full_coverage_list" ) or die "Can't open file $full_coverage_list: $!\n"; foreach $dir (@dir_list) { #print "$dir\n"; if( $dir eq $source_dir ) { print "Skipping top level dir\n"; next; } @image_tally = (); for( $i = 0; $i < $tile_scheme * $tile_scheme; $i ++) { push( @image_tally, 0); } @file_list = (); if( $dir =~ /.*\/(\w+)/ ) { $dir_name = $1; } #print "Directory $dir_name\n"; @file_list = split( "\n", `find $dir -name "*.tif"` ); $total = 0; foreach $file (@file_list) { $total++; #print "\tFile: $file\n"; system( "$imageCoverage_path $file" ); $retval = $? >> 8; #print "\t\tretval $retval\n"; if( $retval >= 0 ) { $image_tally[$retval]++; if( $retval >= 12 && $retval <= 16 ) { $file =~ /^\S*\/t_(\S+)/; print FILE "$retval\t$dir_name/$1\n"; } } } print "$dir_name \t\t" . join( "\t", @image_tally ) . "\t$total\n"; } close FILE; # Get a list of all the files to be operated on. # run the executable on it and capture its return value # write the name of the file and the return value onto it own output line