| 1 | package PDL::IO::CSV; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | our @EXPORT_OK = qw(rcsv1D rcsv2D wcsv1D wcsv2D); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | our %EXPORT_TAGS = (all => \@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | our $VERSION = '0.009'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Config; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use constant NO64BITINT => ($Config{ivsize} < 8) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use constant NODATETIME => eval { require PDL::DateTime; require Time::Moment; 1 } ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use constant DEBUG => $ENV{PDL_IO_CSV_DEBUG} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use PDL; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Text::CSV_XS; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Scalar::Util qw(looks_like_number openhandle blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use POSIX qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | $Carp::Internal{ (__PACKAGE__) }++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 3 | ▶ | my $package = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | *{'PDL::wcsv2D'} = \&wcsv2D if grep { /^(:all|wcsv2D)$/ } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | ▶ | *{'PDL::wcsv1D'} = \&wcsv1D if grep { /^(:all|wcsv1D)$/ } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 3 | ▶ | __PACKAGE__->export_to_level(1, $package, @_) if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | my %pck = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | byte => "C", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | short => "s", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ushort => "S", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | long => "l", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | longlong => "q", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | float => "f", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | double => "d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | sub wcsv1D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | my ($fh, $O, $C) = _proc_wargs('1D', @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wcsv1D: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $cols = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my $rows = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my @c_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my @c_rows; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my @c_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my @c_size; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my @c_pack; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my @c_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my @c_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my @c_max_offset; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my @c_bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $bad2empty = $O->{bad2empty}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | while (blessed $_[0] && $_[0]->isa('PDL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($_[0]) and $_[0]->isa("PDL")
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("PDL")
builtin::blessed($_[0])
$_[0]->isa("PDL")
Truth table0%0/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("PDL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $c_pdl[$cols] = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | croak "FATAL: wcsv1D() expects 1D piddles" unless $c_pdl[$cols]->ndims == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $c_size[$cols] = PDL::Core::howbig($c_pdl[$cols]->get_datatype); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $c_dataref[$cols] = $c_pdl[$cols]->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $c_offset[$cols] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $type = $c_pdl[$cols]->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $dim = $c_pdl[$cols]->dim(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $c_pack[$cols] = $pck{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | croak "FATAL: your perl does not support 64bitint (avoid using type longlong)" if $c_pack[$cols] eq 'q' && NO64BITINT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$c_pack[$cols] eq "q" and 0
MC/DC0%0/1
$c_pack[$cols] eq "q" and 0
$c_pack[$cols] eq "q"
Truth table0%0/2
A
A= $c_pack[$cols] eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | $c_max_offset[$cols] = $c_size[$cols] * $dim; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | $rows = $dim if $rows < $dim; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($bad2empty && $c_pdl[$cols]->check_badflag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$bad2empty and $c_pdl[$cols]->check_badflag
MC/DC0%0/2
$bad2empty and $c_pdl[$cols]->check_badflag
$bad2empty
$c_pdl[$cols]->check_badflag
Truth table0%0/3
A and B
A= $bad2emptyB= $c_pdl[$cols]->check_badflag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $b = pdl($type, 1)->setbadif(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $d = $b->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $c_bad[$cols] = substr($$d, 0, $c_size[$cols]); # raw bytes representind BAD value | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | $cols++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $csv = Text::CSV_XS->new($C) or croak "" . Text::CSV_XS->error_diag(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ($O->{header}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $count = scalar @{$O->{header}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | croak "FATAL: wrong header (expected $cols items, got $count)" if $cols != $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $csv->print($fh, $O->{header}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | for my $r (0..$rows-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my @v = ('') x $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | for my $c (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($c_max_offset[$c] >= $c_offset[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if ($bad2empty && $c_bad[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$bad2empty and $c_bad[$c]
MC/DC0%0/2
$bad2empty and $c_bad[$c]
$bad2empty
$c_bad[$c]
Truth table0%0/3
A and B
A= $bad2emptyB= $c_bad[$c]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $v = substr(${$c_dataref[$c]}, $c_offset[$c], $c_size[$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | if ($v ne $c_bad[$c]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $v[$c] = unpack($c_pack[$c], $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | $v[$c] = PDL::DateTime::ll2dt($v[$c]) if ref $c_pdl[$c] eq 'PDL::DateTime'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my $v = substr(${$c_dataref[$c]}, $c_offset[$c], $c_size[$c]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $v[$c] = unpack($c_pack[$c], $v); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | $v[$c] = PDL::DateTime::ll2dt($v[$c]) if ref $c_pdl[$c] eq 'PDL::DateTime'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $c_offset[$c] += $c_size[$c]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $csv->print($fh, \@v); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | #XXX close $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | sub wcsv2D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my $pdl = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
wcsv2D: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my ($fh, $O, $C) = _proc_wargs('2D', @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | croak "FATAL: wcsv2D() expects 2D piddle" unless $pdl->ndims == 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $p = $pdl->transpose; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | my ($cols, $rows) = $p->dims; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $type = $p->type; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $size = PDL::Core::howbig($p->get_datatype); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $packC = $pck{$type} . "[$cols]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $pack1 = $pck{$type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | croak "FATAL: your perl does not support 64bitint (avoid using type longlong)" if $pck{$type} eq 'q' && NO64BITINT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$pck{$type} eq "q" and 0
MC/DC0%0/1
$pck{$type} eq "q" and 0
$pck{$type} eq "q"
Truth table0%0/2
A
A= $pck{$type} eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $dataref = $p->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $colsize = $size * $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $max_offset = $colsize * ($rows - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($O->{bad2empty} && $p->check_badflag) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$O->{"bad2empty"} and $p->check_badflag
MC/DC0%0/2
$O->{"bad2empty"} and $p->check_badflag
$O->{"bad2empty"}
$p->check_badflag
Truth table0%0/3
A and B
A= $O->{"bad2empty"}B= $p->check_badflag
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my $b = pdl($type, 1)->setbadif(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $d = $b->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $bad = substr($$d, 0, $size); # raw bytes representind BAD value | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | my $csv = Text::CSV_XS->new($C) or croak "" . Text::CSV_XS->error_diag(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if ($O->{header}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $n = scalar @{$O->{header}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | croak "FATAL: wrong header (expected $cols items, got $n)" if $cols != $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $csv->print($fh, $O->{header}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | while ($offset <= $max_offset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if (defined $bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my @v = map { my $v = substr($$dataref, $offset + $_*$size, $size); $v eq $bad ? '' : unpack($pack1, $v) } (0..$cols-1); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $csv->print($fh, \@v); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my @v = unpack($packC, substr($$dataref, $offset, $colsize)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $csv->print($fh, \@v); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $offset += $colsize; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | #XXX close $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | sub rcsv1D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | my ($fh, $coli, $O, $C) = _proc_rargs('1D', @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rcsv1D: called CC=55 SCAR=69.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | my ($c_type, $c_pack, $c_sizeof, $c_pdl, $c_bad, $c_dataref, $c_idx, $c_dt, $allocated, $cols); # initialize after we get 1st line | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | my $csv = Text::CSV_XS->new($C) or croak "" . Text::CSV_XS->error_diag(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | my $processed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | my $finished = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 2 | my $chunk = $O->{fetch_chunk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | my $empty2bad = $O->{empty2bad}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | my $text2bad = $O->{text2bad}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | my $dec_comma = $O->{decimal_comma}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | warn "Fetching 1D " . _dbg_msg($O, $C) . "\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # skip headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | my $headerline; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | my $headerdetection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2 | ▶ | if (looks_like_number($O->{header})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ($O->{header} == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # get the header line (only if skipping exactly 1 line) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $headerline = $csv->getline($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $csv->getline($fh) for (1..$O->{header}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | ▶ | elsif ($O->{header} && $O->{header} eq 'auto') { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$O->{"header"} and $O->{"header"} eq "auto"
MC/DC0%0/2
$O->{"header"} and $O->{"header"} eq "auto"
$O->{"header"}
$O->{"header"} eq "auto"
Truth table33%1/3
A and B
A= $O->{"header"}B= $O->{"header"} eq "auto"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | $headerdetection = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | ▶ | while (!$finished) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | my $rows = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | my @bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | my $r; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 2 | ▶ | while ($rows < $chunk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 3 | my $r = $csv->getline($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 3 | ▶ | if (defined $r) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 3 | ▶ | if (defined $headerdetection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 3 | my $numeric = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | for (@$r) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 11 | ▶ | if (looks_like_number($_)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | $numeric++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | elsif (!NODATETIME) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | my $v = $O->{strptime} ? _strptime($_, $O->{strptime}) : PDL::DateTime::dt2ll($_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $numeric++ if defined $v; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | ▶ | if ($numeric == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | # no numeric values found => skip this line but keep it as a potential header | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | $headerline = $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | $headerdetection = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | unless (defined $c_type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | ($c_type, $c_pack, $c_sizeof, $c_pdl, $c_bad, $c_dataref, $c_idx, $c_dt, $allocated, $cols) = _init_1D($coli, $r, $O); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | warn "Initialized size=$allocated, cols=$cols, type=".join(",",@$c_type)."\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if ($dec_comma) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | for (@$r) { s/,/./ if defined $_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($empty2bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if (defined $coli) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | my $i = $coli->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | unless (defined $r->[$i]) { $r->[$i] = $c_bad->[$_]; $c_pdl->[$_]->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | unless (defined $r->[$_]) { $r->[$_] = $c_bad->[$_]; $c_pdl->[$_]->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (defined $c_dt) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | next unless defined $c_dt->[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | my $v = $c_dt->[$_] ne 'datetime' ? _strptime($r->[$_], $c_dt->[$_]) : PDL::DateTime::dt2ll($r->[$_]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $r->[$_] = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $r->[$_] = $c_bad->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $c_pdl->[$_]->badflag(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | if ($text2bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if (defined $coli) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | my $i = $coli->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | unless (looks_like_number($r->[$i])) { $r->[$i] = $c_bad->[$_]; $c_pdl->[$_]->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | unless (looks_like_number($r->[$_])) { $r->[$_] = $c_bad->[$_]; $c_pdl->[$_]->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if (defined $coli) { # only selected columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | no warnings 'pack'; # intentionally disable all pack related warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 3 | ▶ | no warnings 'numeric'; # disable: Argument ??? isn't numeric in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 3 | ▶ | no warnings 'uninitialized'; # disable: Use of uninitialized value in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $bytes[$_] .= pack($c_pack->[$_], $r->[$coli->[$_]]) for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | else { # all columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | no warnings 'pack'; # intentionally disable all pack related warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | no warnings 'numeric'; # disable: Argument ??? isn't numeric in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | ▶ | no warnings 'uninitialized'; # disable: Use of uninitialized value in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | $bytes[$_] .= pack($c_pack->[$_], $r->[$_]) for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | $rows++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $finished = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | if ($rows > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $processed += $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if ($allocated < $processed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $allocated += $O->{reshape_inc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | warn "Reshape to: '$allocated'\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $c_pdl->[$_]->reshape($allocated); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $c_dataref->[$_] = $c_pdl->[$_]->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | for my $ci (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | my $len = length $bytes[$ci]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $expected_len = $c_sizeof->[$ci] * $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | croak "FATAL: len mismatch $len != $expected_len" if $len != $expected_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | substr(${$c_dataref->[$ci]}, $c_idx->[$ci], $len) = $bytes[$ci]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $c_idx->[$ci] += $expected_len; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | #XXX close $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | if (ref $c_pdl eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | if ($processed != $allocated) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | warn "Reshape to: '$processed' (final)\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $c_pdl->[$_]->reshape($processed) for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | $c_pdl->[$_]->upd_data for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if (ref $headerline eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | $c_pdl->[$_]->hdr->{col_name} = $headerline->[$_] if $headerline->[$_] && $headerline->[$_] ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$headerline->[$_] and $headerline->[$_] ne ""
MC/DC0%0/2
$headerline->[$_] and $headerline->[$_] ne ""
$headerline->[$_]
$headerline->[$_] ne ""
Truth table0%0/3
A and B
A= $headerline->[$_]B= $headerline->[$_] ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return @$c_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | warn "rcsv1D: no data\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | sub rcsv2D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | ▶ | my ($fh, $coli, $O, $C) = _proc_rargs('2D', @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rcsv2D: called CC=34 SCAR=48.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my ($c_type, $c_pack, $c_sizeof, $c_pdl, $c_bad, $c_dataref, $allocated, $cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | my $csv = Text::CSV_XS->new($C) or croak "" . Text::CSV_XS->error_diag(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | my $processed = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my $c_idx = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | my $finished; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | my $pck; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 2 | my $chunk = $O->{fetch_chunk}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | my $empty2bad = $O->{empty2bad}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 2 | my $text2bad = $O->{text2bad}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | my $dec_comma = $O->{decimal_comma}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 2 | my $bcount = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | ▶ | warn "Fetching 2D " . _dbg_msg($O, $C) . "\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | # skip headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 2 | $csv->getline($fh) for (1..$O->{header}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | while (!$finished) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | my $bytes = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 2 | my $rows = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | ▶ | while ($rows < $chunk) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 12 | my $r = $csv->getline($fh); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | ▶ | if (defined $r) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 10 | ▶ | unless (defined $pck) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 2 | ($c_type, $c_pack, $c_sizeof, $c_pdl, $c_bad, $c_dataref, $allocated, $cols) = _init_2D($coli, scalar @$r, $O); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | warn "Initialized size=$allocated, cols=$cols, type=$c_type\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 2 | $pck = "$c_pack\[$cols\]"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 2 | ▶ | next if $O->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 10 | ▶ | if ($dec_comma) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | for (@$r) { s/,/./ if defined $_ }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | ▶ | if ($empty2bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if (defined $coli) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $i = $coli->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | unless (defined $r->[$i]) { $r->[$i] = $c_bad; $c_pdl->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | unless (defined $r->[$_]) { $r->[$_] = $c_bad; $c_pdl->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 10 | ▶ | if ($text2bad) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if (defined $coli) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $i = $coli->[$_]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | unless (looks_like_number($r->[$i])) { $r->[$i] = $c_bad; $c_pdl->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | unless (looks_like_number($r->[$_])) { $r->[$_] = $c_bad; $c_pdl->badflag(1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 10 | ▶ | if (defined $coli) { # only selected columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 3 | ▶ | no warnings 'pack'; # intentionally disable all pack related warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 3 | ▶ | no warnings 'numeric'; # disable: Argument ??? isn't numeric in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 3 | ▶ | no warnings 'uninitialized'; # disable: Use of uninitialized value in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $bytes .= pack($pck, map { $r->[$_] } @$coli); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | else { # all columns | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3 | ▶ | no warnings 'pack'; # intentionally disable all pack related warnings | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 3 | ▶ | no warnings 'numeric'; # disable: Argument ??? isn't numeric in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | ▶ | no warnings 'uninitialized'; # disable: Use of uninitialized value in pack | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 10 | $bytes .= pack($pck, @$r); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 10 | $rows++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 2 | $finished = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | ▶ | if ($rows > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | $processed += $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 2 | ▶ | if ($allocated < $processed) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $allocated += $O->{reshape_inc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | warn "Reshaping to $allocated\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $c_pdl->reshape($cols, $allocated); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $c_dataref = $c_pdl->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 2 | my $len = length $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | my $expected_len = $c_sizeof * $cols * $rows; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | ▶ | croak "FATAL: len mismatch $len != $expected_len" if $len != $expected_len; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | substr($$c_dataref, $c_idx, $len) = $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | $c_idx += $len; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | #XXX close $fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 2 | ▶ | if (blessed $c_pdl && $c_pdl->isa('PDL')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($c_pdl) and $c_pdl->isa("PDL")
MC/DC0%0/2
builtin::blessed($c_pdl) and $c_pdl->isa("PDL")
builtin::blessed($c_pdl)
$c_pdl->isa("PDL")
Truth table33%1/3
A and B
A= builtin::blessed($c_pdl)B= $c_pdl->isa("PDL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | if ($processed != $allocated) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 2 | ▶ | warn "Reshaping to $processed (final)\n" if $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | $c_pdl->reshape($cols, $processed); # allocate the exact size | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | $c_pdl->upd_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 2 | return $c_pdl->transpose; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | warn "rcsv2D: no data\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | sub _dbg_msg { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | my ($O, $C) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbg_msg: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | sprintf "chunk=%s, reshape=%s, bad=%s/%s, sep_char='%s'", | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | $O->{fetch_chunk} ||= '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | $O->{reshape_inc} ||= '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | $O->{empty2bad} ||= '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | $O->{text2bad} ||= '?', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | $C->{sep_char} ||= '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/10
$O->{"fetch_chunk"} ||= "?"
$O->{"reshape_inc"} ||= "?"
$O->{"empty2bad"} ||= "?"
$O->{"text2bad"} ||= "?"
$C->{"sep_char"} ||= "?"
MC/DC0%0/1
$O->{"fetch_chunk"} ||= "?"
$O->{"fetch_chunk"}
MC/DC0%0/1
$O->{"reshape_inc"} ||= "?"
$O->{"reshape_inc"}
MC/DC0%0/1
$O->{"empty2bad"} ||= "?"
$O->{"empty2bad"}
MC/DC0%0/1
$O->{"text2bad"} ||= "?"
$O->{"text2bad"}
MC/DC0%0/1
$C->{"sep_char"} ||= "?"
$C->{"sep_char"}
Truth table0%0/2
A
A= $O->{"fetch_chunk"}
Truth table0%0/2
A
A= $O->{"reshape_inc"}
Truth table0%0/2
A
A= $O->{"empty2bad"}
Truth table0%0/2
A
A= $O->{"text2bad"}
Truth table0%0/2
A
A= $C->{"sep_char"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | sub _proc_wargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | ▶ | my $options = ref $_[-1] eq 'HASH' ? pop : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_proc_wargs: not called CC=21 SCAR=61.4
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | my $filename_or_fh = !blessed $_[-1] || !$_[-1]->isa('PDL') ? pop : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
builtin::blessed($_[-1]) && $_[-1]->isa('PDL')
MC/DC0%0/2
builtin::blessed($_[-1]) && $_[-1]->isa('PDL')
builtin::blessed($_[-1])
$_[-1]->isa('PDL')
Truth table0%0/3
A && B
A= builtin::blessed($_[-1])B= $_[-1]->isa('PDL')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $fn = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | my $C = { %$options }; # make a copy | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my @keys = qw/ debug header bad2empty encoding /; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my $O = { map { $_ => delete $C->{$_} } @keys }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | $O->{debug} = DEBUG unless defined $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | $O->{bad2empty} = 1 unless defined $O->{bad2empty}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | $O->{header} = ($fn eq '1D' ? 'auto' : 0) if !defined $O->{header}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # explicitely set | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | ▶ | $C->{sep_char} = ',' unless defined $C->{sep_char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | $C->{eol} = "\n" unless defined $C->{eol}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | ▶ | if (defined $O->{header}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | croak "FATAL: header should be arrayref" unless ref $O->{header} eq 'ARRAY' || $O->{header} eq 'auto'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $O->{"header"} eq "ARRAY" or $O->{"header"} eq "auto"
MC/DC0%0/2
ref $O->{"header"} eq "ARRAY" or $O->{"header"} eq "auto"
ref $O->{"header"} eq "ARRAY"
$O->{"header"} eq "auto"
Truth table0%0/3
A or B
A= ref $O->{"header"} eq "ARRAY"B= $O->{"header"} eq "auto"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | ▶ | if ($O->{header} eq 'auto') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | my @n; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | for (@_) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | push @n, my $n = $_->hdr->{col_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | $count++ if defined $n; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | ▶ | $O->{header} = $count > 0 ? \@n : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if (!defined $filename_or_fh) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $fh = \*STDOUT; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | elsif (openhandle($filename_or_fh)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | $fh = $filename_or_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | ▶ | open $fh, ">", $filename_or_fh or croak "$filename_or_fh: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | ▶ | binmode $fh, $O->{encoding} if $O->{encoding}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | return ($fh, $O, $C); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | sub _proc_rargs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 4 | ▶ | my $options = ref $_[-1] eq 'HASH' ? pop : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_proc_rargs: called CC=22 SCAR=34.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 4 | my ($fn, $filename_or_fh, $coli) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 4 | ▶ | croak "FATAL: invalid column ids" if defined $coli && ref $coli ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $coli and ref $coli ne "ARRAY"
MC/DC0%0/2
defined $coli and ref $coli ne "ARRAY"
defined $coli
ref $coli ne "ARRAY"
Truth table33%1/3
A and B
A= defined $coliB= ref $coli ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 4 | ▶ | croak "FATAL: invalid filename" unless defined $filename_or_fh; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | my $C = { %$options }; # make a copy | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # get options related to this module the rest will be passed to Text::CSV_XS | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | my @keys = qw/ reshape_inc fetch_chunk type debug empty2bad text2bad header decimal_comma encoding detect_datetime /; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | my $O = { map { $_ => delete $C->{$_} } @keys }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 4 | ▶ | $O->{fetch_chunk} ||= 40_000; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$O->{"fetch_chunk"} ||= 40000
MC/DC0%0/1
$O->{"fetch_chunk"} ||= 40000
$O->{"fetch_chunk"}
Truth table50%1/2
A
A= $O->{"fetch_chunk"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | $O->{reshape_inc} ||= 80_000; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$O->{"reshape_inc"} ||= 80000
MC/DC0%0/1
$O->{"reshape_inc"} ||= 80000
$O->{"reshape_inc"}
Truth table50%1/2
A
A= $O->{"reshape_inc"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | ▶ | $O->{type} ||= ($fn eq '1D' ? 'auto' : double); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$O->{"type"} ||= $fn eq "1D" ? "auto" : double()
MC/DC0%0/2
$O->{"type"} ||= $fn eq "1D" ? "auto" : double()
$O->{"type"}
$fn eq "1D" ? "auto" : double()
Truth table33%1/3
A ||= B
A= $O->{"type"}B= $fn eq "1D" ? "auto" : double()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | ▶ | $O->{header} ||= ($fn eq '1D' ? 'auto' : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$O->{"header"} ||= $fn eq "1D" ? "auto" : 0
MC/DC100%2/2
$O->{"header"} ||= $fn eq "1D" ? "auto" : 0
$O->{"header"}
$fn eq "1D" ? "auto" : 0
Truth table100%3/3
A ||= B
A= $O->{"header"}B= $fn eq "1D" ? "auto" : 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | ▶ | $O->{detect_datetime} = 1 unless defined $O->{detect_datetime}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | ▶ | if ($O->{detect_datetime} =~ /%/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $O->{strptime} = $O->{detect_datetime}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | $O->{detect_datetime} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 4 | ▶ | $O->{debug} = DEBUG unless defined $O->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | # reshape_inc cannot be lower than fetch_chunk | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 4 | ▶ | $O->{reshape_inc} = $O->{fetch_chunk} if $O->{reshape_inc} < $O->{fetch_chunk}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | # explicitely set column separator default | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | ▶ | $C->{sep_char} = ',' unless defined $C->{sep_char}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | # empty2bad implies some Text::CSV_XS extra options | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | ▶ | if ($O->{empty2bad}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $C->{blank_is_undef} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $C->{empty_is_undef} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 4 | ▶ | croak "FATAL: cannot use decimal_comma + sep_char ','" if $O->{decimal_comma} && $C->{sep_char} eq ','; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$O->{"decimal_comma"} and $C->{"sep_char"} eq ","
MC/DC0%0/2
$O->{"decimal_comma"} and $C->{"sep_char"} eq ","
$O->{"decimal_comma"}
$C->{"sep_char"} eq ","
Truth table33%1/3
A and B
A= $O->{"decimal_comma"}B= $C->{"sep_char"} eq ","
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 4 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 4 | ▶ | if (openhandle($filename_or_fh)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $fh = $filename_or_fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 4 | ▶ | open $fh, "<", $filename_or_fh or croak "$filename_or_fh: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 4 | ▶ | binmode $fh, $O->{encoding} if $O->{encoding}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 4 | return ($fh, $coli, $O, $C); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | sub _init_1D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 2 | ▶ | my ($coli, $firstline, $O) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_1D: called CC=29 SCAR=58.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | my $colcount = scalar @$firstline; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | my $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | ▶ | if (!defined $coli) { # take all columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 2 | $cols = $colcount; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | $cols = scalar @$coli; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | ▶ | ($_<0 || $_>$colcount) and croak "FATAL: invalid column '$_' (column count=$colcount)" for (@$coli); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ < 0 or $_ > $colcount
MC/DC0%0/2
$_ < 0 or $_ > $colcount
$_ < 0
$_ > $colcount
Truth table0%0/3
A or B
A= $_ < 0B= $_ > $colcount
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 2 | ▶ | croak "FATAL: invalid column count" unless $cols && $cols > 0 && $cols <= $colcount; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$cols and $cols > 0 and $cols <= $colcount
$cols and $cols > 0
MC/DC0%0/3
$cols and $cols > 0 and $cols <= $colcount
$cols
$cols > 0
$cols <= $colcount
Truth table25%1/4
A and B and C
A= $colsB= $cols > 0C= $cols <= $colcount
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 2 | my @c_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | my @c_pack; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 2 | my @c_sizeof; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | my @c_pdl; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | my @c_bad; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 2 | my @c_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | my @c_idx; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | ▶ | if (ref $O->{type} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 0 | $c_type[$_] = $O->{type}->[$_] for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | $c_type[$_] = $O->{type} for (0..$cols-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 2 | my @c_dt; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 2 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 2 | ▶ | if (!defined $c_type[$_] || $c_type[$_] eq 'auto') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition33%1/3
not defined $c_type[$_] or $c_type[$_] eq "auto"
MC/DC0%0/2
not defined $c_type[$_] or $c_type[$_] eq "auto"
not defined $c_type[$_]
$c_type[$_] eq "auto"
Truth table33%1/3
not(A) or B
A= not defined $c_type[$_]B= $c_type[$_] eq "auto"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 2 | $c_type[$_] = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 2 | ▶ | if ($O->{detect_datetime}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 2 | croak "PDL::DateTime not installed" if NODATETIME; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 0 | ▶ | my $v = $O->{strptime} ? _strptime($firstline->[$_], $O->{strptime}) : PDL::DateTime::dt2ll($firstline->[$_]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | ▶ | $c_dt[$_] = $O->{strptime} ? $O->{strptime} : 'datetime'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | $c_type[$_] = longlong; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | elsif ($c_type[$_] eq 'datetime') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | croak "PDL::DateTime not installed" if NODATETIME; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | $c_dt[$_] = 'datetime'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | $c_type[$_] = longlong; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | elsif ($c_type[$_] =~ /%/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | $c_dt[$_] = $c_type[$_]; # strptime format | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 0 | $c_type[$_] = longlong; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | ▶ | $c_type[$_] = double if !$c_type[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | my $allocated = $O->{reshape_inc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | for (0..$cols-1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 0 | ▶ | $c_type[$_] = double if !defined $c_type[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | $c_pack[$_] = $pck{$c_type[$_]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | ▶ | croak "FATAL: your perl does not support 64bitint (avoid using type longlong)" if $c_pack[$_] eq 'q' && NO64BITINT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$c_pack[$_] eq "q" and 0
MC/DC0%0/1
$c_pack[$_] eq "q" and 0
$c_pack[$_] eq "q"
Truth table0%0/2
A
A= $c_pack[$_] eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | croak "FATAL: invalid type '$c_type[$_]' for column $_" if !$c_pack[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | $c_sizeof[$_] = length pack($c_pack[$_], 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | $c_pdl[$_] = $c_dt[$_] ? PDL::DateTime->new(zeroes(longlong, $allocated)) : zeroes($c_type[$_], $allocated); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | $c_dataref[$_] = $c_pdl[$_]->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 0 | $c_bad[$_] = $c_pdl[$_]->badvalue; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | $c_idx[$_] = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | my $big = PDL::Core::howbig($c_pdl[$_]->get_datatype); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | ▶ | croak "FATAL: column $_ mismatch (type=$c_type[$_], sizeof=$c_sizeof[$_], big=$big)" if $big != $c_sizeof[$_]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | ▶ | return (\@c_type, \@c_pack, \@c_sizeof, \@c_pdl, \@c_bad, \@c_dataref, \@c_idx, (@c_dt > 0 ? \@c_dt : undef), $allocated, $cols); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | sub _init_2D { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 2 | ▶ | my ($coli, $colcount, $O) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_2D: called CC=12 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 2 | my $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 2 | ▶ | if (!defined $coli) { # take all columns | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 2 | $cols = $colcount; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $cols = scalar @$coli; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | ▶ | ($_<0 || $_>$colcount) and croak "FATAL: invalid column '$_' (column count=$colcount)" for (@$coli); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$_ < 0 or $_ > $colcount
MC/DC0%0/2
$_ < 0 or $_ > $colcount
$_ < 0
$_ > $colcount
Truth table0%0/3
A or B
A= $_ < 0B= $_ > $colcount
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 2 | ▶ | croak "FATAL: invalid column count" unless $cols && $cols > 0 && $cols <= $colcount; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$cols and $cols > 0 and $cols <= $colcount
$cols and $cols > 0
MC/DC0%0/3
$cols and $cols > 0 and $cols <= $colcount
$cols
$cols > 0
$cols <= $colcount
Truth table25%1/4
A and B and C
A= $colsB= $cols > 0C= $cols <= $colcount
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | my $c_type = $O->{type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 2 | my $c_pack = $pck{$c_type}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 2 | ▶ | croak "FATAL: your perl does not support 64bitint (avoid using type longlong)" if $c_pack eq 'q' && NO64BITINT; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$c_pack eq "q" and 0
MC/DC0%0/1
$c_pack eq "q" and 0
$c_pack eq "q"
Truth table50%1/2
A
A= $c_pack eq "q"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | croak "FATAL: invalid type '$c_type' for column $_" if !$c_pack; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 2 | my $allocated = $O->{reshape_inc}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 2 | my $c_sizeof = length pack($c_pack, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 2 | my $c_pdl = zeroes($c_type, $cols, $allocated); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 2 | my $c_dataref = $c_pdl->get_dataref; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 2 | my $c_bad = $c_pdl->badvalue; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 2 | my $big = PDL::Core::howbig($c_pdl->get_datatype); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 2 | ▶ | croak "FATAL: column $_ size mismatch (type=$c_type, sizeof=$c_sizeof, big=$big)" if $big != $c_sizeof; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 2 | return ($c_type, $c_pack, $c_sizeof, $c_pdl, $c_bad, $c_dataref, $allocated, $cols); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | sub _strptime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | my ($string, $format) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strptime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 0 | return eval { int POSIX::floor(Time::Piece->strptime($string, $format)->epoch * 1_000_000 + 0.5) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||