diff options
author | torset | 2009-02-05 12:53:51 +0000 |
---|---|---|
committer | torset | 2009-02-05 12:53:51 +0000 |
commit | 7e7df6ec419bfcb7d5dc97dc4af973b6ea5c2c09 (patch) | |
tree | 7655c8e6ceef4a1a68cd1d220713cb291252734c /src | |
parent | 7616da91495decee1b3aabaa2099d4c25235ac72 (diff) | |
download | scilab2c-7e7df6ec419bfcb7d5dc97dc4af973b6ea5c2c09.tar.gz scilab2c-7e7df6ec419bfcb7d5dc97dc4af973b6ea5c2c09.tar.bz2 scilab2c-7e7df6ec419bfcb7d5dc97dc4af973b6ea5c2c09.zip |
Adapt find2d for generation
Diffstat (limited to 'src')
-rw-r--r-- | src/auxiliaryFunctions/find2d/cfind2da.c | 22 | ||||
-rw-r--r-- | src/auxiliaryFunctions/find2d/dfind2da.c | 22 | ||||
-rw-r--r-- | src/auxiliaryFunctions/find2d/sfind2da.c | 25 | ||||
-rw-r--r-- | src/auxiliaryFunctions/find2d/testFind2d.c | 311 | ||||
-rw-r--r-- | src/auxiliaryFunctions/find2d/zfind2da.c | 22 | ||||
-rw-r--r-- | src/auxiliaryFunctions/includes/find2d.h | 9 | ||||
-rw-r--r-- | src/auxiliaryFunctions/interfaces/int_find.h | 39 |
7 files changed, 200 insertions, 250 deletions
diff --git a/src/auxiliaryFunctions/find2d/cfind2da.c b/src/auxiliaryFunctions/find2d/cfind2da.c index 2acdd882..8aefa06d 100644 --- a/src/auxiliaryFunctions/find2d/cfind2da.c +++ b/src/auxiliaryFunctions/find2d/cfind2da.c @@ -13,25 +13,23 @@ #include "find2d.h" #include <malloc.h> -void cfind2da(floatComplex* x, int rows, int columns, float** out1, float** out2) { +void cfind2da(floatComplex* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2) { int i = 0, j=0; - int indiceOut = 0; - float* out_1 = NULL, *out_2=NULL; + indiceOut1[1] = 0; - /* We suppose out1 and out2 are NULL on input */ + /* if out are empties */ + out1[0]=-1; + out2[0]=-1; for (i = 0; i < rows ; ++i) { for (j = 0; j < columns ; ++j) { - if ((creals(x[i*columns+j]) != 0) || (cimags(x[i*columns+j])!=0) ) { - out_1 = realloc(out_1, (uint)(indiceOut+1)*sizeof(float)); - out_2 = realloc(out_2, (uint)(indiceOut+1)*sizeof(float)); + if ((creals(x[j*rows+i]) != 0) || (cimags(x[j*rows+i])!=0) ) { - out_1[indiceOut] = (float)i; - out_2[indiceOut] = (float)j; - indiceOut++; + out1[indiceOut1[1]] = (float)(i+1); + out2[indiceOut1[1]] = (float)(j+1); + indiceOut1[1]++; } } } - *out1=out_1; - *out2=out_2; + indiceOut2[1]=indiceOut1[1]; } diff --git a/src/auxiliaryFunctions/find2d/dfind2da.c b/src/auxiliaryFunctions/find2d/dfind2da.c index 1358b5d4..f4e80de8 100644 --- a/src/auxiliaryFunctions/find2d/dfind2da.c +++ b/src/auxiliaryFunctions/find2d/dfind2da.c @@ -13,25 +13,23 @@ #include "find2d.h" #include <malloc.h> -void dfind2da(double* x, int rows, int columns, double** out1, double** out2) { +void dfind2da(double* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2) { int i = 0, j=0; - int indiceOut = 0; - double* out_1 = NULL, *out_2=NULL; + indiceOut1[1] = 0; - /* We suppose out1 and out2 are NULL on input */ + /* if out are empties */ + out1[0]=-1; + out2[0]=-1; for (i = 0; i < rows ; ++i) { for (j = 0; j < columns ; ++j) { - if (x[i*columns+j] != 0) { - out_1 = realloc(out_1, (uint)(indiceOut+1)*sizeof(double)); - out_2 = realloc(out_2, (uint)(indiceOut+1)*sizeof(double)); + if (x[j*rows+i] != 0) { - out_1[indiceOut] = (double)i; - out_2[indiceOut] = (double)j; - indiceOut++; + out1[indiceOut1[1]] = (double)(i+1); + out2[indiceOut1[1]] = (double)(j+1); + indiceOut1[1]++; } } } - *out1=out_1; - *out2=out_2; + indiceOut2[1]=indiceOut1[1]; } diff --git a/src/auxiliaryFunctions/find2d/sfind2da.c b/src/auxiliaryFunctions/find2d/sfind2da.c index 69b4081e..a0f9fae6 100644 --- a/src/auxiliaryFunctions/find2d/sfind2da.c +++ b/src/auxiliaryFunctions/find2d/sfind2da.c @@ -13,26 +13,23 @@ #include "find2d.h" #include <malloc.h> #include <stdio.h> - -void sfind2da(float* x, int rows, int columns, float** out1, float** out2) { +void sfind2da(float* x, int rows, int columns, float* out1,int* indiceOut1, float* out2,int* indiceOut2) { int i = 0, j=0; - int indiceOut = 0; - float* out_1 = NULL, *out_2=NULL; - - /* We suppose out1 and out2 are NULL on input */ + indiceOut1[1] = 0; + + /* if out are empties */ + out1[0]=-1; + out2[0]=-1; for (i = 0; i < rows ; ++i) { for (j = 0; j < columns ; ++j) { - if (x[i*columns+j] != 0) { - out_1 = realloc(out_1, (uint)(indiceOut+1)*sizeof(float)); - out_2 = realloc(out_2, (uint)(indiceOut+1)*sizeof(float)); + if (x[j*rows+i] != 0) { - out_1[indiceOut] = (float)i; - out_2[indiceOut] = (float)j; - indiceOut++; + out1[indiceOut1[1]] = (float)(i+1); + out2[indiceOut1[1]] = (float)(j+1); + indiceOut1[1]++; } } } - *out1=out_1; - *out2=out_2; + indiceOut2[1]=indiceOut1[1]; } diff --git a/src/auxiliaryFunctions/find2d/testFind2d.c b/src/auxiliaryFunctions/find2d/testFind2d.c index fb9be264..b726ab7d 100644 --- a/src/auxiliaryFunctions/find2d/testFind2d.c +++ b/src/auxiliaryFunctions/find2d/testFind2d.c @@ -17,23 +17,23 @@ int sfind2daTest() { int result = 0, i = 0; float goodArray[6] = {0.,2.,3.,0.,5.,10.}; float badArray[6] = {0.,0.,0.,0.,0.,0.}; - float out1_1_6[4] = {0.,0.,0.,0.}; - float out1_2_3[4] = {0.,0.,1.,1.}; - float out1_3_2[4] = {0.,1.,2.,2.}; - float out1_6_1[4] = {1.,2.,4.,5.}; - float out2_1_6[4] = {1.,2.,4.,5.}; - float out2_2_3[4] = {1.,2.,1.,2.}; - float out2_3_2[4] = {1.,0.,0.,1.}; - float out2_6_1[4] = {0.,0.,0.,0.}; - float *out1Good = NULL, *out1Bad = NULL, *out2Good = NULL, *out2Bad = NULL; - + float out1_1_6[4] = {1.,1.,1.,1.}; + float out1_2_3[4] = {1.,1.,2.,2.}; + float out1_3_2[4] = {2.,2.,3.,3.}; + float out1_6_1[4] = {2.,3.,5.,6.}; + float out2_1_6[4] = {2.,3.,5.,6.}; + float out2_2_3[4] = {2.,3.,1.,3.}; + float out2_3_2[4] = {1.,2.,1.,2.}; + float out2_6_1[4] = {1.,1.,1.,1.}; + float out1Good[6] = {0}, out1Bad[6] = {0}, out2Good[6] = {0}, out2Bad[6] = {0}; + int size1[2]={0},size2[2]={0}; printf(">> Floats \n"); /* Test tab 1 ligne 6 colonnes */ - sfind2da(goodArray, 1, 6, &out1Good, &out2Good); - sfind2da(badArray, 1, 6, &out1Bad, &out2Bad); + sfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + - for (i=0;i<4;i++){ + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_1_6[i]) || (out2Good[i] != out2_1_6[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -43,8 +43,8 @@ int sfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + sfind2da(badArray, 1, 6, out1Bad, size1,out2Bad,size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -54,14 +54,10 @@ int sfind2daTest() { printf("\n"); /* Test tab 2 lignes 3 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - sfind2da(goodArray, 2, 3, &out1Good, &out2Good); - sfind2da(badArray, 2, 3, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + sfind2da(goodArray, 2, 3, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_2_3[i]) || (out2Good[i] != out2_2_3[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -71,8 +67,8 @@ int sfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + sfind2da(badArray, 2, 3, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -82,14 +78,10 @@ int sfind2daTest() { printf("\n"); /* Test tab 3 lignes 2 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - sfind2da(goodArray, 3, 2, &out1Good, &out2Good); - sfind2da(badArray, 3, 2, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + sfind2da(goodArray, 3, 2, out1Good, size1, out2Good, size1); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_3_2[i]) || (out2Good[i] != out2_3_2[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -99,8 +91,8 @@ int sfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + sfind2da(badArray, 3, 2, out1Bad, size1, out2Bad, size1); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -110,14 +102,10 @@ int sfind2daTest() { printf("\n"); /* Test tab 6 lignes 1 colonne */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - sfind2da(goodArray, 6, 1, &out1Good, &out2Good); - sfind2da(badArray, 6, 1, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + sfind2da(goodArray, 6, 1, out1Good, size1, out2Good, size1); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_6_1[i]) || (out2Good[i] != out2_6_1[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -127,8 +115,8 @@ int sfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + sfind2da(badArray, 6, 1, out1Bad, size1, out2Bad, size1); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -145,23 +133,24 @@ int dfind2daTest() { int result = 0, i = 0; double goodArray[6] = {0.,2.,3.,0.,5.,10.}; double badArray[6] = {0.,0.,0.,0.,0.,0.}; - double out1_1_6[4] = {0.,0.,0.,0.}; - double out1_2_3[4] = {0.,0.,1.,1.}; - double out1_3_2[4] = {0.,1.,2.,2.}; - double out1_6_1[4] = {1.,2.,4.,5.}; - double out2_1_6[4] = {1.,2.,4.,5.}; - double out2_2_3[4] = {1.,2.,1.,2.}; - double out2_3_2[4] = {1.,0.,0.,1.}; - double out2_6_1[4] = {0.,0.,0.,0.}; - double *out1Good = NULL, *out1Bad = NULL, *out2Good = NULL, *out2Bad = NULL; + double out1_1_6[4] = {1.,1.,1.,1.}; + double out1_2_3[4] = {1.,1.,2.,2.}; + double out1_3_2[4] = {2.,2.,3.,3.}; + double out1_6_1[4] = {2.,3.,5.,6.}; + double out2_1_6[4] = {2.,3.,5.,6.}; + double out2_2_3[4] = {2.,3.,1.,3.}; + double out2_3_2[4] = {1.,2.,1.,2.}; + double out2_6_1[4] = {1.,1.,1.,1.}; + double out1Good[6] = {0}, out1Bad[6] = {0}, out2Good[6] = {0}, out2Bad[6] = {0}; + int size1[2]={0},size2[2]={0}; printf(">> Double \n"); /* Test tab 1 ligne 6 colonnes */ - dfind2da(goodArray, 1, 6, &out1Good, &out2Good); - dfind2da(badArray, 1, 6, &out1Bad, &out2Bad); + dfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); - for (i=0;i<4;i++){ + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_1_6[i]) || (out2Good[i] != out2_1_6[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -171,8 +160,8 @@ int dfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + dfind2da(badArray, 1, 6, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -182,25 +171,21 @@ int dfind2daTest() { printf("\n"); /* Test tab 2 lignes 3 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - dfind2da(goodArray, 2, 3, &out1Good, &out2Good); - dfind2da(badArray, 2, 3, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + dfind2da(goodArray, 2, 3, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_2_3[i]) || (out2Good[i] != out2_2_3[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; } - else + else printf("(%f-%f) ",out1Good[i],out2Good[i]); } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + dfind2da(badArray, 2, 3, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -210,14 +195,10 @@ int dfind2daTest() { printf("\n"); /* Test tab 3 lignes 2 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - dfind2da(goodArray, 3, 2, &out1Good, &out2Good); - dfind2da(badArray, 3, 2, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + dfind2da(goodArray, 3, 2, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_3_2[i]) || (out2Good[i] != out2_3_2[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -227,8 +208,8 @@ int dfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + dfind2da(badArray, 3, 2, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -238,14 +219,10 @@ int dfind2daTest() { printf("\n"); /* Test tab 6 lignes 1 colonne */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - dfind2da(goodArray, 6, 1, &out1Good, &out2Good); - dfind2da(badArray, 6, 1, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + dfind2da(goodArray, 6, 1, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_6_1[i]) || (out2Good[i] != out2_6_1[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -255,8 +232,8 @@ int dfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + dfind2da(badArray, 6, 1, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -273,15 +250,16 @@ int cfind2daTest() { int result = 0, i = 0; floatComplex goodArray[6]; floatComplex badArray[6]; - float out1_1_6[4] = {0.,0.,0.,0.}; - float out1_2_3[4] = {0.,0.,1.,1.}; - float out1_3_2[4] = {0.,1.,2.,2.}; - float out1_6_1[4] = {1.,2.,4.,5.}; - float out2_1_6[4] = {1.,2.,4.,5.}; - float out2_2_3[4] = {1.,2.,1.,2.}; - float out2_3_2[4] = {1.,0.,0.,1.}; - float out2_6_1[4] = {0.,0.,0.,0.}; - float *out1Good = NULL, *out1Bad = NULL, *out2Good = NULL, *out2Bad = NULL; + float out1_1_6[4] = {1.,1.,1.,1.}; + float out1_2_3[4] = {1.,1.,2.,2.}; + float out1_3_2[4] = {2.,2.,3.,3.}; + float out1_6_1[4] = {2.,3.,5.,6.}; + float out2_1_6[4] = {2.,3.,5.,6.}; + float out2_2_3[4] = {2.,3.,1.,3.}; + float out2_3_2[4] = {1.,2.,1.,2.}; + float out2_6_1[4] = {1.,1.,1.,1.}; + float out1Good[6] = {0}, out1Bad[6] = {0}, out2Good[6] = {0}, out2Bad[6] = {0}; + int size1[2]={0},size2[2]={0}; /* Good values in goodArray */ goodArray[0] = FloatComplex(0., 0.); @@ -301,10 +279,10 @@ int cfind2daTest() { printf(">> Float Complex \n"); /* Test tab 1 ligne 6 colonnes */ - cfind2da(goodArray, 1, 6, &out1Good, &out2Good); - cfind2da(badArray, 1, 6, &out1Bad, &out2Bad); + cfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + - for (i=0;i<4;i++){ + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_1_6[i]) || (out2Good[i] != out2_1_6[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -314,8 +292,8 @@ int cfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + cfind2da(badArray, 1, 6, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -325,14 +303,10 @@ int cfind2daTest() { printf("\n"); /* Test tab 2 lignes 3 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - cfind2da(goodArray, 2, 3, &out1Good, &out2Good); - cfind2da(badArray, 2, 3, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + cfind2da(goodArray, 2, 3, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_2_3[i]) || (out2Good[i] != out2_2_3[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -342,8 +316,8 @@ int cfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + cfind2da(badArray, 2, 3, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -353,14 +327,10 @@ int cfind2daTest() { printf("\n"); /* Test tab 3 lignes 2 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - cfind2da(goodArray, 3, 2, &out1Good, &out2Good); - cfind2da(badArray, 3, 2, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + cfind2da(goodArray, 3, 2, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_3_2[i]) || (out2Good[i] != out2_3_2[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -370,8 +340,8 @@ int cfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + cfind2da(badArray, 3, 2, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -381,14 +351,10 @@ int cfind2daTest() { printf("\n"); /* Test tab 6 lignes 1 colonne */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - cfind2da(goodArray, 6, 1, &out1Good, &out2Good); - cfind2da(badArray, 6, 1, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + cfind2da(goodArray, 6, 1, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_6_1[i]) || (out2Good[i] != out2_6_1[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -398,8 +364,8 @@ int cfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + cfind2da(badArray, 6, 1, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out2Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -416,15 +382,16 @@ int zfind2daTest() { int result = 0, i = 0; doubleComplex goodArray[6]; doubleComplex badArray[6]; - double out1_1_6[4] = {0.,0.,0.,0.}; - double out1_2_3[4] = {0.,0.,1.,1.}; - double out1_3_2[4] = {0.,1.,2.,2.}; - double out1_6_1[4] = {1.,2.,4.,5.}; - double out2_1_6[4] = {1.,2.,4.,5.}; - double out2_2_3[4] = {1.,2.,1.,2.}; - double out2_3_2[4] = {1.,0.,0.,1.}; - double out2_6_1[4] = {0.,0.,0.,0.}; - double *out1Good = NULL, *out1Bad = NULL, *out2Good = NULL, *out2Bad = NULL; + double out1_1_6[4] = {1.,1.,1.,1.}; + double out1_2_3[4] = {1.,1.,2.,2.}; + double out1_3_2[4] = {2.,2.,3.,3.}; + double out1_6_1[4] = {2.,3.,5.,6.}; + double out2_1_6[4] = {2.,3.,5.,6.}; + double out2_2_3[4] = {2.,3.,1.,3.}; + double out2_3_2[4] = {1.,2.,1.,2.}; + double out2_6_1[4] = {1.,1.,1.,1.}; + double out1Good[6] = {0}, out1Bad[6] = {0}, out2Good[6] = {0}, out2Bad[6] = {0}; + int size1[2]={0},size2[2]={0}; /* Good values in goodArray */ @@ -446,10 +413,10 @@ int zfind2daTest() { printf(">> Double Complex \n"); /* Test tab 1 ligne 6 colonnes */ - zfind2da(goodArray, 1, 6, &out1Good, &out2Good); - zfind2da(badArray, 1, 6, &out1Bad, &out2Bad); + zfind2da(goodArray, 1, 6, out1Good, size1, out2Good, size2); + - for (i=0;i<4;i++){ + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_1_6[i]) || (out2Good[i] != out2_1_6[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -459,8 +426,8 @@ int zfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + zfind2da(badArray, 1, 6, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out1Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -470,14 +437,10 @@ int zfind2daTest() { printf("\n"); /* Test tab 2 lignes 3 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - zfind2da(goodArray, 2, 3, &out1Good, &out2Good); - zfind2da(badArray, 2, 3, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + zfind2da(goodArray, 2, 3, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_2_3[i]) || (out2Good[i] != out2_2_3[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -487,8 +450,8 @@ int zfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + zfind2da(badArray, 2, 3, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out1Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -498,14 +461,10 @@ int zfind2daTest() { printf("\n"); /* Test tab 3 lignes 2 colonnes */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - zfind2da(goodArray, 3, 2, &out1Good, &out2Good); - zfind2da(badArray, 3, 2, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + zfind2da(goodArray, 3, 2, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_3_2[i]) || (out2Good[i] != out2_3_2[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -515,8 +474,8 @@ int zfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + zfind2da(badArray, 3, 2, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out1Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } @@ -526,14 +485,10 @@ int zfind2daTest() { printf("\n"); /* Test tab 6 lignes 1 colonne */ - out1Good = NULL; - out1Bad = NULL; - out2Good = NULL; - out2Bad = NULL; - zfind2da(goodArray, 6, 1, &out1Good, &out2Good); - zfind2da(badArray, 6, 1, &out1Bad, &out2Bad); - - for (i=0;i<4;i++){ + zfind2da(goodArray, 6, 1, out1Good, size1, out2Good, size2); + + + for (i=0;i<size1[1];i++){ if ( (out1Good[i] != out1_6_1[i]) || (out2Good[i] != out2_6_1[i]) ) { printf("ERROR ! : Test Failed (non empty array)\n"); result = ERROR; @@ -543,8 +498,8 @@ int zfind2daTest() { } printf("\n"); - - if ((out1Bad!=NULL) || (out2Bad!=NULL) ) { + zfind2da(badArray, 6, 1, out1Bad, size1, out2Bad, size2); + if ((out1Bad[0]!=-1) || (out1Bad[0]!=-1) ) { printf("ERROR ! : Test Failed (empty array)\n"); result = ERROR; } diff --git a/src/auxiliaryFunctions/find2d/zfind2da.c b/src/auxiliaryFunctions/find2d/zfind2da.c index 223ce0ed..db263544 100644 --- a/src/auxiliaryFunctions/find2d/zfind2da.c +++ b/src/auxiliaryFunctions/find2d/zfind2da.c @@ -13,25 +13,23 @@ #include "find2d.h" #include <malloc.h> -void zfind2da(doubleComplex* x, int rows, int columns, double** out1, double** out2) { +void zfind2da(doubleComplex* x, int rows, int columns, double* out1,int* indiceOut1, double* out2,int* indiceOut2) { int i = 0, j=0; - int indiceOut = 0; - double* out_1 = NULL, *out_2=NULL; + indiceOut1[1] = 0; - /* We suppose out1 and out2 are NULL on input */ + /* if out are empties */ + out1[0]=-1; + out2[0]=-1; for (i = 0; i < rows ; ++i) { for (j = 0; j < columns ; ++j) { - if ((zreals(x[i*columns+j]) != 0) || (zimags(x[i*columns+j])!=0) ) { - out_1 = realloc(out_1, (uint)(indiceOut+1)*sizeof(double)); - out_2 = realloc(out_2, (uint)(indiceOut+1)*sizeof(double)); + if ((zreals(x[j*rows+i]) != 0) || (zimags(x[j*rows+i])!=0) ) { - out_1[indiceOut] = (double)i; - out_2[indiceOut] = (double)j; - indiceOut++; + out1[indiceOut1[1]] = (double)(i+1); + out2[indiceOut1[1]] = (double)(j+1); + indiceOut1[1]++; } } } - *out1=out_1; - *out2=out_2; + indiceOut2[1]=indiceOut1[1]; } diff --git a/src/auxiliaryFunctions/includes/find2d.h b/src/auxiliaryFunctions/includes/find2d.h index dd88ddef..264d49d2 100644 --- a/src/auxiliaryFunctions/includes/find2d.h +++ b/src/auxiliaryFunctions/includes/find2d.h @@ -19,20 +19,21 @@ /* ** \brief Float Find function */ -void sfind2da(float* x, int rows, int columns, float** out1, float** out2); +void sfind2da(float* x, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2); /* ** \brief Double Find function */ -void dfind2da(double*x, int rows, int columns, double** out1, double** out2); +void dfind2da(double* x, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2); /* ** \brief Float Complex Find function */ -void cfind2da(floatComplex* z, int rows, int columns, float** out1, float** out2); +void cfind2da(floatComplex* z, int rows, int columns, float* out1, int* sizeOut1, float* out2, int* sizeOut2); /* ** \brief Double Complex Find function */ -void zfind2da(doubleComplex* z, int rows, int columns, double** out1, double** out2); +void zfind2da(doubleComplex* z, int rows, int columns, double* out1, int* sizeOut1, double* out2, int* sizeOut2); + #endif /* !__FIND2D_H__ */ diff --git a/src/auxiliaryFunctions/interfaces/int_find.h b/src/auxiliaryFunctions/interfaces/int_find.h index 78b326a1..7d620e6c 100644 --- a/src/auxiliaryFunctions/interfaces/int_find.h +++ b/src/auxiliaryFunctions/interfaces/int_find.h @@ -17,13 +17,13 @@ /* 1 input, 1 output */ -#define s0finds0(in) (in == 0) ? -1 : in +#define s0finds0(in) (in == 0) ? -1 : 1 -#define d0findd0(in) (in == 0) ? -1 : in +#define d0findd0(in) (in == 0) ? -1 : 1 + +#define c0finds0(in) ((creals(in) == 0) && (cimags(in) == 0)) ? -1 : 1 -#define c0finds0(in) ((creals(in) == 0) && (cimags(in) == 0)) ? -1 : in - -#define z0findd0(in) ((zreals(in) == 0) && (zimags(in) == 0)) ? -1 : in +#define z0findd0(in) ((zreals(in) == 0) && (zimags(in) == 0)) ? -1 : 1 #define s2finds2(in,size,out,sizeOut) sfinda(in, size[0]*size[1], out, sizeOut) @@ -35,21 +35,22 @@ /* 1 input, 2 outputs */ -#define s0finds0s0(in,out1,out2) if (in==0) {out1=0;out2=0;} +#define s0finds0s0(in,out2) *out2 = s0finds0(in);s0finds0(in) + +#define d0findd0d0(in,out2) *out2 = d0findd0(in);d0findd0(in) -#define d0findd0d0(in,out1,out2) if (in==0) {out1=0;out2=0;} +#define c0finds0s0(in,out2) if ((creals(in)==0) && (cimags(in)==0)) {out2=0;} else {out2=1;} -#define c0finds0s0(in,out1,out2) if ((creals(in)==0) && (cimags(in)==0)) {out1=0;out2=0;} +#define z0findd0d0(in,out2) if ((zreals(in)==0) && (zimags(in)==0)) {out2=0;} else {out2=1;} -#define z0findd0d0(in,out1,out2) if ((zreals(in)==0) && (zimags(in)==0)) {out1=0;out2=0;} -#define s2finds2s2(in,size,out1,out2) sfind2d(in,size[0],size[1],&out1,&out2) +#define s2finds2s2(in,size,out1,sizeOut1,out2,sizeOut2) sfind2da(in,size[0],size[1],out1,sizeOut1,out2,sizeOut2) -#define d2findd2d2(in,size,out1,out2) dfind2d(in,size[0],size[1],&out1,&out2) +#define d2findd2d2(in,size,out1,sizeOut1,out2,sizeOut2) dfind2da(in,size[0],size[1],out1,sizeOut1,out2,sizeOut2) -#define c2finds2s2(in,size,out1,out2) cfind2d(in,size[0],size[1],&out1,&out2) +#define c2finds2s2(in,size,out1,sizeOut1,out2,sizeOut2) cfind2da(in,size[0],size[1],out1,sizeOut1,out2,sizeOut2) -#define z2finds2s2(in,size,out1,out2) zfind2d(in,size[0],size[1],&out1,&out2) +#define z2finds2s2(in,size,out1,sizeOut1,out2,sizeOut2) zfind2da(in,size[0],size[1],out1,sizeOut1,out2,sizeOut2) /* 2 inputs, 1 output */ @@ -60,7 +61,7 @@ #define c0s0finds0(in1,in2) c0finds0(in1) #define z0d0findd0(in1,in2) z0findd0(in1) - + #define s2s0finds2(in1,size,in2,out) s2finds2(in1,size,out_tmp);for(int i=0;i<in2;i++) out[i]=out_tmp[i]; #define d2d0findd2(in1,size,in2,out) d2findd2(in1,size,out_tmp);for(int i=0;i<in2;i++) out[i]=out_tmp[i]; @@ -71,14 +72,16 @@ /* 2 inputs, 2 outputs */ -#define s0s0finds0s0(in1,in2,out1,out2) s0finds0s0(in1,out1,out2) +#define s0s0finds0s0(in1,in2,out2) s0finds0s0(in1,out2) + +#define d0d0findd0d0(in1,in2,out2) d0findd0d0(in1,out2) -#define d0d0findd0d0(in1,in2,out1,out2) d0findd0d0(in1,out1,out2) +#define c0s0finds0s0(in1,in2,out2) c0finds0s0(in1,out2) -#define c0s0finds0s0(in1,in2,out1,out2) c0finds0s0(in1,out1,out2) +#define z0d0findd0d0(in1,in2,out2) z0findd0d0(in1,out2) -#define z0d0findd0d0(in1,in2,out1,out2) z0findd0d0(in1,out1,out2) +/*FIXME : prototypes are wrong*/ #define s2s0finds2s2(in1,size,in2,out1,out2) s2finds2s2(in1,size,out1_tmp,out_tmp2);for(int i=0;i<in2;i++) {out1[i]=out1_tmp[i];out2[i]= out2_tmp[i];} #define d2d0findd2d2(in1,size,in2,out1,out2) d2findd2d2(in1,size,out1_tmp,out_tmp2);for(int i=0;i<in2;i++) {out1[i]=out1_tmp[i];out2[i]= out2_tmp[i];} |