File: pgfplot.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 (92 lines) | stat: -rwxr-xr-x 1,887 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
#!/usr/bin/perl
#
use strict;
use warnings;
use utf8;

my ($uroot, $runLatex, $lOrUp) = @ARGV;

defined($uroot) or die "USAGE: $0 root [runLatex=1] [L | U | sz]\n";
defined($runLatex) or $runLatex = 1;

if (!defined($lOrUp)) {
	if ($uroot =~ /(^[^\.]+)\.pgfplots/) {
		$uroot = $1;
	}

	my $file = "sample.tex";
	my $fout = "$uroot.tex";
	my $name = "$uroot.pgfplots";
	fromTexToTex($fout, $file, $name, $runLatex);
	exit(0);
}

my $root = "$uroot$lOrUp"."_ky";

doFile(0, $root, $runLatex);
doFile(1, $root, $runLatex);

sub doFile
{
	my ($ind, $root, $runLatex) = @_;

	my $file = "outSpectrum$ind.pgfplots";
	return unless (-r "$file");
	my $fout = "$root$ind.pgfplots";
	unlink("$fout");
	my $cmd = "cp $file $fout";
	die "$0: Failed to create $fout\n" if (-r "$fout");
	system("$cmd");

	$file = "sample.tex";
	$fout = "$root$ind.tex";

	my $name = $fout;
	$name =~ s/tex$/pgfplots/;
	fromTexToTex($fout, $file, $name, $runLatex);
}

sub fromTexToTex
{
	my ($fout, $file, $name, $runLatex) = @_;

	my $dirForTex = $0;
	$dirForTex =~ s/pgfplot\.pl$//;
	die "$0: Not a directory $dirForTex\n" unless (-d "$dirForTex");

	system("cp $dirForTex/sample.tex .") unless (-r "sample.tex");
	system("cp $dirForTex/palette.tex .") unless (-r "palette.tex");

	copyAndEdit($fout, $file, $name);

	return if (!$runLatex);

	my $cmd = "pdflatex $fout";
	system("$cmd");
	sleep(1);
	my $foutpdf = $fout;
	$foutpdf =~ s/\.tex$/.pdf/;
	$cmd = "/usr/bin/pdftocairo -singlefile -png $foutpdf";
	system("$cmd") if (-x "/usr/bin/pdftocairo");
}

sub copyAndEdit
{
	my ($fout, $file, $name) = @_;
	open(FILE, "<", "$file") or die "$0: Cannot open $file : $!\n";
	my $ret = open(FOUT, ">", "$fout");
	if (!$ret) {
		close(FILE);
		die "$0: Cannot open write to $fout : $!\n";
	}

	while (<FILE>) {
		next if (/^ *\%/);
		s/outSpectrum\d\.pgfplots/$name/;
		print FOUT;
	}

	close(FOUT);
	close(FILE);
}