This document tells you how to implement new projector functions for the projection program. It's rather simple if you know what part of the code you have to look at. And that's exactly what this document tells you.
General comment: If in doubt, draw inspiration from the code for the projector functions that are already implemented.
The parsing of the projector function is done in
projfuncparse
in source/potfit/peinproj.F . The
parser looks at the function name, converts it to an internal
function index (stored in array projifunc
), parses
the function parameters, and stores them in array
projipar
, etc.
Code for parsing a new function label should be added near the
bottom of projfuncparse
(just before the comment
that says so) in a new elseif
-branch.
Variables that can be used:
i
(integer): This is an index into the array
of tokens that make up the function definition. When your code
starts, i=1, which means that it points to the function
name.token(i)
(string): Holds the i-th token of the
function definition. token(1) is the function name,
token(2) is the first parameter, and so on. The tokens
are all lowercase!origtoken(i)
(string): Holds the original
version of the i-th token (not lowercased).ltoken(i)
(integer): The length of the i-th
token.funclab
(string): Holds the function name.
Equal to token(1).Variables that must be set:
projifunc(p,q)
: The internal function
index.projipar(p,q,n)
: The integer parameters of the
function.projrpar(p,q,n)
: The real*8 parameters of the
function, likewise.projcpar(p,q,n)
: The string parameters of the
function, likewise.i
: When your code is finished, the index
should have been increased by the number of tokens you have
read, so it must point to the last token you read.
Recommendation: Always use i=i+1
before accessing
the next token as token(i)
.The numerical evaluation of the projector function happens in
calcprjf
in source/potfit/projcalc.F . To add
code for evaluating your new projector function, do the
following:
calcprjf
, add the new function
index (which was assigned in projlabparse
to
projifunc(p,q)
) to the computed-goto
statement.calcprjf
, add the
evaluation code (before the comment that says so). The first
line of this code must, of course, have the function index as
jump-label. The last line must be "goto 100
". The
coordinate value is in the variable x
, and the
result must be stored in the variable y
.Technical sidenote: your code will be inside a loop that runs
over all DVR grid points for the DOF in question. If your
function evaluation contains parts that only need to be done once
(like calculating the normalization factor) and that are costly,
you should take care that this part is only run once. Look at the
code for evaluating nf
for ifunc=1
to
see how this can be accomplished. However, the projector
functions are only calculated once (for each projector), so this
is probably not time-critical.
Don't forget to add documentation for the new projector function!
projifunc
.