Image/ExifTool/Geotag.pm

filter: Statementstmt 63.1% 544 / 862 Branchbran 48.1% 358 / 744 Conditioncond 35.4% 123 / 347 MC/DCmcdc 14.2% 28 / 196 Subroutinesub 88.2% 15 / 17 Podpod 0.0% 0 / 12 totaltotal 49.0% 1068 / 2178 CC 510 SCAR 89.0
CC
510
Cov
52%
LoadTrackLog
12038.9
SetGeoValues
1657.9
ConvertGeosync
236.9
CRAP 7336.6
« Image/ExifTool/QuickTimeStream.pl ↑ Summary Image/ExifTool/Plot.pm »
1 #------------------------------------------------------------------------------
2 # File: Geotag.pm
3 #
4 # Description: Geotagging utility routines
5 #
6 # Revisions: 2009/04/01 - P. Harvey Created
7 # 2009/09/27 - PH Added Geosync feature
8 # 2009/06/25 - PH Read Garmin TCX track logs
9 # 2009/09/11 - PH Read ITC GPS track logs
10 # 2012/01/08 - PH Extract orientation information from PTNTHPR
11 # 2012/05/08 - PH Read Winplus Beacon .TXT files
12 # 2015/05/30 - PH Read Bramor gEO log files
13 # 2016/07/13 - PH Added ability to geotag date/time only
14 # 2019/07/02 - PH Added ability to read IMU CSV files
15 # 2019/11/10 - PH Also write pitch to CameraElevationAngle
16 # 2020/12/01 - PH Added ability to read DJI CSV log files
17 # 2022/06/21 - PH Added ability to read Google Takeout JSON files
18 # 2024/04/23 - PH Added ability to read more OpenTracks GPS tags
19 # 2024/08/28 - PH Added support for new Google Takeout JSON format
20 # 2024/11/26 - PH Also write GPSMeasureMode and GPSDOP
21 # 2024/11/05 - PH Added support for Google Maps "Export timeline data"
22 # JSON format
23 # 2025/09/22 - PH Added ability to read Columbus CSV log files
24 # 2026/01/24 - PH Added GeoUserTag feature
25 #
26 # References: 1) http://www.topografix.com/GPX/1/1/
27 # 2) http://www.gpsinformation.org/dale/nmea.htm#GSA
28 # 3) http://code.google.com/apis/kml/documentation/kmlreference.html
29 # 4) http://www.fai.org/gliding/system/files/tech_spec_gnss.pdf
30 #------------------------------------------------------------------------------
31  
32 package Image::ExifTool::Geotag;
33  
34 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
36 3 ▶use Image::ExifTool qw(:Public);
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use Image::ExifTool::GPS;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 3 $VERSION = '1.87';
40  
41 10 ▶sub JITTER() { return 2 } # maximum time jitter
Subroutine JITTER: called CC=1 SCAR=0.0
Pod undocumented
42  
43 sub GetTime($);
44 sub SetGeoValues($$;$);
45 sub PrintFixTime($);
46 sub PrintFix($@);
47 sub InitUserTags($);
48  
49 # XML tags that we recognize (keys are forced to lower case)
50 3 my %xmlTag = (
51 lat => 'lat', # GPX
52 latitude => 'lat', # Garmin
53 latitudedegrees => 'lat', # Garmin TCX
54 lon => 'lon', # GPX
55 longitude => 'lon', # Garmin
56 longitudedegrees => 'lon', # Garmin TCX
57 ele => 'alt', # GPX
58 elevation => 'alt', # PH
59 alt => 'alt', # PH
60 altitude => 'alt', # Garmin
61 altitudemeters => 'alt', # Garmin TCX
62 'time' => 'time', # GPX/Garmin
63 fix => 'fixtype', # GPX
64 hdop => 'hdop', # GPX
65 vdop => 'vdop', # GPX
66 pdop => 'pdop', # GPX
67 sat => 'nsats', # GPX
68 atemp => 'atemp', # GPX (Garmin 550t)
69 when => 'time', # KML
70 coordinates => 'coords', # KML
71 coord => 'coords', # KML, as written by Google Location History
72 begin => 'begin', # KML TimeSpan
73 end => 'time', # KML TimeSpan
74 course => 'dir', # (written by Arduino)
75 pitch => 'pitch', # (written by Arduino)
76 roll => 'roll', # (written by Arduino)
77 speed => 'speed', # (OpenTrack gpx)
78 accuracy_horizontal => 'err',#(OpenTrack gpx)
79 # XML containers (fix is reset at the opening tag of these properties)
80 wpt => '', # GPX
81 trkpt => '', # GPX
82 rtept => '', # GPX
83 trackpoint => '', # Garmin
84 placemark => '', # KML
85 );
86  
87 3 my %userTag; # user-defined XML tags
88  
89 # fix information keys which must be interpolated around a circle
90 3 my %cyclical = (lon => 1, track => 1, dir => 1, pitch => 1, roll => 1);
91 3 my %cyc180 = (lon => 1, pitch => 1, roll => 1); # wraps from 180 to -180
92  
93 # fix information keys for each of our general categories
94 3 my %fixInfoKeys = (
95 'pos' => [ 'lat', 'lon' ],
96 track => [ 'track', 'speed' ],
97 alt => [ 'alt' ],
98 orient => [ 'dir', 'pitch', 'roll' ],
99 atemp => [ 'atemp' ],
100 err => [ 'err' ],
101 dop => [ 'hdop', 'vdop', 'pdop' ],
102 );
103  
104 # category for select keys
105 3 my %keyCategory = (
106 dir => 'orient',
107 pitch => 'orient',
108 roll => 'orient',
109 hdop => 'dop',
110 pdop => 'dop',
111 vdop => 'dop',
112 );
113  
114 # tags which may exist separately in some formats (eg. CSV)
115 3 my %sepTags = (
116 dir => 1, pitch => 1, roll => 1, track => 1, speed => 1,
117 # (plus other tags we don't want to scan outwards for)
118 hdop => 1, pdop => 1, vdop => 1,
119 );
120  
121 # conversion factors for GPSSpeed (standard EXIF units only)
122 3 my %speedConv = (
123 'K' => 1.852, # km/h per knot
124 'M' => 1.150779448, # mph per knot
125 'k' => 'K', # (allow lower case)
126 'm' => 'M',
127 'km/h' => 'K', # (allow other formats)
128 'mph' => 'M',
129 );
130  
131 # all recognized speed conversion factors (non-EXIF included)
132 3 my %otherConv = (
133 'km/h' => 1.852,
134 'mph' => 1.150779448,
135 'm/s' => 0.514444,
136 );
137  
138 3 my $secPerDay = 24 * 3600; # a useful constant
139  
140 #------------------------------------------------------------------------------
141 # Split a line of CSV
142 # Inputs: 0) line to split, 1) delimiter
143 # Returns: list of items
144 sub SplitCSV($$)
145 94 ▶{
Subroutine SplitCSV: called CC=6 SCAR=24.6
Pod undocumented
146 94 my ($line, $delim) = @_;
147 94 my @toks = split /\Q$delim/, $line;
148 94 my (@vals, $v);
149 94 ▶ while (@toks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@toks) 465 94 559
150 465 ($v = shift @toks) =~ s/^ +//; # remove leading spaces
151 465 ▶ if ($v =~ s/^"//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^"//) 0 465 465
152 # quoted value must end in an odd number of quotes
153 0 ▶ while ($v !~ /("+)\s*$/ or not length($1) & 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /("+)\s*$/ and length $1 & 1) 0 0 0
Condition0%0/3
$v =~ /("+)\s*$/ and length $1 & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$v =~ /("+)\s*$/ and length $1 & 1
$v =~ /("+)\s*$/ length $1 & 1
Truth table0%0/3
A and B
A= $v =~ /("+)\s*$/B= length $1 & 1
ABresult
0X0
100
111
154 0 ▶ last unless @toks;
Branch: 1 branch
BranchTrueFalseTotal
unless @toks 0 0 0
155 0 $v .= $delim . shift @toks;
156 }
157 0 $v =~ s/"\s*$//; # remove trailing quote and whitespace
158 0 $v =~ s/""/"/g; # un-escape quotes
159 }
160 465 push @vals, $v;
161 }
162 94 return @vals;
163 }
164  
165 #------------------------------------------------------------------------------
166 # Load GPS track log file
167 # Inputs: 0) ExifTool ref, 1) track log data or file name
168 # Returns: geotag hash data reference or error string
169 # - the geotag hash has the following members:
170 # Points - hash of GPS fix information hashes keyed by Unix time
171 # Times - list of sorted Unix times (keys of Points hash)
172 # NoDate - flag if some points have no date (ie. referenced to 1970:01:01)
173 # IsDate - flag if some points have date
174 # Has - hash of flags for available information (track, orient, alt)
175 # - the fix information hash may contain:
176 # lat - signed latitude (required)
177 # lon - signed longitude (required)
178 # alt - signed altitude
179 # time - fix time in UTC as XML string
180 # fixtype- type of fix ('none'|'2d'|'3d'|'dgps'|'pps')
181 # pdop - dilution of precision
182 # hdop - horizontal DOP
183 # vdop - vertical DOP
184 # sats - comma-separated list of active satellites
185 # nsats - number of active satellites
186 # track - track heading (deg true)
187 # dir - image direction (deg true)
188 # pitch - pitch angle (deg)
189 # roll - roll angle (deg)
190 # speed - speed (knots)
191 # first - flag set for first fix of track
192 # - concatenates new data with existing track data stored in ExifTool NEW_VALUE
193 # for the Geotag tag
194 sub LoadTrackLog($$;$)
195 10 ▶{
Subroutine LoadTrackLog: called CC=301 SCAR=94.0
Pod undocumented
196 10 local ($_, $/, *EXIFTOOL_TRKFILE);
197 10 my ($et, $val) = @_;
198 10 my ($raf, $from, $time, $isDate, $noDate, $noDateChanged, $lastDate, $dateFlarm);
199 10 my ($nmeaStart, $fixSecs, @fixTimes, $lastFix, %nmea, @csvHeadings, $sortFixes);
200 10 my ($canCut, $cutPDOP, $cutHDOP, $cutSats, $e0, $e1, @tmp, $trackFile, $trackTime);
201 10 my ($scaleSpeed, $startTime);
202  
203 10 ▶ unless (eval { require Time::Local }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Time::Local } }) 0 10 10
204 0 return 'Geotag feature requires Time::Local installed';
205 }
206 10 InitUserTags($et);
207  
208 # add data to existing track
209 10 ▶ my $geotag = $et->GetNewValue('Geotag') || { };
Condition100%2/2
$et->GetNewValue('Geotag') || {}
l!l
28
MC/DC100%1/1
$et->GetNewValue('Geotag') || {}
$et->GetNewValue('Geotag')
Truth table100%2/2
A
A= $et->GetNewValue('Geotag')
Aresult
11
00
210  
211 # initialize track points lookup
212 10 my $points = $$geotag{Points};
213 10 ▶ $points or $points = $$geotag{Points} = { };
Branch: 1 branch
BranchTrueFalseTotal
$points or $points = ($geotag->{"Points"} = {}) 2 8 10
214  
215 # get lookup for available information types
216 10 my $has = $$geotag{Has};
217 10 ▶ $has or $has = $$geotag{Has} = { 'pos' => 1 };
Branch: 1 branch
BranchTrueFalseTotal
$has or $has = ($geotag->{"Has"} = {"pos", 1}) 2 8 10
218  
219 10 my $format = '';
220 # is $val track log data?
221 10 ▶ if ($val =~ /^(\xef\xbb\xbf)?<(\?xml|gpx)[\s>]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(\xef\xbb\xbf)?<(\?xml|gpx)[\s>]/) { } 0 10 10
elsif ($val =~ /(\x0d\x0a|\x0d|\x0a)/) { } 0 10 10
222 0 $format = 'XML';
223 0 $/ = '>'; # set input record separator to '>' for XML/GPX data
224 } elsif ($val =~ /(\x0d\x0a|\x0d|\x0a)/) {
225 0 $/ = $1;
226 } else {
227 # $val is track file name
228 10 ▶ if ($et->Open(\*EXIFTOOL_TRKFILE, $val)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($et->Open(\*EXIFTOOL_TRKFILE, $val)) { } 9 1 10
elsif ($val eq 'DATETIMEONLY') { } 1 0 1
229 9 $trackFile = $val;
230 9 $raf = File::RandomAccess->new(\*EXIFTOOL_TRKFILE);
231 9 ▶ unless ($raf->Read($_, 256)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($_, 256)) 0 9 9
232 0 close EXIFTOOL_TRKFILE;
233 0 return "Empty track file '${val}'";
234 }
235 # look for XML or GPX header (might as well allow UTF-8 BOM)
236 9 ▶ if (/^(\xef\xbb\xbf)?<(\?xml|gpx)[\s>]/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^(\xef\xbb\xbf)?<(\?xml|gpx)[\s>]/) { } 4 5 9
elsif (/(\x0d\x0a|\x0d|\x0a)/) { } 5 0 5
237 4 $format = 'XML';
238 4 $/ = '>'; # set input record separator to '>' for XML/GPX data
239 } elsif (/(\x0d\x0a|\x0d|\x0a)/) {
240 5 $/ = $1;
241 } else {
242 0 close EXIFTOOL_TRKFILE;
243 0 return "Invalid track file '${val}'";
244 }
245 9 $raf->Seek(0,0);
246 9 $from = "file '${val}'";
247 } elsif ($val eq 'DATETIMEONLY') {
248 1 $$geotag{DateTimeOnly} = 1;
249 1 $$geotag{IsDate} = 1;
250 1 $et->VPrint(0, 'Geotagging date/time only');
251 1 return $geotag;
252 } else {
253 0 return "Error opening GPS file '${val}'";
254 }
255 }
256 9 ▶ unless ($from) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($from) 0 9 9
257 # set up RAF for reading log file in memory
258 0 $raf = File::RandomAccess->new(\$val);
259 0 $from = 'data';
260 }
261  
262 # initialize cuts
263 9 my $maxHDOP = $et->Options('GeoMaxHDOP');
264 9 my $maxPDOP = $et->Options('GeoMaxPDOP');
265 9 my $minSats = $et->Options('GeoMinSats');
266 9 ▶ my $isCut = $maxHDOP || $maxPDOP || $minSats;
Condition33%2/6
$maxHDOP || $maxPDOP || $minSats
l!l&&r!l&&!r
009
$maxHDOP or $maxPDOP
l!l&&r!l&&!r
009
MC/DC0%0/3
$maxHDOP || $maxPDOP || $minSats
$maxHDOP $maxPDOP $minSats
Truth table25%1/4
A or B || C
A= $maxHDOPB= $maxPDOPC= $minSats
ABCresult
1XX1
01X1
0011
0000
267  
268 9 my $numPoints = 0;
269 9 my $skipped = 0;
270 9 my $lastSecs = 0;
271 9 my $fix = { };
272 9 my $csvDelim = $et->Options('CSVDelim');
273 9 ▶ $csvDelim = ',' unless defined $csvDelim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $csvDelim 9 0 9
274 9 my (@saveFix, @saveTime, $timeSpan);
275 9 for (;;) {
276 397 ▶ $raf->ReadLine($_) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($_) or last 388 9 397
277 # determine file format
278 388 ▶ if (not $format) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($format) 7 381 388
279 7 s/^\xef\xbb\xbf//; # remove leading BOM if it exists
280 7 ▶ if (/^\xff\xfe|\xfe\xff/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^\xff\xfe|\xfe\xff/) 0 7 7
281 0 return "ExifTool doesn't yet read UTF16-format track logs";
282 }
283 7 ▶ if (/^<(\?xml|gpx)[\s>]/) { # look for XML or GPX header
Branch: 10 branches
BranchTrueFalseTotal
if (/^<(\?xml|gpx)[\s>]/) { } 0 7 7
elsif (/^.*\$([A-Z]{2}(RMC|GGA|GLL|ZDA)|PMGNTRK),/) { } 2 5 7
elsif (/^A(FLA|XSY|FIL)/) { } 0 5 5
elsif (/^HFDTE(?:DATE:)?(\d{2})(\d{2})(\d{2})/) { } 1 4 5
elsif ($nmeaStart and /^B/) { } 0 4 4
elsif (/^TP,D,/) { } 0 4 4
elsif (/^\s*\d+\s+.*\sypr\s*$/ and (@tmp = split(' ', $_, 0)) == 12) { } 1 3 4
elsif (/\b(GPS)?Date/i && /\b(GPS)?(Date)?Time/i || /\bTime\(seconds\)/i and /\Q$csvDelim\E/) { } 1 2 3
elsif (/"(timelineObjects|placeVisit|activitySegment|latitudeE7)"\s*:/) { } 0 2 2
elsif (/"(durationMinutesOffsetFromStartTime|startTime)"\s*:/) { } 0 2 2
284 0 $format = 'XML';
285 # check for NMEA sentence
286 # (must ONLY start with ones that have timestamps! eg. not GSA or PTNTHPR!)
287 } elsif (/^.*\$([A-Z]{2}(RMC|GGA|GLL|ZDA)|PMGNTRK),/) {
288 2 $format = 'NMEA';
289 2 ▶ $nmeaStart = $2 || $1; # save type of first sentence
Condition66%2/3
$2 || $1
l!l&&r!l&&!r
110
MC/DC0%0/2
$2 || $1
$2 $1
Truth table66%2/3
A || B
A= $2B= $1
ABresult
1X1
011
000
290 } elsif (/^A(FLA|XSY|FIL)/) {
291 # (don't set format yet because we want to read HFDTE first)
292 0 $nmeaStart = 'B' ;
293 0 next;
294 } elsif (/^HFDTE(?:DATE:)?(\d{2})(\d{2})(\d{2})/) {
295 1 ▶ my $year = $3 + ($3 >= 70 ? 1900 : 2000);
Branch: 1 branch
BranchTrueFalseTotal
$3 >= 70 ? : 0 1 1
296 1 $dateFlarm = Time::Local::timegm(0,0,0,$1,$2-1,$year);
297 1 $nmeaStart = 'B' ;
298 1 $format = 'IGC';
299 1 next;
300 ▶ } elsif ($nmeaStart and /^B/) {
Condition33%1/3
$nmeaStart and /^B/
!ll&&!rl&&r
400
MC/DC0%0/2
$nmeaStart and /^B/
$nmeaStart /^B/
Truth table33%1/3
A and B
A= $nmeaStartB= /^B/
ABresult
0X0
100
111
301 # parse IGC fixes without a date
302 0 $format = 'IGC';
303 } elsif (/^TP,D,/) {
304 0 $format = 'Winplus';
305 ▶ } elsif (/^\s*\d+\s+.*\sypr\s*$/ and (@tmp=split) == 12) {
Condition66%2/3
/^\s*\d+\s+.*\sypr\s*$/ and (@tmp = split(' ', $_, 0)) == 12
!ll&&!rl&&r
301
MC/DC50%1/2
/^\s*\d+\s+.*\sypr\s*$/ and (@tmp = split(' ', $_, 0)) == 12
/^\s*\d+\s+.*\sypr\s*$/ (@tmp = split(' ', $_, 0)) == 12
Truth table66%2/3
A and B
A= /^\s*\d+\s+.*\sypr\s*$/B= (@tmp = split(' ', $_, 0)) == 12
ABresult
0X0
100
111
306 1 $format = 'Bramor';
307 ▶ } elsif (((/\b(GPS)?Date/i and /\b(GPS)?(Date)?Time/i) or /\bTime\(seconds\)/i) and /\Q$csvDelim/) {
Condition55%5/9
/\b(GPS)?Date/i && /\b(GPS)?(Date)?Time/i || /\bTime\(seconds\)/i and /\Q$csvDelim\E/
!ll&&!rl&&r
201
/\b(GPS)?Date/i and /\b(GPS)?(Date)?Time/i or /\bTime\(seconds\)/i
l!l&&r!l&&!r
012
/\b(GPS)?Date/i and /\b(GPS)?(Date)?Time/i
!ll&&!rl&&r
300
MC/DC25%1/4
/\b(GPS)?Date/i && /\b(GPS)?(Date)?Time/i || /\bTime\(seconds\)/i and /\Q$csvDelim\E/
/\b(GPS)?Date/i /\b(GPS)?(Date)?Time/i /\bTime\(seconds\)/i /\Q$csvDelim\E/
Truth table25%2/8
A and B or C and D
A= /\b(GPS)?Date/iB= /\b(GPS)?(Date)?Time/iC= /\bTime\(seconds\)/iD= /\Q$csvDelim\E/
ABCDresult
0X0X0
100X0
11X00
0X100
10100
11X11
0X111
10111
308 1 chomp;
309 1 @csvHeadings = SplitCSV($_, $csvDelim);
310 1 ▶ my $isColumbus = ($csvHeadings[0] and $csvHeadings[0] eq 'INDEX'); # (Columbus GPS logger)
Condition33%1/3
$csvHeadings[0] && $csvHeadings[0] eq 'INDEX'
!ll&&!rl&&r
010
MC/DC0%0/2
$csvHeadings[0] && $csvHeadings[0] eq 'INDEX'
$csvHeadings[0] $csvHeadings[0] eq 'INDEX'
Truth table33%1/3
A && B
A= $csvHeadings[0]B= $csvHeadings[0] eq 'INDEX'
ABresult
0X0
100
111
311 1 $format = 'CSV';
312 # convert recognized headings to our parameter names
313 1 foreach (@csvHeadings) {
314 5 my $head = $_;
315 5 my $param;
316 5 my $xtra = '';
317 5 s/^GPS ?//; # remove leading "GPS" to simplify regex patterns
318 5 ▶ if (/^Time ?\(seconds\)$/i) { # DJI
Branch: 13 branches
BranchTrueFalseTotal
if (/^Time ?\(seconds\)$/i) { } 1 4 5
elsif (/^Date ?Time/i) { } 0 4 4
elsif (/^Date/i) { } 0 4 4
elsif (/^Time(?! ?\(text\))/i) { } 0 4 4
elsif (/^(Pos)?Lat/i) { } 1 3 4
elsif (/^(Pos)?Lon/i) { } 1 2 3
elsif (/^(Pos)?(Alt|Height)/i) { } 0 2 2
elsif (/^Speed/i) { } 0 2 2
elsif (/^(Angle)?(Heading|Track|Bearing)/i) { } 0 2 2
elsif (/^(Angle)?Pitch/i or /^Camera ?Elevation ?Angle/i) { } 0 2 2
elsif (/^(Angle)?Roll/i) { } 0 2 2
elsif (/^Img ?Dir/i) { } 0 2 2
elsif ($userTag{lc $_}) { } 0 2 2
319 # DJI CSV log files have a column "Time(seconds)" which is seconds since
320 # the start of the flight. The date/time is obtained from the file name.
321 1 $param = 'runtime';
322 1 ▶ if ($trackFile and $trackFile =~ /(\d{4})-(\d{2})-(\d{2})[^\/]+(\d{2})-(\d{2})-(\d{2})[^\/]*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trackFile and $trackFile =~ m[(\d{4})-(\d{2})-(\d{2})[^/]+(\d{2})-(\d{2})-(\d{2})[^/]*$]) { } 1 0 1
Condition33%1/3
$trackFile and $trackFile =~ m[(\d{4})-(\d{2})-(\d{2})[^/]+(\d{2})-(\d{2})-(\d{2})[^/]*$]
!ll&&!rl&&r
001
MC/DC0%0/2
$trackFile and $trackFile =~ m[(\d{4})-(\d{2})-(\d{2})[^/]+(\d{2})-(\d{2})-(\d{2})[^/]*$]
$trackFile $trackFile =~ m[(\d{4})-(\d{2})-(\d{2})[^/]+(\d{2})-(\d{2})-(\d{2})[^/]*$]
Truth table33%1/3
A and B
A= $trackFileB= $trackFile =~ m[(\d{4})-(\d{2})-(\d{2})[^/]+(\d{2})-(\d{2})-(\d{2})[^/]*$]
ABresult
0X0
100
111
323 1 $trackTime = Image::ExifTool::TimeLocal($6,$5,$4,$3,$2-1,$1);
324 1 my $utc = PrintFixTime($trackTime);
325 1 my $tzs = Image::ExifTool::TimeZoneString([$6,$5,$4,$3,$2-1,$1-1900],$trackTime);
326 1 $et->VPrint(2, " DJI start time: $utc (local timezone is $tzs)\n");
327 } else {
328 0 return 'Error getting start time from file name for DJI CSV track file';
329 }
330 } elsif (/^Date ?Time/i) { # ExifTool addition
331 0 $param = 'datetime';
332 } elsif (/^Date/i) {
333 0 $param = 'date';
334 } elsif (/^Time(?! ?\(text\))/i) { # (ignore DJI "Time(text)" column)
335 0 $param = 'time';
336 } elsif (/^(Pos)?Lat/i) {
337 1 $param = 'lat';
338 1 ▶ /ref$/i and $param .= 'ref';
Branch: 1 branch
BranchTrueFalseTotal
/ref$/i and $param .= 'ref' 0 1 1
339 } elsif (/^(Pos)?Lon/i) {
340 1 $param = 'lon';
341 1 ▶ /ref$/i and $param .= 'ref';
Branch: 1 branch
BranchTrueFalseTotal
/ref$/i and $param .= 'ref' 0 1 1
342 } elsif (/^(Pos)?(Alt|Height)/i) {
343 0 $param = 'alt';
344 } elsif (/^Speed/i) {
345 0 $param = 'speed';
346 # (recognize units in brackets)
347 0 ▶ if (m{\((mph|km/h|m/s)\)}) {
Branch: 2 branches
BranchTrueFalseTotal
if (m[\((mph|km/h|m/s)\)]) { } 0 0 0
elsif ($isColumbus) { } 0 0 0
348 0 $scaleSpeed = $otherConv{$1};
349 0 $xtra = " in $1";
350 } elsif ($isColumbus) { # (Columbus GPS logger)
351 0 $scaleSpeed = $otherConv{'km/h'};
352 0 $xtra = " in km/h";
353 } else {
354 0 $xtra = ' in knots';
355 }
356 } elsif (/^(Angle)?(Heading|Track|Bearing)/i) {
357 0 $param = 'track';
358 ▶ } elsif (/^(Angle)?Pitch/i or /^Camera ?Elevation ?Angle/i) {
Condition33%1/3
/^(Angle)?Pitch/i or /^Camera ?Elevation ?Angle/i
l!l&&r!l&&!r
002
MC/DC0%0/2
/^(Angle)?Pitch/i or /^Camera ?Elevation ?Angle/i
/^(Angle)?Pitch/i /^Camera ?Elevation ?Angle/i
Truth table33%1/3
A or B
A= /^(Angle)?Pitch/iB= /^Camera ?Elevation ?Angle/i
ABresult
1X1
011
000
359 0 $param = 'pitch';
360 } elsif (/^(Angle)?Roll/i) {
361 0 $param = 'roll';
362 } elsif (/^Img ?Dir/i) {
363 0 $param = 'dir';
364 } elsif ($userTag{lc $_}) {
365 0 $param = $userTag{lc $_};
366 }
367 5 ▶ if ($param) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param) { } 3 2 5
368 3 $et->VPrint(2, "CSV column '${head}' is $param$xtra\n");
369 3 $_ = $param;
370 } else {
371 2 $et->VPrint(2, "CSV column '${head}' ignored\n");
372 2 $_ = ''; # ignore this column
373 }
374 }
375 1 next;
376 } elsif (/"(timelineObjects|placeVisit|activitySegment|latitudeE7)"\s*:/) {
377 # Google Takeout JSON format
378 0 $format = 'JSON';
379 0 $sortFixes = 1; # (fixes are not all in order for this format)
380 } elsif (/"(durationMinutesOffsetFromStartTime|startTime)"\s*:/) {
381 0 $format = 'JSON'; # new Google Takeout JSON format (fixes seem to be in order)
382 0 $raf->Seek(0,0); # rewind to start of file
383 } else {
384 # search only first 50 lines of file for a valid fix
385 2 ▶ last if ++$skipped > 50;
Branch: 1 branch
BranchTrueFalseTotal
if ++$skipped > 50 0 2 2
386 2 next;
387 }
388 }
389 #
390 # XML format (GPX, KML, Garmin XML/TCX etc)
391 #
392 384 ▶ if ($format eq 'XML') {
Branch: 5 branches
BranchTrueFalseTotal
if ($format eq 'XML') { } 243 141 384
elsif ($format eq 'Winplus') { } 0 141 141
elsif ($format eq 'Bramor') { } 7 134 141
elsif ($format eq 'CSV') { } 93 41 134
elsif ($format eq 'JSON') { } 0 41 41
393 243 my (@args, $arg, $tok, $td, $value);
394 243 ▶ if (/^([^<]+<\/[^>]+>)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[^([^<]+</[^>]+>)]) { } 99 144 243
395 # handle simple property
396 99 s/^\s+</</; # remove whitespace if only whitespace before "<"
397 # Workaround for KML generated by Google Location History:
398 # lat/lon/alt are space-separated; we want commas.
399 99 s{(\S+)\s+(\S+)\s+(\S+)(</gx:coord>)}{$1,$2,$3$4};
400 99 push @args, $_;
401 } else {
402 # handle property with attributes
403 144 s/\s*=\s*(['"])\s*/=$1/g; # remove unnecessary white space in attributes
404 144 push @args, split;
405 }
406 243 foreach $arg (@args) {
407 # parse attributes (eg. GPX 'lat' and 'lon')
408 # (note: ignore namespace prefixes if they exist)
409 319 ▶ if ($arg =~ /^(\w+:)?(\w+)=(['"])(.*?)\3/g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^(\w+:)?(\w+)=(['"])(.*?)\3/g) 63 256 319
410 63 my $tag = $xmlTag{lc $2};
411 63 ▶ $tag = $userTag{lc $2} unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 27 36 63
412 63 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 36 27 63
413 36 $$fix{$tag} = $4;
414 36 ▶ if ($keyCategory{$tag}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($keyCategory{$tag}) { } 0 36 36
elsif ($tag eq 'alt') { } 0 36 36
elsif ($tag eq 'atemp' or $tag eq 'speed' or $tag eq 'err') { } 0 36 36
415 0 $$has{$keyCategory{$tag}} = 1;
416 } elsif ($tag eq 'alt') {
417 # validate altitude
418 0 ▶ undef $$fix{alt} if defined $$fix{alt} and $$fix{alt} !~ /^[+-]?\d+\.?\d*/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/ 0 0 0
Condition0%0/3
defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
defined $fix->{"alt"} not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
Truth table0%0/3
A and not(B)
A= defined $fix->{"alt"}B= not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
ABresult
0X0
100
111
419 0 ▶ $$has{alt} = 1 if $$fix{alt}; # set "has altitude" flag if appropriate
Branch: 1 branch
BranchTrueFalseTotal
if $fix->{"alt"} 0 0 0
420 ▶ } elsif ($tag eq 'atemp' or $tag eq 'speed' or $tag eq 'err') {
Condition33%2/6
$tag eq "atemp" or $tag eq "speed" or $tag eq "err"
l!l&&r!l&&!r
0036
$tag eq "atemp" or $tag eq "speed"
l!l&&r!l&&!r
0036
MC/DC0%0/3
$tag eq "atemp" or $tag eq "speed" or $tag eq "err"
$tag eq "atemp" $tag eq "speed" $tag eq "err"
Truth table25%1/4
A or B or C
A= $tag eq "atemp"B= $tag eq "speed"C= $tag eq "err"
ABCresult
1XX1
01X1
0011
0000
421 0 $$has{$tag} = 1;
422 }
423 }
424 }
425 # loop through XML elements
426 319 ▶ while ($arg =~ m{([^<>]*)<(/)?(\w+:)?(\w+)(>|$)}g) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ m[([^<>]*)<(/)?(\w+:)?(\w+)(>|$)]g) 234 319 553
427 234 $tok = lc $4;
428 234 my $tag = $xmlTag{$tok};
429 234 ▶ $tag = $userTag{$tok} unless defined $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag 92 142 234
430 # parse as a simple property if this element has a value
431 234 ▶ if (defined $tag and not $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tag and not $tag) 42 192 234
Condition100%3/3
defined $tag and not $tag
!ll&&!rl&&r
9210042
MC/DC100%2/2
defined $tag and not $tag
defined $tag not $tag
Truth table100%3/3
A and not(B)
A= defined $tagB= not $tag
ABresult
0X0
100
111
432 # a containing property was opened or closed
433 42 ▶ if (not $2) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $2) { } 21 21 42
elsif ($fix and $lastFix and %$fix) { } 20 1 21
434 # opened: start a new fix
435 21 $lastFix = $fix = { };
436 21 undef @saveFix;
437 21 next;
438 ▶ } elsif ($fix and $lastFix and %$fix) {
Condition50%3/6
$fix and $lastFix and %$fix
!ll&&!rl&&r
0120
$fix and $lastFix
!ll&&!rl&&r
0021
MC/DC33%1/3
$fix and $lastFix and %$fix
$fix $lastFix %$fix
Truth table50%2/4
A and B and C
A= $fixB= $lastFixC= %$fix
ABCresult
0XX0
10X0
1100
1111
439 # closed: transfer additional tags from current fix
440 20 foreach (keys %$fix) {
441 80 ▶ $$lastFix{$_} = $$fix{$_} unless defined $$lastFix{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lastFix->{$_} 0 80 80
442 }
443 20 undef $lastFix;
444 }
445 }
446 213 ▶ if (length $1) {
Branch: 2 branches
BranchTrueFalseTotal
if (length $1) { } 71 142 213
elsif ($tok eq 'td') { } 0 142 142
447 71 ▶ if ($tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) 50 21 71
448 50 ▶ if ($tag eq 'coords') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'coords') { } 3 47 50
449 # save other fixes if there are more than one
450 3 ▶ if (defined $$fix{lon} and defined $$fix{lat} and defined $$fix{alt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fix->{"lon"} and defined $fix->{"lat"} and defined $fix->{"alt"}) 0 3 3
Condition33%2/6
defined $fix->{"lon"} and defined $fix->{"lat"} and defined $fix->{"alt"}
!ll&&!rl&&r
300
defined $fix->{"lon"} and defined $fix->{"lat"}
!ll&&!rl&&r
300
MC/DC0%0/3
defined $fix->{"lon"} and defined $fix->{"lat"} and defined $fix->{"alt"}
defined $fix->{"lon"} defined $fix->{"lat"} defined $fix->{"alt"}
Truth table25%1/4
A and B and C
A= defined $fix->{"lon"}B= defined $fix->{"lat"}C= defined $fix->{"alt"}
ABCresult
0XX0
10X0
1100
1111
451 0 push @saveFix, [ @$fix{'lon','lat','alt'} ];
452 }
453 # read KML "Point" coordinates
454 3 @$fix{'lon','lat','alt'} = split ',', $1;
455 3 ▶ $$has{alt} = 1 if $$fix{alt};
Branch: 1 branch
BranchTrueFalseTotal
if $fix->{"alt"} 0 3 3
456 } else {
457 47 ▶ if ($tok eq 'when' and $$fix{'time'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq 'when' and $fix->{'time'}) { } 0 47 47
Condition66%2/3
$tok eq "when" and $fix->{"time"}
!ll&&!rl&&r
4430
MC/DC0%0/2
$tok eq "when" and $fix->{"time"}
$tok eq "when" $fix->{"time"}
Truth table66%2/3
A and B
A= $tok eq "when"B= $fix->{"time"}
ABresult
0X0
100
111
458 0 push @saveTime, $1; # flightaware KML stores times in array
459 } else {
460 47 $$fix{$tag} = $1;
461 }
462 47 ▶ if ($keyCategory{$tag}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($keyCategory{$tag}) { } 0 47 47
elsif ($tag eq 'alt') { } 20 27 47
elsif ($tag eq 'atemp' or $tag eq 'speed' or $tag eq 'err') { } 0 27 27
463 0 $$has{$keyCategory{$tag}} = 1;
464 } elsif ($tag eq 'alt') {
465 # validate altitude
466 20 ▶ undef $$fix{alt} if defined $$fix{alt} and $$fix{alt} !~ /^[+-]?\d+\.?\d*/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/ 0 20 20
Condition33%1/3
defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
!ll&&!rl&&r
0200
MC/DC0%0/2
defined $fix->{"alt"} and not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
defined $fix->{"alt"} not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
Truth table33%1/3
A and not(B)
A= defined $fix->{"alt"}B= not $fix->{"alt"} =~ /^[+-]?\d+\.?\d*/
ABresult
0X0
100
111
467 20 ▶ $$has{alt} = 1 if $$fix{alt}; # set "has altitude" flag if appropriate
Branch: 1 branch
BranchTrueFalseTotal
if $fix->{"alt"} 20 0 20
468 ▶ } elsif ($tag eq 'atemp' or $tag eq 'speed' or $tag eq 'err') {
Condition33%2/6
$tag eq "atemp" or $tag eq "speed" or $tag eq "err"
l!l&&r!l&&!r
0027
$tag eq "atemp" or $tag eq "speed"
l!l&&r!l&&!r
0027
MC/DC0%0/3
$tag eq "atemp" or $tag eq "speed" or $tag eq "err"
$tag eq "atemp" $tag eq "speed" $tag eq "err"
Truth table25%1/4
A or B or C
A= $tag eq "atemp"B= $tag eq "speed"C= $tag eq "err"
ABCresult
1XX1
01X1
0011
0000
469 0 $$has{$tag} = 1;
470 }
471 }
472 }
473 71 next;
474 } elsif ($tok eq 'td') {
475 0 $td = 1;
476 }
477 # validate and store GPS fix
478 142 ▶ next unless defined $$fix{lat} and defined $$fix{lon};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fix->{"lat"} and defined $fix->{"lon"} 77 65 142
Condition100%3/3
defined $fix->{"lat"} and defined $fix->{"lon"}
!ll&&!rl&&r
75265
MC/DC100%2/2
defined $fix->{"lat"} and defined $fix->{"lon"}
defined $fix->{"lat"} defined $fix->{"lon"}
Truth table100%3/3
A and B
A= defined $fix->{"lat"}B= defined $fix->{"lon"}
ABresult
0X0
100
111
479 65 ▶ unless (defined $$fix{'time'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fix->{"time"}) 42 23 65
480 42 ▶ next unless @saveTime;
Branch: 1 branch
BranchTrueFalseTotal
unless @saveTime 42 0 42
481 0 $$fix{'time'} = shift @saveTime; # get next time in flightaware KML list
482 }
483 23 ▶ unless ($$fix{lat} =~ /^[+-]?\d+\.?\d*/ and $$fix{lon} =~ /^[+-]?\d+\.?\d*/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fix->{"lat"} =~ /^[+-]?\d+\.?\d*/ and $fix->{"lon"} =~ /^[+-]?\d+\.?\d*/) 0 23 23
Condition33%1/3
$fix->{"lat"} =~ /^[+-]?\d+\.?\d*/ and $fix->{"lon"} =~ /^[+-]?\d+\.?\d*/
!ll&&!rl&&r
0023
MC/DC0%0/2
$fix->{"lat"} =~ /^[+-]?\d+\.?\d*/ and $fix->{"lon"} =~ /^[+-]?\d+\.?\d*/
$fix->{"lat"} =~ /^[+-]?\d+\.?\d*/ $fix->{"lon"} =~ /^[+-]?\d+\.?\d*/
Truth table33%1/3
A and B
A= $fix->{"lat"} =~ /^[+-]?\d+\.?\d*/B= $fix->{"lon"} =~ /^[+-]?\d+\.?\d*/
ABresult
0X0
100
111
484 0 ▶ $e0 or $et->VPrint(0, "Coordinate format error in $from\n"), $e0 = 1;
Branch: 1 branch
BranchTrueFalseTotal
$e0 or $et->VPrint(0, "Coordinate format error in $from\n"), $e0 = 1 0 0 0
485 0 next;
486 }
487 23 ▶ unless (defined($time = GetTime($$fix{'time'}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined($time = &GetTime($fix->{"time"}))) 0 23 23
488 0 ▶ $e1 or $et->VPrint(0, "Timestamp format error in $from\n"), $e1 = 1;
Branch: 1 branch
BranchTrueFalseTotal
$e1 or $et->VPrint(0, "Timestamp format error in $from\n"), $e1 = 1 0 0 0
489 0 next;
490 }
491 23 $isDate = 1;
492 23 ▶ $canCut= 1 if defined $$fix{pdop} or defined $$fix{hdop} or defined $$fix{nsats};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"pdop"} or defined $fix->{"hdop"} or defined $fix->{"nsats"} 0 23 23
Condition33%2/6
defined $fix->{"pdop"} or defined $fix->{"hdop"} or defined $fix->{"nsats"}
l!l&&r!l&&!r
0023
defined $fix->{"pdop"} or defined $fix->{"hdop"}
l!l&&r!l&&!r
0023
MC/DC0%0/3
defined $fix->{"pdop"} or defined $fix->{"hdop"} or defined $fix->{"nsats"}
defined $fix->{"pdop"} defined $fix->{"hdop"} defined $fix->{"nsats"}
Truth table25%1/4
A or B or C
A= defined $fix->{"pdop"}B= defined $fix->{"hdop"}C= defined $fix->{"nsats"}
ABCresult
1XX1
01X1
0011
0000
493 # generate extra fixes assuming an equally spaced track
494 23 ▶ if ($$fix{begin}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fix->{"begin"}) 0 23 23
495 0 my $begin = GetTime($$fix{begin});
496 0 undef $$fix{begin};
497 0 ▶ if (defined $begin and $begin < $time) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $begin and $begin < $time) 0 0 0
Condition0%0/3
defined $begin and $begin < $time
!ll&&!rl&&r
000
MC/DC0%0/2
defined $begin and $begin < $time
defined $begin $begin < $time
Truth table0%0/3
A and B
A= defined $beginB= $begin < $time
ABresult
0X0
100
111
498 0 ▶ $$fix{span} = $timeSpan = ($timeSpan || 0) + 1;
Condition0%0/2
$timeSpan || 0
l!l
00
MC/DC0%0/1
$timeSpan || 0
$timeSpan
Truth table0%0/2
A
A= $timeSpan
Aresult
11
00
499 0 my $i;
500 # duplicate the fix if there is only one so we will have
501 # a fix and the start and end of the TimeSpan
502 0 ▶ @saveFix or push @saveFix, [ @$fix{'lon','lat','alt'} ];
Branch: 1 branch
BranchTrueFalseTotal
@saveFix or push @saveFix, [@$fix{"lon", "lat", "alt"}] 0 0 0
503 0 ▶ for ($i=0; $i<@saveFix; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @saveFix) 0 0 0
504 0 my $t = $begin + ($time - $begin) * ($i / scalar(@saveFix));
505 0 my %f;
506 0 @f{'lon','lat','alt'} = @{$saveFix[$i]};
507 0 ▶ $t += 0.001 if not $i and $$points{$t}; # (avoid dupicates)
Branch: 1 branch
BranchTrueFalseTotal
if not $i and $points->{$t} 0 0 0
Condition0%0/3
not $i and $points->{$t}
!ll&&!rl&&r
000
MC/DC0%0/2
not $i and $points->{$t}
not $i $points->{$t}
Truth table0%0/3
not(A) and B
A= not $iB= $points->{$t}
ABresult
0X0
100
111
508 0 $f{span} = $timeSpan;
509 0 $$points{$t} = \%f;
510 0 push @fixTimes, $t;
511 }
512 }
513 }
514 23 $$points{$time} = $fix;
515 23 push @fixTimes, $time; # save times of all fixes in order
516 23 $fix = { };
517 23 undef @saveFix;
518 23 ++$numPoints;
519 }
520 }
521 # last ditch check KML description for timestamp (assume it is UTC)
522 243 ▶ $$fix{'time'} = "$1T$2Z" if $td and not $$fix{'time'} and
Branch: 1 branch
BranchTrueFalseTotal
if $td and not $fix->{"time"} and /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/ 0 243 243
Condition33%2/6
$td and not $fix->{"time"} and /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/
!ll&&!rl&&r
24300
$td and not $fix->{"time"}
!ll&&!rl&&r
24300
MC/DC0%0/3
$td and not $fix->{"time"} and /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/
$td not $fix->{"time"} /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/
Truth table25%1/4
A and not(B) and C
A= $tdB= not $fix->{"time"}C= /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/
ABCresult
0XX0
10X0
1100
1111
523 /[\s>](\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2}(\.\d+)?)/;
524 243 next;
525 #
526 # Winplus Beacon text file
527 #
528 } elsif ($format eq 'Winplus') {
529 # TP,D, 44.933666667, -93.186555556, 10/26/2011, 19:07:28, 0
530 # latitude longitude date time
531 0 ▶ /^TP,D,\s*([-+]?\d+\.\d*),\s*([-+]?\d+\.\d*),\s*(\d+)\/(\d+)\/(\d{4}),\s*(\d+):(\d+):(\d+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
m[^TP,D,\s*([-+]?\d+\.\d*),\s*([-+]?\d+\.\d*),\s*(\d+)/(\d+)/(\d{4}),\s*(\d+):(\d+):(\d+)] or next 0 0 0
532 0 $$fix{lat} = $1;
533 0 $$fix{lon} = $2;
534 0 $time = Time::Local::timegm($8,$7,$6,$4,$3-1,$5);
535 96 DoneFix: $isDate = 1;
536 96 $$points{$time} = $fix;
537 96 push @fixTimes, $time;
538 96 $fix = { };
539 96 ++$numPoints;
540 96 next;
541 #
542 # Bramor gEO log file
543 #
544 } elsif ($format eq 'Bramor') {
545 # 1 0015 18.723675 50.672752 149 169.31 22/04/2015 07:06:55 169.31 8.88 28.07 ypr
546 # ? index latitude longitude alt track date time dir pitch roll
547 7 my @parts = split ' ', $_;
548 7 ▶ next unless @parts == 12 and $parts[11] eq 'ypr';
Branch: 1 branch
BranchTrueFalseTotal
unless @parts == 12 and $parts[11] eq "ypr" 3 4 7
Condition66%2/3
@parts == 12 and $parts[11] eq "ypr"
!ll&&!rl&&r
304
MC/DC50%1/2
@parts == 12 and $parts[11] eq "ypr"
@parts == 12 $parts[11] eq "ypr"
Truth table66%2/3
A and B
A= @parts == 12B= $parts[11] eq "ypr"
ABresult
0X0
100
111
549 4 my @d = split m{/}, $parts[6]; # date (dd/mm/YYYY)
550 4 my @t = split m{:}, $parts[7]; # time (HH:MM:SS)
551 4 ▶ next unless @d == 3 and @t == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @d == 3 and @t == 3 0 4 4
Condition33%1/3
@d == 3 and @t == 3
!ll&&!rl&&r
004
MC/DC0%0/2
@d == 3 and @t == 3
@d == 3 @t == 3
Truth table33%1/3
A and B
A= @d == 3B= @t == 3
ABresult
0X0
100
111
552 4 @$fix{qw(lat lon alt track dir pitch roll)} = @parts[2,3,4,5,8,9,10];
553 # (add the seconds afterwards in case some models have decimal seconds)
554 4 $time = Time::Local::timegm(0,$t[1],$t[0],$d[0],$d[1]-1,$d[2]) + $t[2];
555 # set necessary flags for extra available information
556 4 @$has{qw(alt track orient)} = (1,1,1);
557 4 goto DoneFix; # save this fix
558 } elsif ($format eq 'CSV') {
559 93 chomp;
560 93 my @vals = SplitCSV($_, $csvDelim);
561 #
562 # CSV format output of GPS/IMU POS system
563 # Date* - date in DD/MM/YYYY format
564 # Time* - time in HH:MM:SS.SSS format
565 # [Pos]Lat* - latitude in decimal degrees
566 # [Pos]Lon* - longitude in decimal degrees
567 # [Pos]Alt* - altitude in m relative to sea level
568 # [Angle]Heading* - GPSTrack in degrees true
569 # [Angle]Pitch* - pitch angle in degrees
570 # [Angle]Roll* - roll angle in degrees
571 # (ExifTool enhancements allow for standard tag names or descriptions as the column headings,
572 # add support for time zones and flexible coordinates, and allow new DateTime and Shift columns)
573 #
574 93 my ($param, $date, $secs, %neg);
575 93 foreach $param (@csvHeadings) {
576 461 my $val = shift @vals;
577 461 ▶ last unless defined $val and length($val);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and length $val 1 460 461
Condition66%2/3
defined $val and length $val
!ll&&!rl&&r
10460
MC/DC50%1/2
defined $val and length $val
defined $val length $val
Truth table66%2/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
578 460 ▶ next unless $param;
Branch: 1 branch
BranchTrueFalseTotal
unless $param 184 276 460
579 276 ▶ if ($param eq 'datetime') {
Branch: 8 branches
BranchTrueFalseTotal
if ($param eq 'datetime') { } 0 276 276
elsif ($param eq 'date') { } 0 276 276
elsif ($param eq 'time') { } 0 276 276
elsif ($param eq 'lat' or $param eq 'lon') { } 184 92 276
elsif ($param eq 'latref') { } 0 92 92
elsif ($param eq 'lonref') { } 0 92 92
elsif ($param eq 'runtime') { } 92 0 92
elsif ($param =~ /^_/) { } 0 0 0
580 # (fix formats like "24.07.2016 13:47:30")
581 0 $val =~ s/^(\d{2})[^\d](\d{2})[^\d](\d{4}) /$3:$2:$1 /;
582 0 ▶ local $SIG{'__WARN__'} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
583 0 my $dateTime = $et->InverseDateTime($val);
584 0 ▶ if ($dateTime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dateTime) 0 0 0
585 0 $date = Image::ExifTool::GetUnixTime($val, 2);
586 0 $secs = 0;
587 }
588 } elsif ($param eq 'date') {
589 0 ▶ if ($val =~ m{^(\d{2})/(\d{2})/(\d{4})$}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($val =~ m[^(\d{2})/(\d{2})/(\d{4})$]) { } 0 0 0
elsif ($val =~ /(\d{4}).*?(\d{2}).*?(\d{2})/) { } 0 0 0
elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { } 0 0 0
590 0 $date = Time::Local::timegm(0,0,0,$1,$2-1,$3);
591 } elsif ($val =~ /(\d{4}).*?(\d{2}).*?(\d{2})/) {
592 0 $date = Time::Local::timegm(0,0,0,$3,$2-1,$1);
593 } elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { # (Columbus GPS logger)
594 0 $date = Time::Local::timegm(0,0,0,$3,$2-1,$1+2000);
595 }
596 } elsif ($param eq 'time') {
597 0 ▶ if ($val =~ /^(\d{1,2}):(\d{2}):(\d{2}(\.\d+)?).*?(([-+])(\d{1,2}):?(\d{2}))?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(\d{1,2}):(\d{2}):(\d{2}(\.\d+)?).*?(([-+])(\d{1,2}):?(\d{2}))?/) { } 0 0 0
elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { } 0 0 0
598 0 $secs = (($1 * 60) + $2) * 60 + $3;
599 # adjust for time zone if specified
600 0 ▶ $secs += ($7 * 60 + $8) * ($6 eq '-' ? 60 : -60) if $5;
Branch: 2 branches
BranchTrueFalseTotal
if $5 0 0 0
$6 eq '-' ? : 0 0 0
601 } elsif ($val =~ /^(\d{2})(\d{2})(\d{2})$/) { # (Columbus GPS logger)
602 0 $secs = (($1 * 60) + $2) * 60 + $3;
603 }
604 ▶ } elsif ($param eq 'lat' or $param eq 'lon') {
Condition100%3/3
$param eq "lat" or $param eq "lon"
l!l&&r!l&&!r
929292
MC/DC100%2/2
$param eq "lat" or $param eq "lon"
$param eq "lat" $param eq "lon"
Truth table100%3/3
A or B
A= $param eq "lat"B= $param eq "lon"
ABresult
1X1
011
000
605 184 $$fix{$param} = Image::ExifTool::GPS::ToDegrees($val, 1);
606 } elsif ($param eq 'latref') {
607 0 ▶ $neg{lat} = 1 if $val =~ /^S/i;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^S/i 0 0 0
608 } elsif ($param eq 'lonref') {
609 0 ▶ $neg{lon} = 1 if $val =~ /^W/i;
Branch: 1 branch
BranchTrueFalseTotal
if $val =~ /^W/i 0 0 0
610 } elsif ($param eq 'runtime') {
611 92 $date = $trackTime;
612 92 $secs = $val;
613 } elsif ($param =~ /^_/) {
614 0 $$fix{$param} = $val;
615 } else {
616 0 ▶ $val /= $scaleSpeed if $scaleSpeed and $param eq 'speed';
Branch: 1 branch
BranchTrueFalseTotal
if $scaleSpeed and $param eq "speed" 0 0 0
Condition0%0/3
$scaleSpeed and $param eq "speed"
!ll&&!rl&&r
000
MC/DC0%0/2
$scaleSpeed and $param eq "speed"
$scaleSpeed $param eq "speed"
Truth table0%0/3
A and B
A= $scaleSpeedB= $param eq "speed"
ABresult
0X0
100
111
617 0 $$fix{$param} = $val;
618 0 ▶ $$has{$param} = 1 if $sepTags{$param};
Branch: 1 branch
BranchTrueFalseTotal
if $sepTags{$param} 0 0 0
619 }
620 }
621 # make coordinate negative according to reference direction if necessary
622 93 foreach $param (keys %neg) {
623 0 ▶ next unless defined $$fix{$param};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fix->{$param} 0 0 0
624 0 $$fix{$param} = -abs($$fix{$param});
625 }
626 93 ▶ if ($date and defined $secs and defined $$fix{lat} and defined $$fix{lon}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date and defined $secs and defined $fix->{"lat"} and defined $fix->{"lon"}) 92 1 93
Condition66%6/9
$date and defined $secs and defined $fix->{"lat"} and defined $fix->{"lon"}
!ll&&!rl&&r
1092
$date and defined $secs and defined $fix->{"lat"}
!ll&&!rl&&r
1092
$date and defined $secs
!ll&&!rl&&r
1092
MC/DC25%1/4
$date and defined $secs and defined $fix->{"lat"} and defined $fix->{"lon"}
$date defined $secs defined $fix->{"lat"} defined $fix->{"lon"}
Truth table40%2/5
A and B and C and D
A= $dateB= defined $secsC= defined $fix->{"lat"}D= defined $fix->{"lon"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
627 92 $time = $date + $secs;
628 92 ▶ $$has{alt} = 1 if defined $$fix{alt};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"alt"} 0 92 92
629 92 ▶ $$has{track} = 1 if defined $$fix{track};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"track"} 0 92 92
630 92 ▶ $$has{orient} = 1 if defined $$fix{pitch};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{"pitch"} 0 92 92
631 92 goto DoneFix;
632 }
633 1 next;
634 } elsif ($format eq 'JSON') {
635 # Google Takeout JSON format
636 0 ▶ if (/"(latitudeE7|longitudeE7|latE7|lngE7|timestamp|startTime|point|durationMinutesOffsetFromStartTime|time)"\s*:\s*"?(.*?)"?,?\s*[\x0d\x0a]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/"(latitudeE7|longitudeE7|latE7|lngE7|timestamp|startTime|point|durationMinutesOffsetFromStartTime|time)"\s*:\s*"?(.*?)"?,?\s*[\x0d\x0a]/) 0 0 0
637 0 ▶ if ($1 eq 'timestamp' or $1 eq 'time') {
Branch: 6 branches
BranchTrueFalseTotal
if ($1 eq 'timestamp' or $1 eq 'time') { } 0 0 0
elsif ($1 eq 'startTime') { } 0 0 0
elsif ($1 eq 'latitudeE7' or $1 eq 'latE7') { } 0 0 0
elsif ($1 eq 'longitudeE7' or $1 eq 'lngE7') { } 0 0 0
elsif ($1 eq 'point') { } 0 0 0
elsif ($1 eq 'durationMinutesOffsetFromStartTime' and defined $startTime) { } 0 0 0
Condition0%0/3
$1 eq "timestamp" or $1 eq "time"
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq "timestamp" or $1 eq "time"
$1 eq "timestamp" $1 eq "time"
Truth table0%0/3
A or B
A= $1 eq "timestamp"B= $1 eq "time"
ABresult
1X1
011
000
638 0 $time = GetTime($2);
639 0 ▶ goto DoneFix if $time and $$fix{lat} and $$fix{lon};
Branch: 1 branch
BranchTrueFalseTotal
if $time and $fix->{"lat"} and $fix->{"lon"} 0 0 0
Condition0%0/6
$time and $fix->{"lat"} and $fix->{"lon"}
!ll&&!rl&&r
000
$time and $fix->{"lat"}
!ll&&!rl&&r
000
MC/DC0%0/3
$time and $fix->{"lat"} and $fix->{"lon"}
$time $fix->{"lat"} $fix->{"lon"}
Truth table0%0/4
A and B and C
A= $timeB= $fix->{"lat"}C= $fix->{"lon"}
ABCresult
0XX0
10X0
1100
1111
640 } elsif ($1 eq 'startTime') { # (new format)
641 0 $startTime = GetTime($2);
642 ▶ } elsif ($1 eq 'latitudeE7' or $1 eq 'latE7') {
Condition0%0/3
$1 eq "latitudeE7" or $1 eq "latE7"
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq "latitudeE7" or $1 eq "latE7"
$1 eq "latitudeE7" $1 eq "latE7"
Truth table0%0/3
A or B
A= $1 eq "latitudeE7"B= $1 eq "latE7"
ABresult
1X1
011
000
643 0 $$fix{lat} = $2 * 1e-7;
644 ▶ } elsif ($1 eq 'longitudeE7' or $1 eq 'lngE7') {
Condition0%0/3
$1 eq "longitudeE7" or $1 eq "lngE7"
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq "longitudeE7" or $1 eq "lngE7"
$1 eq "longitudeE7" $1 eq "lngE7"
Truth table0%0/3
A or B
A= $1 eq "longitudeE7"B= $1 eq "lngE7"
ABresult
1X1
011
000
645 0 $$fix{lon} = $2 * 1e-7;
646 } elsif ($1 eq 'point') { # (new format)
647 0 my $point = $2;
648 0 my @coords = $point =~ /[-+]?\d+\.\d+/g;
649 0 ▶ @$fix{'lat','lon'} = @coords[0,1] if @coords == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @coords == 2 0 0 0
650 ▶ } elsif ($1 eq 'durationMinutesOffsetFromStartTime' and defined $startTime) { # (new format)
Condition0%0/3
$1 eq "durationMinutesOffsetFromStartTime" and defined $startTime
!ll&&!rl&&r
000
MC/DC0%0/2
$1 eq "durationMinutesOffsetFromStartTime" and defined $startTime
$1 eq "durationMinutesOffsetFromStartTime" defined $startTime
Truth table0%0/3
A and B
A= $1 eq "durationMinutesOffsetFromStartTime"B= defined $startTime
ABresult
0X0
100
111
651 0 $time = $startTime + $2 * 60;
652 # note: this assumes that "point" comes first, which it does in my sample
653 0 ▶ goto DoneFix if $time and $$fix{lat} and $$fix{lon};
Branch: 1 branch
BranchTrueFalseTotal
if $time and $fix->{"lat"} and $fix->{"lon"} 0 0 0
Condition0%0/6
$time and $fix->{"lat"} and $fix->{"lon"}
!ll&&!rl&&r
000
$time and $fix->{"lat"}
!ll&&!rl&&r
000
MC/DC0%0/3
$time and $fix->{"lat"} and $fix->{"lon"}
$time $fix->{"lat"} $fix->{"lon"}
Truth table0%0/4
A and B and C
A= $timeB= $fix->{"lat"}C= $fix->{"lon"}
ABCresult
0XX0
10X0
1100
1111
654 }
655 }
656 0 next;
657 }
658 41 my (%fix, $secs, $date, $nmea);
659 41 ▶ if ($format eq 'NMEA') {
Branch: 1 branch
BranchTrueFalseTotal
if ($format eq "NMEA") 19 22 41
660 # ignore unrecognized NMEA sentences
661 # (first 2 characters: GP=GPS, GL=GLONASS, GA=Gallileo, GN=combined, BD=Beidou)
662 19 ▶ next unless /^(.*)\$([A-Z]{2}(RMC|GGA|GLL|GSA|ZDA)|PMGNTRK|PTNTHPR),/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^(.*)\$([A-Z]{2}(RMC|GGA|GLL|GSA|ZDA)|PMGNTRK|PTNTHPR),/ 1 18 19
663 18 ▶ $nmea = $3 || $2;
Condition66%2/3
$3 || $2
l!l&&r!l&&!r
3150
MC/DC0%0/2
$3 || $2
$3 $2
Truth table66%2/3
A || B
A= $3B= $2
ABresult
1X1
011
000
664 18 ▶ $_ = substr($_, length($1)) if length($1);
Branch: 1 branch
BranchTrueFalseTotal
if length $1 0 18 18
665 }
666 #
667 # IGC (flarm) (ref 4)
668 #
669 40 ▶ if ($format eq 'IGC') {
Branch: 8 branches
BranchTrueFalseTotal
if ($format eq 'IGC') { } 22 18 40
elsif ($nmea eq 'RMC') { } 3 15 18
elsif ($nmea eq 'GGA') { } 0 15 15
elsif ($nmea eq 'GLL') { } 0 15 15
elsif ($nmea eq 'GSA') { } 0 15 15
elsif ($nmea eq 'ZDA') { } 0 15 15
elsif ($nmea eq 'PMGNTRK') { } 12 3 15
elsif ($nmea eq 'PTNTHPR') { } 3 0 3
670 # B0939564531208N00557021EA007670089100207
671 # BHHMMSSDDMMmmmNDDDMMmmmEAaaaaaAAAAAxxyy
672 # HH MM SS DD MM mmm DDD MM mmm aaaaa AAAAA
673 # 1 2 3 4 5 6 7 8 9 10 11 12 13 14
674 22 ▶ /^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})([NS])(\d{3})(\d{2})(\d{3})([EW])([AV])(\d{5})(\d{5})/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^B(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{3})([NS])(\d{3})(\d{2})(\d{3})([EW])([AV])(\d{5})(\d{5})/ or next 10 12 22
675 10 ▶ $fix{lat} = ($4 + ($5 + $6/1000)/60) * ($7 eq 'N' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$7 eq 'N' ? : 10 0 10
676 10 ▶ $fix{lon} = ($8 + ($9 +$10/1000)/60) * ($11 eq 'E' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$11 eq 'E' ? : 10 0 10
677 10 ▶ $fix{alt} = $12 eq 'A' ? $14 : undef;
Branch: 1 branch
BranchTrueFalseTotal
$12 eq 'A' ? : 10 0 10
678 10 $secs = (($1 * 60) + $2) * 60 + $3;
679 # wrap to next day if necessary
680 10 ▶ if ($dateFlarm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dateFlarm) 10 0 10
681 10 ▶ $dateFlarm += $secPerDay if $secs < $lastSecs - JITTER();
Branch: 1 branch
BranchTrueFalseTotal
if $secs < $lastSecs - &JITTER() 0 10 10
682 10 $date = $dateFlarm;
683 }
684 10 $nmea = 'B';
685 #
686 # NMEA RMC sentence (contains date)
687 #
688 } elsif ($nmea eq 'RMC') {
689 # $GPRMC,092204.999,A,4250.5589,S,14718.5084,E,0.00,89.68,211200,,*25
690 # $GPRMC,093657.007,,3652.835020,N,01053.104094,E,1.642,,290913,,,A*0F
691 # $GPRMC,hhmmss.sss,A/V,ddmm.mmmm,N/S,dddmm.mmmm,E/W,spd(knots),dir(deg),DDMMYY,,*cs
692 3 ▶ /^\$[A-Z]{2}RMC,(\d{2})(\d{2})(\d+(\.\d*)?),A?,(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),(\d*\.?\d*),(\d*\.?\d*),(\d{2})(\d{2})(\d+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$[A-Z]{2}RMC,(\d{2})(\d{2})(\d+(\.\d*)?),A?,(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),(\d*\.?\d*),(\d*\.?\d*),(\d{2})(\d{2})(\d+)/ or next 3 0 3
693 3 ▶ next if $13 > 31 or $14 > 12 or $15 > 99; # validate day/month/year
Branch: 1 branch
BranchTrueFalseTotal
if $13 > 31 or $14 > 12 or $15 > 99 0 3 3
Condition33%2/6
$13 > 31 or $14 > 12 or $15 > 99
l!l&&r!l&&!r
003
$13 > 31 or $14 > 12
l!l&&r!l&&!r
003
MC/DC0%0/3
$13 > 31 or $14 > 12 or $15 > 99
$13 > 31 $14 > 12 $15 > 99
Truth table25%1/4
A or B or C
A= $13 > 31B= $14 > 12C= $15 > 99
ABCresult
1XX1
01X1
0011
0000
694 3 ▶ $fix{lat} = (($5 || 0) + $6/60) * ($7 eq 'N' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$7 eq 'N' ? : 3 0 3
Condition50%1/2
$5 || 0
l!l
30
MC/DC0%0/1
$5 || 0
$5
Truth table50%1/2
A
A= $5
Aresult
11
00
695 3 ▶ $fix{lon} = (($8 || 0) + $9/60) * ($10 eq 'E' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$10 eq 'E' ? : 3 0 3
Condition50%1/2
$8 || 0
l!l
30
MC/DC0%0/1
$8 || 0
$8
Truth table50%1/2
A
A= $8
Aresult
11
00
696 3 ▶ $fix{speed} = $11 if length $11;
Branch: 1 branch
BranchTrueFalseTotal
if length $11 3 0 3
697 3 ▶ $fix{track} = $12 if length $12;
Branch: 1 branch
BranchTrueFalseTotal
if length $12 3 0 3
698 3 ▶ my $year = $15 + ($15 >= 70 ? 1900 : 2000);
Branch: 1 branch
BranchTrueFalseTotal
$15 >= 70 ? : 0 3 3
699 3 $secs = (($1 * 60) + $2) * 60 + $3;
700 3 $date = Time::Local::timegm(0,0,0,$13,$14-1,$year);
701 #
702 # NMEA GGA sentence (no date)
703 #
704 } elsif ($nmea eq 'GGA') {
705 # $GPGGA,092204.999,4250.5589,S,14718.5084,E,1,04,24.4,19.7,M,,,,0000*1F
706 # $GPGGA,093657.000,3652.835020,N,01053.104094,E,,8,,166.924,M,40.9,M,,*77
707 # $GPGGA,hhmmss.sss,ddmm.mmmm,N/S,dddmm.mmmm,E/W,0=invalid,sats,hdop,alt,M,...
708 0 ▶ /^\$[A-Z]{2}GGA,(\d{2})(\d{2})(\d+(\.\d*)?),(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),[1-6]?,(\d+)?,(\.\d+|\d+\.?\d*)?,(-?\d+\.?\d*)?,M?/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$[A-Z]{2}GGA,(\d{2})(\d{2})(\d+(\.\d*)?),(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),[1-6]?,(\d+)?,(\.\d+|\d+\.?\d*)?,(-?\d+\.?\d*)?,M?/ or next 0 0 0
709 0 ▶ $fix{lat} = (($5 || 0) + $6/60) * ($7 eq 'N' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$7 eq 'N' ? : 0 0 0
Condition0%0/2
$5 || 0
l!l
00
MC/DC0%0/1
$5 || 0
$5
Truth table0%0/2
A
A= $5
Aresult
11
00
710 0 ▶ $fix{lon} = (($8 || 0) + $9/60) * ($10 eq 'E' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$10 eq 'E' ? : 0 0 0
Condition0%0/2
$8 || 0
l!l
00
MC/DC0%0/1
$8 || 0
$8
Truth table0%0/2
A
A= $8
Aresult
11
00
711 0 @fix{qw(nsats hdop alt)} = ($11,$12,$13);
712 0 $secs = (($1 * 60) + $2) * 60 + $3;
713 0 $canCut = 1;
714 #
715 # NMEA GLL sentence (no date)
716 #
717 } elsif ($nmea eq 'GLL') {
718 # $GPGLL,4250.5589,S,14718.5084,E,092204.999,A*2D
719 # $GPGLL,ddmm.mmmm,N/S,dddmm.mmmm,E/W,hhmmss.sss,A/V*cs
720 0 ▶ /^\$[A-Z]{2}GLL,(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),(\d{2})(\d{2})(\d+(\.\d*)?),A/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$[A-Z]{2}GLL,(\d*?)(\d{1,2}\.\d+),([NS]),(\d*?)(\d{1,2}\.\d+),([EW]),(\d{2})(\d{2})(\d+(\.\d*)?),A/ or next 0 0 0
721 0 ▶ $fix{lat} = (($1 || 0) + $2/60) * ($3 eq 'N' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$3 eq 'N' ? : 0 0 0
Condition0%0/2
$1 || 0
l!l
00
MC/DC0%0/1
$1 || 0
$1
Truth table0%0/2
A
A= $1
Aresult
11
00
722 0 ▶ $fix{lon} = (($4 || 0) + $5/60) * ($6 eq 'E' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$6 eq 'E' ? : 0 0 0
Condition0%0/2
$4 || 0
l!l
00
MC/DC0%0/1
$4 || 0
$4
Truth table0%0/2
A
A= $4
Aresult
11
00
723 0 $secs = (($7 * 60) + $8) * 60 + $9;
724 #
725 # NMEA GSA sentence (satellite status, no date)
726 #
727 } elsif ($nmea eq 'GSA') {
728 # $GPGSA,A,3,04,05,,,,,,,,,,,pdop,hdop,vdop*HH
729 0 ▶ /^\$[A-Z]{2}GSA,[AM],([23]),((?:\d*,){11}(?:\d*)),(\d+\.?\d*|\.\d+)?,(\d+\.?\d*|\.\d+)?,(\d+\.?\d*|\.\d+)?\*/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$[A-Z]{2}GSA,[AM],([23]),((?:\d*,){11}(?:\d*)),(\d+\.?\d*|\.\d+)?,(\d+\.?\d*|\.\d+)?,(\d+\.?\d*|\.\d+)?\*/ or next 0 0 0
730 0 @fix{qw(fixtype sats pdop hdop vdop)} = ($1.'d',$2,$3,$4,$5);
731 # count the number of acquired satellites
732 0 my @a = ($fix{sats} =~ /\d+/g);
733 0 $fix{nsats} = scalar @a;
734 0 $canCut = 1;
735 #
736 # NMEA ZDA sentence (date/time, contains date)
737 #
738 } elsif ($nmea eq 'ZDA') {
739 # $GPZDA,093655.000,29,09,2013,,*58
740 # $GPZDA,hhmmss.ss,DD,MM,YYYY,tzh,tzm (hhmmss in UTC)
741 0 ▶ /^\$[A-Z]{2}ZDA,(\d{2})(\d{2})(\d{2}(\.\d*)?),(\d+),(\d+),(\d+)/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$[A-Z]{2}ZDA,(\d{2})(\d{2})(\d{2}(\.\d*)?),(\d+),(\d+),(\d+)/ or next 0 0 0
742 0 $secs = (($1 * 60) + $2) * 60 + $3;
743 0 $date = Time::Local::timegm(0,0,0,$5,$6-1,$7);
744 #
745 # Magellan eXplorist PMGNTRK (Proprietary MaGellaN TRacK) sentence (optional date)
746 #
747 } elsif ($nmea eq 'PMGNTRK') {
748 # $PMGNTRK,4415.026,N,07631.091,W,00092,M,185031.06,A,,020409*65
749 # $PMGNTRK,ddmm.mmm,N/S,dddmm.mmm,E/W,alt,F/M,hhmmss.ss,A/V,trkname,DDMMYY*cs
750 12 ▶ /^\$PMGNTRK,(\d+)(\d{2}\.\d+),([NS]),(\d+)(\d{2}\.\d+),([EW]),(-?\d+\.?\d*),([MF]),(\d{2})(\d{2})(\d+(\.\d*)?),A,(?:[^,]*,(\d{2})(\d{2})(\d+))?/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$PMGNTRK,(\d+)(\d{2}\.\d+),([NS]),(\d+)(\d{2}\.\d+),([EW]),(-?\d+\.?\d*),([MF]),(\d{2})(\d{2})(\d+(\.\d*)?),A,(?:[^,]*,(\d{2})(\d{2})(\d+))?/ or next 12 0 12
751 12 ▶ $fix{lat} = ($1 + $2/60) * ($3 eq 'N' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$3 eq 'N' ? : 12 0 12
752 12 ▶ $fix{lon} = ($4 + $5/60) * ($6 eq 'E' ? 1 : -1);
Branch: 1 branch
BranchTrueFalseTotal
$6 eq 'E' ? : 0 12 12
753 12 ▶ $fix{alt} = $8 eq 'M' ? $7 : $7 * 12 * 0.0254;
Branch: 1 branch
BranchTrueFalseTotal
$8 eq 'M' ? : 12 0 12
754 12 $secs = (($9 * 60) + $10) * 60 + $11;
755 12 ▶ if (defined $15) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $15) 12 0 12
756 12 ▶ next if $13 > 31 or $14 > 12 or $15 > 99; # validate day/month/year
Branch: 1 branch
BranchTrueFalseTotal
if $13 > 31 or $14 > 12 or $15 > 99 0 12 12
Condition33%2/6
$13 > 31 or $14 > 12 or $15 > 99
l!l&&r!l&&!r
0012
$13 > 31 or $14 > 12
l!l&&r!l&&!r
0012
MC/DC0%0/3
$13 > 31 or $14 > 12 or $15 > 99
$13 > 31 $14 > 12 $15 > 99
Truth table25%1/4
A or B or C
A= $13 > 31B= $14 > 12C= $15 > 99
ABCresult
1XX1
01X1
0011
0000
757 # optional date is available in PMGNTRK sentence
758 12 ▶ my $year = $15 + ($15 >= 70 ? 1900 : 2000);
Branch: 1 branch
BranchTrueFalseTotal
$15 >= 70 ? : 0 12 12
759 12 $date = Time::Local::timegm(0,0,0,$13,$14-1,$year);
760 }
761 #
762 # Honeywell HMR3000 PTNTHPR (Heading Pitch Roll) sentence (no date)
763 # (ref http://www.gpsarea.com/uploadfile/download/introduce/hmr3000_manual.pdf)
764 #
765 } elsif ($nmea eq 'PTNTHPR') {
766 # $PTNTHPR,85.9,N,-0.9,N,0.8,N*HH
767 # $PTNTHPR,heading,heading status,pitch,pitch status,roll,roll status,*cs
768 # status: L=low alarm, M=low warning, N=normal, O=high warning
769 # P=high alarm, C=tuning analog circuit
770 # (ignore this information on any alarm status)
771 3 ▶ /^\$PTNTHPR,(-?[\d.]+),[MNO],(-?[\d.]+),[MNO],(-?[\d.]+),[MNO]/ or next;
Branch: 1 branch
BranchTrueFalseTotal
/^\$PTNTHPR,(-?[\d.]+),[MNO],(-?[\d.]+),[MNO],(-?[\d.]+),[MNO]/ or next 3 0 3
772 3 @fix{qw(dir pitch roll)} = ($1,$2,$3);
773  
774 } else {
775 0 next; # this shouldn't happen
776 }
777 # remember the NMEA formats we successfully read
778 28 $nmea{$nmea} = 1;
779 # use last date if necessary (and appropriate)
780 28 ▶ if (defined $secs and not defined $date and defined $lastDate) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $secs and not defined $date and defined $lastDate) 0 28 28
Condition50%3/6
defined $secs and not defined $date and defined $lastDate
!ll&&!rl&&r
2800
defined $secs and not defined $date
!ll&&!rl&&r
3250
MC/DC0%0/3
defined $secs and not defined $date and defined $lastDate
defined $secs not defined $date defined $lastDate
Truth table50%2/4
A and not(B) and C
A= defined $secsB= not defined $dateC= defined $lastDate
ABCresult
0XX0
10X0
1100
1111
781 # wrap to next day if necessary
782 0 ▶ if ($secs < $lastSecs - JITTER()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secs < $lastSecs - &JITTER()) 0 0 0
783 0 $lastSecs -= $secPerDay;
784 0 $lastDate += $secPerDay;
785 }
786 # use earlier date only if we are within 10 seconds
787 0 ▶ if ($secs - $lastSecs < 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($secs - $lastSecs < 10) { } 0 0 0
788 # last date is close, use it for this fix
789 0 $date = $lastDate;
790 } else {
791 # last date is old, discard it
792 0 undef $lastDate;
793 0 undef $lastSecs;
794 }
795 }
796 # save our last date/time
797 28 ▶ if (defined $date) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date) 25 3 28
798 25 $lastDate = $date;
799 25 $lastSecs = $secs;
800 }
801 #
802 # Add NMEA/IGC fix to our lookup
803 # (this is much more complicated than it needs to be because
804 # the stupid NMEA format provides no end-of-fix indication)
805 #
806 # assumptions for each NMEA sentence:
807 # - we only parse a time if we get a lat/lon
808 # - we always get a time if we have a date
809 28 ▶ if ($nmea eq $nmeaStart or (defined $secs and (not defined $fixSecs or
Branch: 1 branch
BranchTrueFalseTotal
if ($nmea eq $nmeaStart or defined $secs and !defined($fixSecs) || $secs >= $fixSecs && $secs - $fixSecs >= 10 || $secs < $fixSecs && $secs + $secPerDay - $fixSecs >= 10) { } 25 3 28
Condition16%3/18
$nmea eq $nmeaStart or defined $secs and !defined($fixSecs) || $secs >= $fixSecs && $secs - $fixSecs >= 10 || $secs < $fixSecs && $secs + $secPerDay - $fixSecs >= 10
l!l&&r!l&&!r
2503
defined $secs and !defined($fixSecs) || $secs >= $fixSecs && $secs - $fixSecs >= 10 || $secs < $fixSecs && $secs + $secPerDay - $fixSecs >= 10
!ll&&!rl&&r
300
not defined $fixSecs or $secs >= $fixSecs and $secs - $fixSecs >= 10 or $secs < $fixSecs and $secs + $secPerDay - $fixSecs >= 10
l!l&&r!l&&!r
000
not defined $fixSecs or $secs >= $fixSecs and $secs - $fixSecs >= 10
l!l&&r!l&&!r
000
$secs >= $fixSecs and $secs - $fixSecs >= 10
!ll&&!rl&&r
000
$secs < $fixSecs and $secs + $secPerDay - $fixSecs >= 10
!ll&&!rl&&r
000
MC/DC14%1/7
$nmea eq $nmeaStart or defined $secs and !defined($fixSecs) || $secs >= $fixSecs && $secs - $fixSecs >= 10 || $secs < $fixSecs && $secs + $secPerDay - $fixSecs >= 10
$nmea eq $nmeaStart defined $secs not defined $fixSecs $secs >= $fixSecs $secs - $fixSecs >= 10 $secs < $fixSecs $secs + $secPerDay - $fixSecs >= 10
Truth table20%2/10
A or B and not(C) or D and E or F and G
A= $nmea eq $nmeaStartB= defined $secsC= not defined $fixSecsD= $secs >= $fixSecsE= $secs - $fixSecs >= 10F= $secs < $fixSecsG= $secs + $secPerDay - $fixSecs >= 10
ABCDEFGresult
1XXXXXX1
011XXXX1
01011XX1
0100X111
01010111
00XXXXX0
0100X0X0
0100X100
010100X0
01010100
810 # don't combine sentences that are outside 10 seconds apart
811 ($secs >= $fixSecs and $secs - $fixSecs >= 10) or
812 ($secs < $fixSecs and $secs + $secPerDay - $fixSecs >= 10))))
813 {
814 # start a new fix
815 25 $fix = \%fix;
816 25 $fixSecs = $secs;
817 25 undef $noDateChanged;
818 # does this fix have a date/time or time stamp?
819 25 ▶ if (defined $date) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $date) { } 25 0 25
elsif (defined $secs) { } 0 0 0
820 25 $fix{isDate} = $isDate = 1;
821 25 $time = $date + $secs;
822 } elsif (defined $secs) {
823 0 $time = $secs;
824 0 $noDate = $noDateChanged = 1;
825 } else {
826 0 next; # wait until we have a time before adding to lookup
827 }
828 } else {
829 # add new data to existing fix (but don't overwrite earlier values to
830 # keep the coordinates in sync with the fix time)
831 3 foreach (keys %fix) {
832 9 ▶ $$fix{$_} = $fix{$_} unless defined $$fix{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $fix->{$_} 9 0 9
833 }
834 3 ▶ if (defined $date) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $date) { } 0 3 3
elsif (defined $secs and not defined $fixSecs) { } 0 3 3
835 0 ▶ next if $$fix{isDate};
Branch: 1 branch
BranchTrueFalseTotal
if $fix->{"isDate"} 0 0 0
836 # move this fix to the proper date
837 0 ▶ if (defined $fixSecs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fixSecs) { } 0 0 0
838 0 delete $$points{$fixSecs};
839 0 ▶ pop @fixTimes if @fixTimes and $fixTimes[-1] == $fixSecs;
Branch: 1 branch
BranchTrueFalseTotal
if @fixTimes and $fixTimes[-1] == $fixSecs 0 0 0
Condition0%0/3
@fixTimes and $fixTimes[-1] == $fixSecs
!ll&&!rl&&r
000
MC/DC0%0/2
@fixTimes and $fixTimes[-1] == $fixSecs
@fixTimes $fixTimes[-1] == $fixSecs
Truth table0%0/3
A and B
A= @fixTimesB= $fixTimes[-1] == $fixSecs
ABresult
0X0
100
111
840 0 --$numPoints;
841 # if we wrapped to the next day since the start of this fix,
842 # we must shift the date back to the day of $fixSecs
843 0 ▶ $date -= $secPerDay if $secs < $fixSecs;
Branch: 1 branch
BranchTrueFalseTotal
if $secs < $fixSecs 0 0 0
844 } else {
845 0 $fixSecs = $secs;
846 }
847 0 $time = $date + $fixSecs;
848 0 $$fix{isDate} = $isDate = 1;
849 # revert noDate flag if it was set for this fix
850 0 ▶ $noDate = 0 if $noDateChanged;
Branch: 1 branch
BranchTrueFalseTotal
if $noDateChanged 0 0 0
851 ▶ } elsif (defined $secs and not defined $fixSecs) {
Condition33%1/3
defined $secs and not defined $fixSecs
!ll&&!rl&&r
300
MC/DC0%0/2
defined $secs and not defined $fixSecs
defined $secs not defined $fixSecs
Truth table33%1/3
A and not(B)
A= defined $secsB= not defined $fixSecs
ABresult
0X0
100
111
852 0 $time = $fixSecs = $secs;
853 0 $noDate = $noDateChanged = 1;
854 } else {
855 3 next; # wait until we have a time
856 }
857 }
858 # add fix to our lookup
859 25 $$points{$time} = $fix;
860 25 push @fixTimes, $time; # save time of all fixes in order
861 25 ++$numPoints;
862 }
863 9 $raf->Close();
864  
865 # set date flags
866 9 ▶ if ($noDate and not $$geotag{NoDate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($noDate and not $geotag->{"NoDate"}) 0 9 9
Condition33%1/3
$noDate and not $geotag->{"NoDate"}
!ll&&!rl&&r
900
MC/DC0%0/2
$noDate and not $geotag->{"NoDate"}
$noDate not $geotag->{"NoDate"}
Truth table33%1/3
A and not(B)
A= $noDateB= not $geotag->{"NoDate"}
ABresult
0X0
100
111
867 0 ▶ if ($isDate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isDate) { } 0 0 0
868 0 $et->Warn('Fixes are date-less -- will use time-only interpolation');
869 } else {
870 0 $et->Warn('Some fixes are date-less -- may use time-only interpolation');
871 }
872 0 $$geotag{NoDate} = 1;
873 }
874 9 ▶ $$geotag{IsDate} = 1 if $isDate;
Branch: 1 branch
BranchTrueFalseTotal
if $isDate 9 0 9
875  
876 # cut bad fixes if necessary
877 9 ▶ if ($isCut and $canCut) {
Branch: 1 branch
BranchTrueFalseTotal
if ($isCut and $canCut) 0 9 9
Condition33%1/3
$isCut and $canCut
!ll&&!rl&&r
900
MC/DC0%0/2
$isCut and $canCut
$isCut $canCut
Truth table33%1/3
A and B
A= $isCutB= $canCut
ABresult
0X0
100
111
878 0 $cutPDOP = $cutHDOP = $cutSats = 0;
879 0 my @goodTimes;
880 0 foreach (@fixTimes) {
881 0 ▶ $fix = $$points{$_} or next;
Branch: 1 branch
BranchTrueFalseTotal
$fix = $points->{$_} or next 0 0 0
882 0 ▶ if ($maxPDOP and $$fix{pdop} and $$fix{pdop} > $maxPDOP) {
Branch: 3 branches
BranchTrueFalseTotal
if ($maxPDOP and $fix->{'pdop'} and $fix->{'pdop'} > $maxPDOP) { } 0 0 0
elsif ($maxHDOP and $fix->{'hdop'} and $fix->{'hdop'} > $maxHDOP) { } 0 0 0
elsif ($minSats and defined $fix->{'nsats'} and $fix->{'nsats'} ne '' and $fix->{'nsats'} < $minSats) { } 0 0 0
Condition0%0/6
$maxPDOP and $fix->{"pdop"} and $fix->{"pdop"} > $maxPDOP
!ll&&!rl&&r
000
$maxPDOP and $fix->{"pdop"}
!ll&&!rl&&r
000
MC/DC0%0/3
$maxPDOP and $fix->{"pdop"} and $fix->{"pdop"} > $maxPDOP
$maxPDOP $fix->{"pdop"} $fix->{"pdop"} > $maxPDOP
Truth table0%0/4
A and B and C
A= $maxPDOPB= $fix->{"pdop"}C= $fix->{"pdop"} > $maxPDOP
ABCresult
0XX0
10X0
1100
1111
883 0 delete $$points{$_};
884 0 ++$cutPDOP;
885 ▶ } elsif ($maxHDOP and $$fix{hdop} and $$fix{hdop} > $maxHDOP) {
Condition0%0/6
$maxHDOP and $fix->{"hdop"} and $fix->{"hdop"} > $maxHDOP
!ll&&!rl&&r
000
$maxHDOP and $fix->{"hdop"}
!ll&&!rl&&r
000
MC/DC0%0/3
$maxHDOP and $fix->{"hdop"} and $fix->{"hdop"} > $maxHDOP
$maxHDOP $fix->{"hdop"} $fix->{"hdop"} > $maxHDOP
Truth table0%0/4
A and B and C
A= $maxHDOPB= $fix->{"hdop"}C= $fix->{"hdop"} > $maxHDOP
ABCresult
0XX0
10X0
1100
1111
886 0 delete $$points{$_};
887 0 ++$cutHDOP;
888 ▶ } elsif ($minSats and defined $$fix{nsats} and $$fix{nsats} ne '' and
Condition0%0/9
$minSats and defined $fix->{"nsats"} and $fix->{"nsats"} ne "" and $fix->{"nsats"} < $minSats
!ll&&!rl&&r
000
$minSats and defined $fix->{"nsats"} and $fix->{"nsats"} ne ""
!ll&&!rl&&r
000
$minSats and defined $fix->{"nsats"}
!ll&&!rl&&r
000
MC/DC0%0/4
$minSats and defined $fix->{"nsats"} and $fix->{"nsats"} ne "" and $fix->{"nsats"} < $minSats
$minSats defined $fix->{"nsats"} $fix->{"nsats"} ne "" $fix->{"nsats"} < $minSats
Truth table0%0/5
A and B and C and D
A= $minSatsB= defined $fix->{"nsats"}C= $fix->{"nsats"} ne ""D= $fix->{"nsats"} < $minSats
ABCDresult
0XXX0
10XX0
110X0
11100
11111
889 $$fix{nsats} < $minSats)
890 {
891 0 delete $$points{$_};
892 0 ++$cutSats;
893 } else {
894 0 push @goodTimes, $_;
895 }
896 }
897 0 @fixTimes = @goodTimes; # update fix times
898 0 $numPoints -= $cutPDOP;
899 0 $numPoints -= $cutHDOP;
900 0 $numPoints -= $cutSats;
901 }
902 # sort fixes if necessary
903 0 ▶ @fixTimes = sort { $a <=> $b } @fixTimes if $sortFixes;
Branch: 1 branch
BranchTrueFalseTotal
if $sortFixes 0 9 9
904 # mark first fix of the track
905 9 ▶ while (@fixTimes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fixTimes) 9 0 9
906 9 ▶ $fix = $$points{$fixTimes[0]} or shift(@fixTimes), next;
Branch: 1 branch
BranchTrueFalseTotal
$fix = $$points{$fixTimes[0]} or shift @fixTimes, next 9 0 9
907 9 $$fix{first} = 1;
908 9 last;
909 }
910 9 my $verbose = $et->Options('Verbose');
911 9 ▶ if ($verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose) 1 8 9
912 1 my $out = $et->Options('TextOut');
913 1 ▶ $format or $format = 'unknown';
Branch: 1 branch
BranchTrueFalseTotal
$format or $format = "unknown" 1 0 1
914 1 print $out "Loaded $numPoints points from $format-format GPS track log $from\n";
915 1 ▶ print $out "Ignored $cutPDOP points due to GeoMaxPDOP cut\n" if $cutPDOP;
Branch: 1 branch
BranchTrueFalseTotal
if $cutPDOP 0 1 1
916 1 ▶ print $out "Ignored $cutHDOP points due to GeoMaxHDOP cut\n" if $cutHDOP;
Branch: 1 branch
BranchTrueFalseTotal
if $cutHDOP 0 1 1
917 1 ▶ print $out "Ignored $cutSats points due to GeoMinSats cut\n" if $cutSats;
Branch: 1 branch
BranchTrueFalseTotal
if $cutSats 0 1 1
918 1 ▶ if ($numPoints and $verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($numPoints and $verbose > 1) 1 0 1
Condition33%1/3
$numPoints and $verbose > 1
!ll&&!rl&&r
001
MC/DC0%0/2
$numPoints and $verbose > 1
$numPoints $verbose > 1
Truth table33%1/3
A and B
A= $numPointsB= $verbose > 1
ABresult
0X0
100
111
919 1 my @lbl = ('start:', 'end: ');
920 # (fixes may be in reverse order in GPX files)
921 1 ▶ @lbl = reverse @lbl if $fixTimes[0] > $fixTimes[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $fixTimes[0] > $fixTimes[-1] 0 1 1
922 1 print $out " GPS track $lbl[0] " . PrintFixTime($fixTimes[0]) . "\n";
923 1 ▶ if ($verbose > 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 3) 0 1 1
924 0 print $out PrintFix($points, $_) foreach @fixTimes;
925 }
926 1 print $out " GPS track $lbl[1] " . PrintFixTime($fixTimes[-1]) . "\n";
927 }
928 }
929 9 ▶ if ($numPoints) {
Branch: 1 branch
BranchTrueFalseTotal
if ($numPoints) 9 0 9
930 # reset timestamp list to force it to be regenerated
931 9 delete $$geotag{Times};
932 # set flags for available information
933 9 ▶ $$has{alt} = 1 if $nmea{GGA} or $nmea{PMGNTRK} or $nmea{B}; # alt
Branch: 1 branch
BranchTrueFalseTotal
if $nmea{"GGA"} or $nmea{"PMGNTRK"} or $nmea{"B"} 2 7 9
Condition83%5/6
$nmea{"GGA"} or $nmea{"PMGNTRK"} or $nmea{"B"}
l!l&&r!l&&!r
117
$nmea{"GGA"} or $nmea{"PMGNTRK"}
l!l&&r!l&&!r
018
MC/DC66%2/3
$nmea{"GGA"} or $nmea{"PMGNTRK"} or $nmea{"B"}
$nmea{"GGA"} $nmea{"PMGNTRK"} $nmea{"B"}
Truth table75%3/4
A or B or C
A= $nmea{"GGA"}B= $nmea{"PMGNTRK"}C= $nmea{"B"}
ABCresult
1XX1
01X1
0011
0000
934 9 ▶ $$has{track} = 1 if $nmea{RMC}; # track, speed
Branch: 1 branch
BranchTrueFalseTotal
if $nmea{"RMC"} 1 8 9
935 9 ▶ $$has{orient} = 1 if $nmea{PTNTHPR}; # dir, pitch, roll
Branch: 1 branch
BranchTrueFalseTotal
if $nmea{"PTNTHPR"} 1 8 9
936 9 return $geotag; # success!
937 }
938 0 return "No track points found in GPS $from";
939 }
940  
941  
942 #------------------------------------------------------------------------------
943 # Get floating point UTC time
944 # Inputs: 0) XML time string
945 # Returns: floating point time or undef on error
946 sub GetTime($)
947 23 ▶{
Subroutine GetTime: called CC=7 SCAR=19.8
Pod undocumented
948 23 my $timeStr = shift;
949 23 ▶ $timeStr =~ /^(\d{4})-(\d+)-(\d+)T(\d+):(\d+):(\d+)(\.\d+)?(.*)/ or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$timeStr =~ /^(\d{4})-(\d+)-(\d+)T(\d+):(\d+):(\d+)(\.\d+)?(.*)/ or return undef 23 0 23
950 23 my $time = Time::Local::timegm($6,$5,$4,$3,$2-1,$1);
951 23 ▶ $time += $7 if $7; # add fractional seconds
Branch: 1 branch
BranchTrueFalseTotal
if $7 3 20 23
952 23 my $tz = $8;
953 # adjust for time zone (otherwise assume UTC)
954 # - allow timezone of +-HH:MM, +-H:MM, +-HHMM or +-HH since
955 # the spec is unclear about timezone format
956 23 ▶ if ($tz =~ /^([-+])(\d+):(\d{2})\b/ or $tz =~ /^([-+])(\d{2})(\d{2})?\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz =~ /^([-+])(\d+):(\d{2})\b/ or $tz =~ /^([-+])(\d{2})(\d{2})?\b/) 3 20 23
Condition66%2/3
$tz =~ /^([-+])(\d+):(\d{2})\b/ or $tz =~ /^([-+])(\d{2})(\d{2})?\b/
l!l&&r!l&&!r
3020
MC/DC50%1/2
$tz =~ /^([-+])(\d+):(\d{2})\b/ or $tz =~ /^([-+])(\d{2})(\d{2})?\b/
$tz =~ /^([-+])(\d+):(\d{2})\b/ $tz =~ /^([-+])(\d{2})(\d{2})?\b/
Truth table66%2/3
A or B
A= $tz =~ /^([-+])(\d+):(\d{2})\b/B= $tz =~ /^([-+])(\d{2})(\d{2})?\b/
ABresult
1X1
011
000
957 3 ▶ $tz = ($2 * 60 + ($3 || 0)) * 60;
Condition50%1/2
$3 || 0
l!l
30
MC/DC0%0/1
$3 || 0
$3
Truth table50%1/2
A
A= $3
Aresult
11
00
958 3 ▶ $tz *= -1 if $1 eq '+'; # opposite sign to change back to UTC
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "+" 0 3 3
959 3 $time += $tz;
960 }
961 23 return $time;
962 }
963  
964 #------------------------------------------------------------------------------
965 # Apply Geosync time correction
966 # Inputs: 0) ExifTool ref, 1) Unix UTC time value
967 # Returns: sync time difference (and updates input time), or undef if no sync
968 sub ApplySyncCorr($$)
969 11 ▶{
Subroutine ApplySyncCorr: called CC=6 SCAR=18.6
Pod undocumented
970 11 my ($et, $time) = @_;
971 11 my $sync = $et->GetNewValue('Geosync');
972 11 ▶ if (ref $sync eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sync eq 'HASH') { } 3 8 11
973 3 my $syncTimes = $$sync{Times};
974 3 ▶ if ($syncTimes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($syncTimes) { } 2 1 3
975 # find the nearest 2 sync points
976 2 my ($i0, $i1) = (0, scalar(@$syncTimes) - 1);
977 2 ▶ while ($i1 > $i0 + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 > $i0 + 1) 0 2 2
978 0 my $pt = int(($i0 + $i1) / 2);
979 0 ▶ ($time < $$syncTimes[$pt] ? $i1 : $i0) = $pt;
Branch: 1 branch
BranchTrueFalseTotal
$time < $syncTimes->[$pt] ? : 0 0 0
980 }
981 2 my ($t0, $t1) = ($$syncTimes[$i0], $$syncTimes[$i1]);
982 # interpolate/extrapolate to account for linear camera clock drift
983 2 my $syncPoints = $$sync{Points};
984 2 ▶ my $f = $t1 == $t0 ? 0 : ($time - $t0) / ($t1 - $t0);
Branch: 1 branch
BranchTrueFalseTotal
$t1 == $t0 ? : 0 2 2
985 2 $sync = $$syncPoints{$t1} * $f + $$syncPoints{$t0} * (1 - $f);
986 } else {
987 1 $sync = $$sync{Offset}; # use fixed time offset
988 }
989 3 $_[1] += $sync;
990 } else {
991 8 undef $sync;
992 }
993 11 return $sync;
994 }
995  
996 #------------------------------------------------------------------------------
997 # Scan outwards for a fix containing the requested parameter
998 # Inputs: 0) name of fix parameter, 1) reference to list of fix times,
999 # 2) reference to fix points hash, 3) index of starting time,
1000 # 4) direction to scan (-1 or +1), 5) maximum time difference
1001 # Returns: 0) time for fix containing requested information (or undef)
1002 # 1) the corresponding fix, 2) the value of the requested fix parameter
1003 sub ScanOutwards($$$$$$)
1004 4 ▶{
Subroutine ScanOutwards: called CC=5 SCAR=16.1
Pod undocumented
1005 4 my ($key, $times, $points, $i, $dir, $maxSecs) = @_;
1006 4 my $t0 = $$times[$i];
1007 4 for (;;) {
1008 8 $i += $dir;
1009 8 ▶ last if $i < 0 or $i >= scalar @$times;
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 or $i >= scalar @$times 2 6 8
Condition66%2/3
$i < 0 or $i >= scalar @$times
l!l&&r!l&&!r
026
MC/DC50%1/2
$i < 0 or $i >= scalar @$times
$i < 0 $i >= scalar @$times
Truth table66%2/3
A or B
A= $i < 0B= $i >= scalar @$times
ABresult
1X1
011
000
1010 6 my $t = $$times[$i];
1011 6 ▶ last if abs($t - $t0) > $maxSecs; # don't look too far
Branch: 1 branch
BranchTrueFalseTotal
if abs $t - $t0 > $maxSecs 2 4 6
1012 4 my $p = $$points{$t};
1013 4 my $v = $$p{$key};
1014 4 ▶ return($t,$p,$v) if defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v 0 4 4
1015 }
1016 4 return();
1017 }
1018  
1019 #------------------------------------------------------------------------------
1020 # Find nearest fix containing the specified parameter
1021 # Inputs: 0) ExifTool ref, 1) name of fix parameter, 2) reference to list of fix times,
1022 # 3) reference to fix points hash, 4) index of starting time,
1023 # 5) direction to scan (-1, +1 or undef), 6) maximum time difference
1024 # Returns: reference to fix hash or undef
1025 sub FindFix($$$$$$$)
1026 2 ▶{
Subroutine FindFix: called CC=8 SCAR=29.3
Pod undocumented
1027 2 my ($et, $key, $times, $points, $i, $dir, $maxSecs) = @_;
1028 2 my ($t,$p);
1029 2 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 2 2
1030 0 ($t,$p) = ScanOutwards($key, $times, $points, $i, $dir, $maxSecs);
1031 } else {
1032 2 my ($t1, $p1) = ScanOutwards($key, $times, $points, $i, -1, $maxSecs);
1033 2 my ($t2, $p2) = ScanOutwards($key, $times, $points, $i, 1, $maxSecs);
1034 2 ▶ if (defined $t1) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $t1) { } 0 2 2
elsif (defined $t2) { } 0 2 2
1035 0 ▶ if (defined $t2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t2) { } 0 0 0
1036 # both surrounding points are valid, so take the closest one
1037 0 ▶ ($t, $p) = ($t - $t1 < $t2 - $t) ? ($t1, $p1) : ($t2, $p2);
Branch: 1 branch
BranchTrueFalseTotal
$t - $t1 < $t2 - $t ? : 0 0 0
1038 } else {
1039 0 ($t, $p) = ($t1, $p1);
1040 }
1041 } elsif (defined $t2) {
1042 0 ($t, $p) = ($t2, $p2);
1043 }
1044 }
1045 2 ▶ if (defined $p and $$et{OPTIONS}{Verbose} > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $p and $et->{"OPTIONS"}{"Verbose"} > 2) 0 2 2
Condition33%1/3
defined $p and $et->{"OPTIONS"}{"Verbose"} > 2
!ll&&!rl&&r
200
MC/DC0%0/2
defined $p and $et->{"OPTIONS"}{"Verbose"} > 2
defined $p $et->{"OPTIONS"}{"Verbose"} > 2
Truth table33%1/3
A and B
A= defined $pB= $et->{"OPTIONS"}{"Verbose"} > 2
ABresult
0X0
100
111
1046 0 $et->VPrint(2, " Taking $key from fix:\n", PrintFix($points, $t))
1047 }
1048 2 return $p;
1049 }
1050  
1051 #------------------------------------------------------------------------------
1052 # Set new geotagging values according to date/time
1053 # Inputs: 0) ExifTool object ref, 1) date/time value (or undef to delete tags)
1054 # 2) optional write group
1055 # Returns: error string, or '' on success
1056 # Notes: Uses track data stored in ExifTool NEW_VALUE for Geotag tag
1057 sub SetGeoValues($$;$)
1058 14 ▶{
Subroutine SetGeoValues: called CC=136 SCAR=74.1
Pod undocumented
1059 14 local $_;
1060 14 my ($et, $val, $writeGroup) = @_;
1061 14 my $geotag = $et->GetNewValue('Geotag');
1062 14 my $verbose = $et->Options('Verbose');
1063 14 my ($fix, $time, $fsec, $noDate, $secondTry, $iExt, $iDir);
1064  
1065 # remove date if none of our fixes had date information
1066 14 ▶ $val =~ s/^\S+\s+// if $val and $geotag and not $$geotag{IsDate};
Branch: 1 branch
BranchTrueFalseTotal
if $val and $geotag and not $geotag->{"IsDate"} 0 14 14
Condition66%4/6
$val and $geotag and not $geotag->{"IsDate"}
!ll&&!rl&&r
3110
$val and $geotag
!ll&&!rl&&r
3011
MC/DC0%0/3
$val and $geotag and not $geotag->{"IsDate"}
$val $geotag not $geotag->{"IsDate"}
Truth table50%2/4
A and B and not(C)
A= $valB= $geotagC= not $geotag->{"IsDate"}
ABCresult
0XX0
10X0
1100
1111
1067  
1068 # maximum time (sec) from nearest GPS fix when position is still considered valid
1069 14 my $geoMaxIntSecs = $et->Options('GeoMaxIntSecs');
1070 14 my $geoMaxExtSecs = $et->Options('GeoMaxExtSecs');
1071  
1072 # use 30 minutes for a default
1073 14 ▶ defined $geoMaxIntSecs or $geoMaxIntSecs = 1800;
Branch: 1 branch
BranchTrueFalseTotal
defined $geoMaxIntSecs or $geoMaxIntSecs = 1800 14 0 14
1074 14 ▶ defined $geoMaxExtSecs or $geoMaxExtSecs = 1800;
Branch: 1 branch
BranchTrueFalseTotal
defined $geoMaxExtSecs or $geoMaxExtSecs = 1800 14 0 14
1075  
1076 14 my $times = $$geotag{Times};
1077 14 my $points = $$geotag{Points};
1078 14 my $has = $$geotag{Has};
1079 14 my $err = '';
1080 # loop to try date/time value first, then time-only value
1081 14 ▶ while (defined $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val) 11 3 14
1082 11 ▶ unless (defined $geotag) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $geotag) 0 11 11
1083 0 $err = 'No GPS track loaded';
1084 0 last;
1085 }
1086 11 ▶ unless ($times) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($times) 10 1 11
1087 # generate sorted timestamp list for binary search
1088 10 my @times = sort { $a <=> $b } keys %$points;
1089 10 $times = $$geotag{Times} = \@times;
1090 }
1091 11 ▶ unless ($times and @$times or $$geotag{DateTimeOnly}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($times and @$times or $geotag->{"DateTimeOnly"}) 0 11 11
Condition66%4/6
$times and @$times or $geotag->{"DateTimeOnly"}
l!l&&r!l&&!r
1010
$times and @$times
!ll&&!rl&&r
0110
MC/DC0%0/3
$times and @$times or $geotag->{"DateTimeOnly"}
$times @$times $geotag->{"DateTimeOnly"}
Truth table40%2/5
A and B or C
A= $timesB= @$timesC= $geotag->{"DateTimeOnly"}
ABCresult
11X1
0X11
1011
0X00
1000
1092 0 $err = 'GPS track is empty';
1093 0 last;
1094 }
1095 11 ▶ unless (eval { require Time::Local }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require Time::Local } }) 0 11 11
1096 0 $err = 'Geotag feature requires Time::Local installed';
1097 0 last;
1098 }
1099 # convert date/time to UTC
1100 11 my ($year,$mon,$day,$hr,$min,$sec,$fs,$tz,$t0,$t1,$t2);
1101 11 ▶ if ($val =~ /^(\d{4}):(\d+):(\d+)\s+(\d+):(\d+):(\d+)(\.\d*)?(Z|([-+])(\d+):(\d+))?/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /^(\d{4}):(\d+):(\d+)\s+(\d+):(\d+):(\d+)(\.\d*)?(Z|([-+])(\d+):(\d+))?/) { } 11 0 11
elsif ($val =~ /^(\d{2}):(\d+):(\d+)(\.\d*)?(Z|([-+])(\d+):(\d+))?/) { } 0 0 0
1102 # valid date/time value
1103 11 ($year,$mon,$day,$hr,$min,$sec,$fs,$tz,$t0,$t1,$t2) = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);
1104 } elsif ($val =~ /^(\d{2}):(\d+):(\d+)(\.\d*)?(Z|([-+])(\d+):(\d+))?/) {
1105 # valid time-only value
1106 0 ($hr,$min,$sec,$fs,$tz,$t0,$t1,$t2) = ($1,$2,$3,$4,$5,$6,$7,$8);
1107 # use Jan. 2 to avoid going negative after tz adjustment
1108 0 ($year,$mon,$day) = (1970,1,2);
1109 0 $noDate = 1;
1110 } else {
1111 0 $err = 'Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z])';
1112 0 last;
1113 }
1114 11 ▶ if ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz) { } 10 1 11
1115 10 $time = Time::Local::timegm($sec,$min,$hr,$day,$mon-1,$year);
1116 # use timezone from date/time value
1117 10 ▶ if ($tz ne 'Z') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz ne "Z") 5 5 10
1118 5 my $tzmin = $t1 * 60 + $t2;
1119 5 ▶ $time -= ($t0 eq '-' ? -$tzmin : $tzmin) * 60;
Branch: 1 branch
BranchTrueFalseTotal
$t0 eq '-' ? : 4 1 5
1120 }
1121 } else {
1122 # assume local timezone
1123 1 $time = Image::ExifTool::TimeLocal($sec,$min,$hr,$day,$mon-1,$year);
1124 }
1125 # add fractional seconds
1126 11 ▶ $time += $fs if $fs and $fs ne '.';
Branch: 1 branch
BranchTrueFalseTotal
if $fs and $fs ne "." 1 10 11
Condition66%2/3
$fs and $fs ne "."
!ll&&!rl&&r
1001
MC/DC50%1/2
$fs and $fs ne "."
$fs $fs ne "."
Truth table66%2/3
A and B
A= $fsB= $fs ne "."
ABresult
0X0
100
111
1127  
1128 # bring UTC time back to Jan. 1 if no date is given
1129 # (don't use '%' operator here because it drops fractional seconds)
1130 11 ▶ $time -= int($time / $secPerDay) * $secPerDay if $noDate;
Branch: 1 branch
BranchTrueFalseTotal
if $noDate 0 11 11
1131  
1132 # apply time synchronization if available
1133 11 my $sync = ApplySyncCorr($et, $time);
1134  
1135 # save fractional seconds string
1136 11 ▶ $fsec = ($time =~ /(\.\d+)$/) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$time =~ /(\.\d+)$/ ? : 2 9 11
1137  
1138 11 ▶ if ($et->Options('Verbose') > 1 and not $secondTry) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->Options("Verbose") > 1 and not $secondTry) 1 10 11
Condition66%2/3
$et->Options("Verbose") > 1 and not $secondTry
!ll&&!rl&&r
1001
MC/DC50%1/2
$et->Options("Verbose") > 1 and not $secondTry
$et->Options("Verbose") > 1 not $secondTry
Truth table66%2/3
A and not(B)
A= $et->Options("Verbose") > 1B= not $secondTry
ABresult
0X0
100
111
1139 1 my $out = $et->Options('TextOut');
1140 1 my $str = '';
1141 1 ▶ $str .= sprintf(" (incl. Geosync offset of %+.3f sec)", $sync) if defined $sync;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sync 1 0 1
1142 1 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 0 1 1
1143 0 my $tzs = Image::ExifTool::TimeZoneString([$sec,$min,$hr,$day,$mon-1,$year-1900],$time);
1144 0 $str .= " (local timezone is $tzs)";
1145 }
1146 1 print $out ' Geotime value: ' . PrintFixTime($time) . "$str\n";
1147 }
1148 11 ▶ if (not $times or not @$times) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $times && @$times) { } 1 10 11
elsif ($time < $times->[0]) { } 0 10 10
elsif ($time > $times->[-1]) { } 1 9 10
Condition66%2/3
$times && @$times
!ll&&!rl&&r
0110
MC/DC50%1/2
$times && @$times
$times @$times
Truth table66%2/3
A && B
A= $timesB= @$times
ABresult
0X0
100
111
1149 1 $fix = { }; # dummy fix to geotag date/time only
1150 # interpolate GPS track at $time
1151 } elsif ($time < $$times[0]) {
1152 0 ▶ if ($time < $$times[0] - $geoMaxExtSecs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time < $times->[0] - $geoMaxExtSecs) { } 0 0 0
1153 0 ▶ $err or $err = 'Time is too far before track';
Branch: 1 branch
BranchTrueFalseTotal
$err or $err = "Time is too far before track" 0 0 0
1154 0 ▶ $et->VPrint(2, ' Track start: ', PrintFixTime($$times[0]), "\n") if $verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1155 0 ▶ $fix = { } if $$geotag{DateTimeOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $geotag->{"DateTimeOnly"} 0 0 0
1156 } else {
1157 0 $fix = $$points{$$times[0]};
1158 0 $iExt = 0; $iDir = 1;
1159 0 ▶ $et->VPrint(2, " Taking pos from fix:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1160 PrintFix($points, $$times[0])) if $verbose > 2;
1161 }
1162 } elsif ($time > $$times[-1]) {
1163 1 ▶ if ($time > $$times[-1] + $geoMaxExtSecs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time > $times->[-1] + $geoMaxExtSecs) { } 1 0 1
1164 1 ▶ $err or $err = 'Time is too far beyond track';
Branch: 1 branch
BranchTrueFalseTotal
$err or $err = "Time is too far beyond track" 0 1 1
1165 1 ▶ $et->VPrint(2, ' Track end: ', PrintFixTime($$times[-1]), "\n") if $verbose > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 1 1
1166 1 ▶ $fix = { } if $$geotag{DateTimeOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $geotag->{"DateTimeOnly"} 0 1 1
1167 } else {
1168 0 $fix = $$points{$$times[-1]};
1169 0 $iExt = $#$times; $iDir = -1;
1170 0 ▶ $et->VPrint(2, " Taking pos from fix:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1171 PrintFix($points, $$times[-1])) if $verbose > 2;
1172 }
1173 } else {
1174 # find nearest 2 points in time
1175 9 my ($i0, $i1) = (0, scalar(@$times) - 1);
1176 9 ▶ while ($i1 > $i0 + 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 > $i0 + 1) 27 9 36
1177 27 my $pt = int(($i0 + $i1) / 2);
1178 27 ▶ ($time < $$times[$pt] ? $i1 : $i0) = $pt;
Branch: 1 branch
BranchTrueFalseTotal
$time < $times->[$pt] ? : 12 15 27
1179 }
1180 # do linear interpolation for position
1181 9 my $t0 = $$times[$i0];
1182 9 my $t1 = $$times[$i1];
1183 9 my $p1 = $$points{$t1};
1184 # check to see if we are extrapolating before the first entry in a track
1185 9 ▶ my $maxSecs = ($$p1{first} and $geoMaxIntSecs) ? $geoMaxExtSecs : $geoMaxIntSecs;
Branch: 1 branch
BranchTrueFalseTotal
$p1->{'first'} && $geoMaxIntSecs ? : 0 9 9
Condition33%1/3
$p1->{"first"} and $geoMaxIntSecs
!ll&&!rl&&r
900
MC/DC0%0/2
$p1->{"first"} and $geoMaxIntSecs
$p1->{"first"} $geoMaxIntSecs
Truth table33%1/3
A and B
A= $p1->{"first"}B= $geoMaxIntSecs
ABresult
0X0
100
111
1186 9 my $tn; # find time of nearest fix
1187 9 ▶ if ($time - $t0 < $t1 - $time) {
Branch: 1 branch
BranchTrueFalseTotal
if ($time - $t0 < $t1 - $time) { } 7 2 9
1188 7 $tn = $t0;
1189 7 $iExt = $i0;
1190 } else {
1191 2 $tn = $t1;
1192 2 $iExt = $i1;
1193 }
1194 # don't interpolate if fixes are too far apart
1195 # (but always interpolate fixes inside the same TimeSpan)
1196 9 ▶ if ($t1 - $t0 > $maxSecs and (not $$p1{span} or not $$points{$t0}{span} or
Branch: 1 branch
BranchTrueFalseTotal
if ($t1 - $t0 > $maxSecs and !($p1->{'span'} && $points->{$t0}{'span'}) || $p1->{'span'} != $points->{$t0}{'span'}) { } 0 9 9
Condition11%1/9
$t1 - $t0 > $maxSecs and !($p1->{"span"} && $points->{$t0}{"span"}) || $p1->{"span"} != $points->{$t0}{"span"}
!ll&&!rl&&r
900
not $p1->{"span"} && $points->{$t0}{"span"} or $p1->{"span"} != $points->{$t0}{"span"}
l!l&&r!l&&!r
000
$p1->{'span'} && $points->{$t0}{'span'}
!ll&&!rl&&r
000
MC/DC0%0/4
$t1 - $t0 > $maxSecs and !($p1->{"span"} && $points->{$t0}{"span"}) || $p1->{"span"} != $points->{$t0}{"span"}
$t1 - $t0 > $maxSecs $p1->{'span'} $points->{$t0}{'span'} $p1->{"span"} != $points->{$t0}{"span"}
Truth table20%1/5
A and not(B && C) or D
A= $t1 - $t0 > $maxSecsB= $p1->{'span'}C= $points->{$t0}{'span'}D= $p1->{"span"} != $points->{$t0}{"span"}
ABCDresult
0XXX0
11100
10XX1
110X1
11111
1197 $$p1{span} != $$points{$t0}{span}))
1198 {
1199 # treat as an extrapolation -- use nearest fix if close enough
1200 0 ▶ if (abs($time - $tn) > $geoMaxExtSecs) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $time - $tn > $geoMaxExtSecs) { } 0 0 0
1201 0 ▶ $err or $err = 'Time is too far from nearest GPS fix';
Branch: 1 branch
BranchTrueFalseTotal
$err or $err = "Time is too far from nearest GPS fix" 0 0 0
1202 0 ▶ $et->VPrint(2, ' Nearest fix: ', PrintFixTime($tn), ' (',
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1203 int(abs $time-$tn), " sec away)\n") if $verbose > 2;
1204 0 ▶ $fix = { } if $$geotag{DateTimeOnly};
Branch: 1 branch
BranchTrueFalseTotal
if $geotag->{"DateTimeOnly"} 0 0 0
1205 } else {
1206 0 $fix = $$points{$tn};
1207 0 ▶ $et->VPrint(2, " Taking pos from fix:\n",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1208 PrintFix($points, $tn)) if $verbose > 2;
1209 }
1210 } else {
1211 9 ▶ my $f0 = $t1 == $t0 ? 0 : ($time - $t0) / ($t1 - $t0);
Branch: 1 branch
BranchTrueFalseTotal
$t1 == $t0 ? : 0 9 9
1212 9 my $p0 = $$points{$t0};
1213 9 ▶ $et->VPrint(2, " Interpolating between fixes (f=$f0):\n",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 9 9
1214 PrintFix($points, $t0, $t1)) if $verbose > 2;
1215 9 $fix = { };
1216 # copy user-defined tags from nearest fix
1217 9 $$fix{$_} = $$points{$tn}{$_} foreach values %userTag;
1218 # loop through available fix information categories
1219 # (pos, track, alt, orient)
1220 9 my ($category, $key);
1221 9 Category: foreach $category (qw{pos track alt orient atemp err dop}) {
1222 63 ▶ next unless $$has{$category};
Branch: 1 branch
BranchTrueFalseTotal
unless $has->{$category} 42 21 63
1223 21 my ($f, $p0b, $p1b, $f0b);
1224 # loop through specific fix information keys
1225 # (lat, lon, alt, track, speed, dir, pitch, roll)
1226 21 foreach $key (@{$fixInfoKeys{$category}}) {
1227 39 my $v0 = $$p0{$key};
1228 39 my $v1 = $$p1{$key};
1229 39 ▶ if (defined $v0 and defined $v1) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $v0 and defined $v1) { } 33 6 39
elsif (defined $f0b) { } 0 6 6
Condition66%2/3
defined $v0 and defined $v1
!ll&&!rl&&r
6033
MC/DC50%1/2
defined $v0 and defined $v1
defined $v0 defined $v1
Truth table66%2/3
A and B
A= defined $v0B= defined $v1
ABresult
0X0
100
111
1230 33 $f = $f0;
1231 } elsif (defined $f0b) {
1232 0 $v0 = $$p0b{$key};
1233 0 $v1 = $$p1b{$key};
1234 0 ▶ next unless defined $v0 and defined $v1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v0 and defined $v1 0 0 0
Condition0%0/3
defined $v0 and defined $v1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $v0 and defined $v1
defined $v0 defined $v1
Truth table0%0/3
A and B
A= defined $v0B= defined $v1
ABresult
0X0
100
111
1235 0 $f = $f0b;
1236 } else {
1237 6 ▶ next if $sepTags{$key}; # (don't scan outwards for some formats, eg. CSV)
Branch: 1 branch
BranchTrueFalseTotal
if $sepTags{$key} 6 0 6
1238 # scan outwards looking for fixes with the required information
1239 # (NOTE: SHOULD EVENTUALLY DO THIS FOR EXTRAPOLATION TOO!)
1240 0 my ($t0b, $t1b);
1241 0 ▶ if (defined $v0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v0) { } 0 0 0
1242 0 $t0b = $t0; $p0b = $p0;
1243 } else {
1244 0 ($t0b,$p0b,$v0) = ScanOutwards($key,$times,$points,$i0,-1,$maxSecs);
1245 0 ▶ next Category unless defined $t0b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t0b 0 0 0
1246 }
1247 0 ▶ if (defined $v1) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v1) { } 0 0 0
1248 0 $t1b = $t1; $p1b = $p1;
1249 } else {
1250 0 ($t1b,$p1b,$v1) = ScanOutwards($key,$times,$points,$i1,1,$maxSecs);
1251 0 ▶ next Category unless defined $t1b;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t1b 0 0 0
1252 }
1253 # re-calculate the interpolation factor
1254 0 ▶ $f = $f0b = $t1b == $t0b ? 0 : ($time - $t0b) / ($t1b - $t0b);
Branch: 1 branch
BranchTrueFalseTotal
$t1b == $t0b ? : 0 0 0
1255 0 ▶ $et->VPrint(2, " Interpolating $category between fixes (f=$f):\n",
Branch: 1 branch
BranchTrueFalseTotal
if $verbose > 2 0 0 0
1256 PrintFix($points, $t0b, $t1b)) if $verbose > 2;
1257 }
1258 # must interpolate cyclical values differently
1259 33 ▶ if ($cyclical{$key} and abs($v1 - $v0) > 180) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cyclical{$key} and abs $v1 - $v0 > 180) { } 0 33 33
Condition66%2/3
$cyclical{$key} and abs $v1 - $v0 > 180
!ll&&!rl&&r
16170
MC/DC0%0/2
$cyclical{$key} and abs $v1 - $v0 > 180
$cyclical{$key} abs $v1 - $v0 > 180
Truth table66%2/3
A and B
A= $cyclical{$key}B= abs $v1 - $v0 > 180
ABresult
0X0
100
111
1260 # the acute angle spans the discontinuity, so add
1261 # 360 degrees to the smaller angle before interpolating
1262 0 ▶ $v0 < $v1 ? $v0 += 360 : $v1 += 360;
Branch: 1 branch
BranchTrueFalseTotal
$v0 < $v1 ? : 0 0 0
1263 0 $$fix{$key} = $v1 * $f + $v0 * (1 - $f);
1264 # some ranges are -180 to 180, others are 0 to 360
1265 0 ▶ my $max = $cyc180{$key} ? 180 : 360;
Branch: 1 branch
BranchTrueFalseTotal
$cyc180{$key} ? : 0 0 0
1266 0 ▶ $$fix{$key} -= 360 if $$fix{$key} >= $max;
Branch: 1 branch
BranchTrueFalseTotal
if $fix->{$key} >= $max 0 0 0
1267 } else {
1268 # simple linear interpolation
1269 33 $$fix{$key} = $v1 * $f + $v0 * (1 - $f);
1270 }
1271 }
1272 }
1273 }
1274 }
1275 11 ▶ if ($fix) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fix) { } 10 1 11
elsif ($geotag->{'NoDate'} and not $noDate and $val =~ s/^\S+\s+//) { } 0 2 2
1276 10 $err = ''; # success!
1277 ▶ } elsif ($$geotag{NoDate} and not $noDate and $val =~ s/^\S+\s+//) {
Condition33%2/6
$geotag->{"NoDate"} and not $noDate and $val =~ s/^\S+\s+//
!ll&&!rl&&r
100
$geotag->{"NoDate"} and not $noDate
!ll&&!rl&&r
100
MC/DC0%0/3
$geotag->{"NoDate"} and not $noDate and $val =~ s/^\S+\s+//
$geotag->{"NoDate"} not $noDate $val =~ s/^\S+\s+//
Truth table25%1/4
A and not(B) and C
A= $geotag->{"NoDate"}B= not $noDateC= $val =~ s/^\S+\s+//
ABCresult
0XX0
10X0
1100
1111
1278 # try again with no date since some of our track points are date-less
1279 0 $secondTry = 1;
1280 0 next;
1281 }
1282 11 last;
1283 }
1284 14 ▶ if ($fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fix) { } 10 4 14
1285 10 my ($gpsDate, $gpsAlt, $gpsAltRef);
1286 10 my @t = gmtime(int $time);
1287 10 my $gpsTime = sprintf('%.2d:%.2d:%.2d', $t[2], $t[1], $t[0]) . $fsec;
1288 # write GPSDateStamp if date included in track log, otherwise delete it
1289 10 ▶ $gpsDate = sprintf('%.2d:%.2d:%.2d', $t[5]+1900, $t[4]+1, $t[3]) unless $noDate;
Branch: 1 branch
BranchTrueFalseTotal
unless $noDate 10 0 10
1290 # write GPSAltitude tags if altitude included in track log, otherwise delete them
1291 10 my $alt = $$fix{alt};
1292 10 ▶ if (not defined $alt and $$has{alt} and defined $iExt) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $alt and $has->{"alt"} and defined $iExt) 0 10 10
Condition50%3/6
not defined $alt and $has->{"alt"} and defined $iExt
!ll&&!rl&&r
1000
not defined $alt and $has->{"alt"}
!ll&&!rl&&r
640
MC/DC0%0/3
not defined $alt and $has->{"alt"} and defined $iExt
not defined $alt $has->{"alt"} defined $iExt
Truth table50%2/4
not(A) and B and C
A= not defined $altB= $has->{"alt"}C= defined $iExt
ABCresult
0XX0
10X0
1100
1111
1293 0 my $tFix = FindFix($et,'alt',$times,$points,$iExt,$iDir,$geoMaxExtSecs);
1294 0 ▶ $alt = $$tFix{alt} if $tFix;
Branch: 1 branch
BranchTrueFalseTotal
if $tFix 0 0 0
1295 }
1296 # set new GPS tag values (EXIF, or XMP if write group is 'xmp')
1297 10 my ($xmp, $exif, $qt, @r);
1298 10 my %opts = ( Type => 'ValueConv' ); # write ValueConv values
1299 10 ▶ if ($writeGroup) {
Branch: 1 branch
BranchTrueFalseTotal
if ($writeGroup) 1 9 10
1300 1 $opts{Group} = $writeGroup;
1301 1 $xmp = ($writeGroup =~ /xmp/i);
1302 1 $exif = ($writeGroup =~ /^(exif|gps)$/i);
1303 1 $qt = $writeGroup =~ /^(quicktime|keys|itemlist|userdata)$/i;
1304 }
1305 # set QuickTime GPSCoordinates
1306 10 my $coords = "$$fix{lat} $$fix{lon}";
1307 10 ▶ if (defined $alt) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $alt) 6 4 10
1308 6 $gpsAlt = abs $alt;
1309 6 ▶ $gpsAltRef = ($alt < 0 ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$alt < 0 ? : 0 6 6
1310 6 $coords .= " $alt";
1311 }
1312 10 @r = $et->SetNewValue(GPSCoordinates => $coords, %opts);
1313 # also Geolocate if specified
1314 10 my $nvHash;
1315 10 my $geoloc = $et->GetNewValue('Geolocate', \$nvHash);
1316 10 ▶ if ($geoloc and $geoloc =~ /\bgeotag\b/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($geoloc and $geoloc =~ /\bgeotag\b/i) 1 9 10
Condition66%2/3
$geoloc and $geoloc =~ /\bgeotag\b/i
!ll&&!rl&&r
901
MC/DC50%1/2
$geoloc and $geoloc =~ /\bgeotag\b/i
$geoloc $geoloc =~ /\bgeotag\b/i
Truth table66%2/3
A and B
A= $geolocB= $geoloc =~ /\bgeotag\b/i
ABresult
0X0
100
111
1317 1 ▶ my $tag = ($$nvHash{WantGroup} ? "$$nvHash{WantGroup}:" : '') . 'Geolocate';
Branch: 1 branch
BranchTrueFalseTotal
$nvHash->{'WantGroup'} ? : 1 0 1
1318 # pass along any regular expressions to qualify geolocation search
1319 1 my $parms = join ',', grep m(/), split /\s*,\s*/, $geoloc;
1320 1 ▶ $parms and $parms = ",$parms,both";
Branch: 1 branch
BranchTrueFalseTotal
$parms and $parms = ",$parms,both" 0 1 1
1321 1 $et->SetNewValue($tag => "$$fix{lat},$$fix{lon}$parms");
1322 # (the Geolocate tag will be restored to its original value
1323 # by RestoreNewValues before the next file in batch processing)
1324 }
1325 10 ▶ return $err if $qt; # all done if writing to QuickTime only
Branch: 1 branch
BranchTrueFalseTotal
if $qt 0 10 10
1326 # (capture error messages by calling SetNewValue in list context)
1327 10 @r = $et->SetNewValue(GPSLatitude => $$fix{lat}, %opts);
1328 10 @r = $et->SetNewValue(GPSLongitude => $$fix{lon}, %opts);
1329 10 @r = $et->SetNewValue(GPSAltitude => $gpsAlt, %opts);
1330 10 @r = $et->SetNewValue(GPSAltitudeRef => $gpsAltRef, %opts);
1331 10 ▶ if ($$has{track} or $$has{speed}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has->{"track"} or $has->{"speed"}) 3 7 10
Condition66%2/3
$has->{"track"} or $has->{"speed"}
l!l&&r!l&&!r
307
MC/DC50%1/2
$has->{"track"} or $has->{"speed"}
$has->{"track"} $has->{"speed"}
Truth table66%2/3
A or B
A= $has->{"track"}B= $has->{"speed"}
ABresult
1X1
011
000
1332 3 ▶ my $type = $$has{track} ? 'track' : 'speed';
Branch: 1 branch
BranchTrueFalseTotal
$has->{'track'} ? : 3 0 3
1333 3 my $tFix = $fix;
1334 3 ▶ if (not defined $$fix{$type} and defined $iExt) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fix->{$type} and defined $iExt) 1 2 3
Condition66%2/3
not defined $fix->{$type} and defined $iExt
!ll&&!rl&&r
201
MC/DC50%1/2
not defined $fix->{$type} and defined $iExt
not defined $fix->{$type} defined $iExt
Truth table66%2/3
not(A) and B
A= not defined $fix->{$type}B= defined $iExt
ABresult
0X0
100
111
1335 1 my $p = FindFix($et,$type,$times,$points,$iExt,$iDir,$geoMaxExtSecs);
1336 1 ▶ $tFix = $p if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 1 1
1337 }
1338 3 @r = $et->SetNewValue(GPSTrack => $$tFix{track}, %opts);
1339 3 ▶ @r = $et->SetNewValue(GPSTrackRef => (defined $$tFix{track} ? 'T' : undef), %opts);
Branch: 1 branch
BranchTrueFalseTotal
defined $tFix->{'track'} ? : 2 1 3
1340 3 my ($spd, $ref);
1341 3 ▶ if (defined($spd = $$tFix{speed})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($spd = $tFix->{"speed"})) 1 2 3
1342 # convert to specified units if necessary
1343 1 $ref = $$et{OPTIONS}{GeoSpeedRef};
1344 1 ▶ if ($ref and defined $speedConv{$ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref and defined $speedConv{$ref}) { } 0 1 1
Condition33%1/3
$ref and defined $speedConv{$ref}
!ll&&!rl&&r
100
MC/DC0%0/2
$ref and defined $speedConv{$ref}
$ref defined $speedConv{$ref}
Truth table33%1/3
A and B
A= $refB= defined $speedConv{$ref}
ABresult
0X0
100
111
1345 0 ▶ $ref = $speedConv{$ref} if $speedConv{$speedConv{$ref}};
Branch: 1 branch
BranchTrueFalseTotal
if $speedConv{$speedConv{$ref}} 0 0 0
1346 0 $spd *= $speedConv{$ref};
1347 } else {
1348 1 $ref = 'N'; # knots by default
1349 }
1350 }
1351 3 @r = $et->SetNewValue(GPSSpeed => $spd, %opts);
1352 3 @r = $et->SetNewValue(GPSSpeedRef => $ref, %opts);
1353 }
1354 10 ▶ if ($$has{orient}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has->{"orient"}) 3 7 10
1355 3 my $tFix = $fix;
1356 3 ▶ if (not defined $$fix{dir} and defined $iExt) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fix->{"dir"} and defined $iExt) 1 2 3
Condition66%2/3
not defined $fix->{"dir"} and defined $iExt
!ll&&!rl&&r
201
MC/DC50%1/2
not defined $fix->{"dir"} and defined $iExt
not defined $fix->{"dir"} defined $iExt
Truth table66%2/3
not(A) and B
A= not defined $fix->{"dir"}B= defined $iExt
ABresult
0X0
100
111
1357 1 my $p = FindFix($et,'dir',$times,$points,$iExt,$iDir,$geoMaxExtSecs);
1358 1 ▶ $tFix = $p if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 1 1
1359 }
1360 3 @r = $et->SetNewValue(GPSImgDirection => $$tFix{dir}, %opts);
1361 3 ▶ @r = $et->SetNewValue(GPSImgDirectionRef => (defined $$tFix{dir} ? 'T' : undef), %opts);
Branch: 1 branch
BranchTrueFalseTotal
defined $tFix->{'dir'} ? : 2 1 3
1362 3 @r = $et->SetNewValue(CameraElevationAngle => $$tFix{pitch}, %opts);
1363 # Note: GPSPitch and GPSRoll are non-standard, and must be user-defined
1364 3 @r = $et->SetNewValue(GPSPitch => $$tFix{pitch}, %opts);
1365 3 @r = $et->SetNewValue(GPSRoll => $$tFix{roll}, %opts);
1366 }
1367 10 ▶ if ($$has{atemp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has->{"atemp"}) 0 10 10
1368 0 my $tFix = $fix;
1369 0 ▶ if (not defined $$fix{atemp} and defined $iExt) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fix->{"atemp"} and defined $iExt) 0 0 0
Condition0%0/3
not defined $fix->{"atemp"} and defined $iExt
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $fix->{"atemp"} and defined $iExt
not defined $fix->{"atemp"} defined $iExt
Truth table0%0/3
not(A) and B
A= not defined $fix->{"atemp"}B= defined $iExt
ABresult
0X0
100
111
1370 # (not all fixes have atemp, so try interpolating specifically for this)
1371 0 my $p = FindFix($et,'atemp',$times,$points,$iExt,$iDir,$geoMaxExtSecs);
1372 0 ▶ $tFix = $p if $p;
Branch: 1 branch
BranchTrueFalseTotal
if $p 0 0 0
1373 }
1374 0 @r = $et->SetNewValue(AmbientTemperature => $$tFix{atemp}, %opts);
1375 }
1376 10 ▶ if ($$has{err}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has->{"err"}) 0 10 10
1377 0 @r = $et->SetNewValue(GPSHPositioningError => $$fix{err}, %opts);
1378 }
1379 10 ▶ if ($$has{dop}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has->{"dop"}) 0 10 10
1380 0 my ($dop, $mm);
1381 0 ▶ if (defined $$fix{pdop}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $fix->{'pdop'}) { } 0 0 0
elsif (defined $fix->{'hdop'}) { } 0 0 0
1382 0 $dop = $$fix{pdop};
1383 0 $mm = 3;
1384 } elsif (defined $$fix{hdop}) {
1385 0 ▶ if (defined $$fix{vdop}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fix->{'vdop'}) { } 0 0 0
1386 0 $dop = sqrt($$fix{hdop} * $$fix{hdop} + $$fix{vdop} * $$fix{vdop});
1387 0 $mm = 3;
1388 } else {
1389 0 $dop = $$fix{hdop};
1390 0 $mm = 2;
1391 }
1392 }
1393 0 ▶ if (defined $dop) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dop) 0 0 0
1394 0 $et->SetNewValue(GPSMeasureMode => $mm, %opts);
1395 0 $et->SetNewValue(GPSDOP => $dop, %opts);
1396 # also set GPSHPositioningError if specified
1397 0 my $hposErr = $$et{OPTIONS}{GeoHPosErr};
1398 0 ▶ if ($hposErr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hposErr) 0 0 0
1399 0 $hposErr =~ s/gpsdop/GPSDOP/i;
1400 0 my $GPSDOP = $dop;
1401 0 local $SIG{'__WARN__'} = \&Image::ExifTool::SetWarning;
1402 0 undef $Image::ExifTool::evalWarning;
1403 #### eval GeoHPosErr ($GPSDOP)
1404 0 $hposErr = eval $hposErr;
1405 0 ▶ my $err = Image::ExifTool::GetWarning() || $@;
Condition0%0/3
&Image::ExifTool::GetWarning() || $@
l!l&&r!l&&!r
000
MC/DC0%0/2
&Image::ExifTool::GetWarning() || $@
&Image::ExifTool::GetWarning() $@
Truth table0%0/3
A || B
A= &Image::ExifTool::GetWarning()B= $@
ABresult
1X1
011
000
1406 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) { } 0 0 0
1407 0 $err = Image::ExifTool::CleanWarning($err);
1408 0 $et->Warn("Error calculating GPSHPositioningError: $err", 1);
1409 } else {
1410 0 $et->SetNewValue(GPSHPositioningError => $hposErr, %opts);
1411 }
1412 }
1413 }
1414 }
1415 10 ▶ unless ($xmp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($xmp) 9 1 10
1416 9 my ($latRef, $lonRef);
1417 9 ▶ $latRef = ($$fix{lat} > 0 ? 'N' : 'S') if defined $$fix{lat};
Branch: 2 branches
BranchTrueFalseTotal
if defined $fix->{"lat"} 8 1 9
$fix->{'lat'} > 0 ? : 7 1 8
1418 9 ▶ $lonRef = ($$fix{lon} > 0 ? 'E' : 'W') if defined $$fix{lon};
Branch: 2 branches
BranchTrueFalseTotal
if defined $fix->{"lon"} 8 1 9
$fix->{'lon'} > 0 ? : 4 4 8
1419 9 @r = $et->SetNewValue(GPSLatitudeRef => $latRef, %opts);
1420 9 @r = $et->SetNewValue(GPSLongitudeRef => $lonRef, %opts);
1421 9 @r = $et->SetNewValue(GPSDateStamp => $gpsDate, %opts);
1422 9 @r = $et->SetNewValue(GPSTimeStamp => $gpsTime, %opts);
1423 # set options to edit XMP:GPSDateTime only if it already exists
1424 9 $opts{EditOnly} = 1;
1425 9 $opts{Group} = 'XMP';
1426 }
1427 10 ▶ unless ($exif) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exif) 10 0 10
1428 10 @r = $et->SetNewValue(GPSDateTime => "$gpsDate $gpsTime", %opts);
1429 }
1430 # set user-defined tags
1431 10 foreach (sort values %userTag) {
1432 0 ▶ @r = $et->SetNewValue(substr($_, 1) => $$fix{$_}) if defined $$fix{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fix->{$_} 0 0 0
1433 }
1434 } else {
1435 4 my %opts = ( IgnorePermanent => 1 );
1436 4 ▶ $opts{Replace} = 2 if defined $val; # remove existing new values
Branch: 1 branch
BranchTrueFalseTotal
if defined $val 1 3 4
1437 # reset user-defined GPX tags
1438 4 InitUserTags($et); # (won't be set yet because we didn't read a GPX file)
1439 4 foreach (values %userTag) {
1440 0 my @r = $et->SetNewValue(substr($_, 1), undef, %opts);
1441 }
1442 4 ▶ $opts{Group} = $writeGroup if $writeGroup;
Branch: 1 branch
BranchTrueFalseTotal
if $writeGroup 2 2 4
1443 # reset any GPS values we might have already set
1444 4 foreach (qw(GPSLatitude GPSLatitudeRef GPSLongitude GPSLongitudeRef
1445 GPSAltitude GPSAltitudeRef GPSDateStamp GPSTimeStamp GPSDateTime
1446 GPSTrack GPSTrackRef GPSSpeed GPSSpeedRef GPSImgDirection
1447 GPSImgDirectionRef GPSPitch GPSRoll CameraElevationAngle
1448 AmbientTemperature GPSHPositioningError GPSCoordinates
1449 GPSMeasureMode GPSDOP))
1450 {
1451 92 my @r = $et->SetNewValue($_, undef, %opts);
1452 }
1453 }
1454 14 return $err;
1455 }
1456  
1457 #------------------------------------------------------------------------------
1458 # Convert Geotagging time synchronization value
1459 # Inputs: 0) exiftool object ref,
1460 # 1) time difference string ("[+-]DD MM:HH:SS.ss"), geosync'd file name,
1461 # "GPSTIME@IMAGETIME", or "GPSTIME@FILENAME"
1462 # Returns: geosync hash:
1463 # Offset = Offset in seconds for latest synchronization (GPS - image time)
1464 # Points = hash of all sync offsets keyed by image times in seconds
1465 # Times = sorted list of image synchronization times (keys in Points hash)
1466 # Notes: calling this routine with more than one geosync'd file causes time drift
1467 # correction to be implemented
1468 sub ConvertGeosync($$)
1469 5 ▶{
Subroutine ConvertGeosync: called CC=39 SCAR=54.7
Pod undocumented
1470 5 my ($et, $val) = @_;
1471 5 ▶ my $sync = $et->GetNewValue('Geosync') || { };
Condition100%2/2
$et->GetNewValue('Geosync') || {}
l!l
23
MC/DC100%1/1
$et->GetNewValue('Geosync') || {}
$et->GetNewValue('Geosync')
Truth table100%2/2
A
A= $et->GetNewValue('Geosync')
Aresult
11
00
1472 5 my ($syncFile, $gpsTime, $imgTime);
1473  
1474 5 ▶ if ($val =~ /(.*?)\@(.*)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val =~ /(.*?)\@(.*)/) { } 4 1 5
elsif (not $val =~ /^\d/ && $val =~ /:/) { } 0 1 1
1475 4 $gpsTime = $1;
1476 4 ▶ (-f $2 ? $syncFile : $imgTime) = $2;
Branch: 1 branch
BranchTrueFalseTotal
-f $2 ? : 0 4 4
1477 # (take care because "-f '1:30'" crashes ActivePerl 5.10)
1478 ▶ } elsif ($val !~ /^\d/ or $val !~ /:/) {
Condition33%1/3
$val =~ /^\d/ && $val =~ /:/
!ll&&!rl&&r
001
MC/DC0%0/2
$val =~ /^\d/ && $val =~ /:/
$val =~ /^\d/ $val =~ /:/
Truth table33%1/3
A && B
A= $val =~ /^\d/B= $val =~ /:/
ABresult
0X0
100
111
1479 0 ▶ $syncFile = $val if -f $val;
Branch: 1 branch
BranchTrueFalseTotal
if -f $val 0 0 0
1480 }
1481 5 ▶ if ($gpsTime or defined $syncFile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gpsTime or defined $syncFile) { } 4 1 5
Condition66%2/3
$gpsTime or defined $syncFile
l!l&&r!l&&!r
401
MC/DC50%1/2
$gpsTime or defined $syncFile
$gpsTime defined $syncFile
Truth table66%2/3
A or B
A= $gpsTimeB= defined $syncFile
ABresult
1X1
011
000
1482 # (this is a time synchronization vector)
1483 4 ▶ if (defined $syncFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $syncFile) 0 4 4
1484 # check the following tags in order to obtain the image timestamp
1485 0 my @timeTags = qw(SubSecDateTimeOriginal SubSecCreateDate SubSecModifyDate
1486 DateTimeOriginal CreateDate ModifyDate FileModifyDate);
1487 0 my $info = ImageInfo($syncFile, { PrintConv => 0 }, @timeTags,
1488 'GPSDateTime', 'GPSTimeStamp');
1489 0 ▶ $$info{Error} and warn("$$info{Err}\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$info->{"Error"} and warn(qq[$info->{"Err"}\n]), (return undef) 0 0 0
1490 0 ▶ unless ($gpsTime) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gpsTime) 0 0 0
1491 0 ▶ $gpsTime = $$info{GPSDateTime} || $$info{GPSTimeStamp};
Condition0%0/3
$info->{'GPSDateTime'} || $info->{'GPSTimeStamp'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$info->{'GPSDateTime'} || $info->{'GPSTimeStamp'}
$info->{'GPSDateTime'} $info->{'GPSTimeStamp'}
Truth table0%0/3
A || B
A= $info->{'GPSDateTime'}B= $info->{'GPSTimeStamp'}
ABresult
1X1
011
000
1492 0 ▶ $gpsTime .= 'Z' if $gpsTime and not $$info{GPSDateTime};
Branch: 1 branch
BranchTrueFalseTotal
if $gpsTime and not $info->{"GPSDateTime"} 0 0 0
Condition0%0/3
$gpsTime and not $info->{"GPSDateTime"}
!ll&&!rl&&r
000
MC/DC0%0/2
$gpsTime and not $info->{"GPSDateTime"}
$gpsTime not $info->{"GPSDateTime"}
Truth table0%0/3
A and not(B)
A= $gpsTimeB= not $info->{"GPSDateTime"}
ABresult
0X0
100
111
1493 }
1494 0 ▶ $gpsTime or warn("No GPSTimeStamp in '$syncFile\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$gpsTime or warn("No GPSTimeStamp in '$syncFile\n"), (return undef) 0 0 0
1495 0 my $tag;
1496 0 foreach $tag (@timeTags) {
1497 0 ▶ if ($$info{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{$tag}) 0 0 0
1498 0 $imgTime = $$info{$tag};
1499 0 $et->VPrint(2, "Geosyncing with $tag from '${syncFile}'\n");
1500 0 last;
1501 }
1502 }
1503 0 ▶ $imgTime or warn("No image timestamp in '${syncFile}'\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
$imgTime or warn("No image timestamp in '${syncFile}'\n"), (return undef) 0 0 0
1504 }
1505 # add date to date-less timestamps
1506 4 my ($imgDateTime, $gpsDateTime, $noDate);
1507 4 ▶ if ($imgTime =~ /^(\d+:\d+:\d+)\s+\d+/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($imgTime =~ /^(\d+:\d+:\d+)\s+\d+/) { } 4 0 4
elsif ($gpsTime =~ /^(\d+:\d+:\d+)\s+\d+/) { } 0 0 0
1508 4 $imgDateTime = $imgTime;
1509 4 my $date = $1;
1510 4 ▶ if ($gpsTime =~ /^\d+:\d+:\d+\s+\d+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gpsTime =~ /^\d+:\d+:\d+\s+\d+/) { } 4 0 4
1511 4 $gpsDateTime = $gpsTime;
1512 } else {
1513 0 $gpsDateTime = "$date $gpsTime";
1514 }
1515 } elsif ($gpsTime =~ /^(\d+:\d+:\d+)\s+\d+/) {
1516 0 $imgDateTime = "$1 $imgTime";
1517 0 $gpsDateTime = $gpsTime;
1518 } else {
1519 # use a today's date (so hopefully the DST setting will be intuitive)
1520 0 my @tm = localtime;
1521 0 my $date = sprintf('%.4d:%.2d:%.2d', $tm[5]+1900, $tm[4]+1, $tm[3]);
1522 0 $gpsDateTime = "$date $gpsTime";
1523 0 $imgDateTime = "$date $imgTime";
1524 0 $noDate = 1;
1525 }
1526 # calculate Unix seconds since the epoch
1527 4 my $imgSecs = Image::ExifTool::GetUnixTime($imgDateTime, 1);
1528 4 ▶ defined $imgSecs or warn("Invalid image time '${imgTime}'\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $imgSecs or warn("Invalid image time '${imgTime}'\n"), (return undef) 4 0 4
1529 4 my $gpsSecs = Image::ExifTool::GetUnixTime($gpsDateTime, 1);
1530 4 ▶ defined $gpsSecs or warn("Invalid GPS time '${gpsTime}'\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $gpsSecs or warn("Invalid GPS time '${gpsTime}'\n"), (return undef) 4 0 4
1531 # add fractional seconds
1532 4 ▶ $gpsSecs += $1 if $gpsTime =~ /(\.\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $gpsTime =~ /(\.\d+)/ 0 4 4
1533 4 ▶ $imgSecs += $1 if $imgTime =~ /(\.\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if $imgTime =~ /(\.\d+)/ 0 4 4
1534 # shift dates within 12 hours of each other if either timestamp was date-less
1535 4 ▶ if ($gpsDateTime ne $gpsTime or $imgDateTime ne $imgTime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gpsDateTime ne $gpsTime or $imgDateTime ne $imgTime) 0 4 4
Condition33%1/3
$gpsDateTime ne $gpsTime or $imgDateTime ne $imgTime
l!l&&r!l&&!r
004
MC/DC0%0/2
$gpsDateTime ne $gpsTime or $imgDateTime ne $imgTime
$gpsDateTime ne $gpsTime $imgDateTime ne $imgTime
Truth table33%1/3
A or B
A= $gpsDateTime ne $gpsTimeB= $imgDateTime ne $imgTime
ABresult
1X1
011
000
1536 0 my $diff = ($imgSecs - $gpsSecs) % (24 * 3600);
1537 0 ▶ $diff -= 24 * 3600 if $diff > 12 * 3600;
Branch: 1 branch
BranchTrueFalseTotal
if $diff > 43200 0 0 0
1538 0 ▶ $diff += 24 * 3600 if $diff < -12 * 3600;
Branch: 1 branch
BranchTrueFalseTotal
if $diff < -43200 0 0 0
1539 0 ▶ if ($gpsDateTime ne $gpsTime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gpsDateTime ne $gpsTime) { } 0 0 0
1540 0 $gpsSecs = $imgSecs - $diff;
1541 } else {
1542 0 $imgSecs = $gpsSecs + $diff;
1543 }
1544 }
1545 # save the synchronization offset
1546 4 $$sync{Offset} = $gpsSecs - $imgSecs;
1547 # save this synchronization point if either timestamp had a date
1548 4 ▶ unless ($noDate) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($noDate) 4 0 4
1549 4 ▶ $$sync{Points} or $$sync{Points} = { };
Branch: 1 branch
BranchTrueFalseTotal
$sync->{"Points"} or $sync->{"Points"} = {} 2 2 4
1550 4 $$sync{Points}{$imgSecs} = $$sync{Offset};
1551 # print verbose output
1552 4 ▶ if ($et->Options('Verbose') > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->Options("Verbose") > 1) 2 2 4
1553 # print GPS and image timestamps in UTC
1554 2 $et->VPrint(1, "Added Geosync point:\n",
1555 ' GPS time stamp: ', PrintFixTime($gpsSecs), "\n",
1556 ' Image date/time: ', PrintFixTime($imgSecs), "\n");
1557 }
1558 # save sorted list of image sync times if we have more than one
1559 4 my @times = keys %{$$sync{Points}};
1560 4 ▶ if (@times > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@times > 1) 2 2 4
1561 2 @times = sort { $a <=> $b } @times;
1562 2 $$sync{Times} = \@times;
1563 }
1564 }
1565 } else {
1566 # (this is a simple time difference)
1567 1 my @vals = $val =~ /(?=\d|\.\d)\d*(?:\.\d*)?/g; # (allow decimal values too)
1568 1 ▶ @vals or warn("Invalid value (please refer to geotag documentation)\n"), return undef;
Branch: 1 branch
BranchTrueFalseTotal
@vals or warn("Invalid value (please refer to geotag documentation)\n"), (return undef) 1 0 1
1569 1 my $secs = 0;
1570 1 my $mult;
1571 1 foreach $mult (1, 60, 3600, $secPerDay) {
1572 2 $secs += $mult * pop(@vals);
1573 2 ▶ last unless @vals;
Branch: 1 branch
BranchTrueFalseTotal
unless @vals 1 1 2
1574 }
1575 # set constant sync offset
1576 1 ▶ $$sync{Offset} = $val =~ /^\s*-/ ? -$secs : $secs;
Branch: 1 branch
BranchTrueFalseTotal
$val =~ /^\s*-/ ? : 0 1 1
1577 }
1578 5 return $sync;
1579 }
1580  
1581 #------------------------------------------------------------------------------
1582 # Print fix time
1583 # Inputs: 0) time since the epoch
1584 # Returns: UTC time string with fractional seconds
1585 sub PrintFixTime($)
1586 8 ▶{
Subroutine PrintFixTime: called CC=1 SCAR=0.0
Pod undocumented
1587 8 my $time = shift;
1588 8 return Image::ExifTool::ConvertUnixTime($time, undef, 3) . ' UTC';
1589 }
1590  
1591 #------------------------------------------------------------------------------
1592 # Print fix information
1593 # Inputs: 0) lookup for all fix points, 1-n) list of fix times
1594 # Returns: fix string (including leading indent and trailing newline)
1595 sub PrintFix($@)
1596 0 ▶{
Subroutine PrintFix: not called CC=6 SCAR=37.4
Pod undocumented
1597 0 local $_;
1598 0 my $points = shift;
1599 0 my $str = '';
1600 0 ▶ while (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1601 0 my $time = shift;
1602 0 $str .= ' ' . PrintFixTime($time) . ' -';
1603 0 my $fix = $$points{$time};
1604 0 ▶ if ($fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fix) 0 0 0
1605 0 foreach (sort keys %$fix) {
1606 0 ▶ $str .= " $_=$$fix{$_}" unless $_ eq 'time' or not defined $$fix{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $_ eq "time" or not defined $fix->{$_} 0 0 0
Condition0%0/3
$_ eq "time" or not defined $fix->{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq "time" or not defined $fix->{$_}
$_ eq "time" not defined $fix->{$_}
Truth table0%0/3
A or not(B)
A= $_ eq "time"B= not defined $fix->{$_}
ABresult
1X1
011
000
1607 }
1608 }
1609 0 $str .= "\n";
1610 }
1611 0 return $str;
1612 }
1613  
1614 #------------------------------------------------------------------------------
1615 # Initialize %userTag for reading user-defined GPX tags
1616 # Inputs: 0) ExifTool ref
1617 sub InitUserTags($)
1618 14 ▶{
Subroutine InitUserTags: called CC=5 SCAR=25.9
Pod undocumented
1619 14 my $et = shift;
1620 14 %userTag = ( );
1621 14 ▶ if ($$et{OPTIONS}{GeoUserTag}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"OPTIONS"}{"GeoUserTag"}) 0 14 14
1622 0 foreach (split /\s*,\s*/, $$et{OPTIONS}{GeoUserTag}) {
1623 0 ▶ next unless /^(.+)=(.+)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^(.+)=(.+)$/ 0 0 0
1624 0 ▶ $xmlTag{lc $2} and $et->Warn("User-defined GPX tag '${2}' conflicts with existing tag"), next;
Branch: 1 branch
BranchTrueFalseTotal
$xmlTag{lc $2} and $et->Warn("User-defined GPX tag '$2' conflicts with existing tag"), next 0 0 0
1625 0 $userTag{lc $2} = "_$1"; # (leading underline prevents conflicts)
1626 }
1627 }
1628 }
1629  
1630 #------------------------------------------------------------------------------
1631 3 1; # end
1632  
1633 __END__
« Image/ExifTool/QuickTimeStream.pl ↑ Summary Image/ExifTool/Plot.pm »