1 | /** |
---|
2 | * @file szd_float_ts.c |
---|
3 | * @author Sheng Di and Dingwen Tao |
---|
4 | * @date Aug, 2016 |
---|
5 | * @brief |
---|
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 "szd_float.h" |
---|
14 | #include "TightDataPointStorageF.h" |
---|
15 | #include "sz.h" |
---|
16 | #include "Huffman.h" |
---|
17 | #include "szd_float_ts.h" |
---|
18 | |
---|
19 | void decompressDataSeries_float_1D_ts(float** data, size_t dataSeriesLength, sz_multisteps* multisteps, TightDataPointStorageF* tdps) |
---|
20 | { |
---|
21 | float* lastSnapshotData = (float*)multisteps->hist_data; |
---|
22 | updateQuantizationInfo(tdps->intervals); |
---|
23 | size_t i, j, k = 0, p = 0, l = 0; // k is to track the location of residual_bit |
---|
24 | // in resiMidBits, p is to track the |
---|
25 | // byte_index of resiMidBits, l is for |
---|
26 | // leadNum |
---|
27 | unsigned char* leadNum; |
---|
28 | double interval = tdps->realPrecision*2; |
---|
29 | |
---|
30 | convertByteArray2IntArray_fast_2b(tdps->exactDataNum, tdps->leadNumArray, tdps->leadNumArray_size, &leadNum); |
---|
31 | |
---|
32 | *data = (float*)malloc(sizeof(float)*dataSeriesLength); |
---|
33 | |
---|
34 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
35 | |
---|
36 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
37 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
38 | SZ_ReleaseHuffman(huffmanTree); |
---|
39 | |
---|
40 | unsigned char preBytes[4]; |
---|
41 | unsigned char curBytes[4]; |
---|
42 | |
---|
43 | memset(preBytes, 0, 4); |
---|
44 | |
---|
45 | size_t curByteIndex = 0; |
---|
46 | int reqBytesLength, resiBitsLength, resiBits; |
---|
47 | unsigned char leadingNum; |
---|
48 | float medianValue, exactData, predValue = 0; |
---|
49 | |
---|
50 | reqBytesLength = tdps->reqLength/8; |
---|
51 | resiBitsLength = tdps->reqLength%8; |
---|
52 | medianValue = tdps->medianValue; |
---|
53 | |
---|
54 | int type_; |
---|
55 | for (i = 0; i < dataSeriesLength; i++) { |
---|
56 | type_ = type[i]; |
---|
57 | switch (type_) { |
---|
58 | case 0: |
---|
59 | // compute resiBits |
---|
60 | resiBits = 0; |
---|
61 | if (resiBitsLength != 0) { |
---|
62 | int kMod8 = k % 8; |
---|
63 | int rightMovSteps = getRightMovingSteps(kMod8, resiBitsLength); |
---|
64 | if (rightMovSteps > 0) { |
---|
65 | int code = getRightMovingCode(kMod8, resiBitsLength); |
---|
66 | resiBits = (tdps->residualMidBits[p] & code) >> rightMovSteps; |
---|
67 | } else if (rightMovSteps < 0) { |
---|
68 | int code1 = getLeftMovingCode(kMod8); |
---|
69 | int code2 = getRightMovingCode(kMod8, resiBitsLength); |
---|
70 | int leftMovSteps = -rightMovSteps; |
---|
71 | rightMovSteps = 8 - leftMovSteps; |
---|
72 | resiBits = (tdps->residualMidBits[p] & code1) << leftMovSteps; |
---|
73 | p++; |
---|
74 | resiBits = resiBits |
---|
75 | | ((tdps->residualMidBits[p] & code2) >> rightMovSteps); |
---|
76 | } else // rightMovSteps == 0 |
---|
77 | { |
---|
78 | int code = getRightMovingCode(kMod8, resiBitsLength); |
---|
79 | resiBits = (tdps->residualMidBits[p] & code); |
---|
80 | p++; |
---|
81 | } |
---|
82 | k += resiBitsLength; |
---|
83 | } |
---|
84 | |
---|
85 | // recover the exact data |
---|
86 | memset(curBytes, 0, 4); |
---|
87 | leadingNum = leadNum[l++]; |
---|
88 | memcpy(curBytes, preBytes, leadingNum); |
---|
89 | for (j = leadingNum; j < reqBytesLength; j++) |
---|
90 | curBytes[j] = tdps->exactMidBytes[curByteIndex++]; |
---|
91 | if (resiBitsLength != 0) { |
---|
92 | unsigned char resiByte = (unsigned char) (resiBits << (8 - resiBitsLength)); |
---|
93 | curBytes[reqBytesLength] = resiByte; |
---|
94 | } |
---|
95 | |
---|
96 | exactData = bytesToFloat(curBytes); |
---|
97 | (*data)[i] = exactData + medianValue; |
---|
98 | memcpy(preBytes,curBytes,4); |
---|
99 | break; |
---|
100 | default: |
---|
101 | //predValue = (*data)[i-1]; |
---|
102 | if(confparams_dec->szMode == SZ_TEMPORAL_COMPRESSION) |
---|
103 | predValue = lastSnapshotData[i]; |
---|
104 | (*data)[i] = predValue + (type_-exe_params->intvRadius)*interval; |
---|
105 | break; |
---|
106 | } |
---|
107 | //printf("%.30G\n",(*data)[i]); |
---|
108 | } |
---|
109 | |
---|
110 | memcpy(multisteps->hist_data, (*data), dataSeriesLength*sizeof(float)); |
---|
111 | |
---|
112 | free(leadNum); |
---|
113 | free(type); |
---|
114 | return; |
---|
115 | } |
---|