Image/ExifTool/FITS.pm

filter: Statementstmt 84.7% 50 / 59 Branchbran 61.1% 22 / 36 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 72.7% 80 / 110 CC 21 SCAR 33.4
CC
21
Cov
74%
ProcessFITS
32.0
BEGIN
1.0
BEGIN
1.0
CRAP 28.1
« Image/ExifTool/FLIF.pm ↑ Summary Image/ExifTool/Palm.pm »
1 #------------------------------------------------------------------------------
2 # File: FITS.pm
3 #
4 # Description: Read Flexible Image Transport System metadata
5 #
6 # Revisions: 2018/03/07 - P. Harvey Created
7 #
8 # References: 1) https://fits.gsfc.nasa.gov/fits_standard.html
9 #------------------------------------------------------------------------------
10  
11 package Image::ExifTool::FITS;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 $VERSION = '1.02';
18  
19 # FITS tags (ref 1)
20 1 %Image::ExifTool::FITS::Main = (
21 GROUPS => { 2 => 'Image' },
22 NOTES => q{
23 This table lists some standard Flexible Image Transport System (FITS) tags,
24 but ExifTool will extract any other tags found. See
25 L<https://fits.gsfc.nasa.gov/fits_standard.html> for the specification.
26 },
27 TELESCOP => 'Telescope',
28 BACKGRND => 'Background',
29 INSTRUME => 'Instrument',
30 OBJECT => 'Object',
31 OBSERVER => 'Observer',
32 DATE => { Name => 'CreateDate', Groups => { 2 => 'Time' } },
33 AUTHOR => { Name => 'Author', Groups => { 2 => 'Author' } },
34 REFERENC => 'Reference',
35 'DATE-OBS'=> { Name => 'ObservationDate', Groups => { 2 => 'Time' } },
36 'TIME-OBS'=> { Name => 'ObservationTime', Groups => { 2 => 'Time' } },
37 'DATE-END'=> { Name => 'ObservationDateEnd', Groups => { 2 => 'Time' } },
38 'TIME-END'=> { Name => 'ObservationTimeEnd', Groups => { 2 => 'Time' } },
39 COMMENT => { Name => 'Comment', PrintConv => '$val =~ s/^ +//; $val',
40 Notes => 'leading spaces are removed if L<PrintConv|../ExifTool.html#PrintConv> is enabled' },
41 HISTORY => { Name => 'History', PrintConv => '$val =~ s/^ +//; $val',
42 Notes => 'leading spaces are removed if L<PrintConv|../ExifTool.html#PrintConv> is enabled' },
43 );
44  
45 #------------------------------------------------------------------------------
46 # Read information in a FITS document
47 # Inputs: 0) ExifTool ref, 1) dirInfo ref
48 # Returns: 1 on success, 0 if this wasn't a valid FITS file
49 sub ProcessFITS($$)
50 1 ▶{
Subroutine ProcessFITS: called CC=21 SCAR=34.7
Pod undocumented
51 1 my ($et, $dirInfo) = @_;
52 1 my $raf = $$dirInfo{RAF};
53 1 my ($buff, $tag, $continue);
54  
55 1 ▶ return 0 unless $raf->Read($buff, 80) == 80 and $buff =~ /^SIMPLE = {20}T/;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 80) == 80 and $buff =~ /^SIMPLE = {20}T/ 0 1 1
Condition33%1/3
$raf->Read($buff, 80) == 80 and $buff =~ /^SIMPLE = {20}T/
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($buff, 80) == 80 and $buff =~ /^SIMPLE = {20}T/
$raf->Read($buff, 80) == 80 $buff =~ /^SIMPLE = {20}T/
Truth table33%1/3
A and B
A= $raf->Read($buff, 80) == 80B= $buff =~ /^SIMPLE = {20}T/
ABresult
0X0
100
111
56 1 $et->SetFileType();
57 1 my $tagTablePtr = GetTagTable('Image::ExifTool::FITS::Main');
58  
59 1 for (;;) {
60 37 ▶ $raf->Read($buff, 80) == 80 or $et->Warn('Truncated FITS header'), last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 80) == 80 or $et->Warn("Truncated FITS header"), last 37 0 37
61 37 my $key = substr($buff, 0, 8);
62 37 $key =~ s/ +$//; # remove trailing space from key
63 37 ▶ if ($key eq 'CONTINUE') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'CONTINUE') { } 0 37 37
64 0 ▶ defined $continue or $et->Warn('Unexpected FITS CONTINUE keyword'), next;
Branch: 1 branch
BranchTrueFalseTotal
defined $continue or $et->Warn("Unexpected FITS CONTINUE keyword"), next 0 0 0
65 } else {
66 37 ▶ if (defined $continue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $continue) 0 37 37
67 # the previous value wasn't continued, so store with the trailing '&'
68 0 $et->HandleTag($tagTablePtr, $tag, $continue . '&');
69 0 undef $continue;
70 }
71 37 ▶ last if $key eq 'END';
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "END" 1 36 37
72 # make sure the key is valid
73 36 ▶ $key =~ /^[-_A-Z0-9]*$/ or $et->Warn('Format error in FITS header'), last;
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^[-_A-Z0-9]*$/ or $et->Warn("Format error in FITS header"), last 36 0 36
74 36 ▶ if ($key eq 'COMMENT' or $key eq 'HISTORY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq "COMMENT" or $key eq "HISTORY") 6 30 36
Condition66%2/3
$key eq "COMMENT" or $key eq "HISTORY"
l!l&&r!l&&!r
6030
MC/DC50%1/2
$key eq "COMMENT" or $key eq "HISTORY"
$key eq "COMMENT" $key eq "HISTORY"
Truth table66%2/3
A or B
A= $key eq "COMMENT"B= $key eq "HISTORY"
ABresult
1X1
011
000
75 6 my $val = substr($buff, 8); # comments start in column 9
76 6 $val =~ s/ +$//; # remove trailing spaces
77 6 $et->HandleTag($tagTablePtr, $key, $val);
78 6 next;
79 }
80 # ignore other lines that aren't tags
81 30 ▶ next unless substr($buff,8,2) eq '= ';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($buff, 8, 2) eq "= " 0 30 30
82 # save tag name (avoiding potential conflict with ExifTool variables)
83 30 ▶ $tag = $Image::ExifTool::specialTags{$key} ? "_$key" : $key;
Branch: 1 branch
BranchTrueFalseTotal
$Image::ExifTool::specialTags{$key} ? : 0 30 30
84 # add to tag table if necessary
85 30 ▶ unless ($$tagTablePtr{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr->{$tag}) 23 7 30
86 23 my $name = ucfirst lc $tag; # make tag name lower case with leading capital
87 23 $name =~ s/_(.)/\U$1/g; # remove all '_' and capitalize subsequent letter
88 23 AddTagToTable($tagTablePtr, $tag, { Name => $name });
89 }
90 }
91 30 my $val = substr($buff, 10);
92 # parse quoted values
93 30 ▶ if ($val =~ /^'(.*?)'(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^'(.*?)'(.*)/) { } 18 12 30
elsif (defined $continue) { } 0 12 12
94 18 ($val, $buff) = ($1, $2);
95 18 ▶ while ($buff =~ /^('.*?)'(.*)/) { # handle escaped quotes
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ /^('.*?)'(.*)/) 0 18 18
96 0 $val .= $1;
97 0 $buff = $2;
98 }
99 18 $val =~ s/ +$//; # remove trailing spaces
100 18 ▶ if (defined $continue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $continue) 0 18 18
101 0 $val = $continue . $val;
102 0 undef $continue;
103 }
104 # check for possible continuation, removing trailing '&'
105 18 ▶ $val =~ s/\&$// and $continue = $val, next;
Branch: 1 branch
BranchTrueFalseTotal
$val =~ s/\&$// and $continue = $val, next 0 18 18
106 } elsif (defined $continue) {
107 0 $et->Warn('Invalid FITS CONTINUE value');
108 0 next;
109 } else {
110 12 $val =~ s/ *(\/.*)?$//; # remove trailing spaces and comment
111 12 ▶ next unless length $val; # ignore undefined values
Branch: 1 branch
BranchTrueFalseTotal
unless length $val 0 12 12
112 12 $val =~ s/^ +//; # remove leading spaces
113 # re-format floating-point values to use 'e'
114 12 ▶ $val =~ tr/DE/e/ if $val =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?([ED]([+-]?\d+))?$/;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?([ED]([+-]?\d+))?$/ 10 2 12
115 }
116 30 $et->HandleTag($tagTablePtr, $tag, $val);
117 }
118 1 return 1;
119 }
120  
121 1 1; # end
122  
123 __END__
« Image/ExifTool/FLIF.pm ↑ Summary Image/ExifTool/Palm.pm »