| 1 | package Text::NumericData::App::txdmean; | ||||||||||
| 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 = 'find means in textual data files | |||||||||
| 14 | |||||||||||
| 15 | Usage: | ||||||||||
| 16 | txdmean < data.dat | ||||||||||
| 17 | |||||||||||
| 18 | should result in a line with the mean values being printed'; | ||||||||||
| 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 | 1 | return $class->SUPER::new | |||||||||
| 28 | ({ | ||||||||||
| 29 | parconf => | ||||||||||
| 30 | { | ||||||||||
| 31 | info=>$infostring # default version | ||||||||||
| 32 | # default author | ||||||||||
| 33 | # default copyright | ||||||||||
| 34 | } | ||||||||||
| 35 | ,pardef => \@pars | ||||||||||
| 36 | ,pipemode => 1 | ||||||||||
| 37 | ,pipe_begin => \&init | ||||||||||
| 38 | ,pipe_header => \&ignore | ||||||||||
| 39 | ,pipe_data => \&process_data | ||||||||||
| 40 | ,pipe_end => \&result | ||||||||||
| 41 | }); | ||||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | sub init | ||||||||||
| 45 | { | ||||||||||
| 46 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 47 | |||||||||||
| 48 | 1 | $self->new_txd(); | |||||||||
| 49 | 1 | $self->{mean} = []; | |||||||||
| 50 | 1 | $self->{ln} = 0; | |||||||||
| 51 | |||||||||||
| 52 | 1 | return 0; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | sub ignore | ||||||||||
| 56 | { | ||||||||||
| 57 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
ignore: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 58 | 2 | $_[0] = ''; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub process_data | ||||||||||
| 62 | { | ||||||||||
| 63 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
process_data: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 64 | |||||||||||
| 65 | 4 | my $data = $self->{txd}->line_data($_[0]); | |||||||||
| 66 | 4 | $_[0] = ''; | |||||||||
| 67 | 4 | ▶ | return unless @{$data}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | 4 | ++$self->{ln}; | |||||||||
| 70 | |||||||||||
| 71 | 4 | ▶ | if(@{$self->{mean}}) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | { | ||||||||||
| 73 | 3 | ▶ | for(my $i = 0; $i <= $#{$self->{mean}}; ++$i) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | { | ||||||||||
| 75 | 9 | $self->{mean}[$i] += $data->[$i]; | |||||||||
| 76 | } | ||||||||||
| 77 | } | ||||||||||
| 78 | else | ||||||||||
| 79 | { | ||||||||||
| 80 | 1 | $self->{mean} = $data; | |||||||||
| 81 | } | ||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | sub result | ||||||||||
| 85 | { | ||||||||||
| 86 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
result: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 87 | |||||||||||
| 88 | # If no data there, nothing will happen. | ||||||||||
| 89 | 1 | ▶ | for(my $i = 0; $i <= $#{$self->{mean}}; ++$i) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 90 | { | ||||||||||
| 91 | 3 | $self->{mean}[$i] /= $self->{ln}; | |||||||||
| 92 | } | ||||||||||
| 93 | 1 | $_[0] = ${$self->{txd}->data_line($self->{mean})}; | |||||||||
| 94 | } | ||||||||||