Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright (C) 2015 - Home - Basileus
- // Date of creation: 23.03.2015 11:08:15
- //
- //Standart headers
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- //System headers
- #include <sys/types.h>
- //Scilab headers
- #include "api_scilab.h"
- #include "Scierror.h"
- #include "localization.h"
- #include "sciprint.h"
- //Constants
- //Extern funtions
- extern int vt_func(int Width, int Length, double *inputAlpha, double *inputVel, double *outVel);
- //Function declaration
- int sci_vt_func(char *fname, unsigned long fname_len)
- {
- //Error managment variables
- SciErr sciErr;
- int iRet = 0;
- //Variables declaration
- //Input variables
- int m1 = 0, n1 = 0;
- int *piAddressVarAlpha = NULL;
- double *matrixOfDoubleAlpha = NULL;
- int m2 = 0, n2 = 0;
- int *piAddressVarVelocity = NULL;
- double *matrixOfDoubleVelocity = NULL;
- //Output variables
- double *outMatrixOfDouble = NULL;
- //********************************************************************************
- //Check the number of input and output variables
- CheckInputArgument(pvApiCtx,2,2); //only 2 input argument
- CheckOutputArgument(pvApiCtx,1,1);//only 1 output argument
- //Manage the first input argument
- //Get address of input one
- sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarAlpha);
- if(sciErr.iErr)
- {
- printError(&sciErr,0);
- return (0);
- }
- // Check that the first input argument is a real matrix (and not complex)
- if ( !isDoubleType(pvApiCtx, piAddressVarAlpha) || isVarComplex(pvApiCtx, piAddressVarAlpha))
- {
- Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 1);
- return 0;
- }
- //Get matrix one
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarAlpha, &m1, &n1, &matrixOfDoubleAlpha);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
- //Get address of input two
- sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarVelocity);
- if(sciErr.iErr)
- {
- printError(&sciErr,0);
- return (0);
- }
- // Check that the third input argument is a real matrix (and not complex)
- if ( !isDoubleType(pvApiCtx, piAddressVarVelocity) || isVarComplex(pvApiCtx, piAddressVarVelocity))
- {
- Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 2);
- return 0;
- }
- //Get matrix one
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarVelocity, &m2, &n2, &matrixOfDoubleVelocity);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
- //********************************************************************************
- //Application code
- outMatrixOfDouble = (double*) malloc(sizeof(double) * m1 * 10);
- vt_func(m1, 10, matrixOfDoubleAlpha, matrixOfDoubleVelocity, outMatrixOfDouble);
- //********************************************************************************
- //Create a matrix as return of the function
- sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+3,m1,10,outMatrixOfDouble);
- free(outMatrixOfDouble); //Data have been copied into Scilab memory
- if(sciErr.iErr)
- {
- printError(&sciErr,0);
- return (0);
- }
- //Return the output arguments to the Scilab engine
- AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 3;
- //Return the various variables declared through AssignOutputVariable(pvApiCtx, X)
- ReturnArguments(pvApiCtx);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement