#!/usr/bin/perl
use strict;
use warnings;
my $numargs=@ARGV;
if($numargs<3){
	print "\n";
	print "Usage:perl getaddedpdb.pl [inputdir][resultfile][resutldir]\n";
	exit;
}

my $inputdir=$ARGV[0];
my $resultfile=$ARGV[1];
my $resultdir=$ARGV[2];
opendir(INPUT,$inputdir);

readdir(INPUT);

my @files=readdir(INPUT);
unless(open(RESULT,">>$resultfile")){
	die("can not open $resultfile"); 
}	
for(my $i=0;$i<@files;$i++){
	if($files[$i]=~/T0(\d+)/){
		my $pdbid=$1;
		$pdbid="T".$pdbid;
		print RESULT $pdbid."\n";
		my $thisfile=$inputdir.$files[$i];
		my $thatfile=$resultdir."pdb".$pdbid.".ent";
		system("cp $thisfile $thatfile");
		system("gzip $thatfile");
	}
}
close(RESULT);

exit;