//============================================================================= /// <summary> /// Read a named matrix of string from scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <returns>a matrix of string from scilab. If Variable name does not exist returns null</returns> public unsafe string[] readNamedMatrixOfString(string matrixName) { string[] matrixString = null; int[] iDim = getNamedVarDimension(matrixName); if (iDim != null) { int iRows = iDim[0]; int iCols = iDim[1]; // we allocate lengthmatrixString int[] lengthmatrixString = new int[iRows * iCols]; System.IntPtr ptrEmpty = new System.IntPtr(); // we get length of strings //cEngineDlls.api_Err SciErr = m_objScilabInvoker.readStrMat(ptrEmpty, matrixName, &iRows, &iCols, lengthmatrixString, null); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, &iRows, &iCols, lengthmatrixString, null); // we allocate each string matrixString = new string[iRows * iCols]; for (int i = 0; i < iRows * iCols; i++) { matrixString[i] = new string(' ', lengthmatrixString[i]); } // we get strings from scilab //SciErr = m_objScilabInvoker.readStrMat(ptrEmpty, matrixName, &iRows, &iCols, lengthmatrixString, matrixString); SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, &iRows, &iCols, lengthmatrixString, matrixString); } return(matrixString); }
//============================================================================= /// <summary> /// Write a named matrix of string in scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <param name="iRows"> Number of row</param> /// <param name="iCols"> Number of column</param> /// <param name="matrixDouble"> pointer on data</param> /// <returns> if the operation successes (0) or not ( !0 )</returns> public int createNamedMatrixOfString(string matrixName, int iRows, int iCols, string[] matrixString) { System.IntPtr ptrEmpty = new System.IntPtr(); //cEngineDlls.api_Err SciErr = m_objScilabInvoker.createStrMat(ptrEmpty, matrixName, iRows, iCols, matrixString); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfString(ptrEmpty, matrixName, iRows, iCols, matrixString); return(SciErr.iErr); }
//============================================================================= /// <summary> /// Write a named matrix of boolean in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <param name="iRows"> Number of row</param> /// <param name="iCols"> Number of column</param> /// <param name="matrixBoolean"> pointer on data</param> /// <returns> if the operation successes (0) or not ( !0 )</returns> //public int createNamedMatrixOfBoolean(string matrixName, int iRows, int iCols, Boolean[] matrixBoolean) //{ // int[] matrixInt = new int[matrixBoolean.Length]; // for (int i = 0; i < matrixBoolean.Length; i++) // { // if (matrixBoolean[i] == true) // { // matrixInt[i] = 1; // } // else // { // matrixInt[i] = 0; // } // } // System.IntPtr ptrEmpty = new System.IntPtr(); // cEngineDlls.api_Err SciErr = cEngineDlls.createNamedMatrixOfBoolean(ptrEmpty, matrixName, iRows, iCols, matrixInt); // return SciErr.iErr; //} //============================================================================= /// <summary> /// Write a named matrix of int(32) in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <param name="iRows"> Number of row</param> /// <param name="iCols"> Number of column</param> /// <param name="matrixInt"> pointer on data</param> public int createNamedMatrixOfInt32(string matrixName, int iRows, int iCols, int[] matrixInt) { System.IntPtr ptrEmpty = new System.IntPtr(); //cEngineDlls.api_Err SciErr = m_objScilabInvoker.createIntMat(ptrEmpty, matrixName, iRows, iCols, matrixInt); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfInteger32(ptrEmpty, matrixName, iRows, iCols, matrixInt); return(SciErr.iErr); }
//============================================================================= /// <summary> /// Write a named matrix of complex double in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <param name="iRows">Number of row</param> /// <param name="iCols">Number of column</param> /// <param name="matrixRealPart">real part</param> /// <param name="matrixImagPart">imag part</param> /// <returns></returns> public int createNamedComplexMatrixOfDouble(string matrixName, int iRows, int iCols, double[] matrixRealPart, double[] matrixImagPart) { System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedComplexMatrixOfDouble(ptrEmpty, matrixName, iRows, iCols, matrixRealPart, matrixImagPart); return(SciErr.iErr); }
//============================================================================= /// <summary> /// Detect if a variable name exists in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <returns> true if exists</returns> public unsafe Boolean existNamedVariable(string matrixName) { int *piAdress = null; System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getVarAddressFromName(ptrEmpty, matrixName, &piAdress); if (SciErr.iErr == 0) { return(true); } return(false); }
//============================================================================= /// <summary> /// get scilab type of named matrix /// </summary> /// <param name="matrixName"> variable name</param> /// <returns>scilab type (see enum ScilabType)</returns> public unsafe int getNamedVarType(string matrixName) { int iType = 0; System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarType(ptrEmpty, matrixName, &iType); if (SciErr.iErr == 0) { return(iType); } return(0); }
//============================================================================= /// <summary> /// Get dimensions of a named matrix in scilab /// </summary> /// <returns>a int array. /// if variable name does not exist dimensions are null </returns> public unsafe int[] getNamedVarDimension(string matrixName) { int[] iDim = null; int iRows = 0; int iCols = 0; System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarDimension(ptrEmpty, matrixName, &iRows, &iCols); if (SciErr.iErr == 0) { iDim = new int[2]; iDim[0] = iRows; iDim[1] = iCols; } return(iDim); }
//============================================================================= /// <summary> /// Write a named matrix of boolean in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <param name="iRows"> Number of row</param> /// <param name="iCols"> Number of column</param> /// <param name="matrixBoolean"> pointer on data</param> /// <returns> if the operation successes (0) or not ( !0 )</returns> public int createNamedMatrixOfBoolean(string matrixName, int iRows, int iCols, Boolean[] matrixBoolean) { int[] matrixInt = new int[matrixBoolean.Length]; for (int i = 0; i < matrixBoolean.Length; i++) { if (matrixBoolean[i] == true) { matrixInt[i] = 1; } else { matrixInt[i] = 0; } } System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfBoolean(ptrEmpty, matrixName, iRows, iCols, matrixInt); return(SciErr.iErr); }
//============================================================================= /// <summary> /// Read a named matrix of int(32) in Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <returns>a matrix of int(32) from scilab. If Variable name does not exist returns null</returns> public unsafe int[] readNamedMatrixOfInt32(string matrixName) { int[] matrixInt = null; int[] iDim = getNamedVarDimension(matrixName); if (iDim != null) { int iRows = iDim[0]; int iCols = iDim[1]; // we allocate matrixInt array matrixInt = new int[iRows * iCols]; System.IntPtr ptrEmpty = new System.IntPtr(); // get values in matrixInt Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfInteger32(ptrEmpty, matrixName, &iRows, &iCols, matrixInt); } return(matrixInt); }
//============================================================================= /// <summary> /// Read a named matrix of complex double in Scilab (Imag part) /// </summary> /// <param name="matrixName">variable name</param> /// <returns> img part. If Variable name does not exist returns null</returns> public unsafe double[] readNamedComplexMatrixOfDoubleImgPart(string matrixName) { double[] dImagPart = null; int[] iDim = getNamedVarDimension(matrixName); if (iDim != null) { int iRows = iDim[0]; int iCols = iDim[1]; double[] dRealPart = new double[iRows * iCols]; dImagPart = new double[iRows * iCols]; System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedComplexMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, dRealPart, dImagPart); } return(dImagPart); }
//============================================================================= /// <summary> /// Read a named matrix of double from Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <returns>a matrix of double from scilab. If Variable name does not exist returns null</returns> public unsafe double[] readNamedMatrixOfDouble(string matrixName) { int iRows = 0; int iCols = 0; System.IntPtr ptrEmpty = new System.IntPtr(); Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, null); if (iRows * iCols > 0) { double[] matrixDouble = new double[iRows * iCols]; // get values in matrixDouble SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, matrixDouble); if (SciErr.iErr != 0) { return(null); } return(matrixDouble); } return(null); }
//============================================================================= /// <summary> /// Read a named matrix of boolean from Scilab /// </summary> /// <param name="matrixName"> variable name</param> /// <returns>a matrix of boolean from scilab. If Variable name does not exist returns null</returns> public unsafe Boolean[] getNamedMatrixOfBoolean(string matrixName) { Boolean[] matrixBoolean = null; int[] iDim = getNamedVarDimension(matrixName); if (iDim != null) { int iRows = iDim[0]; int iCols = iDim[1]; int[] matrixInt = new int[iRows * iCols]; System.IntPtr ptrEmpty = new System.IntPtr(); // get values in matrixDouble Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfBoolean(ptrEmpty, matrixName, &iRows, &iCols, matrixInt); if (matrixInt != null) { matrixBoolean = new Boolean[iRows * iCols]; for (int i = 0; i < iRows * iCols; i++) { if (matrixInt[i] == 1) { matrixBoolean[i] = true; } else { matrixBoolean[i] = false; } } } } return(matrixBoolean); }