File: createOracle.pl

package info (click to toggle)
dmrgpp 6.06-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 113,900 kB
  • sloc: cpp: 80,986; perl: 14,772; ansic: 2,923; makefile: 83; sh: 17
file content (98 lines) | stat: -rw-r--r-- 1,836 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/perl
#
use strict;
use warnings;

# Accepted runs between 1 minute and 1/2 hour
my ($tmin, $tmax) = (1, 1800);
# Accepted files up to 10MB
my $sizemax = 1024*1024*10; # 10 MB

my $cannotAccept = "$0: I cannot accept this run";

my ($input) = @ARGV;
defined ($input) or die "USAGE: $0 input.inp\n";

my $root = $input;

if ($root =~ /\.inp$/) {
	$root =~ s/\.inp$//;
} else {
	$input .= ".inp";
}

my $datafile = readLabel($input, "OutputFile=");
my $cout = "runFor$root.cout";
my $t = getRunTime($cout);

if ($t < $tmin || $t > $tmax) {
	print STDERR "$cannotAccept due to runtime=$t\n";
	die "$0: Runtime must be between $tmin and $tmax seconds\n";
}

my @files;

push @files, $input;

push @files, $cout;

push @files, $datafile;

my $targz = "$root.tar.gz";
tarAndGzipFiles($targz, \@files);
# Check file size

my $size = -s "$targz";
if ($size > $sizemax) {
	print STDERR "$0: $cannotAccept due to filesize=$size > maxsize=$sizemax\n";
}

sub readLabel
{
	my ($file, $label) = @_;
	my $value;
	open(FILE, "<", "$file") or die "$0: Cannot open file $file : $!\n";
	while (<FILE>) {
		if (/^$label(.*$)/) {
			$value = $1;
			last;
		}
	}

	close(FILE);

	defined($value) or die "$0: File $file does not contain label $label\n";
	return $value;
}

sub getRunTime
{
	my ($file) = @_;
	my $v1 = readLabel($file, "UnixTimeStart=");
	my $v2 = readLabel($file, "UnixTimeEnd=");
	return ($v2 - $v1);
}

sub tarAndGzipFiles
{
	my ($targz, $files) = @_;
	if (-w "$targz") {
		my $cmd = "cp $targz $targz.bak";
		print STDERR "$0: Making backup $cmd ...\n";
		system($cmd);
	}

	my $cmd = "tar --owner=nobody --group=nobody -zcf $targz @files";
	print STDERR "$0: Running $cmd ...\n";
	my $ret = system($cmd);
	if ($ret != 0) {
		die "$0: tar command failed\n";
	}

	print STDERR "$0: File $targz created successfully\n";
}