Advertisement
basilio_2004

sci_vt_func.c

Mar 25th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.45 KB | None | 0 0
  1. // Copyright (C) 2015 - Home - Basileus
  2. // Date of creation: 23.03.2015 11:08:15
  3. //
  4. //Standart headers
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9. //System headers
  10. #include <sys/types.h>
  11.  
  12.  
  13. //Scilab headers
  14. #include "api_scilab.h"
  15. #include "Scierror.h"
  16. #include "localization.h"
  17. #include "sciprint.h"
  18.  
  19. //Constants
  20.  
  21.  
  22. //Extern funtions
  23. extern int vt_func(int Width, int Length, double *inputAlpha, double *inputVel, double *outVel);
  24.  
  25. //Function declaration  
  26. int sci_vt_func(char *fname, unsigned long fname_len)
  27. {
  28.     //Error managment variables
  29.     SciErr sciErr;
  30.     int iRet = 0;
  31.    
  32.     //Variables declaration
  33.     //Input variables
  34.     int m1 = 0, n1 = 0;
  35.     int *piAddressVarAlpha = NULL;
  36.     double *matrixOfDoubleAlpha = NULL;
  37.    
  38.     int m2 = 0, n2 = 0;
  39.     int *piAddressVarVelocity = NULL;
  40.     double *matrixOfDoubleVelocity = NULL;
  41.    
  42.     //Output variables
  43.    
  44.     double *outMatrixOfDouble = NULL;
  45.    
  46.    
  47.     //********************************************************************************
  48.     //Check the number of input and output variables
  49.     CheckInputArgument(pvApiCtx,2,2); //only 2 input argument
  50.     CheckOutputArgument(pvApiCtx,1,1);//only 1 output argument
  51.    
  52.     //Manage the first input argument
  53.     //Get address of input one
  54.     sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarAlpha);
  55.     if(sciErr.iErr)
  56.     {
  57.         printError(&sciErr,0);
  58.         return (0);
  59.     }
  60.    
  61.     // Check that the first input argument is a real matrix (and not complex)
  62.     if ( !isDoubleType(pvApiCtx, piAddressVarAlpha) ||  isVarComplex(pvApiCtx, piAddressVarAlpha))
  63.     {
  64.         Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 1);
  65.         return 0;
  66.     }
  67.  
  68.     //Get matrix one
  69.     sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarAlpha, &m1, &n1, &matrixOfDoubleAlpha);
  70.     if (sciErr.iErr)
  71.     {
  72.         printError(&sciErr, 0);
  73.         return 0;
  74.     }
  75.    
  76.    
  77.     //Get address of input two
  78.     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarVelocity);
  79.     if(sciErr.iErr)
  80.     {
  81.         printError(&sciErr,0);
  82.         return (0);
  83.     }
  84.    
  85.     // Check that the third input argument is a real matrix (and not complex)
  86.     if ( !isDoubleType(pvApiCtx, piAddressVarVelocity) ||  isVarComplex(pvApiCtx, piAddressVarVelocity))
  87.     {
  88.         Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 2);
  89.         return 0;
  90.     }
  91.  
  92.     //Get matrix one
  93.     sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarVelocity, &m2, &n2, &matrixOfDoubleVelocity);
  94.     if (sciErr.iErr)
  95.     {
  96.         printError(&sciErr, 0);
  97.         return 0;
  98.     }
  99.    
  100.     //********************************************************************************
  101.     //Application code
  102.     outMatrixOfDouble = (double*) malloc(sizeof(double) * m1 * 10);
  103.    
  104.     vt_func(m1, 10, matrixOfDoubleAlpha, matrixOfDoubleVelocity, outMatrixOfDouble);
  105.    
  106.     //********************************************************************************
  107.     //Create a matrix as return of the function
  108.     sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+3,m1,10,outMatrixOfDouble);
  109.     free(outMatrixOfDouble); //Data have been copied into Scilab memory
  110.     if(sciErr.iErr)
  111.     {
  112.         printError(&sciErr,0);
  113.         return (0);
  114.     }
  115.    
  116.    
  117.     //Return the output arguments to the Scilab engine
  118.     AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 3;
  119.     //Return the various variables declared through AssignOutputVariable(pvApiCtx, X)
  120.     ReturnArguments(pvApiCtx);
  121.      
  122.     return (0);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement