Page 1 of 1

venext - FUNC_DESC

Posted: Sun Oct 12, 2014 10:13 am
by linear feedback
I have written an external function which calculates a vector and uses input from three vectors. Everything works as expected - e.g. during the first call, everything is looking good. Unfortunately Vensim calls the routine 3 times vector subscripts and then returns the result times 3 times vector subscripts. If I put any positive value in num_loop to avoid multiple calls the subroutine does not receive the correct inputs. It seems as if they get shifted by one vector...

This is the change I am making:
static FUNC_DESC Flist[] = {{"GROUPCONSOLIDATION"," {vector} , {vector} , {vector} , {vector} ",4,4,GROUPCON_FUNC,0,1,0,0}, {'\0',0,0,0}} ;
static FUNC_DESC Flist[] = {{"GROUPCONSOLIDATION"," {vector} , {vector} , {vector} , {vector} ",4,4,GROUPCON_FUNC,1,1,0,0}, {'\0',0,0,0}} ;

Any ideas what I should better be doing?

It seems that it makes no difference if I use matrix or vector in argument_desc. I always use vector although two of the vectors have 2-dimensions and I accomodate for that in the subroutine.

PS: The reference to venext.h in comments section three had me searching for that file for quite a while...

Re: venext - FUNC_DESC

Posted: Mon Oct 13, 2014 8:17 am
by Administrator
Did you start by modifying one of the existing vector functions?

Try starting with MATRIX_INPLACE_INVERT. This is a user loop function. You declare it as only having one argument (the matrix), but in the external function library, you get two (the matrix, and the array of values to fill in). This could explain why your arrays are shifted by one vector.

Re: venext - FUNC_DESC

Posted: Mon Oct 13, 2014 8:19 pm
by linear feedback
Many thanks - I forgot about that rule whilst making changes... :-o Now everything is ok.

Re: venext - FUNC_DESC

Posted: Thu Oct 30, 2014 6:35 pm
by linear feedback
Things did work well but now I changed the model so that I do not have x[Range1] as variable where the results go into but x[Range1,Range2-element1]. Only one element in Range2 shall be changed. From what I see in the debugger, the first execution of the function works well but then the function gets executed number of Range1 elements * number of Range2 elements which garbels the results. Changing num_loop did not help. Is there a way to achieve only one execution of the external function or do I need to call it with a dummy variable with one subscript and then map the results into the variable with two subscripts?

Re: venext - FUNC_DESC

Posted: Fri Oct 31, 2014 5:37 pm
by tomfid
Reorder your dimensions as x[Range2-element1,Range1] - it always iterates over the last dimensions first, so this should be the same as before.