X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=src%2Ftest%2Futils.c;h=2eac0c22bbe7a50615cd3ae8ebed0281bf801b3f;hb=e8bb47649b9f4e625ef050aae096d23cfc058163;hp=7cdf740eb4ca9ecaebd7eddca3dcd43b46e35c57;hpb=7b2720733e9aebe177c211119a9ec160c7e7117b;p=valse.git diff --git a/src/test/utils.c b/src/test/utils.c index 7cdf740..2eac0c2 100644 --- a/src/test/utils.c +++ b/src/test/utils.c @@ -1,15 +1,20 @@ +#include +#include +#include +#include + // Check if array == refArray void compareArray(const char* ID, const void* array, const void* refArray, int size, - int isInteger) + int isinteger) { - Real EPS = 1e-5; //precision + float EPS = 1e-5; //precision printf("Checking %s\n",ID); - Real maxError = 0.0; - for (mwSize i=0; i= maxError) maxError = error; } @@ -30,52 +35,60 @@ void compareArray_int(const char* ID, const void* array, const void* refArray, i } // Read array by columns (as in MATLAB) and return by-rows encoding -void* readArray(const char* fileName, int isInteger) +void* readArray(const char* fileName, int isinteger) { - // need to prepend '../data/' (not really nice code...) - char* fullFileName = (char*)calloc(5+strlen(fileName)+1,sizeof(char)); + // need to prepend 'data/' (not really nice code...) + char* fullFileName = (char*)calloc(5+strlen(fileName)+1, sizeof(char)); strcat(fullFileName, "data/"); strcat(fullFileName, fileName); - FILE* file = fopen(fullFileName, "r"); - free(fullFileName); // first pass to know how many elements to allocate - // /////................... TODO + char* command = (char*)calloc(12+strlen(fullFileName)+8+1, sizeof(char)); + strcat(command, "wc -l "); + strcat(command, fullFileName); + FILE *arraySize = popen(command, "r"); + char* bufferNum = (char*)calloc(64, sizeof(char)); + fgets(bufferNum, sizeof(bufferNum), arraySize); + int n = atoi(bufferNum); + pclose(arraySize); + + // open file for reading + FILE* arrayFile = fopen(fullFileName, "r"); + free(fullFileName); - int d = 1; - for (int i=0; i