File: rearrangeObserverOutput.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 (102 lines) | stat: -rw-r--r-- 1,768 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
99
100
101
102
#!/usr/bin/perl -w
#
use strict;

my ($file)=@ARGV;

my ($label1,$label2) = ("nupNdown","nUp+nDown");

printSuper($file);

rearrange($file,$label1);

rearrange($file,$label2);

sub printSuper
{
	 my ($file)=@_;
	 open(FILE, "<", $file) or die "Cannot open file $file: $!\n";
	 my $found = 0;
	 my $saved = "NOT_FOUND";
	 while(<FILE>) {
		if (/superdensity/i) {
			my $newSuperDensity = $_;
			last if (!($saved eq "NOT_FOUND") and
				diffBetweenSuperDensities($newSuperDensity,$saved)<1e-5);
			$saved = $_;
			$found = 1;
		}
	}
	close(FILE);
	($found) or die "$0: Cannot find superdensity in file $file\n";

	print "###\n";
	print $saved;
}

sub diffBetweenSuperDensities
{
	my ($t1,$t2)=@_;
	my $t1N = getNumericSuperDensity($t1);
	my $t2N = getNumericSuperDensity($t2);
	return abs($t2N - $t1N);
}

#SuperDensity(Weight of the timeVector)=(1.23456,0)
sub getNumericSuperDensity
{
	my ($t) = @_;
	my $sLabel = "SuperDensity(Weight of the timeVector)=(";
	$t=~s/\Q$sLabel//;
	$t=~s/,.*$//;
	return $t;
}

sub rearrange
{
	my ($file,$label)=@_;
	open(FILE, "<", $file) or die "Cannot open file $file: $!\n";

	while(<FILE>) {
		last if (/^#Using Matrix A:/);
	}
	my $x = $_;
	my $counter = 0;
	while(<FILE>) {
		$x = doOneBlock($label,$x,$counter);
		$counter++;
	}
	close(FILE);

}

sub doOneBlock
{
	my ($label,$saved,$counter)=@_;
	while(<FILE>) {
		if (/^#/) {
			$saved .= $_;
		}
		if (/^site /) {
			$saved .= $_;
			last;
		}
	}
	my $needsPrinting = 0;
	$needsPrinting = 1 if (/\Q$label/i);

	print $saved if ($needsPrinting and $counter<2);

	while(<FILE>) {
		last if (/^#/);
		if (/superdensity/i) {
			print;
			next;
		}
		next if (/^Not found #FERMIONICSIGN in file/);
		next if (/^Ignore prev. error/);
		print if ($needsPrinting);
	}
	return $_;
}