CallsciC.c

Go to the documentation of this file.
00001 /* Allan CORNET */
00002 /* Scilab, INRIA 2004 */
00003 /* Only For Windows */
00004 /*-----------------------------------------------------------------------------------*/
00005 #pragma comment(lib, "../../../../../../bin/libScilab.lib")
00006 #pragma comment(lib, "../../../../../../bin/MALLOC.lib")
00007 /*-----------------------------------------------------------------------------------*/
00008 #include <windows.h>
00009 #include <math.h>
00010 #include <stdio.h> 
00011 #include <string.h> 
00012 #include <conio.h> 
00013 
00014 #include "../../../../../../modules/core/includes/machine.h"
00015 #include "../../../../../../modules/core/includes/stack-c.h"
00016 #include "../../../../../../modules/core/includes/CallScilab.h"
00017 #define TRUE 1
00018 #define FALSE 0
00019 /*-----------------------------------------------------------------------------------*/
00020 /* See SCI/modules/core/includes/CallScilab.h */
00021 /*-----------------------------------------------------------------------------------*/
00022 static int example1(void)
00023 {
00024         static double A[]={1,2,3,4};  int mA=2,nA=2;
00025         static double b[]={4,5};  int mb=2,nb=1;
00026 
00027 
00028         /* Create Scilab matrices A and b */
00029         WriteMatrix("A", &mA, &nA, A);
00030         WriteMatrix("b", &mb, &nb, b);
00031 
00032         SendScilabJob("disp('A=');");
00033         SendScilabJob("disp(A);");
00034         SendScilabJob("disp('b=');");
00035         SendScilabJob("disp(b);");
00036         SendScilabJob("disp('x=A\\b');");
00037 
00038         if ( SendScilabJob("A,b,x=A\\b;") != 0) 
00039         {
00040                 fprintf(stdout,"Error occured during scilab execution (SendScilabJob)\n");
00041         }
00042         else 
00043         {
00044                 double *cxtmp=NULL;
00045                 int m,n,lp,i;
00046 
00047                 /* Get m and n */
00048                 GetMatrixptr("x", &m, &n, &lp);
00049 
00050                 cxtmp=(double*)malloc((m*n)*sizeof(double));
00051 
00052                 ReadMatrix("x", &m, &n, cxtmp);
00053 
00054                 for(i=0;i<m*n;i++)
00055                 {
00056                         fprintf(stdout,"x[%d] = %5.2f\n",i,cxtmp[i]);
00057                 }
00058 
00059                 if (cxtmp) 
00060                 {
00061                         free(cxtmp);
00062                         cxtmp=NULL;
00063                 }
00064         }
00065         return 0;
00066 }
00067 /*-----------------------------------------------------------------------------------*/
00068 static int example2(void)
00069 {
00070         SendScilabJob("plot3d();");
00071         printf("\nClose Graphical Windows to close this example.\n");
00072         while( ScilabHaveAGraph() )
00073         {
00074                 ScilabDoOneEvent();
00075                 Sleep(1);
00076         }
00077         return 1; 
00078 }
00079 /*-----------------------------------------------------------------------------------*/
00080 static int example3(void)
00081 {
00082         int code=0;
00083 
00084         char **JOBS=NULL;
00085         const int SizeJOBS=6;
00086         int i=0;
00087 
00088         JOBS=(char**)malloc(sizeof(char**)*SizeJOBS);
00089 
00090         for (i=0;i<SizeJOBS;i++)
00091         {
00092                 JOBS[i]=(char*)malloc(sizeof(char*)*1024);
00093         }
00094 
00095         strcpy(JOBS[0],"A=1 ..");
00096         strcpy(JOBS[1],"+3;");
00097         strcpy(JOBS[2],"B = 8;");
00098         /* strcpy(JOBS[2],"b = V_NOT_EXIST;"); */
00099         strcpy(JOBS[3],"+3;");
00100         strcpy(JOBS[4],"disp('C=');");
00101         strcpy(JOBS[5],"C=A+B;disp(C);"); /* C = 12 */
00102 
00103         code=SendScilabJobs(JOBS,SizeJOBS);
00104 
00105         if (code)
00106         {
00107                 char lastjob[4096]; // bsiz in scilab 4096 max
00108                 if (GetLastJob(lastjob,4096))
00109                 {
00110                         printf("Error %s\n",lastjob);
00111                 }
00112         }
00113 
00114         for (i=0;i<SizeJOBS;i++)
00115         {
00116                 if (JOBS[i]) {free(JOBS[i]);JOBS[i]=NULL;}
00117         }
00118         return 1;
00119 }
00120 /*-----------------------------------------------------------------------------------*/
00121 int main(void)
00122 /* int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine, int iCmdShow) */
00123 {
00124         if ( StartScilab(NULL,NULL,NULL) == FALSE ) printf("Error : StartScilab \n");
00125 
00126         printf("\nexample 1\n");
00127         example1();
00128         system("pause");
00129         printf("\nexample 2\n");
00130         example2();
00131         system("pause");
00132         printf("\nexample 3\n");
00133         example3();
00134         system("pause");
00135         
00136         if ( TerminateScilab(NULL) == FALSE ) printf("Error : TerminateScilab \n");
00137         return 0;
00138 }
00139 /*-----------------------------------------------------------------------------------*/

Generated on Sun Mar 4 15:03:45 2007 for Scilab [trunk] by  doxygen 1.5.1