Creating user functions in
GENPLOT using "gpextend.lib"
Each user function contains several files.
For this reason I suggest creating a directory for each function under
the following path:
c:\progra~1\cgs\surf\
A collection of template files (which can be copied
into a new directory and then edited to create a new function) is located
in:
c:\progra~1\cgs\surf\template
After copying all the files from this directory into
a new directory you will need to rename them using your chosen name for
your new function (denoted as <name> from now on). This can be
done with the following:
ren template.c <name>.c
ren template.def <name>.def
The following files are needed to generate a function
using gpextend.lib:
<name>.c
makefile
<name>.def
When using the template files you will need to edit
"makefile" & "<name>.def" and replace all occurences of the word
"template" with whatever your function name is (after this you should not
need to edit either of these files again). The next step is to edit
the <name>.c file....
Editing the <name>.c file:
The <name>.c file is
where the code for the function you wish to implement goes. It is
fairly well commented so and should be fairly easy to follow (the default
template file gives the code necessary for a line fitting funcion).
You should change the following:
In the UserInit() function:
Line 12: SetNumParams(2);
Change the "2" to the number of parameters used in the "P"
array.
Line 13: SetNumConstants(0);
Change the "0" to the number of constants used in the "C"
array.
In the FitFunc() function:
Line 24: float y;
Declare your variables at this point in the function.
Line 33: y=p[0]*x + p[1];
This is where the code for your function should go.
Line 35: *result=y;
Set *result to whatever number you wish for your function to
return.
Editing the <name>.def file:
You should only need to change the first line of
the <name>.def file. The first line in template.def is:
LIBRARY template
This should be changed to:
LIBRARY <name>
Compiling your function:
After following the previous steps you should be
able to compile your code by typing "nmake" at the command line prompt
(also you must be in the directory with the "makefile"
and your program files). After typing "nmake" your function will
be automatically placed in a directory where GENPLOT can get to it (assuming
that there were no errors during compilation). You can test to see
if you function will load by typing "user -load <name>" at the GENPLOT
prompt... however this is the only case where you should use the "user
-load" command with a gpextend function.
What about "template.mac"?
In order for the gpextend library to function properly...
user functions created with it must be run from a macro file (you can have
many different macro files for each function but they must follow the same
form as template.mac). This file is not used in the compilation process
so it can be placed where ever it is convinient (perhaps with the data
that the parameters are associated with). The first thing you should
do is rename the file using:
ren template.mac <mymac>.mac
Here <mymac> refers to whatever you wish to call the macro.
To use the macro you need to edit it:
Line 4: user -load template
Change "template" to <name> (from above).
Line 10: declare MacroName c:\progra~1\cgs\surf\template\template.mac
Change the "c:\progra~....\template.mac" to the full path name
of your new macro (ie <path>\<mymac>.mac).
Line 13: alloc P array 20
You generally will not need to change this unless you have
more than 20 parameters in the P array (same goes for the C
array).
Line 19: let P(0)=0.500000
This is where the parameters are stored. I recomend not
changing this by hand. I suggest executing the macro (with
the "x" command), and then use let P(???)=### to change the
param values (to get them to update inside the macro file
simply exit genplot or load another function).
|