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> //System variables
- //Scilab headers
- #include "api_scilab.h"
- #include "Scierror.h"
- #include "localization.h"
- #include "sciprint.h"
- //Constants
- //Extern funtions
- extern int vr_func(int Width, int Length, double *inputAlpha, double *inputBeta, double *inputVel, double *outVel);
- //Function declaration
- int sci_vr_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 *piAddressVarBeta = NULL;
- double *matrixOfDoubleBeta = NULL;
- int m3 = 0, n3 = 0;
- int *piAddressVarVelocity = NULL;
- double *matrixOfDoubleVelocity = NULL;
- //Output variables
- double *outMatrixOfDouble = NULL;
- //********************************************************************************
- //Check the number of input and output variables
- CheckInputArgument(pvApiCtx,3,3); //only 3 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, &piAddressVarBeta);
- if(sciErr.iErr)
- {
- printError(&sciErr,0);
- return (0);
- }
- // Check that the second input argument is a real matrix (and not complex)
- if ( !isDoubleType(pvApiCtx, piAddressVarBeta) || isVarComplex(pvApiCtx, piAddressVarBeta))
- {
- Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 2);
- return 0;
- }
- //Get matrix one
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarBeta, &m2, &n2, &matrixOfDoubleBeta);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
- //Get address of input three
- sciErr = getVarAddressFromPosition(pvApiCtx, 3, &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, 3);
- return 0;
- }
- //Get matrix one
- sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarVelocity, &m3, &n3, &matrixOfDoubleVelocity);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- return 0;
- }
- //********************************************************************************
- //Application code
- outMatrixOfDouble = (double*) malloc(sizeof(double) * m1 * m2);
- vr_func(m1, m2, matrixOfDoubleAlpha, matrixOfDoubleBeta, matrixOfDoubleVelocity, outMatrixOfDouble);
- //********************************************************************************
- //Create a matrix as return of the function
- sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,m1,m2,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) + 1;
- //Return the various variables declared through AssignOutputVariable(pvApiCtx, X)
- ReturnArguments(pvApiCtx);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement