source: main/trunk/greenstone2/perllib/cpan/Image/ExifTool/FITS.pm@ 34921

Last change on this file since 34921 was 34921, checked in by anupama, 3 years ago

Committing the improvements to EmbeddedMetaPlugin's processing of Keywords vs other metadata fields. Keywords were literally stored as arrays of words rather than phrases in PDFs (at least in Diego's sample PDF), whereas other meta fields like Subjects and Creators stored them as arrays of phrases. To get both to work, Kathy updated EXIF to a newer version, to retrieve the actual EXIF values stored in the PDF. And Kathy and Dr Bainbridge came up with a new option that I added called apply_join_before_split_to_metafields that's a regex which can list the metadata fields to apply the join_before_split to and whcih previously always got applied to all metadata fields. Now it's applied to any *Keywords metafields by default, as that's the metafield we have experience of that behaves differently to the others, as it stores by word instead of phrases. Tested on Diego's sample PDF. Diego has double-checked it to works on his sample PDF too, setting the split char to ; and turning on the join_before_split and leaving apply_join_before_split_to_metafields at its default of .*Keywords. File changes are strings.properties for the tooltip, the plugin introducing the option and working with it and Kathy's EXIF updates affecting cpan/File and cpan/Image.

File size: 5.2 KB
Line 
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
11package Image::ExifTool::FITS;
12
13use strict;
14use vars qw($VERSION);
15use Image::ExifTool qw(:DataAccess :Utils);
16
17$VERSION = '1.01';
18
19# FITS tags (ref 1)
20%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 => 'Comment',
40 HISTORY => 'History',
41);
42
43#------------------------------------------------------------------------------
44# Read information in a FITS document
45# Inputs: 0) ExifTool ref, 1) dirInfo ref
46# Returns: 1 on success, 0 if this wasn't a valid FITS file
47sub ProcessFITS($$)
48{
49 my ($et, $dirInfo) = @_;
50 my $raf = $$dirInfo{RAF};
51 my ($buff, $tag, $continue);
52
53 return 0 unless $raf->Read($buff, 80) == 80 and $buff =~ /^SIMPLE = {20}T/;
54 $et->SetFileType();
55 my $tagTablePtr = GetTagTable('Image::ExifTool::FITS::Main');
56
57 for (;;) {
58 $raf->Read($buff, 80) == 80 or $et->Warn('Truncated FITS header'), last;
59 my $key = substr($buff, 0, 8);
60 $key =~ s/ +$//; # remove trailing space from key
61 if ($key eq 'CONTINUE') {
62 defined $continue or $et->WarnOnce('Unexpected FITS CONTINUE keyword'), next;
63 } else {
64 if (defined $continue) {
65 # the previous value wasn't continued, so store with the trailing '&'
66 $et->HandleTag($tagTablePtr, $tag, $continue . '&');
67 undef $continue;
68 }
69 last if $key eq 'END';
70 # make sure the key is valid
71 $key =~ /^[-_A-Z0-9]*$/ or $et->Warn('Format error in FITS header'), last;
72 # ignore lines other than tags, COMMENT or HISTORY
73 next unless substr($buff,8,2) eq '= ' or $key eq 'COMMENT' or $key eq 'HISTORY';
74 # save tag name (avoiding potential conflict with ExifTool variables)
75 $tag = $Image::ExifTool::specialTags{$key} ? "_$key" : $key;
76 # add to tag table if necessary
77 unless ($$tagTablePtr{$tag}) {
78 my $name = ucfirst lc $tag; # make tag name lower case with leading capital
79 $name =~ s/_(.)/\U$1/g; # remove all '_' and capitalize subsequent letter
80 AddTagToTable($tagTablePtr, $tag, { Name => $name });
81 }
82 }
83 my $val = substr($buff, 10);
84 # parse quoted values
85 if ($val =~ /^'(.*?)'(.*)/) {
86 ($val, $buff) = ($1, $2);
87 while ($buff =~ /^('.*?)'(.*)/) { # handle escaped quotes
88 $val .= $1;
89 $buff = $2;
90 }
91 $val =~ s/ +$//; # remove trailing spaces
92 if (defined $continue) {
93 $val = $continue . $val;
94 undef $continue;
95 }
96 # check for possible continuation, removing trailing '&'
97 $val =~ s/\&$// and $continue = $val, next;
98 } elsif (defined $continue) {
99 $et->WarnOnce('Invalid FITS CONTINUE value');
100 next;
101 } else {
102 $val =~ s/ *(\/.*)?$//; # remove trailing spaces and comment
103 next unless length $val; # ignore undefined values
104 $val =~ s/^ +//; # remove leading spaces
105 # re-format floating-point values to use 'e'
106 $val =~ tr/DE/e/ if $val =~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?([ED]([+-]?\d+))?$/;
107 }
108 $et->HandleTag($tagTablePtr, $tag, $val);
109 }
110 return 1;
111}
112
1131; # end
114
115__END__
116
117=head1 NAME
118
119Image::ExifTool::FITS - Read Flexible Image Transport System metadata
120
121=head1 SYNOPSIS
122
123This module is used by Image::ExifTool
124
125=head1 DESCRIPTION
126
127This module contains definitions required by Image::ExifTool to read meta
128information from FITS (Flexible Image Transport System) images.
129
130=head1 AUTHOR
131
132Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
133
134This library is free software; you can redistribute it and/or modify it
135under the same terms as Perl itself.
136
137=head1 REFERENCES
138
139=over 4
140
141=item L<https://fits.gsfc.nasa.gov/fits_standard.html>
142
143=back
144
145=head1 SEE ALSO
146
147L<Image::ExifTool::TagNames/FITS Tags>,
148L<Image::ExifTool(3pm)|Image::ExifTool>
149
150=cut
151
Note: See TracBrowser for help on using the repository browser.