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

filter: Statementstmt 100% 65 / 65 Branchbran 100% 14 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 4 totaltotal 95.5% 85 / 89 SCAR 23.0
CC
10
Cov
100%
process_line
6.0
finish
5.0
BEGIN
1.0
CRAP 10.0
« blib/lib/Text/NumericData/App/txdconstruct.pm ↑ Summary Build »
1 package Text::NumericData::App::txdfromafors;
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 = 'Hacky tool to convert AFORS-HET (photovoltaic cell simulation) output to usual columns of textual data. Filters STDIN to STDOUT. Due to AFORS-HET appending data to the end, the whole input is buffered, but that should not be an issue for the moderate size of the 1D data.';
14  
15 1 our @ISA = ('Text::NumericData::App');
16  
17 sub new
18 {
19 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
20 1 my @pars =
21 (
22 'title', 'AFORS-HET data', 't',
23 'Provide a title for the data set.'
24 );
25  
26 1 return $class->SUPER::new
27 ({
28 parconf =>
29 {
30 info=>$infostring # default version
31 # default author
32 # default copyright
33 }
34 ,pardef => \@pars
35 ,pipemode => 1
36 ,pipe_begin => \&init
37 ,pipe_line => \&process_line
38 ,pipe_end => \&finish
39 });
40 }
41  
42 1 my $head = 0;
43 1 my $data = 1;
44 1 my $post = 2;
45  
46 sub init
47 {
48 2 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
49 2 $self->{place} = $head;
50 2 $self->{data} = [];
51 2 $self->{com} = [];
52 2 $self->{titlesets} = [];
53 }
54  
55 # Collect in advance.
56 sub process_line
57 {
58 1149 ▶ my $self = shift;
Subroutine process_line: called CC=6 SCAR=17.9
Pod undocumented
59  
60 1149 $_[0] =~ s:[\r\n]::g;
61 1149 ▶ if($self->{place} == $head)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"place"} == $head) 8 1141 1149
62 {
63 # first three lines containt title sets
64 8 ▶ if($_[0] =~ /^[\+\-\d]/){ $self->{place} = $data; }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[\+\-\d]/) { } 2 6 8
65 6 else{ push(@{$self->{titlesets}}, [split("\t", $_[0])]); }
66 }
67  
68 1149 ▶ if($self->{place} == $data)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"place"} == $data) 386 763 1149
69 {
70 386 ▶ if($_[0] =~ /^\s*$/)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\s*$/) 2 384 386
71 {
72 2 $self->{place} = $post;
73 2 $_[0] = ''; return;
74 }
75 384 $_[0] =~ s:,:.:g;
76 384 push(@{$self->{data}}, [split("\t", $_[0])]);
77 }
78  
79 1147 ▶ if($self->{place} == $post)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"place"} == $post) 757 390 1147
80 {
81 757 push(@{$self->{com}}, $_[0]);
82 }
83 1147 $_[0] = '';
84 }
85  
86 # It's a bit nasty to push all in one string, but heck, it's
87 # not that we are talking about gibibytes.
88 sub finish
89 {
90 2 ▶ my $self = shift;
Subroutine finish: called CC=5 SCAR=16.1
Pod undocumented
91 2 my $param = $self->{param};
92 2 my $txd = Text::NumericData->new({'separator'=>"\t", 'comment'=>'#'});
93  
94 # output of collected data
95 2 $_[0] = ${$txd->comment_line($param->{title})};
96 2 for my $c (@{$self->{com}})
97 {
98 757 $_[0] .= ${$txd->comment_line($c)};
99 }
100 # Print the titles in reverse, so that txd stuff picks up the first, most definite, title set.
101 2 ▶ while(@{$self->{titlesets}})
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"titlesets"};}) 6 2 8
102 {
103 6 $txd->{titles} = pop(@{$self->{titlesets}});
104 6 $_[0] .= ${$txd->title_line()};
105 }
106 # There can be re-iterations forth and back. Bring it in order.
107 # Also, result files aren't ordered along spatial dimension.
108 2 my $sortcol = 0;
109 $sortcol = 1
110 2 ▶ if $txd->{titles}[1] =~ /^x/;
Branch: 1 branch
BranchTrueFalseTotal
if $txd->{"titles"}[1] =~ /^x/ 1 1 2
111 2 @{$self->{data}} = sort {$a->[$sortcol] <=> $b->[$sortcol]} @{$self->{data}};
112 2 for my $d (@{$self->{data}})
113 {
114 384 $_[0] .= ${$txd->data_line($d)};
115 }
116 }
« blib/lib/Text/NumericData/App/txdconstruct.pm ↑ Summary Build »