#!/usr/bin/perl -w # PURPOSE: concatenate all phd file into a single phd.ball # for the purpose of fast startup of consed # # HOW TO USE IT: # go to the directory where the ace file is and type: # catPhdFiles.perl # # February 2008, David Gordon if ( $#ARGV >= 0 ) { if ( $ARGV[0] eq "-v" || $ARGV[0] eq "-V" ) { print "080221\n"; exit( 0 ); } } $szPhdDirectory = "../phd_dir"; $szPhdBall = "phd.ball"; if ( -e $szPhdBall ) { die "$szPhdBall already exists. If you want to overwrite it, delete it."; } open( filPhdBall, ">$szPhdBall" ) || die "couldn't open $szPhdBall for write"; $nFilesCopied = 0; opendir( filDir, $szPhdDirectory ) || die "couldn't open $szPhdDirectory"; while( defined( $szNextFile = readdir( filDir ) ) ) { if ( $szNextFile =~ /\.phd\.(\d+)$/ ) { $nVersion = $1; $szNextFilePath = "../phd_dir/$szNextFile"; open( filPhd, "$szNextFilePath" ) || die "couldn't open $szNextFilePath"; while( ) { if ( /^BEGIN_SEQUENCE/ ) { @aWords = split; print filPhdBall "BEGIN_SEQUENCE " . $aWords[1] . " " . $nVersion . "\n"; last; } else { print filPhdBall; } } while( ) { print filPhdBall; } close filPhd; ++$nFilesCopied; if ( (( $nFilesCopied % 100 ) == 0 ) || ( $nFilesCopied < 20 ) ) { print "$nFilesCopied files copied\n"; } } } print "$nFilesCopied files copied (total)\n"; close filPhdBall; closedir( filDir );