finalize R 'wrapper' for stage 1; WARNING: changed series encoding. TODO: test
[epclust.git] / code / stage1 / src / TimeSeries / deserialize.c
index 5d1d758..79f7843 100644 (file)
@@ -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)