[2c47b73] | 1 | /** |
---|
| 2 | * @file szd_double_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_double.h" |
---|
| 14 | #include "TightDataPointStorageD.h" |
---|
| 15 | #include "sz.h" |
---|
| 16 | #include "Huffman.h" |
---|
| 17 | #include "szd_double_ts.h" |
---|
| 18 | |
---|
| 19 | void decompressDataSeries_double_1D_ts(double** data, size_t dataSeriesLength, sz_multisteps* multisteps, TightDataPointStorageD* tdps) |
---|
| 20 | { |
---|
| 21 | double* lastSnapshotData = (double*)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 | *data = (double*)malloc(sizeof(double)*dataSeriesLength); |
---|
| 32 | |
---|
| 33 | int* type = (int*)malloc(dataSeriesLength*sizeof(int)); |
---|
| 34 | |
---|
| 35 | HuffmanTree* huffmanTree = createHuffmanTree(tdps->stateNum); |
---|
| 36 | decode_withTree(huffmanTree, tdps->typeArray, dataSeriesLength, type); |
---|
| 37 | SZ_ReleaseHuffman(huffmanTree); |
---|
| 38 | |
---|
| 39 | unsigned char preBytes[8]; |
---|
| 40 | unsigned char curBytes[8]; |
---|
| 41 | |
---|
| 42 | memset(preBytes, 0, 8); |
---|
| 43 | |
---|
| 44 | size_t curByteIndex = 0; |
---|
| 45 | int reqBytesLength, resiBitsLength, resiBits; |
---|
| 46 | unsigned char leadingNum; |
---|
| 47 | double medianValue, exactData, predValue = 0; |
---|
| 48 | |
---|
| 49 | reqBytesLength = tdps->reqLength/8; |
---|
| 50 | resiBitsLength = tdps->reqLength%8; |
---|
| 51 | medianValue = tdps->medianValue; |
---|
| 52 | |
---|
| 53 | int type_; |
---|
| 54 | for (i = 0; i < dataSeriesLength; i++) { |
---|
| 55 | type_ = type[i]; |
---|
| 56 | switch (type_) { |
---|
| 57 | case 0: |
---|
| 58 | // compute resiBits |
---|
| 59 | resiBits = 0; |
---|
| 60 | if (resiBitsLength != 0) { |
---|
| 61 | int kMod8 = k % 8; |
---|
| 62 | int rightMovSteps = getRightMovingSteps(kMod8, resiBitsLength); |
---|
| 63 | if (rightMovSteps > 0) { |
---|
| 64 | int code = getRightMovingCode(kMod8, resiBitsLength); |
---|
| 65 | resiBits = (tdps->residualMidBits[p] & code) >> rightMovSteps; |
---|
| 66 | } else if (rightMovSteps < 0) { |
---|
| 67 | int code1 = getLeftMovingCode(kMod8); |
---|
| 68 | int code2 = getRightMovingCode(kMod8, resiBitsLength); |
---|
| 69 | int leftMovSteps = -rightMovSteps; |
---|
| 70 | rightMovSteps = 8 - leftMovSteps; |
---|
| 71 | resiBits = (tdps->residualMidBits[p] & code1) << leftMovSteps; |
---|
| 72 | p++; |
---|
| 73 | resiBits = resiBits |
---|
| 74 | | ((tdps->residualMidBits[p] & code2) >> rightMovSteps); |
---|
| 75 | } else // rightMovSteps == 0 |
---|
| 76 | { |
---|
| 77 | int code = getRightMovingCode(kMod8, resiBitsLength); |
---|
| 78 | resiBits = (tdps->residualMidBits[p] & code); |
---|
| 79 | p++; |
---|
| 80 | } |
---|
| 81 | k += resiBitsLength; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | // recover the exact data |
---|
| 85 | memset(curBytes, 0, 8); |
---|
| 86 | leadingNum = leadNum[l++]; |
---|
| 87 | memcpy(curBytes, preBytes, leadingNum); |
---|
| 88 | for (j = leadingNum; j < reqBytesLength; j++) |
---|
| 89 | curBytes[j] = tdps->exactMidBytes[curByteIndex++]; |
---|
| 90 | if (resiBitsLength != 0) { |
---|
| 91 | unsigned char resiByte = (unsigned char) (resiBits << (8 - resiBitsLength)); |
---|
| 92 | curBytes[reqBytesLength] = resiByte; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | exactData = bytesToDouble(curBytes); |
---|
| 96 | (*data)[i] = exactData + medianValue; |
---|
| 97 | memcpy(preBytes,curBytes,8); |
---|
| 98 | break; |
---|
| 99 | default: |
---|
| 100 | //predValue = (*data)[i-1]; |
---|
| 101 | if(confparams_dec->szMode == SZ_TEMPORAL_COMPRESSION) |
---|
| 102 | predValue = lastSnapshotData[i]; |
---|
| 103 | (*data)[i] = predValue + (type_-exe_params->intvRadius)*interval; |
---|
| 104 | break; |
---|
| 105 | } |
---|
| 106 | //printf("%.30G\n",(*data)[i]); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | memcpy(multisteps->hist_data, (*data), dataSeriesLength*sizeof(double)); |
---|
| 110 | |
---|
| 111 | free(leadNum); |
---|
| 112 | free(type); |
---|
| 113 | return; |
---|
| 114 | } |
---|