update projects (examples) for Visual Studio 2008
[scilab.git] / scilab / modules / core / examples / call_scilab / c / visual_studio / CallsciC.c
1 /* Allan CORNET */
2 /* Scilab, INRIA 2004 */
3 /* Only For Windows */
4 /*--------------------------------------------------------------------------*/
5 #pragma comment(lib, "../../../../../../bin/libScilab.lib")
6 #pragma comment(lib, "../../../../../../bin/MALLOC.lib")
7 /*--------------------------------------------------------------------------*/
8 #include <stdlib.h> 
9 #include <stdio.h> 
10 #include <string.h>
11 #include "CallScilab.h"
12 #include "stack-c.h"
13 /*--------------------------------------------------------------------------*/
14 /* See SCI/modules/core/includes/CallScilab.h */
15 /*--------------------------------------------------------------------------*/
16 static int example1(void)
17 {
18         static double A[]={1,2,3,4};  int mA=2,nA=2;
19         static double b[]={4,5};  int mb=2,nb=1;
20
21
22         /* Create Scilab matrices A and b */
23         WriteMatrix("A", &mA, &nA, A);
24         WriteMatrix("b", &mb, &nb, b);
25
26         SendScilabJob("disp('A=');");
27         SendScilabJob("disp(A);");
28         SendScilabJob("disp('b=');");
29         SendScilabJob("disp(b);");
30         SendScilabJob("disp('x=A\\b');");
31
32         if ( SendScilabJob("A,b,x=A\\b;") != 0) 
33         {
34                 fprintf(stdout,"Error occured during scilab execution (SendScilabJob)\n");
35         }
36         else 
37         {
38                 double *cxtmp=NULL;
39                 int m,n,lp,i;
40
41                 /* Get m and n */
42                 GetMatrixptr("x", &m, &n, &lp);
43
44                 cxtmp=(double*)malloc((m*n)*sizeof(double));
45
46                 ReadMatrix("x", &m, &n, cxtmp);
47
48                 for(i=0;i<m*n;i++)
49                 {
50                         fprintf(stdout,"x[%d] = %5.2f\n",i,cxtmp[i]);
51                 }
52
53                 if (cxtmp) 
54                 {
55                         free(cxtmp);
56                         cxtmp=NULL;
57                 }
58         }
59         return 0;
60 }
61 /*--------------------------------------------------------------------------*/
62 static int example2(void)
63 {
64         SendScilabJob("plot3d();");
65         printf("\nClose Graphical Windows to close this example.\n");
66         while( ScilabHaveAGraph() )
67         {
68                 ScilabDoOneEvent();
69         }
70         return 1; 
71 }
72 /*--------------------------------------------------------------------------*/
73 static int example3(void)
74 {
75         int code=0;
76
77         char **JOBS=NULL;
78         const int SizeJOBS=6;
79         int i=0;
80
81         JOBS=(char**)malloc(sizeof(char**)*SizeJOBS);
82
83         for (i=0;i<SizeJOBS;i++)
84         {
85                 JOBS[i]=(char*)malloc(sizeof(char*)*1024);
86         }
87
88         strcpy(JOBS[0],"A=1 ..");
89         strcpy(JOBS[1],"+3;");
90         strcpy(JOBS[2],"B = 8;");
91         strcpy(JOBS[3],"+3;");
92         strcpy(JOBS[4],"disp('C=');");
93     strcpy(JOBS[5],"C=A+B;disp(C);"); /* C = 12 */
94
95         code=SendScilabJobs(JOBS,SizeJOBS);
96
97         if (code)
98         {
99                 char lastjob[4096]; // bsiz in scilab 4096 max
100                 if (GetLastJob(lastjob,4096))
101                 {
102                         printf("Error %s\n",lastjob);
103                 }
104         }
105
106         for (i=0;i<SizeJOBS;i++)
107         {
108                 if (JOBS[i]) {free(JOBS[i]);JOBS[i]=NULL;}
109         }
110         return 1;
111 }
112 /*--------------------------------------------------------------------------*/
113 int main(void)
114 /* int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR szCmdLine, int iCmdShow) */
115 {
116         if ( StartScilab(NULL,NULL,NULL) == FALSE ) printf("Error : StartScilab\n");
117         printf("\nexample 1\n");
118         example1();
119         system("pause");
120         printf("\nexample 2\n");
121         example2();
122         system("pause");
123         printf("\nexample 3\n");
124         example3();
125         system("pause");
126         
127         if ( TerminateScilab(NULL) == FALSE ) printf("Error : TerminateScilab\n");
128         return 0;
129 }
130 /*--------------------------------------------------------------------------*/