3

How can the following, increasingly complicated macro stuff be replaced by a function? Calling macros within macros is quite error-prone

sel_col = 'column(selected_column)'
ref_col = 'column(reference_column)'
volume = '( (@sel_col) - grad * ( @ref_col - CM_mean ) )'
plot FILE using (@volume): ...

Should become something like this:

volume(s,r) = ...
plot FILE (volume(selected_column,reference_column)): ...

1 Answer 1

2

If possible I would avoid macros unless there is no other way. As I understand you want to create a function with columnheaders as input parameters to calculate some values.

In gnuplot you can either give column numbers, e.g. using 1:2:3 or using (column(1)):(column(2)):(column(3)) or shorter using ($1):($2):($3) or variables which contain numbers, e.g. for a=1, b=2, c=3 then you can write using a:b:c.

Alternatively, you can use columnheaders using "length":"width":"height" or variables, e.g. L="length", W="width", H="height" and then write using L:W:H or using (column(L)):(column(W)):(column(H)).

So, probably you are looking for something like:

Script:

### functions with headercolumns as parameters
reset session

$Data <<EOD
length  width   height
11      12      13
21      22      23
31      32      33
EOD

volume(l,w,h) = column(l) * column(w) * column(h)

l = "length"
w = "width"
h = "height"

set table $Test
    plot $Data u l:w:h:(volume(l,w,h)) w table
unset table
print $Test
### end of script

Result:

 11      12      13      1716
 21      22      23      10626
 31      32      33      32736
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! With such functions I can finally do without some global variables. It's actually easy to pass parameters to a function. Too bad I didn't know that earlier.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.