Changeset 10125
- Timestamp:
- 11/11/13 18:12:45 (11 years ago)
- Location:
- branches/HeuristicLab.ExternalEvaluation Scientific/DotNetScilab/dotnetsci
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.ExternalEvaluation Scientific/DotNetScilab/dotnetsci/Scilab.cs
r10122 r10125 7 7 * you should have received as part of this distribution. The terms 8 8 * are also available at 9 * http://www.cecill.info/licences/Licence_CeCILL_V2 -en.txt9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt 10 10 * 11 11 */ … … 14 14 //============================================================================= 15 15 using System; 16 using System.Collections.Generic;17 using System.Text;18 using System.Runtime.InteropServices;19 16 using System.Threading; 20 17 //============================================================================= 21 namespace DotNetScilab 22 { 23 /* Scilab Types */ 24 public enum ScilabType 25 { 26 sci_matrix = 1, 27 sci_poly = 2, 28 sci_boolean = 4, 29 sci_sparse = 5, 30 sci_boolean_sparse = 6, 31 sci_matlab_sparse = 7, 32 sci_ints = 8, 33 sci_handles = 9, 34 sci_strings = 10, 35 sci_u_function = 11, 36 sci_c_function = 13, 37 sci_lib = 14, 38 sci_list = 15, 39 sci_tlist = 16, 40 sci_mlist = 17, 41 sci_pointer = 128, 42 sci_implicit_poly = 129, 43 sci_intrinsic_function = 130 44 }; 45 46 public sealed class Scilab 47 { 48 //============================================================================= 49 static Scilab instance = null; 50 static readonly object padlock = new object(); 51 private Boolean withGraphics = false; 52 //============================================================================= 53 /// <summary> 54 /// Constructor, initialize scilab engine. 55 /// </summary> 56 public Scilab() 57 { 58 // Disable TCL/TK and Java graphic interfaces 59 Scilab_cs_wrapper.DisableInteractiveMode(); 60 withGraphics = false; 61 62 // start Scilab engine configurated without java 63 Scilab_cs_wrapper.StartScilab(null, null, null); 18 namespace DotNetScilab { 19 /* Scilab Types */ 20 public enum ScilabType { 21 sci_matrix = 1, 22 sci_poly = 2, 23 sci_boolean = 4, 24 sci_sparse = 5, 25 sci_boolean_sparse = 6, 26 sci_matlab_sparse = 7, 27 sci_ints = 8, 28 sci_handles = 9, 29 sci_strings = 10, 30 sci_u_function = 11, 31 sci_c_function = 13, 32 sci_lib = 14, 33 sci_list = 15, 34 sci_tlist = 16, 35 sci_mlist = 17, 36 sci_pointer = 128, 37 sci_implicit_poly = 129, 38 sci_intrinsic_function = 130 39 }; 40 41 public sealed class Scilab { 42 //============================================================================= 43 static Scilab instance = null; 44 static readonly object padlock = new object(); 45 private Boolean withGraphics = false; 46 //============================================================================= 47 /// <summary> 48 /// Constructor, initialize scilab engine. 49 /// </summary> 50 public Scilab() { 51 // Disable TCL/TK and Java graphic interfaces 52 Scilab_cs_wrapper.DisableInteractiveMode(); 53 withGraphics = false; 54 55 // start Scilab engine configurated without java 56 Scilab_cs_wrapper.StartScilab(null, null, null); 57 } 58 //============================================================================= 59 public Scilab(Boolean _bWithGraphics) { 60 // Disable TCL/TK and Java graphic interfaces 61 if (_bWithGraphics == false) { 62 Scilab_cs_wrapper.DisableInteractiveMode(); 63 withGraphics = false; 64 } else { 65 withGraphics = true; 66 } 67 68 // start Scilab engine 69 Scilab_cs_wrapper.StartScilab(null, null, null); 70 } 71 //============================================================================= 72 /// <summary> 73 /// Singleton 74 /// Only one instance of Scilab can be launch 75 /// thread safe 76 /// </summary> 77 public static Scilab Instance { 78 get { 79 lock (padlock) { 80 if (instance == null) { 81 instance = new Scilab(); 82 } 83 return instance; 64 84 } 65 //============================================================================= 66 public Scilab(Boolean _bWithGraphics) 67 { 68 // Disable TCL/TK and Java graphic interfaces 69 if (_bWithGraphics == false) 70 { 71 Scilab_cs_wrapper.DisableInteractiveMode(); 72 withGraphics = false; 85 } 86 } 87 //============================================================================= 88 /// <summary> 89 /// Destructor 90 /// </summary> 91 ~Scilab() { 92 // freed by O.S 93 //Scilab_cs_wrapper.TerminateScilab(null); 94 } 95 //============================================================================= 96 /// <summary> 97 /// Send a job to scilab 98 /// </summary> 99 /// <param name="command">command to send to scilab</param> 100 /// <returns>error code operation, 0 : OK</returns> 101 public int SendScilabJob(string command) { 102 return Scilab_cs_wrapper.SendScilabJob(command); 103 } 104 //============================================================================= 105 /// <summary> 106 /// get last error code 107 /// </summary> 108 /// <returns>last error code</returns> 109 public int GetLastErrorCode() { 110 return Scilab_cs_wrapper.GetLastErrorCode(); 111 } 112 //============================================================================= 113 /// <summary> 114 /// Write a named matrix of double in Scilab 115 /// </summary> 116 /// <param name="matrixName"> variable name</param> 117 /// <param name="iRows"> Number of row</param> 118 /// <param name="iCols"> Number of column</param> 119 /// <param name="matrixDouble"> pointer on data</param> 120 /// <returns> if the operation successes (0) or not ( !0 )</returns> 121 public int createNamedMatrixOfDouble(string matrixName, int iRows, int iCols, double[] matrixDouble) { 122 System.IntPtr ptrEmpty = new System.IntPtr(); 123 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfDouble(ptrEmpty, matrixName, iRows, iCols, matrixDouble); 124 return SciErr.iErr; 125 } 126 //============================================================================= 127 /// <summary> 128 /// Write a named matrix of string in scilab 129 /// </summary> 130 /// <param name="matrixName"> variable name</param> 131 /// <param name="iRows"> Number of row</param> 132 /// <param name="iCols"> Number of column</param> 133 /// <param name="matrixDouble"> pointer on data</param> 134 /// <returns> if the operation successes (0) or not ( !0 )</returns> 135 public int createNamedMatrixOfString(string matrixName, int iRows, int iCols, string[] matrixString) { 136 System.IntPtr ptrEmpty = new System.IntPtr(); 137 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfString(ptrEmpty, matrixName, iRows, iCols, matrixString); 138 return SciErr.iErr; 139 } 140 //============================================================================= 141 /// <summary> 142 /// Write a named matrix of boolean in Scilab 143 /// </summary> 144 /// <param name="matrixName"> variable name</param> 145 /// <param name="iRows"> Number of row</param> 146 /// <param name="iCols"> Number of column</param> 147 /// <param name="matrixBoolean"> pointer on data</param> 148 /// <returns> if the operation successes (0) or not ( !0 )</returns> 149 public int createNamedMatrixOfBoolean(string matrixName, int iRows, int iCols, Boolean[] matrixBoolean) { 150 int[] matrixInt = new int[matrixBoolean.Length]; 151 for (int i = 0; i < matrixBoolean.Length; i++) { 152 if (matrixBoolean[i] == true) { 153 matrixInt[i] = 1; 154 } else { 155 matrixInt[i] = 0; 156 } 157 } 158 System.IntPtr ptrEmpty = new System.IntPtr(); 159 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfBoolean(ptrEmpty, matrixName, iRows, iCols, matrixInt); 160 return SciErr.iErr; 161 } 162 //============================================================================= 163 /// <summary> 164 /// Write a named matrix of int(32) in Scilab 165 /// </summary> 166 /// <param name="matrixName"> variable name</param> 167 /// <param name="iRows"> Number of row</param> 168 /// <param name="iCols"> Number of column</param> 169 /// <param name="matrixInt"> pointer on data</param> 170 public int createNamedMatrixOfInt32(string matrixName, int iRows, int iCols, int[] matrixInt) { 171 System.IntPtr ptrEmpty = new System.IntPtr(); 172 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfInteger32(ptrEmpty, matrixName, iRows, iCols, matrixInt); 173 return SciErr.iErr; 174 } 175 //============================================================================= 176 /// <summary> 177 /// Write a named matrix of complex double in Scilab 178 /// </summary> 179 /// <param name="matrixName"> variable name</param> 180 /// <param name="iRows">Number of row</param> 181 /// <param name="iCols">Number of column</param> 182 /// <param name="matrixRealPart">real part</param> 183 /// <param name="matrixImagPart">imag part</param> 184 /// <returns></returns> 185 public int createNamedComplexMatrixOfDouble(string matrixName, 186 int iRows, int iCols, 187 double[] matrixRealPart, 188 double[] matrixImagPart) { 189 System.IntPtr ptrEmpty = new System.IntPtr(); 190 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 191 iRows, iCols, 192 matrixRealPart, 193 matrixImagPart); 194 return SciErr.iErr; 195 } 196 //============================================================================= 197 /// <summary> 198 /// Read a named matrix of double from Scilab 199 /// </summary> 200 /// <param name="matrixName"> variable name</param> 201 /// <returns>a matrix of double from scilab. If Variable name does not exist returns null</returns> 202 public unsafe double[] readNamedMatrixOfDouble(string matrixName) { 203 int iRows = 0; 204 int iCols = 0; 205 206 System.IntPtr ptrEmpty = new System.IntPtr(); 207 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, null); 208 209 if (iRows * iCols > 0) { 210 double[] matrixDouble = new double[iRows * iCols]; 211 212 // get values in matrixDouble 213 SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, matrixDouble); 214 if (SciErr.iErr != 0) return null; 215 return matrixDouble; 216 } 217 return null; 218 } 219 //============================================================================= 220 /// <summary> 221 /// Get dimensions of a named matrix in scilab 222 /// </summary> 223 /// <returns>a int array. 224 /// if variable name does not exist dimensions are null </returns> 225 public unsafe int[] getNamedVarDimension(string matrixName) { 226 int[] iDim = null; 227 int iRows = 0; 228 int iCols = 0; 229 230 System.IntPtr ptrEmpty = new System.IntPtr(); 231 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarDimension(ptrEmpty, matrixName, &iRows, &iCols); 232 if (SciErr.iErr == 0) { 233 iDim = new int[2]; 234 iDim[0] = iRows; 235 iDim[1] = iCols; 236 } 237 return iDim; 238 } 239 //============================================================================= 240 /// <summary> 241 /// Read a named matrix of string from scilab 242 /// </summary> 243 /// <param name="matrixName"> variable name</param> 244 /// <returns>a matrix of string from scilab. If Variable name does not exist returns null</returns> 245 public unsafe string[] readNamedMatrixOfString(string matrixName) { 246 string[] matrixString = null; 247 248 int[] iDim = getNamedVarDimension(matrixName); 249 250 if (iDim != null) { 251 int iRows = iDim[0]; 252 int iCols = iDim[1]; 253 254 // we allocate lengthmatrixString 255 int[] lengthmatrixString = new int[iRows * iCols]; 256 257 System.IntPtr ptrEmpty = new System.IntPtr(); 258 259 // we get length of strings 260 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, 261 &iRows, &iCols, 262 lengthmatrixString, null); 263 264 // we allocate each string 265 matrixString = new string[iRows * iCols]; 266 for (int i = 0; i < iRows * iCols; i++) { 267 matrixString[i] = new string(' ', lengthmatrixString[i]); 268 } 269 270 // we get strings from scilab 271 SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, 272 &iRows, &iCols, 273 lengthmatrixString, 274 matrixString); 275 } 276 return matrixString; 277 } 278 //============================================================================= 279 /// <summary> 280 /// Read a named matrix of boolean from Scilab 281 /// </summary> 282 /// <param name="matrixName"> variable name</param> 283 /// <returns>a matrix of boolean from scilab. If Variable name does not exist returns null</returns> 284 public unsafe Boolean[] getNamedMatrixOfBoolean(string matrixName) { 285 Boolean[] matrixBoolean = null; 286 int[] iDim = getNamedVarDimension(matrixName); 287 288 if (iDim != null) { 289 int iRows = iDim[0]; 290 int iCols = iDim[1]; 291 int[] matrixInt = new int[iRows * iCols]; 292 293 System.IntPtr ptrEmpty = new System.IntPtr(); 294 295 // get values in matrixDouble 296 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfBoolean(ptrEmpty, matrixName, 297 &iRows, &iCols, 298 matrixInt); 299 300 if (matrixInt != null) { 301 matrixBoolean = new Boolean[iRows * iCols]; 302 for (int i = 0; i < iRows * iCols; i++) { 303 if (matrixInt[i] == 1) { 304 matrixBoolean[i] = true; 305 } else { 306 matrixBoolean[i] = false; 73 307 } 74 else 75 { 76 withGraphics = true; 77 } 78 79 // start Scilab engine 80 Scilab_cs_wrapper.StartScilab(null, null, null); 308 } 81 309 } 82 //============================================================================= 83 /// <summary> 84 /// Singleton 85 /// Only one instance of Scilab can be launch 86 /// thread safe 87 /// </summary> 88 public static Scilab Instance 89 { 90 get 91 { 92 lock (padlock) 93 { 94 if (instance == null) 95 { 96 instance = new Scilab(); 97 } 98 return instance; 99 } 100 } 101 } 102 //============================================================================= 103 /// <summary> 104 /// Destructor 105 /// </summary> 106 ~Scilab() 107 { 108 // freed by O.S 109 //Scilab_cs_wrapper.TerminateScilab(null); 110 } 111 //============================================================================= 112 /// <summary> 113 /// Send a job to scilab 114 /// </summary> 115 /// <param name="command">command to send to scilab</param> 116 /// <returns>error code operation, 0 : OK</returns> 117 public int SendScilabJob(string command) 118 { 119 return Scilab_cs_wrapper.SendScilabJob(command); 120 } 121 //============================================================================= 122 /// <summary> 123 /// get last error code 124 /// </summary> 125 /// <returns>last error code</returns> 126 public int GetLastErrorCode() 127 { 128 return Scilab_cs_wrapper.GetLastErrorCode(); 129 } 130 //============================================================================= 131 /// <summary> 132 /// Write a named matrix of double in Scilab 133 /// </summary> 134 /// <param name="matrixName"> variable name</param> 135 /// <param name="iRows"> Number of row</param> 136 /// <param name="iCols"> Number of column</param> 137 /// <param name="matrixDouble"> pointer on data</param> 138 /// <returns> if the operation successes (0) or not ( !0 )</returns> 139 public int createNamedMatrixOfDouble(string matrixName, int iRows, int iCols, double[] matrixDouble) 140 { 141 System.IntPtr ptrEmpty = new System.IntPtr(); 142 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfDouble(ptrEmpty, matrixName, iRows, iCols, matrixDouble); 143 return SciErr.iErr; 144 } 145 //============================================================================= 146 /// <summary> 147 /// Write a named matrix of string in scilab 148 /// </summary> 149 /// <param name="matrixName"> variable name</param> 150 /// <param name="iRows"> Number of row</param> 151 /// <param name="iCols"> Number of column</param> 152 /// <param name="matrixDouble"> pointer on data</param> 153 /// <returns> if the operation successes (0) or not ( !0 )</returns> 154 public int createNamedMatrixOfString(string matrixName, int iRows, int iCols, string[] matrixString) 155 { 156 System.IntPtr ptrEmpty = new System.IntPtr(); 157 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfString(ptrEmpty, matrixName, iRows, iCols, matrixString); 158 return SciErr.iErr; 159 } 160 //============================================================================= 161 /// <summary> 162 /// Write a named matrix of boolean in Scilab 163 /// </summary> 164 /// <param name="matrixName"> variable name</param> 165 /// <param name="iRows"> Number of row</param> 166 /// <param name="iCols"> Number of column</param> 167 /// <param name="matrixBoolean"> pointer on data</param> 168 /// <returns> if the operation successes (0) or not ( !0 )</returns> 169 public int createNamedMatrixOfBoolean(string matrixName, int iRows, int iCols, Boolean[] matrixBoolean) 170 { 171 int[] matrixInt = new int[matrixBoolean.Length]; 172 for (int i = 0; i < matrixBoolean.Length; i++) 173 { 174 if (matrixBoolean[i] == true) 175 { 176 matrixInt[i] = 1; 177 } 178 else 179 { 180 matrixInt[i] = 0; 181 } 182 } 183 System.IntPtr ptrEmpty = new System.IntPtr(); 184 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfBoolean(ptrEmpty, matrixName, iRows, iCols, matrixInt); 185 return SciErr.iErr; 186 } 187 //============================================================================= 188 /// <summary> 189 /// Write a named matrix of int(32) in Scilab 190 /// </summary> 191 /// <param name="matrixName"> variable name</param> 192 /// <param name="iRows"> Number of row</param> 193 /// <param name="iCols"> Number of column</param> 194 /// <param name="matrixInt"> pointer on data</param> 195 public int createNamedMatrixOfInt32(string matrixName, int iRows, int iCols, int[] matrixInt) 196 { 197 System.IntPtr ptrEmpty = new System.IntPtr(); 198 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedMatrixOfInteger32(ptrEmpty, matrixName, iRows, iCols, matrixInt); 199 return SciErr.iErr; 200 } 201 //============================================================================= 202 /// <summary> 203 /// Write a named matrix of complex double in Scilab 204 /// </summary> 205 /// <param name="matrixName"> variable name</param> 206 /// <param name="iRows">Number of row</param> 207 /// <param name="iCols">Number of column</param> 208 /// <param name="matrixRealPart">real part</param> 209 /// <param name="matrixImagPart">imag part</param> 210 /// <returns></returns> 211 public int createNamedComplexMatrixOfDouble(string matrixName, 212 int iRows, int iCols, 213 double[] matrixRealPart, 214 double[] matrixImagPart) 215 { 216 System.IntPtr ptrEmpty = new System.IntPtr(); 217 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.createNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 218 iRows, iCols, 219 matrixRealPart, 220 matrixImagPart); 221 return SciErr.iErr; 222 } 223 //============================================================================= 224 /// <summary> 225 /// Read a named matrix of double from Scilab 226 /// </summary> 227 /// <param name="matrixName"> variable name</param> 228 /// <returns>a matrix of double from scilab. If Variable name does not exist returns null</returns> 229 public unsafe double[] readNamedMatrixOfDouble(string matrixName) 230 { 231 int iRows = 0; 232 int iCols = 0; 233 234 System.IntPtr ptrEmpty = new System.IntPtr(); 235 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, null); 236 237 if (iRows * iCols > 0) 238 { 239 double[] matrixDouble = new double[iRows * iCols]; 240 241 // get values in matrixDouble 242 SciErr = Scilab_cs_wrapper.readNamedMatrixOfDouble(ptrEmpty, matrixName, &iRows, &iCols, matrixDouble); 243 if (SciErr.iErr != 0) return null; 244 return matrixDouble; 245 } 246 return null; 247 } 248 //============================================================================= 249 /// <summary> 250 /// Get dimensions of a named matrix in scilab 251 /// </summary> 252 /// <returns>a int array. 253 /// if variable name does not exist dimensions are null </returns> 254 public unsafe int[] getNamedVarDimension(string matrixName) 255 { 256 int[] iDim = null; 257 int iRows = 0; 258 int iCols = 0; 259 260 System.IntPtr ptrEmpty = new System.IntPtr(); 261 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarDimension(ptrEmpty, matrixName, &iRows, &iCols); 262 if (SciErr.iErr == 0) 263 { 264 iDim = new int[2]; 265 iDim[0] = iRows; 266 iDim[1] = iCols; 267 } 268 return iDim; 269 } 270 //============================================================================= 271 /// <summary> 272 /// Read a named matrix of string from scilab 273 /// </summary> 274 /// <param name="matrixName"> variable name</param> 275 /// <returns>a matrix of string from scilab. If Variable name does not exist returns null</returns> 276 public unsafe string[] readNamedMatrixOfString(string matrixName) 277 { 278 string[] matrixString = null; 279 280 int[] iDim = getNamedVarDimension(matrixName); 281 282 if (iDim != null) 283 { 284 int iRows = iDim[0]; 285 int iCols = iDim[1]; 286 287 // we allocate lengthmatrixString 288 int[] lengthmatrixString = new int[iRows * iCols]; 289 290 System.IntPtr ptrEmpty = new System.IntPtr(); 291 292 // we get length of strings 293 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, 294 &iRows, &iCols, 295 lengthmatrixString, null); 296 297 // we allocate each string 298 matrixString = new string[iRows * iCols]; 299 for (int i = 0; i < iRows * iCols; i++) 300 { 301 matrixString[i] = new string(' ', lengthmatrixString[i]); 302 } 303 304 // we get strings from scilab 305 SciErr = Scilab_cs_wrapper.readNamedMatrixOfString(ptrEmpty, matrixName, 306 &iRows, &iCols, 307 lengthmatrixString, 308 matrixString); 309 } 310 return matrixString; 311 } 312 //============================================================================= 313 /// <summary> 314 /// Read a named matrix of boolean from Scilab 315 /// </summary> 316 /// <param name="matrixName"> variable name</param> 317 /// <returns>a matrix of boolean from scilab. If Variable name does not exist returns null</returns> 318 public unsafe Boolean[] getNamedMatrixOfBoolean(string matrixName) 319 { 320 Boolean[] matrixBoolean = null; 321 int[] iDim = getNamedVarDimension(matrixName); 322 323 if (iDim != null) 324 { 325 int iRows = iDim[0]; 326 int iCols = iDim[1]; 327 int[] matrixInt = new int[iRows * iCols]; 328 329 System.IntPtr ptrEmpty = new System.IntPtr(); 330 331 // get values in matrixDouble 332 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfBoolean(ptrEmpty, matrixName, 333 &iRows, &iCols, 334 matrixInt); 335 336 if (matrixInt != null) 337 { 338 matrixBoolean = new Boolean[iRows * iCols]; 339 for (int i = 0; i < iRows * iCols; i++) 340 { 341 if (matrixInt[i] == 1) 342 { 343 matrixBoolean[i] = true; 344 } 345 else 346 { 347 matrixBoolean[i] = false; 348 } 349 } 350 } 351 } 352 return matrixBoolean; 353 } 354 //============================================================================= 355 /// <summary> 356 /// Read a named matrix of complex double in Scilab (Real part) 357 /// </summary> 358 /// <param name="matrixName">variable name</param> 359 /// <returns> real part. If Variable name does not exist returns null</returns> 360 public unsafe double[] readNamedComplexMatrixOfDoubleRealPart(string matrixName) 361 { 362 double[] dRealPart = null; 363 int[] iDim = getNamedVarDimension(matrixName); 364 if (iDim != null) 365 { 366 int iRows = iDim[0]; 367 int iCols = iDim[1]; 368 369 double[] dImagPart = new double[iRows * iCols]; 370 dRealPart = new double[iRows * iCols]; 371 372 System.IntPtr ptrEmpty = new System.IntPtr(); 373 374 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 375 &iRows, &iCols, 376 dRealPart, 377 dImagPart); 378 } 379 return dRealPart; 380 } 381 //============================================================================= 382 /// <summary> 383 /// Read a named matrix of complex double in Scilab (Imag part) 384 /// </summary> 385 /// <param name="matrixName">variable name</param> 386 /// <returns> img part. If Variable name does not exist returns null</returns> 387 public unsafe double[] readNamedComplexMatrixOfDoubleImgPart(string matrixName) 388 { 389 double[] dImagPart = null; 390 int[] iDim = getNamedVarDimension(matrixName); 391 if (iDim != null) 392 { 393 int iRows = iDim[0]; 394 int iCols = iDim[1]; 395 396 double[] dRealPart = new double[iRows * iCols]; 397 dImagPart = new double[iRows * iCols]; 398 399 System.IntPtr ptrEmpty = new System.IntPtr(); 400 401 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 402 &iRows, &iCols, 403 dRealPart, 404 dImagPart); 405 } 406 return dImagPart; 407 } 408 //============================================================================= 409 /// <summary> 410 /// Read a named matrix of int(32) in Scilab 411 /// </summary> 412 /// <param name="matrixName"> variable name</param> 413 /// <returns>a matrix of int(32) from scilab. If Variable name does not exist returns null</returns> 414 public unsafe int[] readNamedMatrixOfInt32(string matrixName) 415 { 416 int[] matrixInt = null; 417 int[] iDim = getNamedVarDimension(matrixName); 418 if (iDim != null) 419 { 420 int iRows = iDim[0]; 421 int iCols = iDim[1]; 422 423 // we allocate matrixInt array 424 matrixInt = new int[iRows * iCols]; 425 426 System.IntPtr ptrEmpty = new System.IntPtr(); 427 428 // get values in matrixInt 429 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfInteger32(ptrEmpty, matrixName, &iRows, &iCols, matrixInt); 430 } 431 return matrixInt; 432 } 433 //============================================================================= 434 /// <summary> 435 /// get scilab type of named matrix 436 /// </summary> 437 /// <param name="matrixName"> variable name</param> 438 /// <returns>scilab type (see enum ScilabType)</returns> 439 public unsafe int getNamedVarType(string matrixName) 440 { 441 int iType = 0; 442 System.IntPtr ptrEmpty = new System.IntPtr(); 443 444 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarType(ptrEmpty, matrixName, &iType); 445 if (SciErr.iErr == 0) return iType; 446 return 0; 447 } 448 //============================================================================= 449 /// <summary> 450 /// Detect if a variable name exists in Scilab 451 /// </summary> 452 /// <param name="matrixName"> variable name</param> 453 /// <returns> true if exists</returns> 454 public unsafe Boolean existNamedVariable(string matrixName) 455 { 456 int* piAdress = null; 457 System.IntPtr ptrEmpty = new System.IntPtr(); 458 459 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getVarAddressFromName(ptrEmpty, matrixName, &piAdress); 460 if (SciErr.iErr == 0) return true; 461 return false; 462 } 463 //============================================================================= 464 /// <summary> 465 /// Execute a scilab script .sce 466 /// </summary> 467 /// <param name="scriptFilename">the path to the .sce file</param> 468 /// <returns>error code operation, 0 : OK</returns> 469 public int execScilabScript(String scriptFilename) 470 { 471 return Scilab_cs_wrapper.SendScilabJob("exec('" + scriptFilename + "');"); 472 } 473 //============================================================================= 474 /// <summary> 475 /// Detect if a Scilab graphic window is opened 476 /// </summary> 477 /// <returns>true or false</returns> 478 public Boolean HaveAGraph() 479 { 480 if (withGraphics) 481 { 482 int ierr = Scilab_cs_wrapper.sciHasFigures(); 483 if (ierr == 1) return true; 484 } 485 return false; 486 } 487 //============================================================================= 488 /// <summary> 489 /// do a scilab event 490 /// parser need to run to do a event 491 /// </summary> 492 /// <returns>error code operation, 0 : OK</returns> 493 public int doEvent() 494 { 495 // do a pause (we do not want 100% CPU used) 496 // ugly but it works ... 497 Thread.Sleep(1); 498 // do a loop of parser 499 return SendScilabJob(""); 500 } 501 //============================================================================= 502 /// <summary> 503 /// get scilab type of named matrix 504 /// </summary> 505 /// <param name="matrixName"> variable name</param> 506 /// <returns>scilab type (see enum ScilabType)</returns> 507 public int isNamedVarComplex(string matrixName) 508 { 509 System.IntPtr ptrEmpty = new System.IntPtr(); 510 return Scilab_cs_wrapper.isNamedVarComplex(ptrEmpty, matrixName); 511 } 512 //============================================================================= 513 } 310 } 311 return matrixBoolean; 312 } 313 //============================================================================= 314 /// <summary> 315 /// Read a named matrix of complex double in Scilab (Real part) 316 /// </summary> 317 /// <param name="matrixName">variable name</param> 318 /// <returns> real part. If Variable name does not exist returns null</returns> 319 public unsafe double[] readNamedComplexMatrixOfDoubleRealPart(string matrixName) { 320 double[] dRealPart = null; 321 int[] iDim = getNamedVarDimension(matrixName); 322 if (iDim != null) { 323 int iRows = iDim[0]; 324 int iCols = iDim[1]; 325 326 double[] dImagPart = new double[iRows * iCols]; 327 dRealPart = new double[iRows * iCols]; 328 329 System.IntPtr ptrEmpty = new System.IntPtr(); 330 331 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 332 &iRows, &iCols, 333 dRealPart, 334 dImagPart); 335 } 336 return dRealPart; 337 } 338 //============================================================================= 339 /// <summary> 340 /// Read a named matrix of complex double in Scilab (Imag part) 341 /// </summary> 342 /// <param name="matrixName">variable name</param> 343 /// <returns> img part. If Variable name does not exist returns null</returns> 344 public unsafe double[] readNamedComplexMatrixOfDoubleImgPart(string matrixName) { 345 double[] dImagPart = null; 346 int[] iDim = getNamedVarDimension(matrixName); 347 if (iDim != null) { 348 int iRows = iDim[0]; 349 int iCols = iDim[1]; 350 351 double[] dRealPart = new double[iRows * iCols]; 352 dImagPart = new double[iRows * iCols]; 353 354 System.IntPtr ptrEmpty = new System.IntPtr(); 355 356 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedComplexMatrixOfDouble(ptrEmpty, matrixName, 357 &iRows, &iCols, 358 dRealPart, 359 dImagPart); 360 } 361 return dImagPart; 362 } 363 //============================================================================= 364 /// <summary> 365 /// Read a named matrix of int(32) in Scilab 366 /// </summary> 367 /// <param name="matrixName"> variable name</param> 368 /// <returns>a matrix of int(32) from scilab. If Variable name does not exist returns null</returns> 369 public unsafe int[] readNamedMatrixOfInt32(string matrixName) { 370 int[] matrixInt = null; 371 int[] iDim = getNamedVarDimension(matrixName); 372 if (iDim != null) { 373 int iRows = iDim[0]; 374 int iCols = iDim[1]; 375 376 // we allocate matrixInt array 377 matrixInt = new int[iRows * iCols]; 378 379 System.IntPtr ptrEmpty = new System.IntPtr(); 380 381 // get values in matrixInt 382 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.readNamedMatrixOfInteger32(ptrEmpty, matrixName, &iRows, &iCols, matrixInt); 383 } 384 return matrixInt; 385 } 386 //============================================================================= 387 /// <summary> 388 /// get scilab type of named matrix 389 /// </summary> 390 /// <param name="matrixName"> variable name</param> 391 /// <returns>scilab type (see enum ScilabType)</returns> 392 public unsafe int getNamedVarType(string matrixName) { 393 int iType = 0; 394 System.IntPtr ptrEmpty = new System.IntPtr(); 395 396 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getNamedVarType(ptrEmpty, matrixName, &iType); 397 if (SciErr.iErr == 0) return iType; 398 return 0; 399 } 400 //============================================================================= 401 /// <summary> 402 /// Detect if a variable name exists in Scilab 403 /// </summary> 404 /// <param name="matrixName"> variable name</param> 405 /// <returns> true if exists</returns> 406 public unsafe Boolean existNamedVariable(string matrixName) { 407 int* piAdress = null; 408 System.IntPtr ptrEmpty = new System.IntPtr(); 409 410 Scilab_cs_wrapper.api_Err SciErr = Scilab_cs_wrapper.getVarAddressFromName(ptrEmpty, matrixName, &piAdress); 411 if (SciErr.iErr == 0) return true; 412 return false; 413 } 414 //============================================================================= 415 /// <summary> 416 /// Execute a scilab script .sce 417 /// </summary> 418 /// <param name="scriptFilename">the path to the .sce file</param> 419 /// <returns>error code operation, 0 : OK</returns> 420 public int execScilabScript(String scriptFilename) { 421 return Scilab_cs_wrapper.SendScilabJob("exec('" + scriptFilename + "');"); 422 } 423 //============================================================================= 424 /// <summary> 425 /// Detect if a Scilab graphic window is opened 426 /// </summary> 427 /// <returns>true or false</returns> 428 public Boolean HaveAGraph() { 429 if (withGraphics) { 430 int ierr = Scilab_cs_wrapper.sciHasFigures(); 431 if (ierr == 1) return true; 432 } 433 return false; 434 } 435 //============================================================================= 436 /// <summary> 437 /// do a scilab event 438 /// parser need to run to do a event 439 /// </summary> 440 /// <returns>error code operation, 0 : OK</returns> 441 public int doEvent() { 442 // do a pause (we do not want 100% CPU used) 443 // ugly but it works ... 444 Thread.Sleep(1); 445 // do a loop of parser 446 return SendScilabJob(""); 447 } 448 //============================================================================= 449 /// <summary> 450 /// get scilab type of named matrix 451 /// </summary> 452 /// <param name="matrixName"> variable name</param> 453 /// <returns>scilab type (see enum ScilabType)</returns> 454 public int isNamedVarComplex(string matrixName) { 455 System.IntPtr ptrEmpty = new System.IntPtr(); 456 return Scilab_cs_wrapper.isNamedVarComplex(ptrEmpty, matrixName); 457 } 458 //============================================================================= 459 } 514 460 } 515 461 //============================================================================= -
branches/HeuristicLab.ExternalEvaluation Scientific/DotNetScilab/dotnetsci/Scilab_cs_wrapper.cs
r10122 r10125 7 7 * you should have received as part of this distribution. The terms 8 8 * are also available at 9 * http://www.cecill.info/licences/Licence_CeCILL_V2 -en.txt9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt 10 10 * 11 11 */ … … 20 20 public String pstName; /**< Function name */ 21 21 } 22 //============================================================================= 23 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] 22 23 //============================================================================= 24 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] 24 25 public unsafe struct api_Err { 25 26 public int iErr; 26 27 public int iMsgCount; 27 public fixed intpstructMsg[5];28 public fixed char pstructMsg[5]; 28 29 } 29 30 //=============================================================================
Note: See TracChangeset
for help on using the changeset viewer.