Here is an example that returns an array with two matrices.
I wouldn't recommend using a matrix of strings (this is a fudge, limited to 8
characters). Instead use an array (of an array) of strings.
Jurgen
void OXCALL FnArrayTest2(OxVALUE *rtn, OxVALUE *pv, int cArg)
{
int i, j, c, r;
MATRIX m;
OxLibCheckType(OX_INT, pv, 0, 1);
r = OxInt(pv, 0);
c = OxInt(pv, 1);
/* allocate an array[2] for the return value */
OxLibValArrayCalloc(rtn, 2);
/* create a r x c matric in rtn[0] */
OxLibValMatMalloc(OxValGetArrayVal(rtn, 0), r, c);
/* get a pointer to the r x c matric in rtn[0] */
m = OxValGetMat(OxValGetArrayVal(rtn, 0));
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
m[i][j] = 3;
/* do the same for rtn[1] */
OxLibValMatMalloc(OxValGetArrayVal(rtn, 1), r, c);
m = OxValGetMat(OxValGetArrayVal(rtn, 1));
for (i = 0; i < r; i++)
for (j = 0; j < c; j++)
m[i][j] = 4;
}
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox Oxford Summer School 2012, 7-14 July
oxoxoxox 12th OxMetrics user conference 2012
oxoxoxox Cass Business School, London, 3-4 September
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
James Martin Fellow, Institute for New Economic Thinking
at the Oxford Martin School, University of Oxford
tel. UK: +44-1865-278610 at Nuffield College
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
On 2012-06-04 10:41, *Marcel Drost wrote:
> Dear Ox users,
>
> I have the example threes.c; from; http://www.doornik.com/ox/OxAppendix.pdf
>
> Works Brilliantly. But how do I return 2 (or more) different Matrices?
>
> 1 Matrix for example filled with doubles (the original 3*3)
> And 1 filled with strings? size for example (2 columns x 4 rows)
>
> original code;
>
> #include "oxexport.h"
> void OXCALL FnThrees(OxVALUE *rtn, OxVALUE *pv, int cArg)
> {
> int i, j, c, r;
> OxLibCheckType(OX_INT, pv, 0, 1);
> r = OxInt(pv, 0);
> c = OxInt(pv, 1);
> OxLibValMatMalloc(rtn, r, c);
> for (i = 0; i< r; i++)
> for (j = 0; j< c; j++)
> OxMat(rtn, 0)[i][j] = 3;
> }
>
> Thanks in Advance
>
> best regards
>
> Marcel
>
> ps; I am/was researching
> OxLibValArrayCalloc(rtn,9)
> which returns;
> [0] = .Null
> ..
> [8]=.Null
> But instead of .Null at position [0] I want a complete matrix/aray/string
(something I do wrong is with the pointers)
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox Oxford Summer School 2012, 7-14 July
oxoxoxox 12th OxMetrics user conference 2012
oxoxoxox Cass Business School, London, 3-4 September
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
James Martin Fellow, Institute for New Economic Thinking
at the Oxford Martin School, University of Oxford
tel. UK: +44-1865-278610 at Nuffield College
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
On 2012-06-04 10:41, *Marcel Drost wrote:
> Dear Ox users,
>
> I have the example threes.c; from; http://www.doornik.com/ox/OxAppendix.pdf
>
> Works Brilliantly. But how do I return 2 (or more) different Matrices?
>
> 1 Matrix for example filled with doubles (the original 3*3)
> And 1 filled with strings? size for example (2 columns x 4 rows)
>
> original code;
>
> #include "oxexport.h"
> void OXCALL FnThrees(OxVALUE *rtn, OxVALUE *pv, int cArg)
> {
> int i, j, c, r;
> OxLibCheckType(OX_INT, pv, 0, 1);
> r = OxInt(pv, 0);
> c = OxInt(pv, 1);
> OxLibValMatMalloc(rtn, r, c);
> for (i = 0; i< r; i++)
> for (j = 0; j< c; j++)
> OxMat(rtn, 0)[i][j] = 3;
> }
>
> Thanks in Advance
>
> best regards
>
> Marcel
>
> ps; I am/was researching
> OxLibValArrayCalloc(rtn,9)
> which returns;
> [0] = .Null
> ..
> [8]=.Null
> But instead of .Null at position [0] I want a complete matrix/aray/string (something I do wrong is with the pointers)
--
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
oxoxoxox Oxford Summer School 2012, 7-14 July
oxoxoxox 12th OxMetrics user conference 2012
oxoxoxox Cass Business School, London, 3-4 September
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
Dr Jurgen A Doornik
James Martin Fellow, Institute for New Economic Thinking
at the Oxford Martin School, University of Oxford
tel. UK: +44-1865-278610 at Nuffield College
http://www.doornik.com
http://www.oxmetrics.net
oxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxoxox
|