X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=src%2Ftest%2Futils.c;h=8895cda938fdf0f365c3ef3e8923b80fb1ac52da;hp=7cdf740eb4ca9ecaebd7eddca3dcd43b46e35c57;hb=7ea8c1e58b3ab98eda5b003ccdffe5e35222bb4f;hpb=7b2720733e9aebe177c211119a9ec160c7e7117b diff --git a/src/test/utils.c b/src/test/utils.c index 7cdf740..8895cda 100644 --- a/src/test/utils.c +++ b/src/test/utils.c @@ -1,15 +1,15 @@ // 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 +30,77 @@ 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)); + 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, "grep -o ' ' "); + strcat(command, fullFileName); + strcat(command, " | wc -l"); + FILE *countSpaces = popen(command, "r"); + char* buffer = (char*)calloc(32, sizeof(char)); + fgets(buffer, sizeof(buffer), command); + int n = atoi(buffer) + 1; + free(buffer); + pclose(countSpaces); + + // open file for reading + FILE* file = fopen(fullFileName, "r"); + free(fullFileName); int d = 1; - for (int i=0; i