@@ -36,7 +36,7 @@ use vars qw($VERSION);
3636use Image::ExifTool qw( :Public) ;
3737use Image::ExifTool::GPS;
3838
39- $VERSION = ' 1.86 ' ;
39+ $VERSION = ' 1.87 ' ;
4040
4141sub JITTER () { return 2 } # maximum time jitter
4242
@@ -137,6 +137,31 @@ my %otherConv = (
137137
138138my $secPerDay = 24 * 3600; # a useful constant
139139
140+ # ------------------------------------------------------------------------------
141+ # Split a line of CSV
142+ # Inputs: 0) line to split, 1) delimiter
143+ # Returns: list of items
144+ sub SplitCSV ($$)
145+ {
146+ my ($line , $delim ) = @_ ;
147+ my @toks = split /\Q$delim /, $line ;
148+ my (@vals , $v );
149+ while (@toks ) {
150+ ($v = shift @toks ) =~ s / ^ +// ; # remove leading spaces
151+ if ($v =~ s / ^"// ) {
152+ # quoted value must end in an odd number of quotes
153+ while ($v !~ / ("+)\s *$ / or not length ($1 ) & 1) {
154+ last unless @toks ;
155+ $v .= $delim . shift @toks ;
156+ }
157+ $v =~ s / "\s *$// ; # remove trailing quote and whitespace
158+ $v =~ s / ""/ "/ g ; # un-escape quotes
159+ }
160+ push @vals , $v ;
161+ }
162+ return @vals ;
163+ }
164+
140165# ------------------------------------------------------------------------------
141166# Load GPS track log file
142167# Inputs: 0) ExifTool ref, 1) track log data or file name
@@ -281,7 +306,7 @@ sub LoadTrackLog($$;$)
281306 $format = ' Bramor' ;
282307 } elsif (((/ \b (GPS)?Date/i and /\b(GPS)?(Date)?Time/i) or /\bTime\(seconds\)/i) and /\Q$csvDelim /) {
283308 chomp ;
284- @csvHeadings = split /\Q $csvDelim / ;
309+ @csvHeadings = SplitCSV( $_ , $csvDelim ) ;
285310 my $isColumbus = ($csvHeadings [0] and $csvHeadings [0] eq ' INDEX' ); # (Columbus GPS logger)
286311 $format = ' CSV' ;
287312 # convert recognized headings to our parameter names
@@ -382,7 +407,8 @@ sub LoadTrackLog($$;$)
382407 # parse attributes (eg. GPX 'lat' and 'lon')
383408 # (note: ignore namespace prefixes if they exist)
384409 if ($arg =~ / ^(\w +:)?(\w +)=(['"])(.*?)\3 /g ) {
385- my $tag = $xmlTag {lc $2 } || $userTag {lc $2 };
410+ my $tag = $xmlTag {lc $2 };
411+ $tag = $userTag {lc $2 } unless defined $tag ;
386412 if ($tag ) {
387413 $$fix {$tag } = $4 ;
388414 if ($keyCategory {$tag }) {
@@ -399,7 +425,8 @@ sub LoadTrackLog($$;$)
399425 # loop through XML elements
400426 while ($arg =~ m { ([^<>]*)<(/)?(\w +:)?(\w +)(>|$) } g ) {
401427 $tok = lc $4 ;
402- my $tag = $xmlTag {$tok } || $userTag {$tok };
428+ my $tag = $xmlTag {$tok };
429+ $tag = $userTag {$tok } unless defined $tag ;
403430 # parse as a simple property if this element has a value
404431 if (defined $tag and not $tag ) {
405432 # a containing property was opened or closed
@@ -530,7 +557,7 @@ DoneFix: $isDate = 1;
530557 goto DoneFix; # save this fix
531558 } elsif ($format eq ' CSV' ) {
532559 chomp ;
533- my @vals = split /\Q $csvDelim / ;
560+ my @vals = SplitCSV( $_ , $csvDelim ) ;
534561#
535562# CSV format output of GPS/IMU POS system
536563# Date* - date in DD/MM/YYYY format
@@ -1557,8 +1584,7 @@ sub ConvertGeosync($$)
15571584# Returns: UTC time string with fractional seconds
15581585sub PrintFixTime ($)
15591586{
1560- my $time = $_ [0] + 0.0005; # round off to nearest ms
1561- my $fsec = int (($time - int ($time )) * 1000);
1587+ my $time = shift ;
15621588 return Image::ExifTool::ConvertUnixTime($time , undef , 3) . ' UTC' ;
15631589}
15641590
0 commit comments