#! /usr/bin/perl
# This file will run one abinis built-in test in a DOS/Windows box.

# Copyright (C) 1999-2005 ABINIT group (LSi)
# This file is distributed under the terms of the
# GNU General Public License, see ~ABINIT/Infos/copyright
# or http://www.gnu.org/copyleft/gpl.txt .
# For the initials of contributors, see ~ABINIT/Infos/contributors .
#
# Usage :
# This script is intended to be called from Run (unix) or Run.pl
# (DOS/Windows). Those scripts start the test in background mode and wait
# for completion. When done, this script creates a test#.end file if required
#
# Arguments :
#   $TestN = test number 1-6 
#   $ENDtest = kind of criterion for test completion; supported values are:
#	ps = unix ps command
#	pstat = Windows NT ResKit pstat command
#	numeric = test#.end file with loop limit
#   $SLASH = subdirectory delimitor in file paths
#   $SUFXstyle = defines suffixes style for binaries, ...;
#		supported values are: unix, DOS
#
$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator
#
($TestN,$ENDtest,$SLASH,$SUFXstyle) = @ARGV;
if ($SUFXstyle eq 'unix') {
# unix suffixes:
	$XSUFX = '';		# no special suffix for binary module
	}
elsif ($SUFXstyle eq 'DOS') {
# DOS suffixes:
	$XSUFX = '.exe';	# suffix for binary module
	}
elsif ($SUFXstyle eq 'vms') {
# DOS suffixes:
	$XSUFX = '.exe';	# suffix for binary module
	}
# make sure "files" file exist
if (! -r "test$TestN.files") {
	print "Test number missing or invalid: $TestN";
	exit 8;
	}
print "dotest: Starting built-in test $TestN";
$abinis = &transpath("../abinis$XSUFX");
if ($SUFXstyle eq 'vms') {
    $cmd = "pipe run [-]abinis < test$TestN.files > test$TestN.log";
    }
else
  {
    $cmd = "$abinis < test$TestN.files > test$TestN.log";
      }
print $cmd;
$rc = system($cmd);		# start abinis
$_ = $ENDtest;
# check numeric value for test completion
if (! /[^0-9]/) {
	open (END,">test$TestN.end");	# create a file to signal end of test to caller
	close (END);
	}
exit;
# ****************************************
sub transpath {
	local($path) = @_;
#
# purpose: translate unix-like path of file to DOS-like according to $SLASH
# argument:
#	$path = path to be translated
# output: this subroutine acts as a function and return the path
# according to host conventions
	
	$path =~ tr/\057/\\/ if ($SLASH eq '\\');
	return $path;
	}
