blib/lib/Text/NumericData/App/txdnorm.pm

filter: Statementstmt 70.2% 33 / 47 Branchbran 33.3% 8 / 24 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 51.0% 48 / 94 SCAR 37.2
CC
16
Cov
54%
process_file
51.8
prepare
4.9
BEGIN
1.0
CRAP 41.3
« blib/lib/Text/NumericData/App/txdcontract.pm ↑ Summary blib/lib/Text/NumericData/App/txdcolumns.pm »
1 package Text::NumericData::App::txdnorm;
2  
3 1 ▶use Text::NumericData::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 1 our $VERSION = '1';
11 1 $VERSION = eval $VERSION;
12  
13 1 my $infostring = 'normalize data sets
14 (c) 2005 (Artistic License) by Thomas Orgis <thomas@orgis.org>
15 textdata version x
16  
17 Usage:
18 pipe | txdnorm [parameters] | pipe';
19  
20 1 our @ISA = ('Text::NumericData::App');
21  
22 sub new
23 {
24 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
25 1 my @pars =
26 (
27 'to',1,'t',
28 'normalize to this (multiplication)'
29 , 'from',-1,'f',
30 'normalize from this (division) - means this value in input becomes the "to" value in output, if < 0, then normalize to maximum found'
31 , 'xcol',0,'x',
32 'if > 0: choose from value via given value in this column (the x data) - see pos parameter'
33 , 'pos',0,'p',
34 'normalize from the value corresponding to this x value'
35 , 'column',2,'c',
36 'column to normalize, starting at 1'
37 , 'append',0,'a',
38 'instead of overwriting existing column, append a new one (you may want to modify titles afterwards!)'
39 , 'verbose', 1, '',
40 'Give note about error conditions beyond the initial parameter checks (normalizing with zero, etc.).'
41 );
42 1 return $class->SUPER::new
43 ({
44 parconf=>
45 {
46 info=>$infostring # default version,
47 # default author
48 # default copyright
49 }
50 ,pardef=>\@pars
51 ,filemode=>1
52 ,pipemode=>1
53 ,pipe_init=>\&prepare
54 ,pipe_file=>\&process_file
55 });
56 }
57  
58 sub prepare
59 {
60 1 ▶ my $self = shift;
Subroutine prepare: called CC=4 SCAR=16.0
Pod undocumented
61 1 my $param = $self->{param};
62 1 ▶ unless($param->{from})
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->{"from"}) 0 1 1
63 {
64 0 print STDERR "txdnorm: invalid from value; must be non-zero!\n";
65 0 return -1;
66 }
67 print STDERR "txdnorm: you really want to make it all zero?"
68 1 ▶ unless $param->{to};
Branch: 1 branch
BranchTrueFalseTotal
unless $param->{"to"} 0 1 1
69  
70 1 $param->{column} = int($param->{column}); #paranoia
71 1 $param->{xcol} = int($param->{xcol}); #paranoia
72 1 ▶ unless($param->{column} > 0)
Branch: 1 branch
BranchTrueFalseTotal
unless ($param->{"column"} > 0) 0 1 1
73 {
74 0 print STDERR "txdnorm: invalid column!\n";
75 0 return -1;
76 }
77  
78 1 return 0;
79 }
80  
81 sub process_file
82 {
83 1 ▶ my $self = shift;
Subroutine process_file: called CC=13 SCAR=39.5
Pod undocumented
84 1 my $param = $self->{param};
85 1 my $good = 0;
86 1 my $normcolumn = $param->{column};
87 1 ▶ if($param->{append} and @{$self->{txd}->{Data}})
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"append"} and @{$self->{"txd"}{"Data"};}) 0 1 1
Condition33%1/3
$param->{"append"} and @{$self->{"txd"}{"Data"};}
!ll&&!rl&&r
100
MC/DC0%0/2
$param->{"append"} and @{$self->{"txd"}{"Data"};}
$param->{"append"} @{$self->{"txd"}{"Data"};}
Truth table33%1/3
A and B
A= $param->{"append"}B= @{$self->{"txd"}{"Data"};}
ABresult
0X0
100
111
88 {
89 0 $normcolumn = $#{$self->{txd}->{Data}[0]}+2;
90 }
91 1 ▶ unless($param->{xcol} > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{'xcol'} > 0) { } 0 1 1
92 {
93 1 ▶ if($param->{from} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{'from'} < 0) { } 1 0 1
94 {
95 1 my $max = $self->{txd}->max("abs([$param->{column}])");
96 print STDERR "txdnorm: unable to perform normalisation from zero!\n"
97 1 ▶ if($max == 0 and $param->{verbose});
Branch: 1 branch
BranchTrueFalseTotal
if $max == 0 and $param->{"verbose"} 0 1 1
Condition33%1/3
$max == 0 and $param->{"verbose"}
!ll&&!rl&&r
100
MC/DC0%0/2
$max == 0 and $param->{"verbose"}
$max == 0 $param->{"verbose"}
Truth table33%1/3
A and B
A= $max == 0B= $param->{"verbose"}
ABresult
0X0
100
111
98 1 ▶ $self->{txd}->calc("[$normcolumn] = [$param->{column}] * $param->{to} / $max")
Branch: 1 branch
BranchTrueFalseTotal
unless $max == 0 1 0 1
99 unless $max == 0;
100 }
101 else
102 {
103 0 $self->{txd}->calc("[$normcolumn] = [$param->{column}] * $param->{to} / $param->{from}");
104 }
105 1 $good = 1;
106 }
107 else
108 {
109 #normalize from chosen point
110 my $val = $self->{txd}->y( $param->{pos}
111 0 , $param->{xcol}-1, $param->{column}-1 );
112 0 ▶ if(defined $val)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) { } 0 0 0
113 {
114 print STDERR "txdnorm: unable to perform normalisation from zero!\n"
115 0 ▶ if($val == 0 and $param->{verbose});
Branch: 1 branch
BranchTrueFalseTotal
if $val == 0 and $param->{"verbose"} 0 0 0
Condition0%0/3
$val == 0 and $param->{"verbose"}
!ll&&!rl&&r
000
MC/DC0%0/2
$val == 0 and $param->{"verbose"}
$val == 0 $param->{"verbose"}
Truth table0%0/3
A and B
A= $val == 0B= $param->{"verbose"}
ABresult
0X0
100
111
116 0 ▶ $self->{txd}->calc("[$normcolumn] = [$param->{column}] * $param->{to} / $val")
Branch: 1 branch
BranchTrueFalseTotal
unless $val == 0 0 0 0
117 unless $val == 0;
118 0 $good = 1;
119 }
120 else
121 {
122 print STDERR "txdnorm: found no value to start with, please try interpolation (if you already have, then you're in trouble).\n"
123 0 ▶ if $param->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $param->{"verbose"} 0 0 0
124 }
125 }
126 1 $self->{txd}->write_all($self->{out});
127 }
128  
« blib/lib/Text/NumericData/App/txdcontract.pm ↑ Summary blib/lib/Text/NumericData/App/txdcolumns.pm »