-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_2D_histogram.wtimecut.pl
62 lines (53 loc) · 1.62 KB
/
make_2D_histogram.wtimecut.pl
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
#!/usr/bin/perl -w
use POSIX;
########## global variables ####################
$usage = "\nUsage: \.\/make_2D_histogram\.pl [data file] [y-column] [y-min] [y-max] [y-resolution] [x-column] [x-min] [x-max] [x-resolution] [TimeCut] [outputFileName]\n";
$data = $ARGV[0] || die "$usage\n";
$Ycol = $ARGV[1] || die "$usage\n";
$Ymin = $ARGV[2] || die "$usage\n";
$Ymax = $ARGV[3] || die "$usage\n";
$Yres = $ARGV[4] || die "$usage\n";
$Xcol = $ARGV[5] || die "$usage\n";
$Xmin = $ARGV[6] || die "$usage\n";
$Xmax = $ARGV[7] || die "$usage\n";
$Xres = $ARGV[8] || die "$usage\n";
$TimeCut = $ARGV[9] || die "$usage\n";
$output = $ARGV[10] || die "$usage\n";
$maxX = (($Xmax - $Xmin)/$Xres);
$maxY = (($Ymax - $Ymin)/$Yres);
## Initializing
for ($i=0;$i<$maxY;$i++){
for ($j=0;$j<$maxX;$j++){
$BIN{"$i:$j"} = 0;
}
}
### open and read in the file and ###
$totaldata = 0;
open(INP,"<$data");
while ($line = <INP>) {
chomp $line;
for($line) { s/^\s+//;s/\s+$//; s/\s+/ /g; }
@lines = split(/ /,$line);
if ($lines[3]>=$TimeCut){ #specify column where time is located
print "$lines[$Ycol] and $lines[$Xcol]\n";
$x = (($lines[$Xcol] - $Xmin)/$Xres);
$y = (($lines[$Ycol] - $Ymin)/$Yres);
$newx = floor($x);
$newy = floor($y);
$BIN{"$newy:$newx"}++;
$totaldata++;
}
}
close(INP);
### and print out the resulting matrix ###
open(OUT,">$output");
for ($yy=0;$yy<$maxY;$yy++) {
for ($xx=0;$xx<$maxX;$xx++) {
printf OUT "%8d", $BIN{"$yy:$xx"};
#print "$BIN{\"$yy:$xx\"}\t";
}
print OUT "\n";
#print "\n";
}
print "\n";
close(OUT);