|
3 | 3 | %include "typemaps.i"
|
4 | 4 | %include "renames.i"
|
5 | 5 |
|
6 |
| -%newobject gsl_odeiv_step_alloc; |
| 6 | + //%newobject gsl_odeiv_step_alloc; |
7 | 7 | %newobject gsl_odeiv_driver_alloc_y_new;
|
8 |
| -%newobject gsl_odeiv_evolve_alloc; |
| 8 | +//%newobject gsl_odeiv_evolve_alloc; |
9 | 9 |
|
10 | 10 | %{
|
11 |
| - #include "gsl/gsl_types.h" |
12 |
| - #include "gsl/gsl_odeiv.h" |
| 11 | + //1 |
| 12 | +#include "gsl/gsl_types.h" |
| 13 | +#include "gsl/gsl_odeiv.h" |
| 14 | +#include <stdarg.h> |
| 15 | +#define SWIG_MATH_GSL_ODEIV_PACKAGE_NAME "Math::GSL::ODEIV" |
| 16 | +#define SWIG_MATH_GSL_ODEIV_GUTS \ |
| 17 | + SWIG_MATH_GSL_ODEIV_PACKAGE_NAME "::_guts" |
| 18 | + |
| 19 | + /* NOTE: We do not use C static variables to store the values since |
| 20 | + static variable are not thread-safe, and SWIG does not currently support the |
| 21 | + MY_CXT framework, see perldoc perlxs for more information. |
| 22 | + Perl package variables are on the other hand thread safe. |
| 23 | + */ |
| 24 | + void swig_math_gsl_odeiv_set_gut_pv( |
| 25 | + const char *varname, const char *value |
| 26 | + ) |
| 27 | + { |
| 28 | + SV *pvname = newSVpvf( "%s::%s", SWIG_MATH_GSL_ODEIV_GUTS, varname); |
| 29 | + /*char *pvname = form( "%s::%s", SWIG_MATH_GSL_ODEIV_GUTS, varname);*/ |
| 30 | + SV* sv = get_sv( SvPV_nolen(pvname), GV_ADD ); |
| 31 | + SvREFCNT_dec(pvname); |
| 32 | + sv_setpv( sv, value ); |
| 33 | + } |
| 34 | + |
| 35 | + const char *swig_math_gsl_odeiv_get_gut_pv(const char *varname) |
| 36 | + { |
| 37 | + SV *pvname = newSVpvf( "%s::%s", SWIG_MATH_GSL_ODEIV_GUTS, varname); |
| 38 | + /*char *pvname = form( "%s::%s", SWIG_MATH_GSL_ODEIV_GUTS, varname);*/ |
| 39 | + SV* sv = get_sv( SvPV_nolen(pvname), GV_ADD ); |
| 40 | + SvREFCNT_dec(pvname); |
| 41 | + return SvPV_nolen(sv); |
| 42 | + } |
| 43 | + |
| 44 | + void swig_math_gsl_odeiv_set_callback_error_param( const char *func ) |
| 45 | + { |
| 46 | + swig_math_gsl_odeiv_set_gut_pv( "cbname", func ); |
| 47 | + } |
| 48 | + |
| 49 | + void swig_math_gsl_odeiv_set_error_param( |
| 50 | + const char *symname, const char *param |
| 51 | + ) |
| 52 | + { |
| 53 | + swig_math_gsl_odeiv_set_gut_pv( "symname", symname ); |
| 54 | + swig_math_gsl_odeiv_set_gut_pv( "param", param ); |
| 55 | + } |
| 56 | + |
| 57 | + void swig_math_gsl_odeiv_callback_error( |
| 58 | + const char *msg, ... |
| 59 | + ) |
| 60 | + { |
| 61 | + const char *cbname = swig_math_gsl_odeiv_get_gut_pv("cbname"); |
| 62 | + va_list args; |
| 63 | + va_start(args, msg); |
| 64 | + /*char *msg2 = form( |
| 65 | + "Math::GSL::ODEIV: callback function : %s() : %s", cbname, msg |
| 66 | + );*/ |
| 67 | + SV *msg2 = newSVpvf( |
| 68 | + "Math::GSL::ODEIV: callback function : %s() : %s", cbname, msg |
| 69 | + ); |
| 70 | + vcroak( SvPV_nolen(msg2), &args ); |
| 71 | + /* NOTE: these two lines will never be reached */ |
| 72 | + SvREFCNT_dec(msg2); |
| 73 | + va_end(args); |
| 74 | + } |
| 75 | + |
| 76 | + void swig_math_gsl_odeiv_input_param_error( |
| 77 | + const char *msg, ... |
| 78 | + ) |
| 79 | + { |
| 80 | + const char *subname = swig_math_gsl_odeiv_get_gut_pv("symname"); |
| 81 | + const char *param = swig_math_gsl_odeiv_get_gut_pv("param"); |
| 82 | + va_list args; |
| 83 | + va_start(args, msg); |
| 84 | + SV *msg2 = newSVpvf( |
| 85 | + "Math::GSL::ODEIV:%s() : parameter $%s : %s", subname, param, msg |
| 86 | + ); |
| 87 | + vcroak( SvPV_nolen(msg2), &args ); |
| 88 | + /* NOTE: these two lines will never be reached */ |
| 89 | + SvREFCNT_dec(msg2); |
| 90 | + va_end(args); |
| 91 | + } |
| 92 | + |
| 93 | + void swig_math_gsl_odeiv_input_error( |
| 94 | + const char *msg, ... |
| 95 | + ) |
| 96 | + { |
| 97 | + const char *subname = swig_math_gsl_odeiv_get_gut_pv("symname"); |
| 98 | + va_list args; |
| 99 | + va_start(args, msg); |
| 100 | + SV *msg2 = newSVpvf( "Math::GSL::ODEIV:%s() : %s", subname, msg); |
| 101 | + vcroak( SvPV_nolen(msg2), &args ); |
| 102 | + /* NOTE: these two lines will never be reached */ |
| 103 | + SvREFCNT_dec(msg2); |
| 104 | + va_end(args); |
| 105 | + } |
| 106 | + |
| 107 | + SV *swig_math_gsl_odeiv_get_hash_sv(HV *hash, const char *key) |
| 108 | + { |
| 109 | + SV *key_sv = newSVpv(key, strlen (key)); |
| 110 | + SV *value; |
| 111 | + if (hv_exists_ent(hash, key_sv, 0)) { |
| 112 | + HE *he = hv_fetch_ent(hash, key_sv, 0, 0); |
| 113 | + value = HeVAL(he); |
| 114 | + } |
| 115 | + else { |
| 116 | + swig_math_gsl_odeiv_input_param_error( |
| 117 | + "The hash key '%s' doesn't exist", key |
| 118 | + ); |
| 119 | + } |
| 120 | + return value; |
| 121 | + } |
| 122 | + |
| 123 | + IV swig_math_gsl_odeiv_get_hash_iv(HV *hash, const char *key) { |
| 124 | + SV *sv = swig_math_gsl_odeiv_get_hash_sv(hash, key); |
| 125 | + if (SvROK(sv)) { |
| 126 | + swig_math_gsl_odeiv_input_param_error( |
| 127 | + "Hash value for key '%s' is not a scalar value", key |
| 128 | + ); |
| 129 | + } |
| 130 | + if (!SvIOK(sv)) { |
| 131 | + swig_math_gsl_odeiv_input_param_error( |
| 132 | + "Hash value for key '%s' is not an integer", key |
| 133 | + ); |
| 134 | + } |
| 135 | + return SvIV(sv); |
| 136 | + } |
| 137 | + |
| 138 | + SV *swig_math_gsl_odeiv_get_hash_hashref(HV *hash, const char *key) { |
| 139 | + SV *sv = swig_math_gsl_odeiv_get_hash_sv(hash, key); |
| 140 | + if (!SvROK(sv)) { |
| 141 | + swig_math_gsl_odeiv_input_param_error( |
| 142 | + "Hash value for key '%s' is not a reference", key |
| 143 | + ); |
| 144 | + } |
| 145 | + if (SvTYPE(SvRV(sv)) != SVt_PVHV) { |
| 146 | + swig_math_gsl_odeiv_input_param_error( |
| 147 | + "Hash value for key '%s' is not a hashref", key |
| 148 | + ); |
| 149 | + } |
| 150 | + return sv; |
| 151 | + } |
| 152 | + |
| 153 | + SV *swig_math_gsl_odeiv_get_hash_coderef(HV *hash, const char *key) { |
| 154 | + SV *sv = swig_math_gsl_odeiv_get_hash_sv(hash, key); |
| 155 | + if (!SvROK(sv)) { |
| 156 | + swig_math_gsl_odeiv_input_param_error( |
| 157 | + "Hash value for key '%s' is not a reference", key |
| 158 | + ); |
| 159 | + } |
| 160 | + if (SvTYPE(SvRV(sv)) != SVt_PVCV) { |
| 161 | + swig_math_gsl_odeiv_input_param_error( |
| 162 | + "Hash value for key '%s' is not a coderef", key |
| 163 | + ); |
| 164 | + } |
| 165 | + return sv; |
| 166 | + } |
| 167 | + |
| 168 | + void swig_math_gsl_odeiv_store_hash_ptr( HV *hash, const char *key, void *ptr) |
| 169 | + { |
| 170 | + SV *sv = newSViv(PTR2IV(ptr)); |
| 171 | + /* Let the hash take ownership of the sv */ |
| 172 | + if( !hv_store(hash, key, strlen(key), sv, 0) ) { |
| 173 | + SvREFCNT_dec(sv); |
| 174 | + swig_math_gsl_odeiv_input_param_error( |
| 175 | + "Cannot store internal information in the hash" |
| 176 | + ); |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + void *swig_math_gsl_odeiv_get_hash_ptr(HV *hash, const char *key) { |
| 181 | + IV ptr = swig_math_gsl_odeiv_get_hash_iv(hash, key); |
| 182 | + return (void *) INT2PTR(SV*, ptr); |
| 183 | + } |
| 184 | + |
| 185 | + void swig_math_gsl_odeiv_store_double_in_av( AV *array, SSize_t index, double val) |
| 186 | + { |
| 187 | + SV *sval = newSVnv(val); |
| 188 | + if( !av_store(array, index, sval) ) { |
| 189 | + SvREFCNT_dec(sval); |
| 190 | + swig_math_gsl_odeiv_callback_error( |
| 191 | + "Cannot store internal information in array" |
| 192 | + ); |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + void swig_math_gsl_odeiv_copy_av_to_carray(AV *array, double *y, size_t dim) |
| 197 | + { |
| 198 | + SSize_t array_len = av_top_index(array) + 1; |
| 199 | + if (array_len != dim ) { |
| 200 | + swig_math_gsl_odeiv_callback_error( |
| 201 | + "Callback returned array of wrong dimension" |
| 202 | + ); |
| 203 | + } |
| 204 | + for (int i = 0; i < dim; i++) { |
| 205 | + SV **sv_ptr = av_fetch( array, i, 0 ); |
| 206 | + if (!sv_ptr) { |
| 207 | + swig_math_gsl_odeiv_callback_error( |
| 208 | + "Cannot extract values from returned array" |
| 209 | + ); |
| 210 | + } |
| 211 | + SV *sv = *sv_ptr; |
| 212 | + if (SvROK(sv)) { |
| 213 | + swig_math_gsl_odeiv_callback_error( |
| 214 | + "Returned array value is not a scalar" |
| 215 | + ); |
| 216 | + } |
| 217 | + /* TODO: Not sure if this check is necessary */ |
| 218 | + if (SvTYPE(sv) >= SVt_PVAV) { |
| 219 | + swig_math_gsl_odeiv_callback_error( |
| 220 | + "Returned array value is not of scalar type" |
| 221 | + ); |
| 222 | + } |
| 223 | + double val = (double ) SvNV(sv); |
| 224 | + y[i] = val; |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + void swig_math_gsl_odeiv_copy_doubles_to_av(AV *array, const double *y, size_t dim) |
| 229 | + { |
| 230 | + for (int i = 0; i < dim; i++) { |
| 231 | + swig_math_gsl_odeiv_store_double_in_av(array, i, y[i]); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + typedef struct { |
| 236 | + SV *func; |
| 237 | + SV *jac; |
| 238 | + SV *params; |
| 239 | + size_t dim; |
| 240 | + gsl_odeiv_system *sys; |
| 241 | + } swig_math_gsl_odeiv_system; |
| 242 | + |
| 243 | + int swig_math_gsl_odeiv_call_perl_jac ( |
| 244 | + SV *callback, double t, const double y[], double *dfdy, double *dfdt, |
| 245 | + swig_math_gsl_odeiv_system *params |
| 246 | + ) |
| 247 | + { |
| 248 | + AV *ay = (AV *)sv_2mortal((SV *)newAV()); |
| 249 | + AV *a_dfdy = (AV *)sv_2mortal((SV *)newAV()); |
| 250 | + AV *a_dfdt = (AV *)sv_2mortal((SV *)newAV()); |
| 251 | + dSP; /* declares a local copy of stack pointer */ |
| 252 | + ENTER; |
| 253 | + SAVETMPS; |
| 254 | + PUSHMARK(SP); |
| 255 | + EXTEND(SP, 5); |
| 256 | + mPUSHs(newSVnv(t)); |
| 257 | + swig_math_gsl_odeiv_copy_doubles_to_av(ay, y, params->dim); |
| 258 | + mPUSHs((SV *)newRV_inc((SV *) ay)); |
| 259 | + mPUSHs((SV *)newRV_inc((SV *) a_dfdy)); |
| 260 | + mPUSHs((SV *)newRV_inc((SV *) a_dfdt)); |
| 261 | + XPUSHs(params->params); |
| 262 | + PUTBACK; |
| 263 | + int count = call_sv(callback, G_SCALAR); /* call the Perl callback */ |
| 264 | + SPAGAIN; |
| 265 | + if (count != 1) { |
| 266 | + swig_math_gsl_odeiv_callback_error( |
| 267 | + "Bad return value from callback: expected 1 value, got %d", count |
| 268 | + ); |
| 269 | + } |
| 270 | + IV result = POPi; /* TODO: check ST(0) instead for valid value */ |
| 271 | + swig_math_gsl_odeiv_copy_av_to_carray(a_dfdy, dfdy, (params->dim)*(params->dim)); |
| 272 | + swig_math_gsl_odeiv_copy_av_to_carray(a_dfdt, dfdt, params->dim); |
| 273 | + PUTBACK; |
| 274 | + FREETMPS; |
| 275 | + LEAVE; |
| 276 | + return (int) result; |
| 277 | + } |
| 278 | + |
| 279 | + int swig_math_gsl_odeiv_call_perl_func ( |
| 280 | + SV *callback, double t, const double y[], double dydt[], |
| 281 | + swig_math_gsl_odeiv_system *params) |
| 282 | + { |
| 283 | + AV *ay = (AV *)sv_2mortal((SV *)newAV()); |
| 284 | + AV *aj = (AV *)sv_2mortal((SV *)newAV()); |
| 285 | + dSP; /* declares a local copy of stack pointer */ |
| 286 | + ENTER; |
| 287 | + SAVETMPS; |
| 288 | + PUSHMARK(SP); |
| 289 | + EXTEND(SP, 4); |
| 290 | + mPUSHs(newSVnv(t)); |
| 291 | + swig_math_gsl_odeiv_copy_doubles_to_av(ay, y, params->dim); |
| 292 | + mPUSHs((SV *)newRV_inc((SV *) ay)); |
| 293 | + mPUSHs((SV *)newRV_inc((SV *) aj)); |
| 294 | + XPUSHs(params->params); |
| 295 | + PUTBACK; |
| 296 | + int count = call_sv(callback, G_SCALAR); /* call the Perl callback */ |
| 297 | + SPAGAIN; |
| 298 | + /* This should happen for G_SCALAR, see perldoc perlcall. |
| 299 | + * Even if the callback does not return anything, count will still be 1 |
| 300 | + * since we are not the G_DISCARD flag |
| 301 | + */ |
| 302 | + if (count != 1) { |
| 303 | + swig_math_gsl_odeiv_callback_error( |
| 304 | + "Bad return value from callback: expected 1 value, got %d", count |
| 305 | + ); |
| 306 | + } |
| 307 | + IV result = POPi; /* TODO: check ST(0) instead for valid value */ |
| 308 | + swig_math_gsl_odeiv_copy_av_to_carray(aj, dydt, params->dim); |
| 309 | + PUTBACK; |
| 310 | + FREETMPS; |
| 311 | + LEAVE; |
| 312 | + return result; |
| 313 | + } |
| 314 | + |
| 315 | + int swig_math_gsl_odeiv_callback_function( |
| 316 | + double t, const double y[], double dydt[], void *params) |
| 317 | + { |
| 318 | + swig_math_gsl_odeiv_set_callback_error_param( "func" ); |
| 319 | + swig_math_gsl_odeiv_system *sparam = (swig_math_gsl_odeiv_system *) params; |
| 320 | + return swig_math_gsl_odeiv_call_perl_func(sparam->func, t, y, dydt, sparam); |
| 321 | + } |
| 322 | + |
| 323 | + int swig_math_gsl_odeiv_callback_jac( |
| 324 | + double t, const double y[], double *dfdy, double *dfdt, void *params |
| 325 | + ) |
| 326 | + { |
| 327 | + swig_math_gsl_odeiv_set_callback_error_param( "jac" ); |
| 328 | + swig_math_gsl_odeiv_system *sparam = (swig_math_gsl_odeiv_system *) params; |
| 329 | + return swig_math_gsl_odeiv_call_perl_jac(sparam->jac, t, y, dfdy, dfdt, sparam); |
| 330 | + } |
| 331 | + |
| 332 | + void swig_math_gsl_odeiv_fill_system_struct( HV *hash, gsl_odeiv_system *sys ) |
| 333 | + { |
| 334 | + swig_math_gsl_odeiv_system *ssys; |
| 335 | + Newx(ssys, 1, swig_math_gsl_odeiv_system); |
| 336 | + ssys->func = swig_math_gsl_odeiv_get_hash_coderef( hash, "func" ); |
| 337 | + ssys->jac = swig_math_gsl_odeiv_get_hash_coderef( hash, "jac" ); |
| 338 | + ssys->params = swig_math_gsl_odeiv_get_hash_hashref( hash, "params" ); |
| 339 | + ssys->dim = (size_t) swig_math_gsl_odeiv_get_hash_iv( hash, "dim" ); |
| 340 | + sys->function = swig_math_gsl_odeiv_callback_function; |
| 341 | + sys->jacobian = swig_math_gsl_odeiv_callback_jac; |
| 342 | + sys->dimension = (size_t) swig_math_gsl_odeiv_get_hash_iv( hash, "dim" ); |
| 343 | + sys->params = (void *) ssys; |
| 344 | + } |
13 | 345 | %}
|
14 | 346 |
|
| 347 | +%typemap(in) const gsl_odeiv_system * { |
| 348 | + SV *sv; |
| 349 | + HV *hash; |
| 350 | + |
| 351 | + swig_math_gsl_odeiv_set_error_param( "$symname", "$1_name" ); |
| 352 | + |
| 353 | + if (!sv_isobject($input)) { |
| 354 | + swig_math_gsl_odeiv_input_error( |
| 355 | + "Input parameter $$1_name is not a blessed reference!" |
| 356 | + ); |
| 357 | + } |
| 358 | + if (!sv_isa($input, "Math::GSL::ODEIV::gsl_odeiv_system")) { |
| 359 | + swig_math_gsl_odeiv_input_error( |
| 360 | + "Input parameter $$1_name is not an object of type " |
| 361 | + "Math::GSL::ODEIV::gsl_odeiv_system!" |
| 362 | + ); |
| 363 | + } |
| 364 | + sv = SvRV($input); |
| 365 | + if ((SvTYPE(sv) != SVt_PVHV)) { |
| 366 | + swig_math_gsl_odeiv_input_error( |
| 367 | + "Input parameter $$1_name is not a blessed hash reference!" |
| 368 | + ); |
| 369 | + } |
| 370 | + gsl_odeiv_system *sys; |
| 371 | + Newx(sys, 1, gsl_odeiv_system); |
| 372 | + swig_math_gsl_odeiv_fill_system_struct( (HV *)sv, sys); |
| 373 | + $1 = sys; |
| 374 | +} |
| 375 | + |
| 376 | +%typemap(freearg) const gsl_odeiv_system * { |
| 377 | + swig_math_gsl_odeiv_system *ssys = (swig_math_gsl_odeiv_system *)$1->params; |
| 378 | + Safefree(ssys); |
| 379 | + Safefree($1); |
| 380 | +} |
| 381 | + |
| 382 | +%ignore gsl_odeiv_evolve_apply; |
15 | 383 | %include "gsl/gsl_types.h"
|
16 | 384 | %include "gsl/gsl_odeiv.h"
|
| 385 | +// unignore gsl_odeiv_evolve_apply() |
| 386 | +%rename("%s") gsl_odeiv_evolve_apply; |
| 387 | +/* We want handle the last parameter to gsl_odeiv_evolve_apply(...), see |
| 388 | + * include file gsl/gsl_odeiv.h for a definition. This parameter is of |
| 389 | + * type 'double []' and acts as an input-output array. |
| 390 | + * |
| 391 | + * NOTE: gsl_typemaps.i has typemaps for a float [] input-output array, |
| 392 | + * but note that that typemap also returns the array elements on the perl stack |
| 393 | + * (in addition to modifying the original array). |
| 394 | + * However, here we do not want to return the result on the stack, we only |
| 395 | + * want to modify the original array. |
| 396 | + * |
| 397 | + * TODO: These typemaps might warrant to be moved to gsl_typemaps.i at a later time, |
| 398 | + * where they could be reused by other interface files, however currently they are |
| 399 | + * regarded as specific to only gsl_odeiv_evolve_apply(). |
| 400 | + */ |
| 401 | + |
| 402 | +%typemap(in) double y[] { |
| 403 | + struct perl_array * p_array = 0; /* see gsl_typemaps.i for definition */ |
| 404 | + I32 len; |
| 405 | + AV *array; |
| 406 | + int i; |
| 407 | + SV **tv; |
| 408 | + swig_math_gsl_odeiv_set_error_param( "$symname", "$1_name" ); |
| 409 | + if (!SvROK($input)) { |
| 410 | + swig_math_gsl_odeiv_input_error( |
| 411 | + "Input parameter $$1_name is not a reference!" |
| 412 | + ); |
| 413 | + } |
| 414 | + if (SvTYPE(SvRV($input)) != SVt_PVAV) { |
| 415 | + swig_math_gsl_odeiv_input_error( |
| 416 | + "Input parameter $$1_name is not an array reference!" |
| 417 | + ); |
| 418 | + } |
| 419 | + array = (AV*)SvRV($input); |
| 420 | + len = av_len(array); |
| 421 | + p_array = (struct perl_array *) |
| 422 | + malloc((len+1)*sizeof(double)+sizeof(struct perl_array)); |
| 423 | + p_array->len=len; |
| 424 | + p_array->array=array; |
| 425 | + $1 = (double *)&p_array[1]; |
| 426 | + for (i = 0; i <= len; i++) { |
| 427 | + tv = av_fetch(array, i, 0); |
| 428 | + $1[i] = (double) SvNV(*tv); |
| 429 | + } |
| 430 | +} |
| 431 | + |
| 432 | +%typemap(argout) double y[] { |
| 433 | + struct perl_array * p_array = 0; /* see gsl_typemaps.i for definition */ |
| 434 | + int i; |
| 435 | + SV **tv; |
| 436 | + p_array=(struct perl_array *)(((char*)$1)-sizeof(struct perl_array)); |
| 437 | + for (i = 0; i <= p_array->len; i++) { |
| 438 | + double val= $1[i]; |
| 439 | + tv = av_fetch(p_array->array, i, 0); |
| 440 | + sv_setnv(*tv, val); |
| 441 | + } |
| 442 | +} |
| 443 | + |
| 444 | +%typemap(freearg) double y[] { |
| 445 | + if ($1) free(((char*)$1)-sizeof(struct perl_array)); |
| 446 | +} |
| 447 | + |
| 448 | +%{ |
| 449 | + typedef struct { |
| 450 | + double h; |
| 451 | + SV *sv; |
| 452 | + } swig_perl_double_in_out; |
| 453 | + |
| 454 | +%} |
| 455 | + |
| 456 | +%typemap(in) double *h { |
| 457 | + swig_math_gsl_odeiv_set_error_param( "$symname", "$1_name" ); |
| 458 | + if (!SvROK($input)) { |
| 459 | + swig_math_gsl_odeiv_input_error( |
| 460 | + "Input parameter $$1_name is not a reference!" |
| 461 | + ); |
| 462 | + } |
| 463 | + if (SvTYPE(SvRV($input)) >= SVt_PVAV) { |
| 464 | + swig_math_gsl_odeiv_input_error( |
| 465 | + "Input parameter $$1_name is not a scalar reference!" |
| 466 | + ); |
| 467 | + } |
| 468 | + SV *sv = SvRV($input); |
| 469 | + swig_perl_double_in_out *h_wrap; |
| 470 | + Newx(h_wrap, 1, swig_perl_double_in_out); |
| 471 | + h_wrap->sv = sv; |
| 472 | + h_wrap->h = (double) SvNV(sv); |
| 473 | + $1 = (double *) &h_wrap->h; |
| 474 | +} |
| 475 | + |
| 476 | +%typemap(argout) double *h { |
| 477 | + swig_perl_double_in_out *h_wrap = (swig_perl_double_in_out *) $1; |
| 478 | + SV *sv = h_wrap->sv; |
| 479 | + sv_setnv(sv, h_wrap->h); |
| 480 | +} |
| 481 | + |
| 482 | +%typemap(freearg) double *h { |
| 483 | + Safefree( $1 ); |
| 484 | +} |
| 485 | + |
| 486 | + |
| 487 | +%typemap(in) double *t = double *h; |
| 488 | +%typemap(argout) double *t = double *h; |
| 489 | +%typemap(freearg) double *t = double *h; |
| 490 | + |
| 491 | +// define our own name for the last parameter to gsl_odeiv_evolve_apply() |
| 492 | +int gsl_odeiv_evolve_apply(gsl_odeiv_evolve *e, gsl_odeiv_control *con, gsl_odeiv_step *step, const gsl_odeiv_system *dydt, double *t, double t1, double *h, double y[]); |
| 493 | + |
| 494 | +%perlcode %{ |
| 495 | + package Math::GSL::ODEIV::gsl_odeiv_system; |
| 496 | + |
| 497 | + sub new { |
| 498 | + my ($class, $func, $jac, $dim, $params ) = @_; |
| 499 | + |
| 500 | + my $check_ref = sub { |
| 501 | + if ( (ref $_[0]) ne $_[1] ) { |
| 502 | + die sprintf 'Usage: %s:new( $func, $jac, $dim, $params ). ' |
| 503 | + . 'Argument %s is not %s reference', |
| 504 | + __PACKAGE__, $_[2], $_[3]; |
| 505 | + } |
| 506 | + }; |
| 507 | + my $check_subref = sub { |
| 508 | + $check_ref->($_[0], "CODE", $_[1], "code"); |
| 509 | + }; |
| 510 | + my $check_hashref = sub { |
| 511 | + $check_ref->($_[0], "HASH", $_[1], "hash"); |
| 512 | + }; |
| 513 | + $check_subref->($func, '$func'); |
| 514 | + $check_subref->($jac, '$jac'); |
| 515 | + $check_hashref->($params, '$params'); |
| 516 | + return bless { func => $func, jac => $jac, dim => $dim, params => $params }, |
| 517 | + $class; |
| 518 | + } |
| 519 | +%} |
| 520 | + |
17 | 521 | %include "../pod/ODEIV.pod"
|
0 commit comments