line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::NumericData::FileCalc; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1729
|
use strict; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
1596
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# This is just a placeholder because of a past build system bug. |
8
|
|
|
|
|
|
|
# The one and only version for Text::NumericData is kept in |
9
|
|
|
|
|
|
|
# the Text::NumericData module itself. |
10
|
|
|
|
|
|
|
our $VERSION = '1'; |
11
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
14
|
|
|
|
|
|
|
our @EXPORT_OK = qw(file_calc); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# Returns list ref of deletion indices, undef on failure. |
17
|
|
|
|
|
|
|
sub file_calc |
18
|
|
|
|
|
|
|
{ |
19
|
421
|
|
|
421
|
0
|
626
|
my $ff = shift; # formula function |
20
|
421
|
|
|
|
|
539
|
my $config = shift; # see defaults below |
21
|
421
|
|
|
|
|
564
|
my $data = shift; # main data set to work on |
22
|
421
|
|
|
|
|
575
|
my $files = shift; # list of Text::NumericData::File objects to use |
23
|
421
|
|
|
|
|
553
|
my $workarray = shift; # \@A |
24
|
421
|
|
|
|
|
574
|
my $constants = shift; # \@C |
25
|
|
|
|
|
|
|
# configuration defaults |
26
|
421
|
100
|
|
|
|
909
|
$config = |
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
bycol=>0 |
29
|
|
|
|
|
|
|
, fromcol=>undef |
30
|
|
|
|
|
|
|
, byrow=>0 |
31
|
|
|
|
|
|
|
, skipempty=>1 # Do nothing on empty data sets, |
32
|
|
|
|
|
|
|
, rowoffset=>0 # offset for byrow ($data starting with that row) |
33
|
|
|
|
|
|
|
} unless(defined $config); |
34
|
|
|
|
|
|
|
|
35
|
421
|
50
|
|
|
|
738
|
return undef unless defined $data; |
36
|
|
|
|
|
|
|
|
37
|
421
|
|
|
|
|
644
|
my @delete; |
38
|
|
|
|
|
|
|
# shortcut for context-less computations |
39
|
421
|
100
|
|
|
|
768
|
unless(defined $files) |
40
|
|
|
|
|
|
|
{ |
41
|
1
|
|
|
|
|
2
|
for my $row (0..$#{$data}) |
|
1
|
|
|
|
|
12
|
|
42
|
|
|
|
|
|
|
{ |
43
|
4
|
0
|
33
|
|
|
5
|
next if(not @{$data->[$row]} and $config->{skipempty}); |
|
4
|
|
|
|
|
10
|
|
44
|
4
|
|
|
|
|
84
|
my $ignore = &$ff([$data->[$row]]); |
45
|
4
|
50
|
|
|
|
13
|
push(@delete, $row) if $ignore; |
46
|
|
|
|
|
|
|
} |
47
|
1
|
|
|
|
|
4
|
return \@delete; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# the real deal, full computation in all complexity |
51
|
420
|
|
|
|
|
627
|
my @fromcol; |
52
|
420
|
|
|
|
|
616
|
my $bycol = 0; |
53
|
|
|
|
|
|
|
$bycol = $config->{bycol} |
54
|
420
|
50
|
|
|
|
854
|
if defined $config->{bycol}; |
55
|
420
|
|
|
|
|
560
|
my $byrow = 0; |
56
|
|
|
|
|
|
|
$byrow = $config->{byrow} |
57
|
420
|
50
|
|
|
|
796
|
if defined $config->{byrow}; |
58
|
420
|
|
|
|
|
571
|
for my $i (0..$#{$files}) |
|
420
|
|
|
|
|
962
|
|
59
|
|
|
|
|
|
|
{ |
60
|
420
|
50
|
|
|
|
801
|
if(defined $config->{fromcol}) |
61
|
|
|
|
|
|
|
{ |
62
|
420
|
|
|
|
|
783
|
$fromcol[$i] = $config->{fromcol}[$i]; |
63
|
|
|
|
|
|
|
} |
64
|
420
|
50
|
|
|
|
990
|
$fromcol[$i] = $bycol unless defined $fromcol[$i]; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
420
|
|
|
|
|
666
|
for my $row (0..$#{$data}) |
|
420
|
|
|
|
|
725
|
|
68
|
|
|
|
|
|
|
{ |
69
|
420
|
0
|
33
|
|
|
564
|
next if(not @{$data->[$row]} and $config->{skipempty}); |
|
420
|
|
|
|
|
856
|
|
70
|
|
|
|
|
|
|
# Construct array for data arrays. |
71
|
420
|
|
|
|
|
782
|
my @fd = ($data->[$row]); # main data set first |
72
|
|
|
|
|
|
|
# Add the files' sets, possibly using interpolation. |
73
|
|
|
|
|
|
|
# This uses Text::Numeric::Data::File methods. |
74
|
420
|
|
|
|
|
703
|
my $realrow = $row + $config->{rowoffset}; |
75
|
420
|
|
|
|
|
550
|
for my $i (0..$#{$files}) |
|
420
|
|
|
|
|
714
|
|
76
|
|
|
|
|
|
|
{ |
77
|
420
|
|
|
|
|
581
|
my $d = undef; |
78
|
|
|
|
|
|
|
# Correlate via row ... |
79
|
420
|
100
|
|
|
|
739
|
if($byrow){ $d = $files->[$i]->{data}->[$realrow]; } |
|
20
|
|
|
|
|
32
|
|
80
|
|
|
|
|
|
|
# Interpolation is possible if configured. |
81
|
|
|
|
|
|
|
else |
82
|
|
|
|
|
|
|
{ |
83
|
400
|
|
|
|
|
1158
|
$d = $files->[$i]->set_of($fd[0]->[$bycol], $fromcol[$i]); |
84
|
|
|
|
|
|
|
} |
85
|
420
|
|
|
|
|
854
|
push(@fd, $d); |
86
|
|
|
|
|
|
|
} |
87
|
420
|
|
|
|
|
664
|
my $ignore = 0; |
88
|
|
|
|
|
|
|
# Ignore data sets that had no match in given files. |
89
|
420
|
100
|
|
|
|
721
|
for(@fd){ if(not defined $_){ $ignore = 1; last; } } |
|
840
|
|
|
|
|
1541
|
|
|
90
|
|
|
|
|
123
|
|
|
90
|
|
|
|
|
125
|
|
90
|
|
|
|
|
|
|
# Finally compute! |
91
|
420
|
100
|
|
|
|
8694
|
$ignore = &$ff(\@fd, $workarray, $constants) unless $ignore; |
92
|
420
|
100
|
|
|
|
1144
|
if($ignore){ push(@delete, $row); } |
|
90
|
|
|
|
|
173
|
|
93
|
|
|
|
|
|
|
} |
94
|
420
|
|
|
|
|
1093
|
return \@delete; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
__END__ |