File: honeycomb.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 (59 lines) | stat: -rwxr-xr-x 1,230 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
#!/usr/bin/perl
# All credit goes to Nirav P.
# All errors go to G.A.

use strict;
use warnings;
use utf8;
use lib ".";
use Honeycomb;

my ($templateInput, $templateTex) = @ARGV;
defined($templateInput) or die "USAGE: $0 templateInput [templateTex]\n";

my $honey = Honeycomb::init($templateInput);

defined($honey) or die "$0: No honey\n";

createInput("test.inp", $honey->{"info"}, $templateInput);

my $params2 = {"plot" => $honey->{"plot"}};

if (defined($templateTex)) {
	createInput("test.tex", $params2, $templateTex);
} else {
	print STDERR "$0: No templateTex given, no tex created\n";
}

sub createInput
{
	my ($file, $params, $templateInput) = @_;

	open(FOUT, ">", "$file") or die "$0: Cannot write to $file\n";

	open(FILE, "<", "$templateInput") or die "$0: Cannot open $templateInput: $!\n";

	my $plot = $params->{"plot"};

	while(<FILE>) {
		if (/^#/) {
			print FOUT;
			next;
		}

		if (/\$([a-zA-Z0-9\[\]]+)/) {
				my $name = $1;
				my $str = "\$"."params->{\"$name\"}";
				my $val = eval "$str";
				defined($val) or die "$0: Undefined substitution for $name\n";
				s/\$\Q$name/$val/g;
		}
		print FOUT;
	}

	close(FILE);
	close(FOUT);
	print STDERR "$0: File $file has been written\n";

	return $file;
}