NASA_Ames/FFIx010.pm

filter: Statementstmt 84.5% 82 / 97 Branchbran 78.5% 33 / 42 Conditioncond 33.3% 4 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 76.3% 129 / 169 CC 27 SCAR 21.0
CC
27
Cov
79%
getXatPos
12.5
_readBlock
8.4
_refillBuffer
8.0
CRAP 8.1
« NASA_Ames/FFI1020.pm ↑ Summary NASA_Ames/FFI2110.pm »
1 package Text::NASA_Ames::FFIx010;
2 3 ▶use base qw(Text::NASA_Ames);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use 5.00600;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf " %d." . "%02d" x $#r, @r };
9  
10  
11 =head1 NAME
12  
13 Text::NASA_Ames::FFIx010 - Implementation of FFIx010 NASA_Ames format
14  
15 =head1 SYNOPSIS
16  
17  
18 =head1 DESCRIPTION
19  
20 This class should normally not be called directly. It is the base class
21 for FFI2010, FFI3010 and FFI4010, but not FFI1010!
22  
23 =head1 PUBLIC METHODS
24  
25 =over 4
26  
27 =item new (Text::NASA_Ames-object || options for new NASA_Ames)
28  
29 parses the (rest of the) header (body and comments)
30  
31 =cut
32  
33 10 ▶sub new {
Subroutine new: called CC=7 SCAR=20.4
Pod documented
34 10 my ($class, $fileObj) = @_;
35 10 ▶ $class = ref $class || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0100
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
36 10 ▶ if (! (ref $fileObj && (ref($fileObj) eq 'Text::NASA_Ames'))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fileObj and ref $fileObj eq "Text::NASA_Ames") 0 10 10
Condition33%1/3
ref $fileObj and ref $fileObj eq "Text::NASA_Ames"
!ll&&!rl&&r
0010
MC/DC0%0/2
ref $fileObj and ref $fileObj eq "Text::NASA_Ames"
ref $fileObj ref $fileObj eq "Text::NASA_Ames"
Truth table33%1/3
A and B
A= ref $fileObjB= ref $fileObj eq "Text::NASA_Ames"
ABresult
0X0
100
111
37 0 return new Text::NASA_Ames($fileObj);
38 }
39 10 my $self = $fileObj;
40 10 bless $self, $class;
41  
42 10 $self->_parseList('dX', $self->nIV);
43 10 $self->_parseList('nX', ($self->nIV - 1));
44 10 push @{ $self->nX }, undef;
45 10 $self->_parseList('nXDef', ($self->nIV - 1));
46 10 push @{ $self->nXDef }, undef;
47 10 $self->x([]);
48 10 ▶ for (my $i = 0; $i < ($self->nIV - 1); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->nIV - 1) 16 10 26
49 16 my $expected = $self->nXDef()->[$i];
50 16 ▶ if ($expected > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expected > 0) 16 0 16
51 16 my @xVals = split ' ', $self->nextLine;
52 16 ▶ if (@xVals != $expected) {
Branch: 1 branch
BranchTrueFalseTotal
if (@xVals != $expected) 0 16 16
53 0 $self->_carp("got ".scalar @xVals .
54 " values for X$i, expected $expected\n");
55 0 return;
56 }
57 16 push @{ $self->x }, \@xVals;
58 }
59 }
60 10 $self->_parseLines('xName', $self->nIV);
61 10 $self->_parseVDeclaration;
62 10 $self->_parseAuxDeclaration;
63 10 $self->_parseTailHeader;
64  
65 10 return $self;
66 }
67  
68 28 ▶sub _refillBuffer {
Subroutine _refillBuffer: called CC=8 SCAR=20.8
69 28 my $self = shift;
70  
71 28 my $line = $self->nextLine;
72 28 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 5 23 28
73  
74 23 my ($xLast, @a) = split ' ', $line;
75 23 ▶ if (@a != $self->nAuxV) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a != $self->nAuxV) 0 23 23
76 0 $self->_carp("not enough elements for Aux, expected ".
77 $self->nAuxV() . ", got ". scalar @a);
78 0 return;
79 }
80 23 ▶ $self->_cleanAndScaleVals($self->aMiss, $self->aScal, \@a)
Branch: 1 branch
BranchTrueFalseTotal
if $self->nAuxV > 0 14 9 23
81 if $self->nAuxV > 0;
82  
83 23 my @vHelp;
84 my @keys;
85 # wrong for 1010, there v-values are in the line
86 23 ▶ for (my $n = 0; $n < $self->nV; $n++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n < $self->nV) 23 23 46
87 23 $vHelp[$n] = {};
88 23 $self->_readBlock($self->nIV - 2, "", $vHelp[$n], \@keys);
89 }
90  
91 23 foreach my $key (@keys) {
92 591 my @pos = split '_', $key;
93 591 my @xList;
94 591 ▶ for (my $i = 0; $i < ($self->nIV - 1); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->nIV - 1) 1375 591 1966
95 1375 $xList[$i] = $self->getXatPos($i, $pos[$i]);
96 }
97 591 my @v;
98 591 ▶ for (my $j = 0; $j < $self->nV; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $self->nV) 591 591 1182
99 591 push @v, delete $vHelp[$j]{$key};
100 }
101 591 $self->_cleanAndScaleVals($self->vMiss, $self->vScal, \@v);
102 591 push @{ $self->dataBuffer },
103 new Text::NASA_Ames::DataEntry({X => [ (@xList, $xLast) ],
104 V => \@v,
105 A => \@a});
106 }
107 }
108  
109 63 ▶sub _readBlock {
Subroutine _readBlock: called CC=8 SCAR=21.3
110 63 my ($self, $xi, $key, $block, $keys) = @_;
111 63 ▶ if ($xi > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xi > 0) { } 8 55 63
112 # wrong for 1010, there v-values are in the line
113 8 ▶ for (my $i = 0; $i < $self->nX->[$xi]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->nX->[$xi]) 40 8 48
114 40 ▶ my $newkey = ($key eq "") ? $i : "$i\_$key";
Branch: 1 branch
BranchTrueFalseTotal
$key eq '' ? : 12 28 40
115 40 $self->_readBlock($xi - 1, $newkey, $block, $keys);
116 }
117 } else {
118 55 my $line = $self->nextLine;
119 55 ▶ unless ($line) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line) 0 55 55
120 0 $self->_carp("not enough elements for XI $xi".
121 " in row ". $self->currentLine);
122 0 return;
123 }
124 # wrong for 1010, there v-values are in the line
125 55 my @vi = split ' ', $line;
126 55 ▶ if (@vi != $self->nX->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@vi != $self->nX->[0]) 0 55 55
127 0 $self->_carp("not enough elements for nX1, expected ".
128 $self->nX->[0] . ", got ". scalar @vi .
129 " in row ". $self->currentLine);
130 0 return;
131 }
132 55 ▶ for (my $i = 0; $i < $self->nX->[0]; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->nX->[0]) 591 55 646
133 591 ▶ my $newkey = ($key eq "") ? $i : "$i\_$key";
Branch: 1 branch
BranchTrueFalseTotal
$key eq '' ? : 171 420 591
134 591 push @{ $keys }, $newkey;
135 591 $block->{$newkey} = $vi[$i];
136 }
137 }
138 }
139  
140 =item X
141  
142 list of list of X->[i][pos]. call getXatPos to retrieve auto-expanded values
143  
144 =item getXatPos (i,pos)
145  
146 get Xi at the position pos (this will modify currentXPos1). positions start
147 at 0, i starts at 0, defined until nIV - 2!
148  
149 =cut
150  
151 1375 ▶sub getXatPos {
Subroutine getXatPos: called CC=7 SCAR=25.2
Pod documented
152 1375 my ($self, $i, $currentPos) = @_;
153 1375 ▶ unless (($i >= 0) && ($i <= ($self->nIV - 2))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($i >= 0 and $i <= $self->nIV - 2) 0 1375 1375
Condition33%1/3
$i >= 0 and $i <= $self->nIV - 2
!ll&&!rl&&r
001375
MC/DC0%0/2
$i >= 0 and $i <= $self->nIV - 2
$i >= 0 $i <= $self->nIV - 2
Truth table33%1/3
A and B
A= $i >= 0B= $i <= $self->nIV - 2
ABresult
0X0
100
111
154 0 $self->_carp("cannot get i-pos: $i");
155 0 return;
156 }
157 1375 ▶ unless (($currentPos >= 0) && ($currentPos < $self->nX->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($currentPos >= 0 and $currentPos < $self->nX->[$i]) 0 1375 1375
Condition33%1/3
$currentPos >= 0 and $currentPos < $self->nX->[$i]
!ll&&!rl&&r
001375
MC/DC0%0/2
$currentPos >= 0 and $currentPos < $self->nX->[$i]
$currentPos >= 0 $currentPos < $self->nX->[$i]
Truth table33%1/3
A and B
A= $currentPos >= 0B= $currentPos < $self->nX->[$i]
ABresult
0X0
100
111
158 0 $self->_carp("undefined position in getXatPos: $currentPos");
159 0 return;
160 }
161 1375 ▶ if ($self->nXDef->[$i] > $currentPos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->nXDef->[$i] > $currentPos) { } 375 1000 1375
162 375 return $self->x->[$i]->[$currentPos];
163 } else {
164 1000 ▶ unless ($self->dX->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dX->[$i]) 0 1000 1000
165 0 $self->_carp("dX($i) not defined or 0, cannot extrapolate".
166 " getXatPos");
167 0 return;
168 }
169 1000 return $self->x->[$i]->[0] + ($currentPos * $self->dX->[$i]);
170 }
171 }
172  
173 3 1;
174 __END__
« NASA_Ames/FFI1020.pm ↑ Summary NASA_Ames/FFI2110.pm »