| 1 | package Text::NumericData::FileCalc; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | 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 | 3 | our $VERSION = '1'; | |||||||||||||||||||||||||||
| 11 | 3 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 14 | 3 | our @EXPORT_OK = qw(file_calc); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | # Returns list ref of deletion indices, undef on failure. | ||||||||||||||||||||||||||||
| 17 | sub file_calc | ||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | 421 | ▶ | my $ff = shift; # formula function | ||||||||||||||||||||||||||
|
Subroutine
file_calc: called CC=22 SCAR=31.6
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 421 | my $config = shift; # see defaults below | |||||||||||||||||||||||||||
| 21 | 421 | my $data = shift; # main data set to work on | |||||||||||||||||||||||||||
| 22 | 421 | my $files = shift; # list of Text::NumericData::File objects to use | |||||||||||||||||||||||||||
| 23 | 421 | my $workarray = shift; # \@A | |||||||||||||||||||||||||||
| 24 | 421 | my $constants = shift; # \@C | |||||||||||||||||||||||||||
| 25 | # configuration defaults | ||||||||||||||||||||||||||||
| 26 | 421 | ▶ | $config = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | return undef unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 421 | my @delete; | |||||||||||||||||||||||||||
| 38 | # shortcut for context-less computations | ||||||||||||||||||||||||||||
| 39 | 421 | ▶ | unless(defined $files) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 1 | for my $row (0..$#{$data}) | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 4 | ▶ | next if(not @{$data->[$row]} and $config->{skipempty}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @{$data->[$row];} and $config->{"skipempty"}
MC/DC0%0/2
not @{$data->[$row];} and $config->{"skipempty"}
not @{$data->[$row];}
$config->{"skipempty"}
Truth table33%1/3
not(A) and B
A= not @{$data->[$row];}B= $config->{"skipempty"}
| |||||||||||||||||||||||||||||
| 44 | 4 | my $ignore = &$ff([$data->[$row]]); | |||||||||||||||||||||||||||
| 45 | 4 | ▶ | push(@delete, $row) if $ignore; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | 1 | return \@delete; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | # the real deal, full computation in all complexity | ||||||||||||||||||||||||||||
| 51 | 420 | my @fromcol; | |||||||||||||||||||||||||||
| 52 | 420 | my $bycol = 0; | |||||||||||||||||||||||||||
| 53 | $bycol = $config->{bycol} | ||||||||||||||||||||||||||||
| 54 | 420 | ▶ | if defined $config->{bycol}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 420 | my $byrow = 0; | |||||||||||||||||||||||||||
| 56 | $byrow = $config->{byrow} | ||||||||||||||||||||||||||||
| 57 | 420 | ▶ | if defined $config->{byrow}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 420 | for my $i (0..$#{$files}) | |||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 420 | ▶ | if(defined $config->{fromcol}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | 420 | $fromcol[$i] = $config->{fromcol}[$i]; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 420 | ▶ | $fromcol[$i] = $bycol unless defined $fromcol[$i]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 420 | for my $row (0..$#{$data}) | |||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||
| 69 | 420 | ▶ | next if(not @{$data->[$row]} and $config->{skipempty}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @{$data->[$row];} and $config->{"skipempty"}
MC/DC0%0/2
not @{$data->[$row];} and $config->{"skipempty"}
not @{$data->[$row];}
$config->{"skipempty"}
Truth table33%1/3
not(A) and B
A= not @{$data->[$row];}B= $config->{"skipempty"}
| |||||||||||||||||||||||||||||
| 70 | # Construct array for data arrays. | ||||||||||||||||||||||||||||
| 71 | 420 | 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 | my $realrow = $row + $config->{rowoffset}; | |||||||||||||||||||||||||||
| 75 | 420 | for my $i (0..$#{$files}) | |||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 420 | my $d = undef; | |||||||||||||||||||||||||||
| 78 | # Correlate via row ... | ||||||||||||||||||||||||||||
| 79 | 420 | ▶ | if($byrow){ $d = $files->[$i]->{data}->[$realrow]; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | # Interpolation is possible if configured. | ||||||||||||||||||||||||||||
| 81 | else | ||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||
| 83 | 400 | $d = $files->[$i]->set_of($fd[0]->[$bycol], $fromcol[$i]); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | 420 | push(@fd, $d); | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 420 | my $ignore = 0; | |||||||||||||||||||||||||||
| 88 | # Ignore data sets that had no match in given files. | ||||||||||||||||||||||||||||
| 89 | 420 | ▶ | for(@fd){ if(not defined $_){ $ignore = 1; last; } } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | # Finally compute! | ||||||||||||||||||||||||||||
| 91 | 420 | ▶ | $ignore = &$ff(\@fd, $workarray, $constants) unless $ignore; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 420 | ▶ | if($ignore){ push(@delete, $row); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 420 | return \@delete; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||