##!/usr/local/bin/perl eval "exec perl -S $0 $*" if $running_under_some_shell; # # Martin & Jon 5-25-93 # Matt 12Oct94 added septexexpand # Matt 26Apr95 give relative path from Adm directory # find additional plot types, handle figs that are commented out # 4may95 added listing .warning files # 4may95 translation into perl # added tabulated statistics # checks with FIGLIST # works on an individual directory $usage = "Usage: $0 - \n"; $selfdoc = " Figstat computes figure statistics for reports and books Figstat has to be run in the chapter/article directory See also: Execstat Figstat Wastestat Tour Grepper\n"; if( $#ARGV < 0 ||$#ARGV > 1 ) { print $usage; die $selfdoc; } $doctype = "paper"; print "I gather the plot statements from the paper.tex files\n"; open(TEXINPUT,"septexexpand $doctype.tex |"); @plotlist = (passiveplot,activeplot,activesideplot,passivesideplot,activeplottop,activeplotbottom,activeplotpage); while($texentry=){ $texentry=~ s/%.*$//; foreach $plottype (@plotlist) { if ($texentry =~ /$plottype/) { $texentry =~ s/\\//; $texentry =~ s/{/ /; $texentry =~ s/}.*//; $texentry =~ s/\n//; $texstem = $texentry; $texstem =~ s/.* //; $figtype = $texentry; $figtype =~ s/ .*//; if ($tex{$texstem}) { $tex{$texstem} = join(":",$tex{$texstem},$figtype); } else { $tex{$texstem} = $figtype; } } } } close(TEXINPUT); @texstems = sort keys(%tex); #this would print the stem of all figures plotted in paper #foreach $texstem (sort keys(%tex)) { # printf "%20s %20s\n", $texstem, $tex{$texstem}; # } print "I gather the FIGLIST information from the Cakefiles\n"; if (-e "Cakefile") { $cakefn = Cakefile; } if (-e "cakefile") { $cakefn = cakefile; } if ($cakefn eq "") {print "Cannot locate Cakefile. I quit at"; die ;} open(CAKEFILE,"$cakefn") || die "Cannot open cakefile."; LINE: while ($cakeline = ) { $cakeline =~ s/\$.*$//; if ($cakeline =~ s/\\\s+$//){ $final = join(" ",$final,$cakeline); next LINE; } else { $final = join(" ",$final,$cakeline); } if ($final =~ /define\s+FIGLIST/) { $figlist = join(":",$figlist,$final); } $final = ""; } close(CAKEFILE); $figlist =~ s/\n/ /g; $figlist =~ s/.*#define\s+FIGLIST\s*//g; $figlist =~ s/\s+/ /g; @tmp = split(" ",$figlist); while($figname = pop(@tmp)) { $cake{$figname}++; } @cakestems = sort keys(%cake); # check if reasonable list foreach $cakestem (sort keys(%cake)) { if ($cake{$cakestem} > 1 ) { print "$cakefn: *** Multiple FIGLIST entry for $cakestem *** \n"; } } #this plots the stem of all figures listed in FIGLIST #foreach $cakestem (sort keys(%cake)) { # printf "%20s %20s\n", $cakestem, $cake{$cakestem}; # } #exit; print "I gather the figure file information from the Fig directories\n"; open(CAKEFILE,"$cakefn") || die "Cannot open cakefile."; while ($cakeline = ) { $cakeline =~ s/\$.*$//; if ($cakeline =~ /.*#define\s+FIGDIR/) { $figdir = join(":",$figdir,$cakeline); } } close(CAKEFILE); $figdir =~ s/\n/ /g; $figdir =~ s/.*#define\s+FIGDIR\s*//g; $figdir =~ s/\s+/ /g; chop($figdir); if ($figdir eq "") {$figdir = "./Fig";} opendir(FIGDIR,"$figdir") || die "Cannot open $figdir directory"; @figfiles = sort readdir(FIGDIR); close(FIGDIR); @plottype = ('ps','ps.save','v','v.save','warning','v3','A'); @filestems = @figfiles; foreach $stem (@filestems) { foreach $plottype (@plottype) { $stem =~ s/\.$plottype$//; } if ($stem ne "." && $stem ne "..") { $files{$stem}++;} } @filestems = sort keys(%files); foreach $plottype (@plottype) { foreach $stem (@filestems) { if (grep(/^$stem.$plottype$/,@figfiles)) { $files{$stem} = join(":",$files{$stem},"$plottype"); } else { $files{$stem} = join(":",$files{$stem},"."); } } } ###this lists the stem of all files in FIGDIR #foreach $filestem (@filestems) { # printf "%20s %20s\n", $filestem, $files{$filestem}; # } #exit; #print "\n"; print "FIGDIR: following files have no known figure suffix:\n"; foreach $filestem (@filestems) { @attributes = split(":",$files{$filestem}); $fignumber = shift(@attributes); foreach $attribute (@attributes) { if ($attribute ne ".") { $fignumber--; } } if ($fignumber > 0) { print "/bin/rm $figdir/$filestem\n"; } } print "\n"; print "I check for consistency\n"; # diff figlist figfiles -> figfiles are missing (should only use ps entries) # -> figlist entry missing print "\n"; print "Following figures are listed in FIGLIST but do not exist in FIGDIR:\n"; foreach $cakestem (@cakestems) { if ( !(join(" ",@filestems) =~ /\b$cakestem\b/)) { print "$cakestem\n"; } } #print "\n"; print "Following figures exist in FIGDIR but are not listed in FIGLIST:\n"; foreach $filestem (@filestems) { if ( !(join(" ",@cakestems) =~ /\b$filestem\b/)) { print "/bin/rm $figdir/$filestem*\n"; } } #print "\n"; # diff figlist figplot -> figlist files not used in paper # -> paper requires additional figlist entries print "Following figures exist in FIGLIST but are not used in $doctype:\n"; foreach $cakestem (@cakestems) { if ( !(join(" ",@texstems) =~ /\b$cakestem\b/)) { print "$cakestem\n"; } } #print "\n"; print "Following figures are used in $doctype but do not exist in FIGLIST:\n"; foreach $texstem (@texstems) { if ( !(join(" ",@cakestems) =~ /\b$texstem\b/)) { print "$texstem\n"; } } #print "\n"; # diff figfiles figplot -> figfiles not used in paper # -> figplot without figfile print "Following figures are used in $doctype but do not exist in FIGDIR:\n"; foreach $texstem (@texstems) { if ( !(join(" ",@filestems) =~ /\b$texstem\b/)) { print "$texstem\n"; } } #print "\n"; print "Following figures exist in FIGDIR but are not used in $doctype:\n"; foreach $filestem (@filestems) { if ( !(join(" ",@texstems) =~ /\b$filestem\b/)) { print "/bin/rm $figdir/$filestem*\n"; } } print "\n"; $noc =0; $psc =0; $pssave =0; $vc =0; $vsavec =0; $warningc =0; $v3c =0;$Ac =0; foreach $cakestem (@cakestems) { if (join(" ",@filestems) =~ /\b$cakestem\b/) { ($no,$ps,$pssave,$v,$vsave,$warning,$v3,$A) = split(":",$files{$cakestem}); $noc += $no; if ($ps eq 'ps' ) {$psc++; } if ($pssave eq 'ps.save') {$pssavec++; } if ($v eq 'v' ) {$vc++; } if ($vsave eq 'v.save' ) {$vsavec++; } if ($warning eq 'warning') {$warningc++;} if ($v3 eq 'v3' ) {$v3c++; } if ($A eq 'A' ) {$Ac++; } } } print "A attribute table for each figure in FIGLIST:\n"; format = @<<<<<<<<<<<<<<<<< @<< @<< @<< @<< @<< @<<<<<<< @< @<<<<<< @<<<<<<< @<< @< $figname $nr $cr $r $no $ps $pssave $v $vsave $warning $v3 $A . $figname = 'figure'; $no = '#'; ($ps,$pssave,$v,$vsave,$warning,$v3,$A) = @plottype; $nr = 'NR'; $cr = 'CR'; $r = 'R'; write; $figname = ''; $no = ''; ($ps,$pssave,$v,$vsave,$warning,$v3,$A) = (); $nr = ''; $cr = ''; $r = ''; write; $nrc = 0; $crc = 0; $rc = 0; foreach $cakestem (@cakestems) { if (join(" ",@filestems) =~ /\b$cakestem\b/) { $figname = $cakestem; ($no,$ps,$pssave,$v,$vsave,$warning,$v3,$A) = split(":",$files{$cakestem}); $nr = '.'; $cr = '.'; $r = '.'; if ($ps ne 'ps' && $pssave eq 'ps.save' && $warning ne 'warning') { $nr = 'NR'; $nrc++; } elsif ($ps eq 'ps' && $pssave ne 'ps.save' && $warning eq 'warning') { $cr = 'CR'; $crc++; } elsif ($ps eq 'ps' && $pssave ne 'ps.save' && $warning ne 'warning') { $r = 'R' ; $rc++; } else { $nr = '?'; $cr = '?'; $r = '?'; } write; } else { print "FIGDIR: No file named $cakestem\n"; } } print "\n"; print "Some summary statistics:\n"; print "\n"; open(OUT,"|tee junk.figstat") || die "Cannot open pipe"; $dir = `pwd`; chop($dir); $dir =~ s/.*\///; print OUT "$dir total=$noc ps=$psc pssave=$pssavec v=$vc vsave=$vsavec warning=$warningc v3=$v3c A=$Ac\n"; print OUT "$dir NR=$nrc CR=$crc R=$rc \n"; #close(OUT); # makes it print out on top instead of bottom # statistics: look at last file: NR CR R weird (single line) # NR pssave no ps, no warn # CR ps warn # R ps no warn # overview statistics: # # of figlist members # of figplot members by type # of figfiles by type # output all to stdout # better std out and turning on and off different options