I think I once upon a time asked this before, but I don’t remember the answer. RPN is probably playing with my head!
I’m trying to figure out a way to take a values from certain columns of a table, do something to them, and write the result out as an appended column. Here’s an example, that doesn’t do what I’m expecting (because I forgot something in the command line, I’m sure!):
1.0000000000 6.0000000000 3.0000000000 4.0000000000 NaN
Another try:
echo “1 2 3 4” | gmtmath -i0-3 -o0-4 STDIN -C4 3 COL 1 COL ADD -Ca =
1.0000000000 0.0000000000 0.0000000000 0.0000000000 NaN
What I’m trying to do is create column 4 (in GMT columns) that consists of the sum of columns 1 and 3. Instead it does something else. In awk, it would go like this:
echo “1 2 3 4” | awk ’ { print $0, $2 + $4 } ', giving the answer expected (in awk, col nums start at 1):
1 2 3 4 6
The reason I’m asking this, is that I want to do something like this with a huge binary file, otherwise, I’d just use awk! THanks!
Thanks, Paul. I’m always pushing the envelope. And I see that little comment at the end of the -N option description: “… then -N will add any missing columns.” Super!
The -Q option provides a simple means to make a quick scalar calculation. Scalars are, by definition, single values, they can’t be considered a column (or a vector of values), per se.
The expression, gmt math -Q 1 1 ADD = is equivalent to echo "1 1" | awk ' { print $1 + $2 } '.
The COL operator is only applicable when working with columnar data. It isn’t applicable when using the -Q option for scalars. So, no “opposite function,” like STACKTOCOL, meaningfully exists.
Perhaps this does what is needed, in the first example (but any real purpose for doing this is elusive):
~ > echo "1 7" | awk ' { print $1, $2 } '
1 7
Finally, the -T option is only useful for creating a columnar sequence of values.
However, it may be better to adopt the suggested shorthand phrasing. The -Q option certainly does negate the need for the -T option.
Also, the docs for gmtmath is way behind the actual coding. Yes, internally the -Q sets the equivalent of -Ca -N1/0 -T0/0/1 but there is never any parsing of a -T option - we just set those values directly. Now that we have checks on -T so max > min you get an error trying to run it that way. I will just change it to -T1 to avoid to have others get confused.
Never mind about -Q. How about in general, if there is
COL: Places column A on the stack
shouldn’t there also be a “antidote” (some new name, XXX) operator to it?:
Whereas “COL XXX” would be equivalent to a NOOP (which by the way would be useful too, so that is why even proj.org implements it.)