scifloat.swg 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * FLOAT SCALAR
  3. */
  4. %fragment(SWIG_AsVal_frag(float), "header", fragment=SWIG_AsVal_frag(double)) {
  5. SWIGINTERN int
  6. SWIG_AsVal_dec(float)(SwigSciObject iVar, float *pfValue) {
  7. double dblValue = 0.0;
  8. if(SWIG_AsVal_dec(double)(iVar, &dblValue) != SWIG_OK) {
  9. return SWIG_ERROR;
  10. }
  11. if (pfValue)
  12. *pfValue = (float) dblValue;
  13. return SWIG_OK;
  14. }
  15. }
  16. %fragment(SWIG_From_frag(float), "header") {
  17. SWIGINTERN int
  18. SWIG_From_dec(float)(float flValue) {
  19. if (createScalarDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx)
  20. + SWIG_Scilab_GetOutputPosition(), (double)flValue))
  21. return SWIG_ERROR;
  22. return SWIG_OK;
  23. }
  24. }
  25. %fragment("SWIG_SciDouble_AsFloatArrayAndSize", "header") {
  26. SWIGINTERN int
  27. SWIG_SciDouble_AsFloatArrayAndSize(void *pvApiCtx, int iVar, int *iRows, int *iCols, float **pfValue, char *fname) {
  28. SciErr sciErr;
  29. int *piAddrVar = NULL;
  30. double *pdValue = NULL;
  31. sciErr = getVarAddressFromPosition(pvApiCtx, iVar, &piAddrVar);
  32. if (sciErr.iErr) {
  33. printError(&sciErr, 0);
  34. return SWIG_ERROR;
  35. }
  36. if (isDoubleType(pvApiCtx, piAddrVar) && !isVarComplex(pvApiCtx, piAddrVar)) {
  37. int i;
  38. sciErr = getMatrixOfDouble(pvApiCtx, piAddrVar, iRows, iCols, &pdValue);
  39. if (sciErr.iErr) {
  40. printError(&sciErr, 0);
  41. return SWIG_ERROR;
  42. }
  43. *pfValue = (float *) malloc((*iRows) * (*iCols) * sizeof(float));
  44. for (i=0; i < (*iRows) * (*iCols); i++)
  45. (*pfValue)[i] = (float) pdValue[i];
  46. return SWIG_OK;
  47. }
  48. else {
  49. Scierror(SCILAB_API_ARGUMENT_ERROR, _("%s: Wrong type for input argument #%d: A real matrix expected.\n"), fname, iVar);
  50. return SWIG_ERROR;
  51. }
  52. }
  53. }
  54. %fragment("SWIG_SciDouble_FromFloatArrayAndSize", "header") {
  55. SWIGINTERN int
  56. SWIG_SciDouble_FromFloatArrayAndSize(void *pvApiCtx, int iVarOut, int iRows, int iCols, float *pfValue) {
  57. SciErr sciErr;
  58. double *pdValue;
  59. int i;
  60. pdValue = (double *) malloc(iRows * iCols * sizeof(double));
  61. for (i = 0; i < iRows * iCols; i++)
  62. pdValue[i] = pfValue[i];
  63. sciErr = createMatrixOfDouble(pvApiCtx, SWIG_NbInputArgument(pvApiCtx) + iVarOut, iRows, iCols, pdValue);
  64. if (sciErr.iErr) {
  65. printError(&sciErr, 0);
  66. return SWIG_ERROR;
  67. }
  68. free(pdValue);
  69. return SWIG_OK;
  70. }
  71. }