00001
00002
00003
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
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
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
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
00099 strcpy(JOBS[3],"+3;");
00100 strcpy(JOBS[4],"disp('C=');");
00101 strcpy(JOBS[5],"C=A+B;disp(C);");
00102
00103 code=SendScilabJobs(JOBS,SizeJOBS);
00104
00105 if (code)
00106 {
00107 char lastjob[4096];
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
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