# perl /home/casp13/DNCON2/scripts/tensorflow2theano_convert_batch.pl /home/casp13/DNCON2/scripts/ /home/casp13/DNCON2/model-config-n-weights /home/casp13/DNCON2/example/feat-T0900.txt  /home/casp13/DNCON2/example/T0900.feat.stage2.txt  /home/casp13/DNCON2/model-config-n-weights-theano-backend/

$num = @ARGV;
if($num !=5)
{
	die "please input the right parameters";
}

$scriptdir   = $ARGV[0];
$dir_config     = $ARGV[1];  # /home/casp13/DNCON2//model-config-n-weights
$fileX          = $ARGV[2]; #/home/casp13/DNCON2/example/feat-T0900.txt
$fileX_stage2          = $ARGV[3]; #/home/casp13/DNCON2/example/T0900.feat.stage2.txt
$outputdir   = $ARGV[4];

opendir(DIR,"$dir_config") || die "Failed to open directory $dir_config\n";
@files =readdir(DIR);
closedir(DIR);

foreach $weight (@files)
{
	if($weight eq '.' or $weight eq '..' or index($weight,'.hdf5') <0) 
	{
		next;
	}
	
	if(index($weight,'stage1')>=0)
	{
		print "python $scriptdir/tensorflow2theano_convert.py $dir_config  $weight  $fileX  $outputdir\n\n";
		`python $scriptdir/tensorflow2theano_convert.py $dir_config  $weight  $fileX  $outputdir`;
	}else
	{
		print "python $scriptdir/tensorflow2theano_convert.py $dir_config  $weight  $fileX_stage2  $outputdir\n\n";
		`python $scriptdir/tensorflow2theano_convert.py $dir_config  $weight  $fileX_stage2  $outputdir`;
	}
}

