FIX: C code (double, float, ...) + wrapper (read/write data, get medoids)
[epclust.git] / code / stage1 / src / TimeSeries / deserialize.c
index 5d1d758..e142fe3 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));
@@ -37,7 +37,7 @@ PowerCurve* deserialize(const char* ifileName, const char* ofileName,
                if (!ofile)
                {
                        powerCurve = powerCurves + i;
-                       powerCurve->values = (Real*) malloc(valuesPerSerie * sizeof(Real));
+                       powerCurve->values = (float*) malloc(valuesPerSerie * sizeof(float));
                }
                
                // translate 4-bytes binary integer into integer ID
@@ -45,29 +45,28 @@ PowerCurve* deserialize(const char* ifileName, const char* ofileName,
                size_t lengthRead = fread(binaryID, 4, 1, ifile);
                if (lengthRead != 1)
                        fprintf(stderr,"Warning: deserializing truncated binary file.\n");
-               uint32_t ID = bInt_to_uint((Byte*) binaryID, 4);
+               uint32_t ID = bInt_to_uint((Byte*) binaryID);
                free(binaryID);
                if (ofile)
                        fprintf(ofile, "%u,", ID);
                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 float
+               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)