File: staticCorrelations.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 (74 lines) | stat: -rwxr-xr-x 1,196 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
#!/usr/bin/perl

use strict;
use warnings;
use utf8;

my ($file, $label) = @ARGV;

my @m = readMatrix($file, $label);

@m = symmetrize(@m);

my $rows = scalar(@m);

for (my $i = 0; $i < $rows; ++$i) {
	my $ptr = $m[$i];
	my $cols = scalar(@$ptr);
	for (my $j = 0; $j < $cols; ++$j) {
		print $ptr->[$j]." ";
	}
	
	print "\n";
}

sub symmetrize
{
	my @m = @_;
	my @m2;
	my $rows = scalar(@m);
	for (my $i = 0; $i < $rows; ++$i) {
		my $ptr = $m[$i];
		my $cols = scalar(@$ptr);
		my @tmp = @$ptr;
		for (my $j = 0; $j < $i; ++$j) {
				@tmp[$j] = $m[$j]->[$i];
		}
	
		$m2[$i] = \@tmp;
}

		return @m2;
}


sub readMatrix
{
	my ($file, $label) = @_;
	open(FILE, "<", $file) or die "$0: Cannot open $file : $!\n";
	while (<FILE>) {
		next if (/CmdLine/);
		last if (/$label/);
	}

	$_ = <FILE>;
	chomp;
	my @temp = split(/\s/, $_);
	die "$0: Rows Cols not found, line $. ** $_ **\n" if (scalar(@temp) != 2);
	my $rows = $temp[0];
	my $cols = $temp[1];

	my $row = 0;
	my @m;
	while (<FILE>) {
		chomp;
		my @tmp = split;
		die "$0: Wrong number of cols, line $., $cols not equal "
		.scalar(@tmp)."\n" if ($cols != scalar(@tmp));

		$m[$row++] = \@tmp;
		last if ($row == $rows);
	}

	return @m;
}