X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=code%2Fstage1%2Fsrc%2FTimeSeries%2Fdeserialize.c;h=79f784307f1c8bc89e6512820422d6345eff6c78;hb=ebf1280e432d51f47238ce8df86750ba3a7d6d1f;hp=5d1d758789f6960893d4ac1caf400fb9fd40048e;hpb=aa7daeaacfda268c392adf1c5efbccea77be9fe0;p=epclust.git diff --git a/code/stage1/src/TimeSeries/deserialize.c b/code/stage1/src/TimeSeries/deserialize.c index 5d1d758..79f7843 100644 --- a/code/stage1/src/TimeSeries/deserialize.c +++ b/code/stage1/src/TimeSeries/deserialize.c @@ -10,7 +10,7 @@ PowerCurve* deserialize(const char* ifileName, const char* ofileName, // Read tsLength at the beginning of the file uint32_t tsLength = get_tsLength(ifileName); - uint32_t valuesPerSerie = (tsLength - 4) / 3; //remove 4 bytes of ID + uint32_t valuesPerSerie = (tsLength - 4) / 4; //remove 4 bytes of ID FILE* ifile = fopen(ifileName, "rb"); FILE* ofile = NULL; @@ -22,7 +22,7 @@ PowerCurve* deserialize(const char* ifileName, const char* ofileName, nbRanks = get_nbSeries(ifileName); ranks = NULL; } - + PowerCurve* powerCurves = NULL; if (!ofile) powerCurves = (PowerCurve*) malloc(nbRanks * sizeof(PowerCurve)); @@ -52,22 +52,21 @@ PowerCurve* deserialize(const char* ifileName, const char* ofileName, else powerCurve->ID = ID; - // translate 3-bytes binary integers into Real - Byte* binarySerie = (Byte*) malloc(3 * valuesPerSerie); - lengthRead = fread(binarySerie, 1, 3*valuesPerSerie, ifile); - if (lengthRead != 3*valuesPerSerie) - fprintf(stderr,"Warning: deserializing truncated binary file.\n"); + // translate 4-bytes binary integers into Real + Byte* binarySerie = (Byte*) malloc(4 * valuesPerSerie); + lengthRead = fread(binarySerie, 1, 4*valuesPerSerie, ifile); + //TODO: assert that lengthRead == 4*valuesPerSerie (...) for (uint32_t i = 0; i < valuesPerSerie; i++) { - uint32_t powerInt = bInt_to_uint(binarySerie + 3 * i, 3); + float power = bReal_to_float(binarySerie + 4 * i); if (ofile) { - fprintf(ofile, "%g", powerInt / 10.0 - 0.0); + fprintf(ofile, "%g", power); if (i < valuesPerSerie-1) fprintf(ofile, ","); } else - powerCurve->values[i] = powerInt / 10.0 - 0.0; + powerCurve->values[i] = power; } free(binarySerie); if (ofile)