summaryrefslogtreecommitdiffstats
path: root/scilab/modules/call_scilab
diff options
context:
space:
mode:
authorSylvestre Ledru <sylvestre.ledru@scilab.org>2010-01-22 15:23:50 +0100
committerSylvestre Ledru <sylvestre.ledru@scilab.org>2010-01-22 15:23:50 +0100
commit168ec420c2a9e5e2e6d13c4a8f7d7d44f023b6c9 (patch)
treedffdeb4b1982e3c7ecc4ebc0c423010529738d33 /scilab/modules/call_scilab
parent4b2f0fef631d6689bd8148acff19a4f3f5bc2954 (diff)
downloadscilab-168ec420c2a9e5e2e6d13c4a8f7d7d44f023b6c9.zip
scilab-168ec420c2a9e5e2e6d13c4a8f7d7d44f023b6c9.tar.gz
Example updated to use api_scilab
Diffstat (limited to 'scilab/modules/call_scilab')
-rw-r--r--scilab/modules/call_scilab/examples/basicExamples/readwritecomplexmatrix.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/scilab/modules/call_scilab/examples/basicExamples/readwritecomplexmatrix.c b/scilab/modules/call_scilab/examples/basicExamples/readwritecomplexmatrix.c
index 9d90237..bf9f922 100644
--- a/scilab/modules/call_scilab/examples/basicExamples/readwritecomplexmatrix.c
+++ b/scilab/modules/call_scilab/examples/basicExamples/readwritecomplexmatrix.c
@@ -10,7 +10,8 @@
10#include <math.h> 10#include <math.h>
11#include <stdio.h> 11#include <stdio.h>
12#include <stdlib.h> 12#include <stdlib.h>
13#include <string.h> 13#include <string.h>
14#include "api_scilab.h"
14#include "stack-c.h" /* Provide functions to access to the memory of Scilab */ 15#include "stack-c.h" /* Provide functions to access to the memory of Scilab */
15#include "call_scilab.h" /* Provide functions to call Scilab engine */ 16#include "call_scilab.h" /* Provide functions to call Scilab engine */
16/*------------------------------------------------------------*/ 17/*------------------------------------------------------------*/
@@ -32,14 +33,25 @@ int main(void)
32 * A=[ 1+%i 3 3+7*%i 2-2*%i ]; 33 * A=[ 1+%i 3 3+7*%i 2-2*%i ];
33 */ 34 */
34 { 35 {
35 double A[]={1,3,3,2,1,0,7,-2}; /* Declare the complex matrix */ 36/* Declare the complex matrix */
37 double A[]={1,3,3,2};
38 double A_img[]={1,0,7,-2};
39/*
40 * Prior to Scilab 5.2:
41 * double A[]={1,3,3,2,1,0,7,-2};
42 */
36 int rowA=1, colA=4; /* Size of the complex matrix 43 int rowA=1, colA=4; /* Size of the complex matrix
37 * (note that colA = sizeof(A)/2 44 * (note that colA = sizeof(A)/2
38 */ 45 */
39 char variableName[]="A"; 46 char variableName[]="A";
40 47
41 C2F(cwritecmat)(variableName, &rowA, &colA, A,strlen(variableName)); /* Write it into Scilab's memory */ 48/* Write it into Scilab's memory */
49 createNamedComplexMatrixOfDouble(pvApiCtx,variableName,rowA,colA, A, A_img);
42 50
51/*
52 * Prior to Scilab 5.2:
53 * C2F(cwritecmat)(variableName, &rowA, &colA, A,strlen(variableName));
54 */
43 printf("Display from Scilab of A:\n"); 55 printf("Display from Scilab of A:\n");
44 SendScilabJob("disp(A);"); /* Display A */ 56 SendScilabJob("disp(A);"); /* Display A */
45 } 57 }
@@ -51,10 +63,17 @@ int main(void)
51 * Note that it is done column by column 63 * Note that it is done column by column
52 */ 64 */
53 { 65 {
54 double B[]={1,3,4,9,2,8,3,2,1,0,-1,0,1/2,42,0,0}; /* Declare the matrix */ 66 double B[]={1,3,4,9,2,8,3,2};
67 double B_img[]={1,0,-1,0,1/2,42,0,0}; /* Declare the matrix */
55 int rowB=2, colB=4; /* Size of the matrix */ 68 int rowB=2, colB=4; /* Size of the matrix */
56 char variableNameB[] = "B"; 69 char variableNameB[] = "B";
57 C2F(cwritecmat)(variableNameB, &rowB, &colB, B, strlen(variableNameB)); /* Write it into Scilab's memory */ 70/* Write it into Scilab's memory */
71 createNamedComplexMatrixOfDouble(pvApiCtx,variableNameB,rowB,colB, B, B_img);
72
73/*
74 * Prior to Scilab 5.2:
75 * 2F(cwritecmat)(variableNameB, &rowB, &colB, B, strlen(variableNameB));
76 */
58 printf("\n"); 77 printf("\n");
59 printf("Display from Scilab of B:\n"); 78 printf("Display from Scilab of B:\n");
60 SendScilabJob("disp(B);"); /* Display B */ 79 SendScilabJob("disp(B);"); /* Display B */
@@ -68,18 +87,29 @@ int main(void)
68 int rowA_ = 0, colA_ = 0,lp = 0; 87 int rowA_ = 0, colA_ = 0,lp = 0;
69 int i = 0,j = 0; 88 int i = 0,j = 0;
70 double *matrixOfComplex = NULL; 89 double *matrixOfComplex = NULL;
90 double *matrixOfComplex_img = NULL;
71 91
72 char variableToBeRetrieved[] = "A"; 92 char variableToBeRetrieved[] = "A";
73 93
74 /* First, retrieve the size of the matrix */ 94 /* First, retrieve the size of the matrix */
75 C2F(cmatcptr)(variableToBeRetrieved, &rowA_, &colA_, &lp, strlen(variableToBeRetrieved)); 95 readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, NULL, NULL);
96
97/*
98 * Prior to Scilab 5.2:
99 * C2F(cmatcptr)(variableToBeRetrieved, &rowA_, &colA_, &lp, strlen(variableToBeRetrieved));
100 */
76 101
77 /* Alloc the memory */ 102 /* Alloc the memory */
78 matrixOfComplex = (double*)malloc((rowA_*colA_*2)*sizeof(double)); 103 matrixOfComplex = (double*)malloc((rowA_*colA_*2)*sizeof(double));
104 matrixOfComplex_img = (double*)malloc((rowA_*colA_*2)*sizeof(double));
79 105
80 /* Load the matrix */ 106 /* Load the matrix */
81 C2F(creadcmat)(variableToBeRetrieved,&rowA_,&colA_,matrixOfComplex,strlen(variableToBeRetrieved) ); 107 readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrieved, &rowA_, &colA_, matrixOfComplex, matrixOfComplex_img);
82 108
109/*
110 * Prior to Scilab 5.2:
111 * C2F(creadcmat)(variableToBeRetrieved,&rowA_,&colA_,matrixOfComplex,strlen(variableToBeRetrieved) );
112 */
83 printf("\n"); 113 printf("\n");
84 printf("Display raw A (size: %d, %d):\n", rowA_, colA_); 114 printf("Display raw A (size: %d, %d):\n", rowA_, colA_);
85 for(i=0; i < rowA_*colA_*2; i++) /* *2 is because complex part is store 115 for(i=0; i < rowA_*colA_*2; i++) /* *2 is because complex part is store
@@ -110,16 +140,28 @@ int main(void)
110 int i = 0,j = 0; 140 int i = 0,j = 0;
111 141
112 double *matrixOfComplexB = NULL; 142 double *matrixOfComplexB = NULL;
143 double *matrixOfComplexB_img = NULL;
113 char variableToBeRetrievedB[] = "B"; 144 char variableToBeRetrievedB[] = "B";
114 145
115 /* First, retrieve the size of the matrix */ 146 /* First, retrieve the size of the matrix */
116 C2F(cmatcptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB)); 147
148 readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, NULL, NULL);
149/*
150 * Prior to Scilab 5.2:
151 * C2F(cmatcptr)(variableToBeRetrievedB, &rowB_, &colB_, &lp_, strlen(variableToBeRetrievedB));
152 */
117 153
118 /* Alloc the memory */ 154 /* Alloc the memory */
119 matrixOfComplexB = (double*)malloc((rowB_*colB_*2)*sizeof(double)); 155 matrixOfComplexB = (double*)malloc((rowB_*colB_*2)*sizeof(double));
156 matrixOfComplexB_img = (double*)malloc((rowB_*colB_*2)*sizeof(double));
120 157
121 /* Load the matrix */ 158 /* Load the matrix */
122 C2F(creadcmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfComplexB,strlen(variableToBeRetrievedB) ); 159 readNamedComplexMatrixOfDouble(pvApiCtx, variableToBeRetrievedB, &rowB_, &colB_, matrixOfComplexB, matrixOfComplexB_img);
160
161/*
162 * Prior to Scilab 5.2:
163 * C2F(creadcmat)(variableToBeRetrievedB,&rowB_,&colB_,matrixOfComplexB,strlen(variableToBeRetrievedB) );
164 */
123 165
124 printf("\n"); 166 printf("\n");
125 printf("Display from B raw (size: %d, %d):\n",rowB_, colB_); 167 printf("Display from B raw (size: %d, %d):\n",rowB_, colB_);