2 ridmc: iDMC->R interface
4 Copyright (C) 2007 Marji Lines and Alfredo Medio.
6 Written by Antonio, Fabio Di Narzo <antonio.fabio@gmail.com>.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or any
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Last modified: $Date: 2007-05-24 16:41:18 +0200 (gio, 24 mag 2007) $
21 #include <idmclib/model.h>
22 #include <idmclib/basin_slow.h>
24 void ridmc_basin_slow_free(SEXP p
);
26 SEXP
ridmc_basin_slow_alloc(SEXP model
, SEXP parms
,
27 SEXP xmin
, SEXP xmax
, SEXP xres
,
28 SEXP ymin
, SEXP ymax
, SEXP yres
,
29 SEXP attractorLimit
, SEXP attractorIterations
, SEXP ntries
) {
32 idmc_basin_slow
*basin
;
34 ians
= idmc_basin_slow_alloc(R_ExternalPtrAddr(model
), REAL(parms
),
35 REAL(xmin
)[0], REAL(xmax
)[0], INTEGER(xres
)[0],
36 REAL(ymin
)[0], REAL(ymax
)[0], INTEGER(yres
)[0],
37 INTEGER(attractorLimit
)[0], INTEGER(attractorIterations
)[0],
38 INTEGER(ntries
)[0], &basin
);
40 RIDMC_GENERIC_ERROR(ians
);
41 PDEBUG("allocated basin %p\n", basin
);
42 PROTECT(ans
= R_MakeExternalPtr(basin
, R_NilValue
, R_NilValue
));
43 R_RegisterCFinalizer(ans
, ridmc_basin_slow_free
);
48 void ridmc_basin_slow_free(SEXP p
) {
49 PDEBUG("deallocating basin %p\n", R_ExternalPtrAddr(p
));
50 idmc_basin_slow_free( R_ExternalPtrAddr(p
) );
53 SEXP
ridmc_basin_slow_step(SEXP p
) {
54 int ians
= idmc_basin_slow_step(R_ExternalPtrAddr(p
));
56 RIDMC_GENERIC_ERROR(ians
);
60 SEXP
ridmc_basin_slow_finished(SEXP p
) {
61 SEXP ans
= allocVector(INTSXP
, 1);
62 INTEGER(ans
)[0] = idmc_basin_slow_finished(R_ExternalPtrAddr(p
));
66 SEXP
ridmc_basin_slow_setGslRngSeed(SEXP b
, SEXP seed
) {
67 idmc_model_setGslRngSeed(((idmc_basin_slow
*)R_ExternalPtrAddr(b
))->model
,
72 SEXP
ridmc_basin_slow_getData(SEXP p
) {
74 idmc_basin_slow
*bp
= (idmc_basin_slow
*) R_ExternalPtrAddr(p
);
75 ans
= allocMatrix(INTSXP
, bp
->raster
->xres
, bp
->raster
->yres
);
76 memcpy(INTEGER(ans
), bp
->raster
->data
, bp
->dataLength
* sizeof(int));