X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=src%2Ftest%2Futils.c;h=2eac0c22bbe7a50615cd3ae8ebed0281bf801b3f;hp=a6370b0dbfa4a7a7647506cb029328fcb5c7d761;hb=e8bb47649b9f4e625ef050aae096d23cfc058163;hpb=9ade3f1b66fa07ad9f1a3b09fc05462c783841de diff --git a/src/test/utils.c b/src/test/utils.c index a6370b0..2eac0c2 100644 --- a/src/test/utils.c +++ b/src/test/utils.c @@ -37,55 +37,38 @@ 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) { - // need to prepend '../data/' (not really nice code...) + // need to prepend 'data/' (not really nice code...) char* fullFileName = (char*)calloc(5+strlen(fileName)+1, sizeof(char)); strcat(fullFileName, "data/"); strcat(fullFileName, fileName); // first pass to know how many elements to allocate char* command = (char*)calloc(12+strlen(fullFileName)+8+1, sizeof(char)); - strcat(command, "grep -o ' ' "); + strcat(command, "wc -l "); strcat(command, fullFileName); - strcat(command, " | wc -l"); - FILE *countSpaces = popen(command, "r"); - char* buffer = (char*)calloc(32, sizeof(char)); - fgets(buffer, sizeof(buffer), countSpaces); - int n = atoi(buffer) + 1; - free(buffer); - pclose(countSpaces); + 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* file = fopen(fullFileName, "r"); + FILE* arrayFile = fopen(fullFileName, "r"); free(fullFileName); - int d = 1; - size_t elementSize = isinteger - ? sizeof(int) - : sizeof(float); - // read all values, and convert them to by-rows matrices format + size_t elementSize = isinteger ? sizeof(int) : sizeof(float); void* array = malloc(n*elementSize); - char curChar = ' '; - char bufferNum[64]; - for (int u=0; u