Arithmetic on extracted tags in fmt file

Started by Martin314, February 19, 2020, 01:25:26 PM

Previous topic - Next topic

Martin314

In FAQ #19 it says you can create an inline perl expression to modify an extracted tag.  Alternately, you can also create a composite tag, although that seems more complicated.

I'm trying to extract data from a logger which apparently scales GPS coordinates, so I want to multiple the numeric latitude and longitude by constants.  The FAQ says the format is ${TAG;EXPR} but it is unclear how to do arithmetic in the expression.  It mentions, $_, _, and $val.  I'm using gpx.fmt as a template and trying to modify that.  I have tried the following (and a few others I have forgotten or which were obviously wrong), none of which work:

lat="${gpslatitude#;$_*2.1}"
lat="${gpslatitude#;_*2.1}"
lat="${gpslatitude#;$val*2.1}"

How can I scale the value of the tag?

StarGeek

Try
"${gpslatitude#;$_*=2.1}"

The $_ variable is the Perl default variable.  It will contain the value of the tag.  In this case, I use the perl Multiply Assignment operator *= to multiple the value of $_ with the number on the right and re-assign it to $_.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Martin314

Ah, I was missing the "=" part of that.  That works, thanks!