example to call scilab from C#
Allan CORNET [Thu, 2 Jul 2009 14:33:17 +0000 (16:33 +0200)]
scilab/CHANGES_5.2.X
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci.sln [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/DotNetScilab.csproj [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Properties/AssemblyInfo.cs [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Scilab.cs [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/Properties/AssemblyInfo.cs [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.cs [new file with mode: 0644]
scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.csproj [new file with mode: 0644]
scilab/modules/call_scilab/examples/readme.txt

index 75615d0..4673596 100644 (file)
@@ -96,6 +96,11 @@ Online Help :
 
  - Sub-Chapters are now allowed (See SEP #24)
  - xmltochm exports help to chm format (Windows)
+ call_scilab module :
+ ====================
+ - a example to call scilab from C#
+   see SCI/modules/call_scilab/examples/call_scilab/dotnetsci directory
 
 
 char encoding bugs :
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci.sln b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci.sln
new file mode 100644 (file)
index 0000000..b70d051
--- /dev/null
@@ -0,0 +1,36 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotNetScilab", "dotnetsci\DotNetScilab.csproj", "{C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "example", "example\example.csproj", "{10B5A5BF-3204-4B47-91C0-7FA614EFA94A}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|x64 = Debug|x64
+               Debug|x86 = Debug|x86
+               Release|x64 = Release|x64
+               Release|x86 = Release|x86
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Debug|x64.ActiveCfg = Debug|x64
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Debug|x64.Build.0 = Debug|x64
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Debug|x86.ActiveCfg = Debug|x86
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Debug|x86.Build.0 = Debug|x86
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Release|x64.ActiveCfg = Release|x64
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Release|x64.Build.0 = Release|x64
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Release|x86.ActiveCfg = Release|x86
+               {C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}.Release|x86.Build.0 = Release|x86
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Debug|x64.ActiveCfg = Debug|x64
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Debug|x64.Build.0 = Debug|x64
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Debug|x86.ActiveCfg = Debug|x86
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Debug|x86.Build.0 = Debug|x86
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Release|x64.ActiveCfg = Release|x64
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Release|x64.Build.0 = Release|x64
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Release|x86.ActiveCfg = Release|x86
+               {10B5A5BF-3204-4B47-91C0-7FA614EFA94A}.Release|x86.Build.0 = Release|x86
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/DotNetScilab.csproj b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/DotNetScilab.csproj
new file mode 100644 (file)
index 0000000..4b56094
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DotNetScilab</RootNamespace>
+    <AssemblyName>DotNetScilab</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Scilab.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Properties/AssemblyInfo.cs b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..313576a
--- /dev/null
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("dotnetsci")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Scilab - DIGITEO")]
+[assembly: AssemblyProduct("dotnetsci")]
+[assembly: AssemblyCopyright("Copyright © Scilab 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("ef7effe8-4440-47b7-b579-433dc94cc859")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Scilab.cs b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/dotnetsci/Scilab.cs
new file mode 100644 (file)
index 0000000..547abce
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Allan CORNET
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+//=============================================================================
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Runtime.InteropServices;
+//=============================================================================
+namespace DotNetScilab
+{
+    public class Scilab
+    {
+        //=============================================================================
+        private const string CALL_SCILAB_DLL = "call_scilab.dll";
+        private const string LIBSCILAB_DLL = "libscilab.dll";
+        //private bool initialized = false;
+        //=============================================================================
+        /// <summary>
+        /// Constructor, initialize scilab engine.
+        /// </summary>
+        public Scilab()
+        {
+            // start Scilab engine
+            StartScilab(null, null, null);
+            // Disable TCL/TK and Java graphic interfaces
+            DisableInteractiveMode();
+        }
+        //=============================================================================
+        /// <summary>
+        /// Terminate Scilab engine.
+        /// </summary>
+        /// <returns>1 if it is correctly finished</returns>
+        public int finish()
+        {
+            int ierr = TerminateScilab(null);
+            return ierr;
+        }
+        //=============================================================================
+        /// <summary>
+        /// Send a job to scilab
+        /// </summary>
+        /// <param name="command">command to send to scilab</param>
+        /// <returns>error code operation, 0 : OK</returns>
+        public int sendScilabJob(string command)
+        {
+            return SendScilabJob(command);
+        }
+        //=============================================================================
+        /// <summary>
+        /// Write a named matrix of 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="matrixDouble"> pointer on data</param>
+        /// <returns> if the operation successes (0) or not ( !0 )</returns>
+        public int setNamedMatrixOfDouble(string matrixName, int iRows, int iCols, double[] matrixDouble)
+        {
+            return createNamedMatrixOfDouble(matrixName, iRows, iCols, matrixDouble);
+        }
+        //=============================================================================
+        /// <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[] getNamedMatrixOfDouble(string matrixName)
+        {
+            int iRows = 0;
+            int iCols = 0;
+
+            double[] matrixDouble = new double[0];
+            // first , we want to known dimensions iRows and iCols
+            readNamedMatrixOfDouble(matrixName, &iRows , &iCols, matrixDouble);
+            // we allocate matrixDouble array
+            if (iRows * iCols > 0)
+            {
+                matrixDouble = new double[iRows * iCols];
+
+                // get values in matrixDouble
+                readNamedMatrixOfDouble(matrixName, &iRows, &iCols, matrixDouble);
+
+                return matrixDouble;
+            }
+            return null;
+        }
+        //=============================================================================
+        /// <summary>
+        /// Get dimensions of a named matrix of double in scilab
+        /// </summary>
+        /// <returns>a int array. if variable name does not exist dimensions are 0 0 </returns>
+        public unsafe int[] getNamedMatrixOfDoubleDimensions(string matrixName)
+        {
+            int iRows = 0;
+            int iCols = 0;
+            int[] iDim = new int[2];
+
+            double[] matrixDouble = new double[0];
+            readNamedMatrixOfDouble(matrixName, &iRows, &iCols, matrixDouble);
+
+            iDim[0] = iRows;
+            iDim[1] = iCols;
+
+            return iDim;
+        }
+        //=============================================================================
+        /// <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 setNamedMatrixOfString(string matrixName, int iRows, int iCols, string[] matrixString)
+        {
+            return createNamedMatrixOfString(matrixName, iRows, iCols, matrixString);
+        }
+        //=============================================================================
+        /// <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[] getNamedMatrixOfString(string matrixName)
+        {
+            int iRows = 0;
+            int iCols = 0;
+
+            // first , we want to known dimensions iRows and iCols
+            readNamedMatrixOfString(matrixName, &iRows, &iCols, null, null);
+
+            // we allocate lengthmatrixString
+            int[] lengthmatrixString = new int[iRows * iCols];
+            // we get length of strings
+            readNamedMatrixOfString(matrixName, &iRows, &iCols, lengthmatrixString, null);
+
+            // we allocate each string
+            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
+            readNamedMatrixOfString(matrixName, &iRows, &iCols, lengthmatrixString, matrixString);
+
+            return matrixString;
+        }
+        //=============================================================================
+        /// <summary>
+        /// Get dimensions of a named matrix of string in scilab
+        /// </summary>
+        /// <returns>a int array. if variable name does not exist dimensions are 0 0 </returns>
+        public unsafe int[] getNamedMatrixOfStringDimensions(string matrixName)
+        {
+            int iRows = 0;
+            int iCols = 0;
+            int[] iDim = new int[2];
+
+            readNamedMatrixOfString(matrixName, &iRows, &iCols, null, null);
+
+            iDim[0] = iRows;
+            iDim[1] = iCols;
+
+            return iDim;
+        }
+        //=============================================================================
+        /// <summary>
+        /// import SendScilabJob from C (see CallScilab.h)
+        /// </summary>
+        [DllImport(CALL_SCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern int SendScilabJob([In]String job);
+        //=============================================================================
+        /// <summary>
+        /// import StartScilab from C (see CallScilab.h)
+        /// </summary>
+        [DllImport(CALL_SCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern int StartScilab([In] String SCIpath,
+                                              [In] String ScilabStartup,
+                                              [In] Int32[] Stacksize);
+        //=============================================================================
+        /// <summary>
+        /// import TerminateScilab from C (see CallScilab.h)
+        /// </summary>
+        [DllImport(CALL_SCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern int TerminateScilab([In] String ScilabQuit);
+        //=============================================================================
+        /// <summary>
+        /// import DisableInteractiveMode from C (see CallScilab.h)
+        /// </summary>
+        [DllImport(CALL_SCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern void DisableInteractiveMode();
+        //=============================================================================
+        /// <summary>
+        /// import createNamedMatrixOfString from C (see api_string.h)
+        /// </summary>
+        [DllImport(LIBSCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern int createNamedMatrixOfString([In] String _pstName,
+                                                            [In] int _iRows, [In] int _iCols,
+                                                            [In] String[] _pstStrings);
+        //=============================================================================
+        /// <summary>
+        /// import createNamedMatrixOfDouble from C (see api_double.h)
+        /// </summary>
+        [DllImport(LIBSCILAB_DLL, CharSet = CharSet.Ansi)]
+        private static extern int createNamedMatrixOfDouble([In] String _pstName,
+                                                            [In] int _iRows, [In] int _iCols,
+                                                            [In] double[] _pdblReal);
+        //=============================================================================
+        /// <summary>
+        /// import readNamedMatrixOfString from C (see api_string.h)
+        /// </summary>
+        [DllImport(LIBSCILAB_DLL, CharSet = CharSet.Ansi)]
+        private unsafe static extern int readNamedMatrixOfString([In] String _pstName,
+                                                          [Out]  Int32* _piRows, [Out]  Int32* _piCols,
+                                                          [In, Out] int[] _piLength,
+                                                          [In, Out] String[] _pstStrings);
+        //=============================================================================
+        /// <summary>
+        /// import readNamedMatrixOfDouble from C (see api_double.h)
+        /// </summary>
+        [DllImport(LIBSCILAB_DLL, CharSet = CharSet.Ansi)]
+        private unsafe static extern int readNamedMatrixOfDouble([In] String _pstName,
+                                                          [Out] Int32* _piRows, [Out] Int32* _piCols,
+                                                          [In, Out] Double[] _pdblReal);
+        //=============================================================================
+    }
+}
+//=============================================================================
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/Properties/AssemblyInfo.cs b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..61c6d33
--- /dev/null
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("example")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Scilab - DIGITEO")]
+[assembly: AssemblyProduct("example")]
+[assembly: AssemblyCopyright("Copyright © Scilab 2009")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("17e29de2-0c66-420c-931c-662ab2883fb8")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.cs b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.cs
new file mode 100644 (file)
index 0000000..8f775b2
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2009 - DIGITEO - Allan CORNET
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+//=============================================================================
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DotNetScilab;
+//=============================================================================
+namespace example
+{
+    class example
+    {
+        /*
+         * A small example to call scilab from C#
+         * read & write matrix of double and matrix of string
+         */
+        static void example_readwriteMatrixOfDouble(Scilab _objScilab)
+        {
+            //=============================================================================
+            // Send a command to scilab
+            // Here , we want to display SCI variable
+            _objScilab.sendScilabJob("disp(\'SCI = \');");
+            _objScilab.sendScilabJob("disp(SCI);");
+            //=============================================================================
+            double[] A = new double[] { 1, 2, 3, 4, 5, 6 };
+            int mA = 2, nA = 3;
+
+            // Write a matrix of double named in scilab
+            _objScilab.setNamedMatrixOfDouble("A", mA, nA, A);
+
+            // display matrix of double by scilab
+            _objScilab.sendScilabJob("disp(\'A =\');");
+            _objScilab.sendScilabJob("disp(A);");
+            //=============================================================================
+            _objScilab.sendScilabJob("B = A + 1;");
+
+            // get dimensions of a named matrix of double
+            int[] DimB = _objScilab.getNamedMatrixOfDoubleDimensions("B");
+
+            // get named matrix of double
+            double[] B = _objScilab.getNamedMatrixOfDouble("B");
+
+            // display matrix of double from C#
+            Console.WriteLine("");
+            Console.WriteLine("(C#) B =");
+            for (int i = 0; i < DimB[0]; i++)
+            {
+                for (int j = 0; j < DimB[1]; j++)
+                {
+                    Console.Write(B[j * DimB[0] + i] + " ");
+                }
+
+                Console.WriteLine("");
+            }
+
+            // display matrix of double by scilab
+            _objScilab.sendScilabJob("disp(\'B =\');");
+            _objScilab.sendScilabJob("disp(B);");
+            //=============================================================================
+        }
+
+        static void example_readwriteMatrixOfString(Scilab _objScilab)
+        {
+            //=============================================================================
+            string[] strA = new string[] { "Scilab", "The", "open",
+                                        "source", "for", "numerical",
+                                        "computation" , ":", ")"};
+            int mstrA = 3, nstrA = 3;
+
+            // Write a matrix of string named in scilab
+            _objScilab.setNamedMatrixOfString("string_A", mstrA, nstrA, strA);
+
+            // display matrix of string by scilab
+            _objScilab.sendScilabJob("disp(\'string_A =\');");
+            _objScilab.sendScilabJob("disp(string_A);");
+            //=============================================================================
+            _objScilab.sendScilabJob("string_B = convstr(string_A,\'u\');");
+
+            // get dimensions of a named matrix of string
+            int[] DimstrB = _objScilab.getNamedMatrixOfStringDimensions("string_B");
+
+            // get named matrix of string
+            string[] strB = _objScilab.getNamedMatrixOfString("string_B");
+
+            Console.WriteLine("");
+            Console.WriteLine("(C#) strB =");
+            for (int i = 0; i < DimstrB[0]; i++)
+            {
+                for (int j = 0; j < DimstrB[1]; j++)
+                {
+                    Console.Write(strB[j * DimstrB[0] + i] + " ");
+                }
+
+                Console.WriteLine("");
+            }
+
+            // display matrix of string by scilab
+            _objScilab.sendScilabJob("disp(\'string_B =\');");
+            _objScilab.sendScilabJob("disp(string_B);");
+            //=============================================================================
+        }
+        //=============================================================================
+        static void Main(string[] args)
+        {
+            // start scilab engine
+            Scilab m_oSCilab = new Scilab();
+
+            example_readwriteMatrixOfDouble(m_oSCilab);
+            example_readwriteMatrixOfString(m_oSCilab);
+
+            // close scilab engine
+            m_oSCilab.finish();
+        }
+        //=============================================================================
+    }
+}
+//=============================================================================
diff --git a/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.csproj b/scilab/modules/call_scilab/examples/call_scilab/c#/dotnetsci/example/example.csproj
new file mode 100644 (file)
index 0000000..01ef8b8
--- /dev/null
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>9.0.30729</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{10B5A5BF-3204-4B47-91C0-7FA614EFA94A}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>example</RootNamespace>
+    <AssemblyName>example</AssemblyName>
+    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x64</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
+    <DebugSymbols>true</DebugSymbols>
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <DebugType>full</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
+    <OutputPath>..\..\..\..\..\..\..\bin\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <Optimize>true</Optimize>
+    <DebugType>pdbonly</DebugType>
+    <PlatformTarget>x86</PlatformTarget>
+    <ErrorReport>prompt</ErrorReport>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Xml.Linq">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data.DataSetExtensions">
+      <RequiredTargetFramework>3.5</RequiredTargetFramework>
+    </Reference>
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="example.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\dotnetsci\DotNetScilab.csproj">
+      <Project>{C3F0C7DC-82AD-405B-990A-BF2C5B7F46FF}</Project>
+      <Name>DotNetScilab</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
index 9449453..ec6f1d3 100644 (file)
@@ -1,4 +1,4 @@
-Examples about the Scilab <=> C/C++/Fortran languages
+Examples about the Scilab <=> C/C++/C#/Fortran languages
 
 call_scilab/c :
 How to call scilab from C
@@ -9,6 +9,8 @@ How to call scilab from C++
 call_scilab/fortran :
 How to call scilab from fortran
 
+call_scilab/C# :
+How to call scilab from #
 
-INRIA 2007
+DIGITEO - 2008 
 A.C