source: thirdparty/SZ/sz/src/TightDataPointStorageF.c @ 9ee2ce3

Revision 9ee2ce3, 25.6 KB checked in by Hal Finkel <hfinkel@…>, 6 years ago (diff)

importing new SZ files

  • Property mode set to 100644
Line 
1/**
2 *  @file TightPointDataStorageF.c
3 *  @author Sheng Di and Dingwen Tao
4 *  @date Aug, 2016
5 *  @brief The functions used to construct the tightPointDataStorage element for storing compressed bytes.
6 *  (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory.
7 *      See COPYRIGHT in top-level directory.
8 */
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <string.h>
13#include "TightDataPointStorageF.h"
14#include "sz.h"
15#include "Huffman.h"
16//#include "rw.h"
17
18void new_TightDataPointStorageF_Empty(TightDataPointStorageF **this)
19{
20        *this = (TightDataPointStorageF*)malloc(sizeof(TightDataPointStorageF));
21        (*this)->dataSeriesLength = 0;
22        (*this)->allSameData = 0;
23        (*this)->exactDataNum = 0;
24        (*this)->reservedValue = 0;
25        (*this)->reqLength = 0;
26        (*this)->radExpo = 0;
27
28        (*this)->rtypeArray = NULL;
29        (*this)->rtypeArray_size = 0;
30
31        (*this)->typeArray = NULL; //its size is dataSeriesLength/4 (or xxx/4+1)
32        (*this)->typeArray_size = 0;
33
34        (*this)->leadNumArray = NULL; //its size is exactDataNum/4 (or exactDataNum/4+1)
35        (*this)->leadNumArray_size = 0;
36
37        (*this)->exactMidBytes = NULL;
38        (*this)->exactMidBytes_size = 0;
39
40        (*this)->residualMidBits = NULL;
41        (*this)->residualMidBits_size = 0;
42       
43        (*this)->intervals = 0;
44        (*this)->isLossless = 0;
45       
46        (*this)->segment_size = 0;
47        (*this)->pwrErrBoundBytes = NULL;
48        (*this)->pwrErrBoundBytes_size = 0;     
49       
50        (*this)->raBytes = NULL;
51        (*this)->raBytes_size = 0;
52}
53
54int new_TightDataPointStorageF_fromFlatBytes(TightDataPointStorageF **this, unsigned char* flatBytes, size_t flatBytesLength)
55{
56        new_TightDataPointStorageF_Empty(this);
57        size_t i, index = 0;
58        size_t pwrErrBoundBytes_size = 0, segmentL = 0, radExpoL = 0, pwrErrBoundBytesL = 0;
59        char version[3];
60        for (i = 0; i < 3; i++)
61                version[i] = flatBytes[index++]; //3
62        unsigned char sameRByte = flatBytes[index++]; //1
63        if(checkVersion(version)!=1)
64        {
65                //wrong version
66                printf("Wrong version: \nCompressed-data version (%d.%d.%d)\n",version[0], version[1], version[2]);
67                printf("Current sz version: (%d.%d.%d)\n", versionNumber[0], versionNumber[1], versionNumber[2]);
68                printf("Please double-check if the compressed data (or file) is correct.\n");
69                exit(0);
70        }
71        int same = sameRByte & 0x01;
72        //confparams_dec->szMode = (sameRByte & 0x06)>>1;
73        (*this)->isLossless = (sameRByte & 0x10)>>4;
74        int isPW_REL = (sameRByte & 0x20)>>5;
75        exe_params->SZ_SIZE_TYPE = ((sameRByte & 0x40)>>6)==1?8:4;
76        int errorBoundMode = ABS;
77        if(isPW_REL)
78        {
79                errorBoundMode = PW_REL;
80                segmentL = exe_params->SZ_SIZE_TYPE;
81                pwrErrBoundBytesL = 4;
82        }
83       
84        sz_params* params = convertBytesToSZParams(&(flatBytes[index]));
85        int mode = confparams_dec->szMode;
86        int predictionMode = confparams_dec->predictionMode;
87        int losslessCompressor = confparams_dec->losslessCompressor;
88        if(confparams_dec!=NULL)
89                free(confparams_dec);
90        confparams_dec = params;
91        confparams_dec->szMode = mode;
92        confparams_dec->losslessCompressor = losslessCompressor;
93
94        if(mode==SZ_TEMPORAL_COMPRESSION)
95        {
96                confparams_dec->szMode = SZ_TEMPORAL_COMPRESSION;
97                confparams_dec->predictionMode = predictionMode;
98        }
99       
100        index += MetaDataByteLength;
101
102        int isRandomAccess = (sameRByte >> 7) & 0x01;
103       
104        unsigned char dsLengthBytes[8];
105        for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
106                dsLengthBytes[i] = flatBytes[index++];
107        (*this)->dataSeriesLength = bytesToSize(dsLengthBytes);// 4 or 8       
108       
109        if((*this)->isLossless==1)
110        {
111                //(*this)->exactMidBytes = flatBytes+8;
112                return errorBoundMode;
113        }
114        else if(same==1)
115        {
116                (*this)->allSameData = 1;
117                size_t exactMidBytesLength = sizeof(float); //flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE;
118                if(exactMidBytesLength>0)
119                        (*this)->exactMidBytes = (unsigned char*)malloc(sizeof(unsigned char)*exactMidBytesLength);
120                else
121                        (*this)->exactMidBytes = NULL;
122                for(i = 0;i<exactMidBytesLength;i++)
123                        (*this)->exactMidBytes[i] = flatBytes[index++];
124                return errorBoundMode;
125        }
126        else
127                (*this)->allSameData = 0;
128        if(isRandomAccess == 1)
129        {
130                (*this)->raBytes_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE;
131                (*this)->raBytes = &(flatBytes[index]);
132                return errorBoundMode;
133        }                       
134
135        int rtype_ = sameRByte & 0x08;          //=00001000
136        unsigned char byteBuf[8];
137
138        for (i = 0; i < 4; i++)
139                byteBuf[i] = flatBytes[index++];
140        int max_quant_intervals = bytesToInt_bigEndian(byteBuf);// 4   
141
142        confparams_dec->maxRangeRadius = max_quant_intervals/2;
143
144        if(errorBoundMode>=PW_REL)
145        {
146                (*this)->radExpo = flatBytes[index++];//1
147                radExpoL = 1;
148                for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
149                        byteBuf[i] = flatBytes[index++];
150                params->segment_size = (*this)->segment_size = bytesToSize(byteBuf);// exe_params->SZ_SIZE_TYPE
151
152                for (i = 0; i < 4; i++)
153                        byteBuf[i] = flatBytes[index++];
154                pwrErrBoundBytes_size = (*this)->pwrErrBoundBytes_size = bytesToInt_bigEndian(byteBuf);// 4             
155        }
156        else
157        {
158                pwrErrBoundBytes_size = 0;
159                (*this)->pwrErrBoundBytes = NULL;
160        }
161        for (i = 0; i < 4; i++)
162                byteBuf[i] = flatBytes[index++];
163        (*this)->intervals = bytesToInt_bigEndian(byteBuf);// 4
164
165        for (i = 0; i < 4; i++)
166                byteBuf[i] = flatBytes[index++];
167        (*this)->medianValue = bytesToFloat(byteBuf); //4
168       
169        (*this)->reqLength = flatBytes[index++]; //1
170       
171        for (i = 0; i < 8; i++)
172                byteBuf[i] = flatBytes[index++];
173        (*this)->realPrecision = bytesToDouble(byteBuf);//8
174
175        for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
176                byteBuf[i] = flatBytes[index++];
177        (*this)->typeArray_size = bytesToSize(byteBuf);// 4             
178        if(rtype_!=0)
179        {
180                for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++) 
181                        byteBuf[i] = flatBytes[index++];
182                (*this)->rtypeArray_size = bytesToSize(byteBuf);//(ST)
183        }
184        else
185                (*this)->rtypeArray_size = 0;
186
187        for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
188                byteBuf[i] = flatBytes[index++];
189        (*this)->exactDataNum = bytesToSize(byteBuf);// ST
190
191        for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
192                byteBuf[i] = flatBytes[index++];
193        (*this)->exactMidBytes_size = bytesToSize(byteBuf);// ST
194
195        if (rtype_ != 0) {
196                if((*this)->rtypeArray_size>0)
197                        (*this)->rtypeArray = (unsigned char*)malloc(sizeof(unsigned char)*(*this)->rtypeArray_size);
198                else
199                        (*this)->rtypeArray = NULL;
200
201                for (i = 0; i < 4; i++)
202                        byteBuf[i] = flatBytes[index++];
203                (*this)->reservedValue = bytesToFloat(byteBuf);//4
204        }
205
206        size_t logicLeadNumBitsNum = (*this)->exactDataNum * 2;
207        if (logicLeadNumBitsNum % 8 == 0)
208        {
209                (*this)->leadNumArray_size = logicLeadNumBitsNum >> 3;
210        }
211        else
212        {
213                (*this)->leadNumArray_size = (logicLeadNumBitsNum >> 3) + 1;
214        }
215
216        int minLogValueSize = 0;
217        if(errorBoundMode>=PW_REL)
218                minLogValueSize = 4;
219
220        if ((*this)->rtypeArray != NULL) 
221        {
222                (*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 4 - 1 - 8 
223                                - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - minLogValueSize - exe_params->SZ_SIZE_TYPE - 4 - (*this)->rtypeArray_size
224                                - minLogValueSize - (*this)->typeArray_size - (*this)->leadNumArray_size
225                                - (*this)->exactMidBytes_size - pwrErrBoundBytes_size;
226                for (i = 0; i < (*this)->rtypeArray_size; i++)
227                        (*this)->rtypeArray[i] = flatBytes[index++];
228        }
229        else
230        {
231                (*this)->residualMidBits_size = flatBytesLength - 3 - 1 - MetaDataByteLength - exe_params->SZ_SIZE_TYPE - 4 - radExpoL - segmentL - pwrErrBoundBytesL - 4 - 4 - 1 - 8 
232                                - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - exe_params->SZ_SIZE_TYPE - minLogValueSize - (*this)->typeArray_size
233                                - (*this)->leadNumArray_size - (*this)->exactMidBytes_size - pwrErrBoundBytes_size;
234        }
235
236        if(errorBoundMode>=PW_REL)
237        {
238                (*this)->minLogValue = bytesToFloat(&flatBytes[index]);
239                index+=4;
240        }
241
242        (*this)->typeArray = &flatBytes[index]; 
243        //retrieve the number of states (i.e., stateNum)
244        (*this)->allNodes = bytesToInt_bigEndian((*this)->typeArray); //the first 4 bytes store the stateNum
245        (*this)->stateNum = ((*this)->allNodes+1)/2;   
246
247        index+=(*this)->typeArray_size;
248       
249        (*this)->pwrErrBoundBytes = &flatBytes[index];
250       
251        index+=pwrErrBoundBytes_size;
252       
253        (*this)->leadNumArray = &flatBytes[index];
254       
255        index+=(*this)->leadNumArray_size;
256       
257        (*this)->exactMidBytes = &flatBytes[index];
258       
259        index+=(*this)->exactMidBytes_size;
260       
261        (*this)->residualMidBits = &flatBytes[index];
262       
263        //index+=(*this)->residualMidBits_size;
264       
265        return errorBoundMode;
266}
267
268/**
269 *
270 * type's length == dataSeriesLength
271 * exactMidBytes's length == exactMidBytes_size
272 * leadNumIntArray's length == exactDataNum
273 * escBytes's length == escBytes_size
274 * resiBitLength's length == resiBitLengthSize
275 * */
276void new_TightDataPointStorageF(TightDataPointStorageF **this,
277                size_t dataSeriesLength, size_t exactDataNum, 
278                int* type, unsigned char* exactMidBytes, size_t exactMidBytes_size,
279                unsigned char* leadNumIntArray,  //leadNumIntArray contains readable numbers....
280                unsigned char* resiMidBits, size_t resiMidBits_size,
281                unsigned char resiBitLength, 
282                double realPrecision, float medianValue, char reqLength, unsigned int intervals, 
283                unsigned char* pwrErrBoundBytes, size_t pwrErrBoundBytes_size, unsigned char radExpo) {
284       
285        *this = (TightDataPointStorageF *)malloc(sizeof(TightDataPointStorageF));
286        (*this)->allSameData = 0;
287        (*this)->realPrecision = realPrecision;
288        (*this)->medianValue = medianValue;
289        (*this)->reqLength = reqLength;
290
291        (*this)->dataSeriesLength = dataSeriesLength;
292        (*this)->exactDataNum = exactDataNum;
293
294        (*this)->rtypeArray = NULL;
295        (*this)->rtypeArray_size = 0;
296
297        int stateNum = 2*intervals;
298        HuffmanTree* huffmanTree = createHuffmanTree(stateNum);
299        encode_withTree(huffmanTree, type, dataSeriesLength, &(*this)->typeArray, &(*this)->typeArray_size);
300        SZ_ReleaseHuffman(huffmanTree);
301               
302        (*this)->exactMidBytes = exactMidBytes;
303        (*this)->exactMidBytes_size = exactMidBytes_size;
304
305        (*this)->leadNumArray_size = convertIntArray2ByteArray_fast_2b(leadNumIntArray, exactDataNum, &((*this)->leadNumArray));
306
307        (*this)->residualMidBits_size = convertIntArray2ByteArray_fast_dynamic(resiMidBits, resiBitLength, exactDataNum, &((*this)->residualMidBits));
308       
309        (*this)->intervals = intervals;
310       
311        (*this)->isLossless = 0;
312       
313        if(confparams_cpr->errorBoundMode>=PW_REL)
314                (*this)->pwrErrBoundBytes = pwrErrBoundBytes;
315        else
316                (*this)->pwrErrBoundBytes = NULL;
317               
318        (*this)->radExpo = radExpo;
319       
320        (*this)->pwrErrBoundBytes_size = pwrErrBoundBytes_size;
321}
322
323void new_TightDataPointStorageF2(TightDataPointStorageF **this,
324                size_t dataSeriesLength, size_t exactDataNum, 
325                int* type, unsigned char* exactMidBytes, size_t exactMidBytes_size,
326                unsigned char* leadNumIntArray,  //leadNumIntArray contains readable numbers....
327                unsigned char* resiMidBits, size_t resiMidBits_size,
328                unsigned char* resiBitLength, size_t resiBitLengthSize, 
329                double realPrecision, float medianValue, char reqLength, unsigned int intervals, 
330                unsigned char* pwrErrBoundBytes, size_t pwrErrBoundBytes_size, unsigned char radExpo) {
331        //int i = 0;
332        *this = (TightDataPointStorageF *)malloc(sizeof(TightDataPointStorageF));
333        (*this)->allSameData = 0;
334        (*this)->realPrecision = realPrecision;
335        (*this)->medianValue = medianValue;
336        (*this)->reqLength = reqLength;
337
338        (*this)->dataSeriesLength = dataSeriesLength;
339        (*this)->exactDataNum = exactDataNum;
340
341        (*this)->rtypeArray = NULL;
342        (*this)->rtypeArray_size = 0;
343
344        int stateNum = 2*intervals;
345        HuffmanTree* huffmanTree = createHuffmanTree(stateNum);
346        encode_withTree(huffmanTree, type, dataSeriesLength, &(*this)->typeArray, &(*this)->typeArray_size);
347        SZ_ReleaseHuffman(huffmanTree);
348       
349        (*this)->exactMidBytes = exactMidBytes;
350        (*this)->exactMidBytes_size = exactMidBytes_size;
351
352        (*this)->leadNumArray_size = convertIntArray2ByteArray_fast_2b(leadNumIntArray, exactDataNum, &((*this)->leadNumArray));
353
354        //(*this)->residualMidBits = resiMidBits;
355        //(*this)->residualMidBits_size = resiMidBits_size;
356
357        (*this)->residualMidBits_size = convertIntArray2ByteArray_fast_dynamic2(resiMidBits, resiBitLength, resiBitLengthSize, &((*this)->residualMidBits));
358       
359        (*this)->intervals = intervals;
360       
361        (*this)->isLossless = 0;
362       
363        if(confparams_cpr->errorBoundMode>=PW_REL)
364                (*this)->pwrErrBoundBytes = pwrErrBoundBytes;
365        else
366                (*this)->pwrErrBoundBytes = NULL;
367               
368        (*this)->radExpo = radExpo;
369       
370        (*this)->pwrErrBoundBytes_size = pwrErrBoundBytes_size;
371}
372
373void convertTDPStoBytes_float(TightDataPointStorageF* tdps, unsigned char* bytes, unsigned char* dsLengthBytes, unsigned char sameByte)
374{
375        size_t i, k = 0;
376        unsigned char intervalsBytes[4];
377        unsigned char typeArrayLengthBytes[8];
378        unsigned char exactLengthBytes[8];
379        unsigned char exactMidBytesLength[8];
380        unsigned char realPrecisionBytes[8];
381       
382        unsigned char medianValueBytes[4];
383       
384        unsigned char segment_sizeBytes[8];
385        unsigned char pwrErrBoundBytes_sizeBytes[4];
386        unsigned char max_quant_intervals_Bytes[4];
387       
388       
389        for(i = 0;i<3;i++)//3 bytes
390                bytes[k++] = versionNumber[i];
391        bytes[k++] = sameByte;  //1     byte   
392       
393        convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
394        k = k + MetaDataByteLength;
395       
396        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST: 4 or 8 bytes
397                bytes[k++] = dsLengthBytes[i]; 
398        intToBytes_bigEndian(max_quant_intervals_Bytes, confparams_cpr->max_quant_intervals);
399        for(i = 0;i<4;i++)//4
400                bytes[k++] = max_quant_intervals_Bytes[i];             
401       
402        if(confparams_cpr->errorBoundMode>=PW_REL)
403        {
404                bytes[k++] = tdps->radExpo; //1 byte                   
405               
406                sizeToBytes(segment_sizeBytes, confparams_cpr->segment_size);
407                for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
408                        bytes[k++] = segment_sizeBytes[i];                             
409                       
410                intToBytes_bigEndian(pwrErrBoundBytes_sizeBytes, tdps->pwrErrBoundBytes_size);
411                for(i = 0;i<4;i++)//4
412                        bytes[k++] = pwrErrBoundBytes_sizeBytes[i];                                     
413        }
414       
415        intToBytes_bigEndian(intervalsBytes, tdps->intervals);
416        for(i = 0;i<4;i++)//4
417                bytes[k++] = intervalsBytes[i];                 
418       
419        floatToBytes(medianValueBytes, tdps->medianValue);
420        for (i = 0; i < 4; i++)// 4
421                bytes[k++] = medianValueBytes[i];               
422
423        bytes[k++] = tdps->reqLength; //1 byte
424
425/*      if(errorBoundMode>=PW_REL)
426                doubleToBytes(realPrecisionBytes, pw_relBoundRatio);
427        else*/
428        doubleToBytes(realPrecisionBytes, tdps->realPrecision);
429
430        for (i = 0; i < 8; i++)// 8
431                bytes[k++] = realPrecisionBytes[i];                     
432
433        sizeToBytes(typeArrayLengthBytes, tdps->typeArray_size);
434        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
435                bytes[k++] = typeArrayLengthBytes[i];
436
437        sizeToBytes(exactLengthBytes, tdps->exactDataNum);
438        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
439                bytes[k++] = exactLengthBytes[i];
440
441        sizeToBytes(exactMidBytesLength, tdps->exactMidBytes_size);
442        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
443                bytes[k++] = exactMidBytesLength[i];
444
445        if(confparams_cpr->errorBoundMode>=PW_REL)
446        {
447                floatToBytes(exactMidBytesLength, tdps->minLogValue);
448                for(i=0;i<4;i++)
449                        bytes[k++] = exactMidBytesLength[i];
450        }
451
452        memcpy(&(bytes[k]), tdps->typeArray, tdps->typeArray_size);
453        k += tdps->typeArray_size;
454        if(confparams_cpr->errorBoundMode>=PW_REL)
455        {
456                memcpy(&(bytes[k]), tdps->pwrErrBoundBytes, tdps->pwrErrBoundBytes_size);
457                k += tdps->pwrErrBoundBytes_size;
458        }
459
460        memcpy(&(bytes[k]), tdps->leadNumArray, tdps->leadNumArray_size);
461        k += tdps->leadNumArray_size;
462        memcpy(&(bytes[k]), tdps->exactMidBytes, tdps->exactMidBytes_size);
463        k += tdps->exactMidBytes_size;
464
465        if(tdps->residualMidBits!=NULL)
466        {
467                memcpy(&(bytes[k]), tdps->residualMidBits, tdps->residualMidBits_size);
468                k += tdps->residualMidBits_size;
469        }       
470}
471
472void convertTDPStoBytes_float_reserve(TightDataPointStorageF* tdps, unsigned char* bytes, unsigned char* dsLengthBytes, unsigned char sameByte)
473{
474        size_t i, k = 0;
475        unsigned char intervalsBytes[4];
476        unsigned char typeArrayLengthBytes[8];
477        unsigned char rTypeLengthBytes[8];
478        unsigned char exactLengthBytes[8];
479        unsigned char exactMidBytesLength[8];
480        unsigned char realPrecisionBytes[8];
481        unsigned char reservedValueBytes[4];
482       
483        unsigned char medianValueBytes[4];
484       
485        unsigned char segment_sizeBytes[8];
486        unsigned char pwrErrBoundBytes_sizeBytes[4];
487        unsigned char max_quant_intervals_Bytes[4];     
488       
489        for(i = 0;i<3;i++)//3
490                bytes[k++] = versionNumber[i];         
491        bytes[k++] = sameByte;                  //1
492
493        convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
494        k = k + MetaDataByteLength;
495       
496        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
497                bytes[k++] = dsLengthBytes[i];         
498
499
500        intToBytes_bigEndian(max_quant_intervals_Bytes, confparams_cpr->max_quant_intervals);
501        for(i = 0;i<4;i++)//4
502                bytes[k++] = max_quant_intervals_Bytes[i];
503
504        if(confparams_cpr->errorBoundMode>=PW_REL)
505        {
506                bytes[k++] = tdps->radExpo; //1 byte                   
507               
508                sizeToBytes(segment_sizeBytes, confparams_cpr->segment_size);
509                for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
510                        bytes[k++] = segment_sizeBytes[i];                             
511                       
512                intToBytes_bigEndian(pwrErrBoundBytes_sizeBytes, tdps->pwrErrBoundBytes_size);
513                for(i = 0;i<4;i++)//4
514                        bytes[k++] = pwrErrBoundBytes_sizeBytes[i];                                     
515        }
516       
517        intToBytes_bigEndian(intervalsBytes, tdps->intervals);
518        for(i = 0;i<4;i++)//4
519                bytes[k++] = intervalsBytes[i]; 
520
521        floatToBytes(medianValueBytes, tdps->medianValue);
522        for (i = 0; i < 4; i++)// 4
523                bytes[k++] = medianValueBytes[i];               
524
525        bytes[k++] = tdps->reqLength; //1 byte
526
527        floatToBytes(realPrecisionBytes, tdps->realPrecision);
528        for (i = 0; i < 8; i++)// 8
529                bytes[k++] = realPrecisionBytes[i];
530
531        sizeToBytes(typeArrayLengthBytes, tdps->typeArray_size);
532        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
533                bytes[k++] = typeArrayLengthBytes[i];
534
535        sizeToBytes(rTypeLengthBytes, tdps->rtypeArray_size);
536        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
537                bytes[k++] = rTypeLengthBytes[i];
538
539        sizeToBytes(exactLengthBytes, tdps->exactDataNum);
540        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
541                bytes[k++] = exactLengthBytes[i];
542
543        sizeToBytes(exactMidBytesLength, tdps->exactMidBytes_size);
544        for(i = 0;i<exe_params->SZ_SIZE_TYPE;i++)//ST
545                bytes[k++] = exactMidBytesLength[i];
546
547        floatToBytes(reservedValueBytes, tdps->reservedValue);
548        for (i = 0; i < 4; i++)// 4
549                bytes[k++] = reservedValueBytes[i];
550
551        memcpy(&(bytes[k]), tdps->rtypeArray, tdps->rtypeArray_size);
552        k += tdps->rtypeArray_size;
553       
554        if(confparams_cpr->errorBoundMode>=PW_REL)
555        {
556                floatToBytes(exactMidBytesLength, tdps->minLogValue);
557                for(i=0;i<4;i++)
558                        bytes[k++] = exactMidBytesLength[i];
559        }       
560       
561        memcpy(&(bytes[k]), tdps->typeArray, tdps->typeArray_size);
562        k += tdps->typeArray_size;
563        if(confparams_cpr->errorBoundMode>=PW_REL)
564        {
565                memcpy(&(bytes[k]), tdps->pwrErrBoundBytes, tdps->pwrErrBoundBytes_size);
566                k += tdps->pwrErrBoundBytes_size;
567        }
568        memcpy(&(bytes[k]), tdps->leadNumArray, tdps->leadNumArray_size);
569        k += tdps->leadNumArray_size;
570        memcpy(&(bytes[k]), tdps->exactMidBytes, tdps->exactMidBytes_size);
571        k += tdps->exactMidBytes_size;
572        if(tdps->residualMidBits!=NULL)
573        {
574                memcpy(&(bytes[k]), tdps->residualMidBits, tdps->residualMidBits_size);
575                k += tdps->residualMidBits_size;
576        }       
577}
578
579//convert TightDataPointStorageD to bytes...
580void convertTDPStoFlatBytes_float(TightDataPointStorageF *tdps, unsigned char** bytes, size_t *size)
581{
582        size_t i, k = 0; 
583        unsigned char dsLengthBytes[8];
584       
585        if(exe_params->SZ_SIZE_TYPE==4)
586                intToBytes_bigEndian(dsLengthBytes, tdps->dataSeriesLength);//4
587        else
588                longToBytes_bigEndian(dsLengthBytes, tdps->dataSeriesLength);//8
589               
590        unsigned char sameByte = tdps->allSameData==1?(unsigned char)1:(unsigned char)0;
591        sameByte = sameByte | (confparams_cpr->szMode << 1);
592        if(tdps->isLossless)
593                sameByte = (unsigned char) (sameByte | 0x10);
594        if(confparams_cpr->errorBoundMode>=PW_REL)
595                sameByte = (unsigned char) (sameByte | 0x20); // 00100000, the 5th bit
596        if(exe_params->SZ_SIZE_TYPE==8)
597                sameByte = (unsigned char) (sameByte | 0x40); // 01000000, the 6th bit
598
599        if(tdps->allSameData==1)
600        {
601                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;
602                *bytes = (unsigned char *)malloc(sizeof(unsigned char)*totalByteLength);
603
604                for (i = 0; i < 3; i++)//3
605                        (*bytes)[k++] = versionNumber[i];
606                (*bytes)[k++] = sameByte;
607               
608                convertSZParamsToBytes(confparams_cpr, &((*bytes)[k]));
609                k = k + MetaDataByteLength;
610                               
611                for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
612                        (*bytes)[k++] = dsLengthBytes[i];
613               
614                for (i = 0; i < tdps->exactMidBytes_size; i++)
615                        (*bytes)[k++] = tdps->exactMidBytes[i];
616
617                *size = totalByteLength;
618        }
619        else if (tdps->rtypeArray == NULL)
620        {
621                size_t residualMidBitsLength = tdps->residualMidBits == NULL ? 0 : tdps->residualMidBits_size;
622                size_t segmentL = 0, radExpoL = 0, pwrBoundArrayL = 0;
623                int minLogValueSize = 0;
624                if(confparams_cpr->errorBoundMode>=PW_REL)
625                {                       
626                        segmentL = exe_params->SZ_SIZE_TYPE;
627                        radExpoL = 1;
628                        pwrBoundArrayL = 4;
629                        minLogValueSize = 4;
630                }
631
632                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 4 + 1 + 8 
633                                + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + minLogValueSize
634                                + tdps->typeArray_size + tdps->leadNumArray_size
635                                + tdps->exactMidBytes_size + residualMidBitsLength + tdps->pwrErrBoundBytes_size;
636
637                *bytes = (unsigned char *)malloc(sizeof(unsigned char)*totalByteLength);
638
639                convertTDPStoBytes_float(tdps, *bytes, dsLengthBytes, sameByte);
640               
641                *size = totalByteLength;
642        }
643        else //the case with reserved value
644        {
645                size_t residualMidBitsLength = tdps->residualMidBits == NULL ? 0 : tdps->residualMidBits_size;         
646                size_t segmentL = 0, radExpoL = 0, pwrBoundArrayL = 0;
647                int minLogValueSize = 0;
648                if(confparams_cpr->errorBoundMode>=PW_REL)
649                {
650                        segmentL = exe_params->SZ_SIZE_TYPE;
651                        radExpoL = 1;
652                        pwrBoundArrayL = 4;
653                        minLogValueSize = 4;
654                }
655
656                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 4 + 1 + 8 
657                                + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + 4 + tdps->rtypeArray_size
658                                + minLogValueSize + tdps->typeArray_size + tdps->leadNumArray_size
659                                + tdps->exactMidBytes_size + residualMidBitsLength + tdps->pwrErrBoundBytes_size;
660
661                sameByte = (unsigned char) (sameByte | 0x08); // 00001000, the 4th bit
662                // denotes whether it is
663                // with "reserved value"
664               
665                if(confparams_cpr->errorBoundMode>=PW_REL)
666                        sameByte = (unsigned char) (sameByte | 0x10); // 00001000, the 5th bit
667
668                *bytes = (unsigned char*)malloc(sizeof(unsigned char)*totalByteLength);
669
670                convertTDPStoBytes_float_reserve(tdps, *bytes, dsLengthBytes, sameByte);
671               
672                *size = totalByteLength;
673        }
674}
675
676void convertTDPStoFlatBytes_float_args(TightDataPointStorageF *tdps, unsigned char* bytes, size_t *size)
677{
678        size_t i, k = 0; 
679        unsigned char dsLengthBytes[8];
680       
681        if(exe_params->SZ_SIZE_TYPE==4)
682                intToBytes_bigEndian(dsLengthBytes, tdps->dataSeriesLength);//4
683        else
684                longToBytes_bigEndian(dsLengthBytes, tdps->dataSeriesLength);//8
685               
686        unsigned char sameByte = tdps->allSameData==1?(unsigned char)1:(unsigned char)0;
687        sameByte = sameByte | (confparams_cpr->szMode << 1);
688        if(tdps->isLossless)
689                sameByte = (unsigned char) (sameByte | 0x10);
690        if(confparams_cpr->errorBoundMode>=PW_REL)
691                sameByte = (unsigned char) (sameByte | 0x20); // 00100000, the 5th bit
692        if(exe_params->SZ_SIZE_TYPE==8)
693                sameByte = (unsigned char) (sameByte | 0x40); // 01000000, the 6th bit
694               
695        if(tdps->allSameData==1)
696        {
697                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + tdps->exactMidBytes_size;
698                //*bytes = (unsigned char *)malloc(sizeof(unsigned char)*totalByteLength);
699
700                for (i = 0; i < 3; i++)//3
701                        bytes[k++] = versionNumber[i];
702                bytes[k++] = sameByte;
703
704                convertSZParamsToBytes(confparams_cpr, &(bytes[k]));
705                k = k + MetaDataByteLength;
706
707                for (i = 0; i < exe_params->SZ_SIZE_TYPE; i++)
708                        bytes[k++] = dsLengthBytes[i];         
709                for (i = 0; i < tdps->exactMidBytes_size; i++)
710                        bytes[k++] = tdps->exactMidBytes[i];
711
712                *size = totalByteLength;
713        }
714        else if (tdps->rtypeArray == NULL)
715        {
716                size_t residualMidBitsLength = tdps->residualMidBits == NULL ? 0 : tdps->residualMidBits_size;
717                size_t segmentL = 0, radExpoL = 0, pwrBoundArrayL = 0;
718                if(confparams_cpr->errorBoundMode>=PW_REL)
719                {                       
720                        segmentL = exe_params->SZ_SIZE_TYPE;
721                        radExpoL = 1;
722                        pwrBoundArrayL = 4;
723                }
724
725                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 4 + 1 + 8 
726                                + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE 
727                                + tdps->typeArray_size + tdps->leadNumArray_size
728                                + tdps->exactMidBytes_size + residualMidBitsLength + tdps->pwrErrBoundBytes_size;
729
730                convertTDPStoBytes_float(tdps, bytes, dsLengthBytes, sameByte);
731               
732                *size = totalByteLength;
733        }
734        else //the case with reserved value
735        {
736                size_t residualMidBitsLength = tdps->residualMidBits == NULL ? 0 : tdps->residualMidBits_size;
737                size_t segmentL = 0, radExpoL = 0, pwrBoundArrayL = 0;
738                if(confparams_cpr->errorBoundMode>=PW_REL)
739                {
740                        segmentL = exe_params->SZ_SIZE_TYPE;
741                        radExpoL = 1;
742                        pwrBoundArrayL = 4;
743                }
744
745                size_t totalByteLength = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrBoundArrayL + 4 + 4 + 1 + 8 
746                                + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + 4 + tdps->rtypeArray_size
747                                + tdps->typeArray_size + tdps->leadNumArray_size
748                                + tdps->exactMidBytes_size + residualMidBitsLength + tdps->pwrErrBoundBytes_size;
749
750                sameByte = (unsigned char) (sameByte | 0x08); // 00001000, the 4th bit
751                // denotes whether it is
752                // with "reserved value"
753               
754                if(confparams_cpr->errorBoundMode>=PW_REL)
755                        sameByte = (unsigned char) (sameByte | 0x10); // 00001000, the 5th bit
756
757                convertTDPStoBytes_float_reserve(tdps, bytes, dsLengthBytes, sameByte);
758               
759                *size = totalByteLength;
760        }
761}
762
763/**
764 * to free the memory used in the compression
765 * */
766void free_TightDataPointStorageF(TightDataPointStorageF *tdps)
767{
768        if(tdps->rtypeArray!=NULL)
769                free(tdps->rtypeArray);
770        if(tdps->typeArray!=NULL)
771                free(tdps->typeArray);
772        if(tdps->leadNumArray!=NULL)
773                free(tdps->leadNumArray);
774        if(tdps->exactMidBytes!=NULL)
775                free(tdps->exactMidBytes);
776        if(tdps->residualMidBits!=NULL)
777                free(tdps->residualMidBits);
778        if(tdps->pwrErrBoundBytes!=NULL)
779                free(tdps->pwrErrBoundBytes);
780        free(tdps);
781}
782
783/**
784 * to free the memory used in the decompression
785 * */
786void free_TightDataPointStorageF2(TightDataPointStorageF *tdps)
787{                       
788        free(tdps);
789}
Note: See TracBrowser for help on using the repository browser.