Custom Dispersal Functions - number of variables

4 views
Skip to first unread message

steven.wangen

unread,
Aug 2, 2010, 9:42:42 AM8/2/10
to mdig
Hey there -

I was just trying to implement a custom dispersal function in MDiG; I
think I have everything figured out, except for the fact that it
requires a larger number of variables (5) compared to all the pre-
existing functions (3). (note: the function itself requires four
variables, but the additional one is for the p or x variable). I
believe implementing this requires modifying the code in the main.c
file for r.mdig.kernel - particularly line 74 to read:

double (*dist_function)(double, double, double, double, double)=NULL;

in order to get it to utilize all of the variables. The trouble is,
doing so makes it require five from all of the other functions. Is
there a way to make two of the variables 'optional' in the statement
on line 74? I realize I could just modify this line and recompile
every time I change between the new and old functions, but I was
hoping for a more streamlined approach.

Any suggestions?

-Steve

Joel Pitt

unread,
Aug 2, 2010, 5:36:18 PM8/2/10
to mdig...@googlegroups.com
Hi Steve,

There are variable length argument lists in C, see e.g. :

http://publications.gbdirect.co.uk/c_book/chapter9/stdarg.html

This would be the most elegant solution, but they are slightly more
complicated to work with. It shouldn't be too difficult though if you
look at enough examples online of how to use va_list and va_start (as
described in the doc at the above link).

If it seems like too much difficulty, then editing the different
functions is the more direct solution although it's less flexible ;-)

J

Reply all
Reply to author
Forward
0 new messages