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...
venext - FUNC_DESC
-
- Member
- Posts: 25
- Joined: Tue Sep 16, 2014 2:20 pm
- Vensim version: DSS
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
Re: venext - FUNC_DESC
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.
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.
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
-
- Member
- Posts: 25
- Joined: Tue Sep 16, 2014 2:20 pm
- Vensim version: DSS
Re: venext - FUNC_DESC
Many thanks - I forgot about that rule whilst making changes... Now everything is ok.
-
- Member
- Posts: 25
- Joined: Tue Sep 16, 2014 2:20 pm
- Vensim version: DSS
Re: venext - FUNC_DESC
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
Reorder your dimensions as x[Range2-element1,Range1] - it always iterates over the last dimensions first, so this should be the same as before.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/