Advertisement
basilio_2004

sci_vr_func.c

Mar 25th, 2015
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.27 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> //System variables
  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 vr_func(int Width, int Length, double *inputAlpha, double *inputBeta, double *inputVel, double *outVel);
  24.  
  25. //Function declaration  
  26. int sci_vr_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 *piAddressVarBeta = NULL;
  40.     double *matrixOfDoubleBeta = NULL;
  41.    
  42.     int m3 = 0, n3 = 0;
  43.     int *piAddressVarVelocity = NULL;
  44.     double *matrixOfDoubleVelocity = NULL;
  45.    
  46.     //Output variables
  47.    
  48.     double *outMatrixOfDouble = NULL;
  49.    
  50.    
  51.     //********************************************************************************
  52.     //Check the number of input and output variables
  53.     CheckInputArgument(pvApiCtx,3,3); //only 3 input argument
  54.     CheckOutputArgument(pvApiCtx,1,1);//only 1 output argument
  55.    
  56.     //Manage the first input argument
  57.     //Get address of input one
  58.     sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarAlpha);
  59.     if(sciErr.iErr)
  60.     {
  61.         printError(&sciErr,0);
  62.         return (0);
  63.     }
  64.    
  65.     // Check that the first input argument is a real matrix (and not complex)
  66.     if ( !isDoubleType(pvApiCtx, piAddressVarAlpha) ||  isVarComplex(pvApiCtx, piAddressVarAlpha))
  67.     {
  68.         Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 1);
  69.         return 0;
  70.     }
  71.  
  72.     //Get matrix one
  73.     sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarAlpha, &m1, &n1, &matrixOfDoubleAlpha);
  74.     if (sciErr.iErr)
  75.     {
  76.         printError(&sciErr, 0);
  77.         return 0;
  78.     }
  79.    
  80.    
  81.     //Get address of input two
  82.     sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarBeta);
  83.     if(sciErr.iErr)
  84.     {
  85.         printError(&sciErr,0);
  86.         return (0);
  87.     }
  88.    
  89.     // Check that the second input argument is a real matrix (and not complex)
  90.     if ( !isDoubleType(pvApiCtx, piAddressVarBeta) ||  isVarComplex(pvApiCtx, piAddressVarBeta))
  91.     {
  92.         Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 2);
  93.         return 0;
  94.     }
  95.  
  96.     //Get matrix one
  97.     sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarBeta, &m2, &n2, &matrixOfDoubleBeta);
  98.     if (sciErr.iErr)
  99.     {
  100.         printError(&sciErr, 0);
  101.         return 0;
  102.     }
  103.    
  104.     //Get address of input three
  105.     sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarVelocity);
  106.     if(sciErr.iErr)
  107.     {
  108.         printError(&sciErr,0);
  109.         return (0);
  110.     }
  111.    
  112.     // Check that the third input argument is a real matrix (and not complex)
  113.     if ( !isDoubleType(pvApiCtx, piAddressVarVelocity) ||  isVarComplex(pvApiCtx, piAddressVarVelocity))
  114.     {
  115.         Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, 3);
  116.         return 0;
  117.     }
  118.  
  119.     //Get matrix one
  120.     sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarVelocity, &m3, &n3, &matrixOfDoubleVelocity);
  121.     if (sciErr.iErr)
  122.     {
  123.         printError(&sciErr, 0);
  124.         return 0;
  125.     }
  126.    
  127.     //********************************************************************************
  128.     //Application code
  129.     outMatrixOfDouble = (double*) malloc(sizeof(double) * m1 * m2);
  130.    
  131.     vr_func(m1, m2, matrixOfDoubleAlpha, matrixOfDoubleBeta, matrixOfDoubleVelocity, outMatrixOfDouble);
  132.    
  133.     //********************************************************************************
  134.     //Create a matrix as return of the function
  135.     sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,m1,m2,outMatrixOfDouble);
  136.     free(outMatrixOfDouble); //Data have been copied into Scilab memory
  137.     if(sciErr.iErr)
  138.     {
  139.         printError(&sciErr,0);
  140.         return (0);
  141.     }
  142.    
  143.    
  144.     //Return the output arguments to the Scilab engine
  145.     AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
  146.     //Return the various variables declared through AssignOutputVariable(pvApiCtx, X)
  147.     ReturnArguments(pvApiCtx);
  148.      
  149.     return (0);
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement