[R-sig-dyn-mod] defining and passing dynamically allocated arrays in C with deSolve
Hi Martin, you could introduce your array as static double. Then write a C function to fill the array. You have to call this function by .C() before running ode(). Probably you will have to assign a fixed size to your static array. But you do not need to fill all elements of the array and in your derivatives function you can determine the number of elements which are read from your array by a parameter that you pass. Best regards, Daniel
On Do, 2015-03-12 at 14:24 +0000, Walker, Martin wrote:
Dear mailing list, I am using the deSolve C interface to write a model describing the dynamics of an infectious disease. I have many arrays in the model whose size and contents depends on a small number of parameter values which are declared at runtime. What I am trying to do is initialize and pass these arrays to the derivative function rather like other parameter values, but with the trick that the size and contents of the arrays is only known once the parameters have been declared at runtime. As it stands, I am defining my arrays within the derivative function which seems rather inefficient since the arrays are constant through time and yet will presumably be re-declared at every single time step. Any thoughts on this would be greatly appreciated! Kind regards, Martin ******************** Dr Martin Walker Research Associate Imperial College London [[alternative HTML version deleted]]
_______________________________________________ R-sig-dynamic-models mailing list R-sig-dynamic-models at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-dynamic-models
Daniel Kaschek Institute of Physics Freiburg University Room 210 Phone: +49 761 2038531