File: getManySites.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 (151 lines) | stat: -rw-r--r-- 2,748 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/perl -w

use strict;

my ($file)=@ARGV;
my $n = 12;
my $offset = 0.2;
my @times;
my %val;
my @nd;

my $sd = getSuperDensity($file);

#Note: the two extreme are not available since
# DMRG++ cannot compute them
my $firstSite = 1;
for (my $site=$firstSite;$site<$n-1;$site++)
{
	doOneSite($site);
}

printTotalNd($file,$sd);
printAllSites($file,$sd);

sub getOutputName
{
	my ($file,$ext) = @_;
	my $fout = $file;
	$fout =~ s/\..*$/\.${ext}/;
	die "$0: Refusing to overwrite $fout\n" if ($fout eq $file);
	#die "$0: Refusing to overwrite $fout\n" if (-e $fout);
	return $fout;
}

sub printTotalNd
{
	my ($file,$sd)=@_;
	my $fout = getOutputName($file,"ndt");

	open(FOUT, ">", "$fout") or die
		"Cannot open $fout for writing: $!\n";

	foreach my $t (@times) {
		$_=$val{$t}/$sd;
		print FOUT "$t $_\n";
	}
	close(FOUT);
}

sub printAllSites
{
	my ($file,$sd)=@_;
	my $fout = getOutputName($file,"nds");
	open(FOUT, ">", "$fout") or die
		"Cannot open $fout for writing: $!\n";

	# first row (labels:):
	print FOUT "#times/sites ";
	foreach my $t (@times) {
		print FOUT "$t ";
	}
	print FOUT "\n";
	
	foreach my $t (@times) {
		print FOUT "$t ";
		for (my $site=$firstSite;$site<$n-1;$site++) {
			$_=$nd[$site]{$t}/$sd; # + $offset * $site;
			print FOUT "$_ ";
		}
		print FOUT "\n";
	}
	close(FOUT);

}

sub getSuperDensity
{
	my ($site)=@_;
	my $sd;
	open(FILE, "<", $file) or die "Cannot open file $file: $!\n";
	while(<FILE>) {
		if (/SuperDensity.*=\(([^,]+),/) {
			$sd = $1;
			last;
		}
	}
	close(FILE);
	defined $sd or die "SuperDensity is not defined\n";
	return $sd;
}

sub doOneSite
{
	my ($site)=@_;

	system("perl getTimeObs.pl $site < $file > out1");
	system("perl gatherTimes.pl < out1 > out ");
	open(FILE, "<", "out") or die "Cannot open file out: $!\n";
	my $counter = 0;
	my @timesNow;
	while(<FILE>) {
		my @temp=split;
		$timesNow[$counter++]=$temp[0];
		if (defined($val{$temp[0]})) {
			$val{$temp[0]} += $temp[1];
		} else {
			$val{$temp[0]} = $temp[1];
		}
		$nd[$site]{$temp[0]}=$temp[1];
	}
	close(FILE);
	if ($site==$firstSite) {
		@times = @timesNow;
		print STDERR "Setting $#times\n";
	} else {
		updateTimes(\@timesNow,$#timesNow+1,$site);
	}
}

sub updateTimes
{
	my ($timesNow,$n,$site)=@_;
	# If there's a time in @times that's not in @timesNow
	# then delete it
	my $counter=0;
	my @newTimes;
	foreach my $t (@times) {
		if (isInVector($timesNow,$n,$t)) {
			$newTimes[$counter++]=$t;
		} else {
			#print STDERR "Eliminated $t when site=$site\n";
			
			#if ($t==0.6) {
			#	die "timesnow: @$timesNow\n";
			#}
		}
	}
	@times = @newTimes;
	print STDERR "Updated to $#times\n";
}

sub isInVector
{
	my ($v,$n,$what)=@_;
	for (my $i=0;$i<$n;$i++) {
		return 1 if ($v->[$i]==$what);
	}
	return 0;
}