| 1 | package Pure::Text::NASA_Ames; | ||||||||||||||||||||||||||||
| 2 | 10 | ▶ | use base qw(Class::Accessor); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 10 | Pure::Text::NASA_Ames->mk_accessors(qw(aMiss aName aScal date dX x | |||||||||||||||||||||||||||
| 5 | ffi iVol lenA lenX mName nAuxC nAuxV | ||||||||||||||||||||||||||||
| 6 | nCom nIV nLHead nNComL nSComL nV nVol | ||||||||||||||||||||||||||||
| 7 | nVPM nX nXDef oName org rDate sCom | ||||||||||||||||||||||||||||
| 8 | sName vMiss vName vScal xName IO_File | ||||||||||||||||||||||||||||
| 9 | fileName currentLine dataBuffer)); | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | package Text::NASA_Ames; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 10 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 10 | ▶ | use IO::File (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 10 | ▶ | use 5.00600; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 10 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 10 | ▶ | use base qw(Pure::Text::NASA_Ames); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 10 | ▶ | use Text::NASA_Ames::DataEntry; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 10 | our $VERSION = 0.03; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub _carp { | ||||||||||||||||||||||||||
|
Subroutine
_carp: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 0 | my $fileMsg = ''; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | $fileMsg = " in ".$self->fileName. " line ".$self->IO_File->input_line_number if ($self->IO_File && $self->IO_File->input_line_number); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->IO_File and $self->IO_File->input_line_number
MC/DC0%0/2
$self->IO_File and $self->IO_File->input_line_number
$self->IO_File
$self->IO_File->input_line_number
Truth table0%0/3
A and B
A= $self->IO_FileB= $self->IO_File->input_line_number
| |||||||||||||||||||||||||||||
| 28 | 0 | return Carp::carp(@_, $fileMsg); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | =head1 NAME | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | Text::NASA_Ames - Reading data from NASA Ames files | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | my $nasaAmes = new Text::NASA_Ames('this_file'); | ||||||||||||||||||||||||||||
| 38 | # or | ||||||||||||||||||||||||||||
| 39 | $nasaAmes = new Text::NASA_Ames(new IO::File "this_file", "r"); | ||||||||||||||||||||||||||||
| 40 | print STDERR "3 independent variables"; | ||||||||||||||||||||||||||||
| 41 | $nasaAmes->nAuxV; # number of (real) auxiliary variables not containing | ||||||||||||||||||||||||||||
| 42 | # a independent variable | ||||||||||||||||||||||||||||
| 43 | $nasaAmes->nV; # number of independent variables | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # scanning through the file: | ||||||||||||||||||||||||||||
| 47 | while (my $entry = $nasaAmes->nextDataEntry) { | ||||||||||||||||||||||||||||
| 48 | my @X = @{ $dataEntry->X }; | ||||||||||||||||||||||||||||
| 49 | my @aux = @{ $dataEntry->A }; | ||||||||||||||||||||||||||||
| 50 | my @V = @{ $dataEntry->V }; | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | This is the factory class for reading on of the Text::NASA_Ames formats | ||||||||||||||||||||||||||||
| 56 | (currently 9). The function-names are related to the format specification | ||||||||||||||||||||||||||||
| 57 | as in L<http://cloud1.arc.nasa.gov/solve/archiv/archive.tutorial.html> by | ||||||||||||||||||||||||||||
| 58 | Gaines and Hipkinds. | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | =head2 METHODS FROM SPECIFICATIONS | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | All lists are returned as references to lists. | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | The names of the public methods are identical to the format specifications. In some formats, auxiliary variables are misused to store independent variables. In those cases, I return the real number of auxiliary variables with nAuxV and not nAuxV as sum of auxiliray variables plus stored independent variables as written in the file. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | =over 4 | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =item a | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | not implemented, see L<nextDataEntry> | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item aMiss | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | list of missing values of the auxiliary variables | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item aName | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | list of names of the auxiliary variables | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | =item aScal | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | list of scaling factors of the auxiliary variables | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =item date | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | UT date marking the beginning of the data: format 'YYYY MM DD' | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =item dX | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | list of interval between the indep. variables (0 means no linear interval) | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =item ffi | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | File Format Index of the parsed file | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =item iVol | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | total number of volumes belonging to complete dataset (see nVol) | ||||||||||||||||||||||||||||
| 104 | (starting at 1) | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =item lenA | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | list of character length of the auxiliary string variables | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =item lenX | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | list of character length of the independent string variables | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =item mName | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | mission name | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =item nAuxC | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | number of auxiliary string variables | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item nAuxV | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | number of total auxiliary variables (including string variables). The numeric | ||||||||||||||||||||||||||||
| 125 | auxiliary variables come allways in front of the string variables. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =item nCom | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | list of normal comment strings | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =item nIV | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | number of independent variables (== first number of ffi) | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =item nLHead | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | number of header lines | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =item nNComL | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | number of normal comment lines | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =item nSComL | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | number of special comment lines | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =item nV | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | number of primary variables | ||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | =item nVol | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | total number of volumes required to store complete dataset | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | =item nVPM | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | number of independent variable between variable marks | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =item nX | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | list of numbers of values of the primary variables | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =item nXDef | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | list of numbers of values of the independent variable defined in the header | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | =item oName | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | originator name | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =item org | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | originators organization | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =item rDate | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | date of last revision (format as data) | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =item sCom | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | list of special comment lines | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =item sName | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | source name | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | =item v | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | not implemented, see L<nextDataEntry> | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =item vMiss | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | list of missing values of the variables | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | =item vName | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | list of variable names | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =item vScal | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | list of scaling factor of variables | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =item x | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | might be used for temporary variables, for iterator-access, | ||||||||||||||||||||||||||||
| 206 | see L<nextDataEntry> | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =item xName | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | list of variable names | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =back | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head2 ADDITIONAL METHODS | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | =over 4 | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =item new (filename || IO::File) | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | parse the first line and distribute the file to the correct Text::NASA_Ames::FFI | ||||||||||||||||||||||||||||
| 221 | object; | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =cut | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=20.7
Pod
documented
| |||||||||||||||||||||||||||||
| 226 | 26 | my ($class, $file) = @_; | |||||||||||||||||||||||||||
| 227 | 26 | ▶ | $class = ref $class || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 228 | 26 | my $self = {}; | |||||||||||||||||||||||||||
| 229 | 26 | bless $self, $class; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 26 | $self->fileName("$file"); # scalar representation | |||||||||||||||||||||||||||
| 232 | 26 | ▶ | if (ref ($file) && $file->isa("IO::File")) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $file and $file->isa("IO::File")
MC/DC0%0/2
ref $file and $file->isa("IO::File")
ref $file
$file->isa("IO::File")
Truth table33%1/3
A and B
A= ref $fileB= $file->isa("IO::File")
| |||||||||||||||||||||||||||||
| 233 | 0 | $self->IO_File($file); | |||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||
| 235 | 26 | $self->IO_File(new IO::File "$file", "r"); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 26 | ▶ | unless (defined $self->IO_File) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | $self->_carp("couldn't initialize file $file: $!"); | |||||||||||||||||||||||||||
| 239 | 0 | return undef; | |||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | 26 | $self->currentLine(1); # lines starting at 1 | |||||||||||||||||||||||||||
| 242 | 26 | $self->dataBuffer([]); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 26 | $self->_parseTopHeader; | |||||||||||||||||||||||||||
| 245 | 26 | my $subclass = 'Text::NASA_Ames::FFI'.$self->ffi; | |||||||||||||||||||||||||||
| 246 | 26 | eval "require $subclass"; | |||||||||||||||||||||||||||
| 247 | 26 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | 0 | $self->_carp("cannot require $subclass"); | |||||||||||||||||||||||||||
| 249 | 0 | return; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | 26 | return $subclass->new($self); | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 26 | ▶ | sub _parseTopHeader { | ||||||||||||||||||||||||||
|
Subroutine
_parseTopHeader: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 256 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 257 | # get the nlhead and format | ||||||||||||||||||||||||||||
| 258 | 26 | my $line = $self->nextLine; | |||||||||||||||||||||||||||
| 259 | 26 | my ($nlhead, $ffi) = split ' ', $line; | |||||||||||||||||||||||||||
| 260 | 26 | $self->nLHead($nlhead); | |||||||||||||||||||||||||||
| 261 | 26 | ▶ | if ($ffi =~ /(\d{4})/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 26 | $ffi = $1; # clean and untaint | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | 26 | $self->ffi($ffi); | |||||||||||||||||||||||||||
| 265 | 26 | $self->nIV( int ($ffi/1000) ); | |||||||||||||||||||||||||||
| 266 | 26 | $self->oName($self->nextLine); | |||||||||||||||||||||||||||
| 267 | 26 | $self->org($self->nextLine); | |||||||||||||||||||||||||||
| 268 | 26 | $self->sName($self->nextLine); | |||||||||||||||||||||||||||
| 269 | 26 | $self->mName($self->nextLine); | |||||||||||||||||||||||||||
| 270 | 26 | my @vol = split ' ', $self->nextLine; | |||||||||||||||||||||||||||
| 271 | 26 | $self->iVol($vol[0]); | |||||||||||||||||||||||||||
| 272 | 26 | $self->nVol($vol[1]); | |||||||||||||||||||||||||||
| 273 | 26 | my @date = split ' ', $self->nextLine; | |||||||||||||||||||||||||||
| 274 | 26 | $self->date("$date[0] $date[1] $date[2]"); | |||||||||||||||||||||||||||
| 275 | 26 | $self->rDate("$date[3] $date[4] $date[5]"); | |||||||||||||||||||||||||||
| 276 | 26 | ▶ | unless ($self->currentLine != 7) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | $self->_carp("problems reading top header, expected 7 lines, got ". | |||||||||||||||||||||||||||
| 278 | $self->currentLine); | ||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 26 | ▶ | sub _parseTailHeader { | ||||||||||||||||||||||||||
|
Subroutine
_parseTailHeader: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 283 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 284 | 26 | $self->nSComL($self->nextLine); | |||||||||||||||||||||||||||
| 285 | 26 | my @scom; | |||||||||||||||||||||||||||
| 286 | 26 | ▶ | for (my $i = 0; $i < $self->nSComL; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 242 | push @scom, $self->nextLine; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 26 | $self->sCom(\@scom); | |||||||||||||||||||||||||||
| 290 | 26 | $self->nNComL($self->nextLine); | |||||||||||||||||||||||||||
| 291 | 26 | my @com; | |||||||||||||||||||||||||||
| 292 | 26 | ▶ | for (my $i = 0; $i < $self->nNComL; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 293 | 280 | push @com, $self->nextLine; | |||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||
| 295 | 26 | $self->nCom(\@com); | |||||||||||||||||||||||||||
| 296 | 26 | ▶ | unless ($self->currentLine != 7) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 297 | 0 | $self->_carp("problems reading header, expected ". $self->nLHeader() . | |||||||||||||||||||||||||||
| 298 | " lines, got ". $self->currentLine); | ||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | # parse a list from a line expecting several entries | ||||||||||||||||||||||||||||
| 303 | 150 | ▶ | sub _parseList { | ||||||||||||||||||||||||||
|
Subroutine
_parseList: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||
| 304 | 150 | my ($self, $type, $expected) = @_; | |||||||||||||||||||||||||||
| 305 | 150 | ▶ | if ($expected != 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | 134 | my @list = split ' ', $self->nextLine; | |||||||||||||||||||||||||||
| 307 | 134 | ▶ | while (@list < $expected) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | 0 | push @list, split ' ', $self->nextLine; | |||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 134 | ▶ | if (@list > $expected) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | 0 | $self->_carp("got ".scalar @list . | |||||||||||||||||||||||||||
| 312 | " $type values, expected $expected\n"); | ||||||||||||||||||||||||||||
| 313 | 0 | return; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 134 | @list = map { $self->_trim($_) } @list; | |||||||||||||||||||||||||||
| 316 | 134 | $self->$type(\@list); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | # parse several lines and join as list | ||||||||||||||||||||||||||||
| 321 | 74 | ▶ | sub _parseLines { | ||||||||||||||||||||||||||
|
Subroutine
_parseLines: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 322 | 74 | my ($self, $type, $lines) = @_; | |||||||||||||||||||||||||||
| 323 | 74 | my @values; | |||||||||||||||||||||||||||
| 324 | 74 | ▶ | for (my $i = 0; $i < $lines; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | 132 | push @values, $self->nextLine; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | 74 | @values = map {$self->_trim($_) } @values; | |||||||||||||||||||||||||||
| 328 | 74 | $self->$type(\@values); | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 26 | ▶ | sub _parseVDeclaration { | ||||||||||||||||||||||||||
|
Subroutine
_parseVDeclaration: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 332 | 26 | my $self = shift; | |||||||||||||||||||||||||||
| 333 | 26 | $self->nV($self->nextLine); | |||||||||||||||||||||||||||
| 334 | 26 | foreach my $type (qw(vScal vMiss)) { | |||||||||||||||||||||||||||
| 335 | 52 | $self->_parseList($type, $self->nV); | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | 26 | $self->_parseLines('vName', $self->nV); | |||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 20 | ▶ | sub _parseAuxDeclaration { | ||||||||||||||||||||||||||
|
Subroutine
_parseAuxDeclaration: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 341 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 342 | 20 | $self->nAuxV($self->nextLine); | |||||||||||||||||||||||||||
| 343 | 20 | foreach my $type (qw(aScal aMiss)) { | |||||||||||||||||||||||||||
| 344 | 40 | $self->_parseList($type, $self->nAuxV); | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | 20 | $self->_parseLines('aName', $self->nAuxV); | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | =item currentLine | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | the current line in the file, starting at 1 | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =item nextLine | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | get the next chomped/trimmed line from the file and set the currentLine counter | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | =cut | ||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||
| 359 | 1394 | ▶ | sub nextLine { | ||||||||||||||||||||||||||
|
Subroutine
nextLine: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 360 | 1394 | my $self = shift; | |||||||||||||||||||||||||||
| 361 | 1394 | my $fh = $self->IO_File; | |||||||||||||||||||||||||||
| 362 | 1394 | my $line = <$fh>; | |||||||||||||||||||||||||||
| 363 | 1394 | ▶ | if (defined $line) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 1381 | chomp $line; | |||||||||||||||||||||||||||
| 365 | 1381 | $self->currentLine($self->currentLine()+1); | |||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||
| 367 | 1394 | return $self->_trim($line); | |||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | =item dataBuffer | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | set/get the complete dataBuffer. Don't use this method manually without | ||||||||||||||||||||||||||||
| 373 | knowing what you're doing. Think about using L<nextDataEntry>. | ||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||
| 375 | =item nextDataEntry | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | fetch the next L<Text::NASA_Ames::DataEntry> from the dataBuffer, which will | ||||||||||||||||||||||||||||
| 378 | be filled automatically. The data will not be set to memory. | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | =cut | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | 822 | ▶ | sub nextDataEntry { | ||||||||||||||||||||||||||
|
Subroutine
nextDataEntry: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 383 | 822 | my $self = shift; | |||||||||||||||||||||||||||
| 384 | 822 | my $buffer = $self->dataBuffer; | |||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | 822 | ▶ | unless (@$buffer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 387 | 131 | ▶ | if ($self->can('_refillBuffer')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 388 | 131 | $self->_refillBuffer; | |||||||||||||||||||||||||||
| 389 | } else { | ||||||||||||||||||||||||||||
| 390 | 0 | $self->_carp("_refillBuffer not set for ".ref($self)); | |||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | 822 | return shift @$buffer; | |||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | # takes to listRefs, sets the values in the second list to undef | ||||||||||||||||||||||||||||
| 397 | # if they are equal to the same entry in the first list | ||||||||||||||||||||||||||||
| 398 | 869 | ▶ | sub _undefMissingVals { | ||||||||||||||||||||||||||
|
Subroutine
_undefMissingVals: called CC=5 SCAR=16.8
| |||||||||||||||||||||||||||||
| 399 | 869 | my ($self, $miss, $vals) = @_; | |||||||||||||||||||||||||||
| 400 | 869 | ▶ | if (@$miss != @$vals) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 0 | $self->_carp("missing values ref (".scalar @$miss . | |||||||||||||||||||||||||||
| 402 | ") and values ref (".scalar @$vals . | ||||||||||||||||||||||||||||
| 403 | ") should be of the same size"); | ||||||||||||||||||||||||||||
| 404 | 0 | return; | |||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||
| 406 | 869 | ▶ | for (my $i = 0; $i < @$miss; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 407 | 1165 | ▶ | if (defined $vals->[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 408 | 1165 | ▶ | if ($miss->[$i] eq $vals->[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 409 | 32 | $vals->[$i] = undef; | |||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 869 | ▶ | sub _scaleVals { | ||||||||||||||||||||||||||
|
Subroutine
_scaleVals: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||
| 416 | 869 | my ($self, $scale, $vals) = @_; | |||||||||||||||||||||||||||
| 417 | 869 | ▶ | if (@$scale != @$vals) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | 0 | $self->_carp("scaling values ref and values ref should be of the same size"); | |||||||||||||||||||||||||||
| 419 | 0 | return; | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | 869 | ▶ | for (my $i = 0; $i < @$scale; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 422 | 1165 | ▶ | if (defined $vals->[$i]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 423 | 1133 | ▶ | $vals->[$i] *= $scale->[$i] | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | if (defined $scale->[$i]); # not defined for string values | ||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 869 | ▶ | sub _cleanAndScaleVals { | ||||||||||||||||||||||||||
|
Subroutine
_cleanAndScaleVals: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 430 | 869 | my ($self, $miss, $scale, $vals) = @_; | |||||||||||||||||||||||||||
| 431 | 869 | $self->_undefMissingVals($miss, $vals); | |||||||||||||||||||||||||||
| 432 | 869 | $self->_scaleVals($scale, $vals); | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 1772 | ▶ | sub _trim { | ||||||||||||||||||||||||||
|
Subroutine
_trim: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 436 | 1772 | my $self = shift; | |||||||||||||||||||||||||||
| 437 | 1772 | local $_ = shift; | |||||||||||||||||||||||||||
| 438 | 1772 | ▶ | return unless defined $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 439 | 1759 | s/^\s+//; | |||||||||||||||||||||||||||
| 440 | 1759 | s/\s+$//; | |||||||||||||||||||||||||||
| 441 | 1759 | return $_; | |||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 10 | 1; | |||||||||||||||||||||||||||
| 445 | __END__ | ||||||||||||||||||||||||||||