| 1 | package Text::NumericData::App::txdsort; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | #the infostring says it all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $infostring = 'sorting of text data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | pipe | txdsort [parameters] | pipe | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | You can sort for multiple columns, in order and down- or upwards for each column.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | our @ISA = ('Text::NumericData::App'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my @pars = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 'col',1,'c', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 'the column(s) concerned (first is 1, comma separated list of integers for multi-stage sorting)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | , 'down',0,'d', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 'sort descending; normal mode is ascending; may be also comma-separated list of 0 or 1 according to col value' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | , 'scan',0,'', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 'Introduce empty lines after each block of the last sorting column (when it starts from a smaller value again). That is for creating "scans" for gnuplot pm3d mode.' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | return $class->SUPER::new | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | parconf=> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | info=>$infostring # default version, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # default author | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # default copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | ,pardef=>\@pars | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ,filemode=>1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ,pipemode=>1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ,pipe_init=>\&prepare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ,pipe_file=>\&process_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | sub prepare | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepare: called CC=6 SCAR=18.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my $param = $self->{param}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | $self->{cols} = [split('\s*,\s*', $param->{col})]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | $self->{down} = [split('\s*,\s*', $param->{down})]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | $self->{maxcol} = 0; # 1-based maximum column value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | for(my $i = 0; $i<=$#{$self->{cols}}; ++$i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $self->{cols}[$i] = int($self->{cols}[$i]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | ▶ | unless($self->{cols}[$i] > 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | print STDERR "txdsort: invalid column: $self->{cols}[$i]!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | ▶ | $self->{maxcol} = $self->{cols}[$i] if $self->{cols}[$i] > $self->{maxcol}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 2 | --$self->{cols}[$i]; # from here on normal array indices | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | $self->{down}[$i] = 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | unless defined $self->{down}[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | unless(@{$self->{cols}}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | print STDERR "txdsort: Need some columns!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | return -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | # possible cache of sort function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | # It should really be generated just once, without side effects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | $self->{sortfunc} = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub process_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_file: called CC=9 SCAR=22.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | my $param = $self->{param}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $file = $self->{txd}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | if($file->columns() < $self->{maxcol}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | print STDERR "txdsort: Error: File doesn't have enough columns for that sort (".$file->columns()." vs. $self->{maxcol}).\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | $self->{sortfunc} = $file->sort_data($self->{cols}, $self->{down}, $self->{sortfunc}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | $file->write_header($self->{out}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | ▶ | if($param->{scan}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $lend = $file->get_end(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | my $lastv = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | my $col = $self->{cols}[$#{$self->{cols}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | my $down = $self->{down}[$#{$self->{cols}}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | foreach my $l (@{$file->{data}}) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | { # Print the lines, watchout for scan border. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | my $newv = $l->[$col]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | if(defined $lastv) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | ▶ | print {$self->{out}} "$lend" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
$down and $newv > $lastv or not $down and $newv < $lastv
$down and $newv > $lastv
not $down and $newv < $lastv
MC/DC0%0/4
$down and $newv > $lastv or not $down and $newv < $lastv
$down
$newv > $lastv
not $down
$newv < $lastv
Truth table14%1/7
A and B or not(C) and D
A= $downB= $newv > $lastvC= not $downD= $newv < $lastv
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | if(($down and $newv > $lastv) or (not $down and $newv < $lastv)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 4 | $lastv = $newv; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | print {$self->{out}} ${$file->data_line($l)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $file->write_data($self->{out}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||