summaryrefslogtreecommitdiff
path: root/src/auxiliaryFunctions
diff options
context:
space:
mode:
authortorset2009-01-20 13:18:25 +0000
committertorset2009-01-20 13:18:25 +0000
commit9906f47e2efe7c113436520c90021eef39751b7e (patch)
tree77643b8ed3ac062c8a60f78a1d69a27f6fd107cc /src/auxiliaryFunctions
parent6c809943b1d0e82c85aa5a76b0e21a664831ab27 (diff)
downloadscilab2c-9906f47e2efe7c113436520c90021eef39751b7e.tar.gz
scilab2c-9906f47e2efe7c113436520c90021eef39751b7e.tar.bz2
scilab2c-9906f47e2efe7c113436520c90021eef39751b7e.zip
it seems all modifications are ok
Diffstat (limited to 'src/auxiliaryFunctions')
-rw-r--r--src/auxiliaryFunctions/find/cfinda.c3
-rw-r--r--src/auxiliaryFunctions/find/dfinda.c5
-rw-r--r--src/auxiliaryFunctions/find/sfinda.c7
-rw-r--r--src/auxiliaryFunctions/find/testFind.c57
-rw-r--r--src/auxiliaryFunctions/find/zfinda.c5
-rw-r--r--src/auxiliaryFunctions/isempty/cisemptya.c12
-rw-r--r--src/auxiliaryFunctions/isempty/disemptya.c12
-rw-r--r--src/auxiliaryFunctions/isempty/sisemptya.c12
-rw-r--r--src/auxiliaryFunctions/isempty/zisemptya.c12
9 files changed, 98 insertions, 27 deletions
diff --git a/src/auxiliaryFunctions/find/cfinda.c b/src/auxiliaryFunctions/find/cfinda.c
index e089fa25..95cb24fd 100644
--- a/src/auxiliaryFunctions/find/cfinda.c
+++ b/src/auxiliaryFunctions/find/cfinda.c
@@ -15,6 +15,9 @@
void cfinda(floatComplex* z, int size, float *out, int *indiceOut) {
int i = 0;
*indiceOut = 0;
+
+ /* Initialisation de out à -1 */
+ for (i=0;i<size;i++) out[i]=-1;
for (i = 0; i < size ; ++i) {
if (creals(z[i]) != 0 || cimags(z[i]) != 0) {
diff --git a/src/auxiliaryFunctions/find/dfinda.c b/src/auxiliaryFunctions/find/dfinda.c
index 2aa5f7fe..f5d80ffc 100644
--- a/src/auxiliaryFunctions/find/dfinda.c
+++ b/src/auxiliaryFunctions/find/dfinda.c
@@ -16,7 +16,10 @@
void dfinda(double* x, int size ,double *out, int *indiceOut) {
int i = 0;
*indiceOut = 0;
-
+
+ /* Initialisation de out à -1 */
+ for (i=0;i<size;i++) out[i]=-1;
+
for (i = 0; i < size ; ++i) {
if (x[i] != 0) {
out[*indiceOut] = (double)(i + 1);
diff --git a/src/auxiliaryFunctions/find/sfinda.c b/src/auxiliaryFunctions/find/sfinda.c
index 67324cda..1030c108 100644
--- a/src/auxiliaryFunctions/find/sfinda.c
+++ b/src/auxiliaryFunctions/find/sfinda.c
@@ -15,8 +15,11 @@
void sfinda(float* x, int size, float* out, int *indiceOut) {
int i = 0;
*indiceOut = 0;
-
- for (i = 0; i < size ; ++i) {
+
+ /* Initialisation de out à -1 */
+ for (i=0;i<size;i++) out[i]=-1;
+
+ for (i = 0; i < size ; ++i) {
if (x[i] != 0) {
out[*indiceOut] = (float)(i+1);
(*indiceOut)++;
diff --git a/src/auxiliaryFunctions/find/testFind.c b/src/auxiliaryFunctions/find/testFind.c
index 95b1b17c..6728b7ac 100644
--- a/src/auxiliaryFunctions/find/testFind.c
+++ b/src/auxiliaryFunctions/find/testFind.c
@@ -16,12 +16,16 @@ int sfindaTest() {
int result = 0, i = 0;
float goodArray[5] = {0.,2.,3.,5.,10.};
float badArray[5] = {0.,0.,0.,0.,0.};
- float res[4] = {1.,2.,3.,4.};
+ float res[4] = {2.,3.,4.,5.};
float *outGood = NULL, *outBad = NULL;
-
+ int indiceOut;
+
+ outGood=malloc((uint)5*sizeof(float));
+ outBad=malloc((uint)5*sizeof(float));
+
printf(">> Floats \n");
- outGood = sfinda(goodArray, 5);
- outBad = sfinda(badArray, 5);
+ sfinda(goodArray, 5, outGood, &indiceOut);
+ sfinda(badArray, 5, outBad, &indiceOut);
for (i=0;i<4;i++){
if ( outGood[i] != res[i]) {
@@ -34,7 +38,7 @@ int sfindaTest() {
printf("\n");
- if (outBad!=NULL) {
+ if (outBad[0]!=-1) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
@@ -49,12 +53,17 @@ int dfindaTest() {
int result = 0, i = 0;
double goodArray[5] = {0.,2.,3.,5.,10.};
double badArray[5] = {0.,0.,0.,0.,0.};
- double res[4] = {1.,2.,3.,4.};
+ double res[4] = {2.,3.,4.,5.};
double *outGood = NULL, *outBad = NULL;
-
+ int indiceOut;
+
+ outGood=malloc((uint)5*sizeof(double));
+ outBad=malloc((uint)5*sizeof(double));
+
+
printf(">> Double \n");
- outGood = dfinda(goodArray, 5);
- outBad = dfinda(badArray, 5);
+ dfinda(goodArray, 5, outGood, &indiceOut);
+ dfinda(badArray, 5, outBad, &indiceOut);
for (i=0;i<4;i++){
if ( outGood[i] != res[i]) {
@@ -67,7 +76,7 @@ int dfindaTest() {
printf("\n");
- if (outBad!=NULL) {
+ if (outBad[0]!=-1) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
@@ -82,8 +91,12 @@ int cfindaTest() {
int result = 0, i = 0;
floatComplex goodArray[5];
floatComplex badArray[5];
- float res[4] = {1.,2.,3.,4.};
+ float res[4] = {2.,3.,4.,5.};
float *outGood = NULL, *outBad = NULL;
+ int indiceOut;
+
+ outGood=malloc((uint)5*sizeof(float));
+ outBad=malloc((uint)5*sizeof(float));
/* Good values in goodArray */
goodArray[0] = FloatComplex(0., 0.);
@@ -99,8 +112,8 @@ int cfindaTest() {
badArray[4] = FloatComplex(0., 0.);
printf(">> Float Complex \n");
- outGood = cfinda(goodArray, 5);
- outBad = cfinda(badArray, 5);
+ cfinda(goodArray, 5, outGood, &indiceOut);
+ cfinda(badArray, 5, outBad, &indiceOut);
for (i=0;i<4;i++){
if ( outGood[i] != res[i]) {
@@ -113,7 +126,7 @@ int cfindaTest() {
printf("\n");
- if (outBad!=NULL) {
+ if (outBad[0]!=-1) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
@@ -128,8 +141,14 @@ int zfindaTest() {
int result = 0, i = 0;
doubleComplex goodArray[5];
doubleComplex badArray[5];
- double res[4] = {1.,2.,3.,4.};
+ double res[4] = {2.,3.,4.,5.};
double *outGood = NULL, *outBad = NULL;
+ int indiceOut;
+
+ outGood=malloc((uint)5*sizeof(double));
+ outBad=malloc((uint)5*sizeof(double));
+
+
/* Good values in goodArray */
goodArray[0] = DoubleComplex(0., 0.);
goodArray[1] = DoubleComplex(0., 2.);
@@ -144,9 +163,9 @@ int zfindaTest() {
badArray[4] = DoubleComplex(0., 0.);
- printf(">> Float Complex \n");
- outGood = zfinda(goodArray, 5);
- outBad = zfinda(badArray, 5);
+ printf(">> Double Complex \n");
+ zfinda(goodArray, 5, outGood, &indiceOut);
+ zfinda(badArray, 5, outBad, &indiceOut);
for (i=0;i<4;i++){
if ( outGood[i] != res[i]) {
@@ -159,7 +178,7 @@ int zfindaTest() {
printf("\n");
- if (outBad!=NULL) {
+ if (outBad[0]!=-1) {
printf("ERROR ! : Test Failed (empty array)\n");
result = ERROR;
}
diff --git a/src/auxiliaryFunctions/find/zfinda.c b/src/auxiliaryFunctions/find/zfinda.c
index 631235d1..63d7ef20 100644
--- a/src/auxiliaryFunctions/find/zfinda.c
+++ b/src/auxiliaryFunctions/find/zfinda.c
@@ -15,10 +15,13 @@
void zfinda(doubleComplex* z, int size, double *out, int* indiceOut) {
int i = 0;
*indiceOut = 0;
+
+ /* Initialisation de out à -1 */
+ for (i=0;i<size;i++) out[i]=-1;
for (i = 0; i < size ; ++i) {
if (zreals(z[i]) != 0 || zimags(z[i]) != 0) {
- out[*indiceOut] = (double)i;
+ out[*indiceOut] = (double)(i+1);
(*indiceOut)++;
}
}
diff --git a/src/auxiliaryFunctions/isempty/cisemptya.c b/src/auxiliaryFunctions/isempty/cisemptya.c
index 1a19e8af..ac017ee5 100644
--- a/src/auxiliaryFunctions/isempty/cisemptya.c
+++ b/src/auxiliaryFunctions/isempty/cisemptya.c
@@ -13,8 +13,18 @@
#include "isempty.h"
float cisemptya(floatComplex* x, int size) {
- if (cfinda(x, size) == NULL) {
+ float* out;
+ int indiceOut;
+
+ out = malloc((uint)size*sizeof(float));
+
+ cfinda(x, size, out, &indiceOut);
+
+ if ( out[0] == -1 /*ie tab=NULL*/) {
+ free(out);
return 1;
}
+
+ free(out);
return 0;
}
diff --git a/src/auxiliaryFunctions/isempty/disemptya.c b/src/auxiliaryFunctions/isempty/disemptya.c
index ce5e3f36..c170e819 100644
--- a/src/auxiliaryFunctions/isempty/disemptya.c
+++ b/src/auxiliaryFunctions/isempty/disemptya.c
@@ -13,8 +13,18 @@
#include "isempty.h"
double disemptya(double* x, int size) {
- if (dfinda(x, size) == NULL) {
+ double* out;
+ int indiceOut;
+
+ out = malloc((uint)size*sizeof(double));
+
+ dfinda(x, size, out, &indiceOut);
+
+ if ( out[0] == -1 /*ie tab=NULL*/) {
+ free(out);
return 1;
}
+
+ free(out);
return 0;
}
diff --git a/src/auxiliaryFunctions/isempty/sisemptya.c b/src/auxiliaryFunctions/isempty/sisemptya.c
index 49ce5e20..cb665e8e 100644
--- a/src/auxiliaryFunctions/isempty/sisemptya.c
+++ b/src/auxiliaryFunctions/isempty/sisemptya.c
@@ -13,8 +13,18 @@
#include "isempty.h"
float sisemptya(float* x, int size) {
- if (sfinda(x, size) == NULL) {
+ float* out;
+ int indiceOut;
+
+ out = malloc((uint)size*sizeof(float));
+
+ sfinda(x, size, out, &indiceOut);
+
+ if ( out[0] == -1 /*ie tab=NULL*/) {
+ free(out);
return 1;
}
+
+ free(out);
return 0;
}
diff --git a/src/auxiliaryFunctions/isempty/zisemptya.c b/src/auxiliaryFunctions/isempty/zisemptya.c
index ea8e078c..c1a6a401 100644
--- a/src/auxiliaryFunctions/isempty/zisemptya.c
+++ b/src/auxiliaryFunctions/isempty/zisemptya.c
@@ -13,8 +13,18 @@
#include "isempty.h"
double zisemptya(doubleComplex* x, int size) {
- if (zfinda(x, size) == NULL) {
+ double* out;
+ int indiceOut;
+
+ out = malloc((uint)size*sizeof(double));
+
+ zfinda(x, size, out, &indiceOut);
+
+ if ( out[0] == -1 /*ie tab=NULL*/) {
+ free(out);
return 1;
}
+
+ free(out);
return 0;
}