[2c47b73] | 1 | /** |
---|
| 2 | * @file sz.c |
---|
| 3 | * @author Sheng Di and Dingwen Tao |
---|
| 4 | * @date Aug, 2016 |
---|
| 5 | * @brief SZ_Init, Compression and Decompression functions |
---|
| 6 | * (C) 2016 by Mathematics and Computer Science (MCS), Argonne National Laboratory. |
---|
| 7 | * See COPYRIGHT in top-level directory. |
---|
| 8 | */ |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | #include <stdio.h> |
---|
| 12 | #include <stdlib.h> |
---|
| 13 | #include <string.h> |
---|
| 14 | #include <unistd.h> |
---|
| 15 | #include "sz.h" |
---|
| 16 | #include "CompressElement.h" |
---|
| 17 | #include "DynamicByteArray.h" |
---|
| 18 | #include "DynamicIntArray.h" |
---|
| 19 | #include "TightDataPointStorageD.h" |
---|
| 20 | #include "TightDataPointStorageF.h" |
---|
| 21 | #include "zlib.h" |
---|
| 22 | #include "rw.h" |
---|
| 23 | #include "Huffman.h" |
---|
| 24 | #include "conf.h" |
---|
[9ee2ce3] | 25 | #include "utility.h" |
---|
[2c47b73] | 26 | //#include "CurveFillingCompressStorage.h" |
---|
| 27 | |
---|
| 28 | int versionNumber[4] = {SZ_VER_MAJOR,SZ_VER_MINOR,SZ_VER_BUILD,SZ_VER_REVISION}; |
---|
| 29 | //int SZ_SIZE_TYPE = 8; |
---|
| 30 | |
---|
| 31 | int dataEndianType = LITTLE_ENDIAN_DATA; //*endian type of the data read from disk |
---|
| 32 | int sysEndianType; //*sysEndianType is actually set automatically. |
---|
| 33 | |
---|
| 34 | //the confparams should be separate between compression and decopmression, in case of mutual-affection when calling compression/decompression alternatively |
---|
| 35 | sz_params *confparams_cpr = NULL; //used for compression |
---|
| 36 | sz_params *confparams_dec = NULL; //used for decompression |
---|
| 37 | |
---|
| 38 | sz_exedata *exe_params = NULL; |
---|
| 39 | |
---|
[9ee2ce3] | 40 | int sz_with_regression = SZ_WITH_LINEAR_REGRESSION; //SZ_NO_REGRESSION |
---|
| 41 | |
---|
[2c47b73] | 42 | /*following global variables are desgined for time-series based compression*/ |
---|
| 43 | /*sz_varset is not used in the single-snapshot data compression*/ |
---|
| 44 | SZ_VarSet* sz_varset = NULL; |
---|
| 45 | sz_multisteps *multisteps = NULL; |
---|
| 46 | sz_tsc_metadata *sz_tsc = NULL; |
---|
| 47 | |
---|
| 48 | //only for Pastri compressor |
---|
| 49 | #ifdef PASTRI |
---|
| 50 | pastri_params pastri_par; |
---|
| 51 | #endif |
---|
| 52 | |
---|
| 53 | HuffmanTree* SZ_Reset() |
---|
| 54 | { |
---|
| 55 | return createDefaultHuffmanTree(); |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | int SZ_Init(const char *configFilePath) |
---|
| 59 | { |
---|
| 60 | int loadFileResult = SZ_LoadConf(configFilePath); |
---|
| 61 | if(loadFileResult==SZ_NSCS) |
---|
| 62 | return SZ_NSCS; |
---|
| 63 | |
---|
| 64 | exe_params->SZ_SIZE_TYPE = sizeof(size_t); |
---|
| 65 | |
---|
| 66 | if(confparams_cpr->szMode == SZ_TEMPORAL_COMPRESSION) |
---|
| 67 | { |
---|
| 68 | initSZ_TSC(); |
---|
| 69 | } |
---|
| 70 | return SZ_SCES; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | int SZ_Init_Params(sz_params *params) |
---|
| 74 | { |
---|
[9ee2ce3] | 75 | SZ_Init(NULL); |
---|
[2c47b73] | 76 | |
---|
[9ee2ce3] | 77 | if(params->losslessCompressor!=GZIP_COMPRESSOR && params->losslessCompressor!=ZSTD_COMPRESSOR) |
---|
| 78 | params->losslessCompressor = ZSTD_COMPRESSOR; |
---|
[2c47b73] | 79 | |
---|
[9ee2ce3] | 80 | if(params->max_quant_intervals > 0) |
---|
[2c47b73] | 81 | params->maxRangeRadius = params->max_quant_intervals/2; |
---|
[9ee2ce3] | 82 | |
---|
| 83 | memcpy(confparams_cpr, params, sizeof(sz_params)); |
---|
[2c47b73] | 84 | |
---|
| 85 | if(params->quantization_intervals%2!=0) |
---|
| 86 | { |
---|
| 87 | printf("Error: quantization_intervals must be an even number!\n"); |
---|
| 88 | return SZ_NSCS; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | return SZ_SCES; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | int computeDimension(size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 95 | { |
---|
| 96 | int dimension; |
---|
| 97 | if(r1==0) |
---|
| 98 | { |
---|
| 99 | dimension = 0; |
---|
| 100 | } |
---|
| 101 | else if(r2==0) |
---|
| 102 | { |
---|
| 103 | dimension = 1; |
---|
| 104 | } |
---|
| 105 | else if(r3==0) |
---|
| 106 | { |
---|
| 107 | dimension = 2; |
---|
| 108 | } |
---|
| 109 | else if(r4==0) |
---|
| 110 | { |
---|
| 111 | dimension = 3; |
---|
| 112 | } |
---|
| 113 | else if(r5==0) |
---|
| 114 | { |
---|
| 115 | dimension = 4; |
---|
| 116 | } |
---|
| 117 | else |
---|
| 118 | { |
---|
| 119 | dimension = 5; |
---|
| 120 | } |
---|
| 121 | return dimension; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | size_t computeDataLength(size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 125 | { |
---|
| 126 | size_t dataLength; |
---|
| 127 | if(r1==0) |
---|
| 128 | { |
---|
| 129 | dataLength = 0; |
---|
| 130 | } |
---|
| 131 | else if(r2==0) |
---|
| 132 | { |
---|
| 133 | dataLength = r1; |
---|
| 134 | } |
---|
| 135 | else if(r3==0) |
---|
| 136 | { |
---|
| 137 | dataLength = r1*r2; |
---|
| 138 | } |
---|
| 139 | else if(r4==0) |
---|
| 140 | { |
---|
| 141 | dataLength = r1*r2*r3; |
---|
| 142 | } |
---|
| 143 | else if(r5==0) |
---|
| 144 | { |
---|
| 145 | dataLength = r1*r2*r3*r4; |
---|
| 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
| 149 | dataLength = r1*r2*r3*r4*r5; |
---|
| 150 | } |
---|
| 151 | return dataLength; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | /*-------------------------------------------------------------------------*/ |
---|
| 155 | /** |
---|
| 156 | @brief Perform Compression |
---|
| 157 | @param data data to be compressed |
---|
| 158 | @param outSize the size (in bytes) after compression |
---|
| 159 | @param r5,r4,r3,r2,r1 the sizes of each dimension (supporting only 5 dimensions at most in this version. |
---|
| 160 | @return compressed data (in binary stream) or NULL(0) if any errors |
---|
| 161 | |
---|
| 162 | **/ |
---|
| 163 | /*-------------------------------------------------------------------------*/ |
---|
| 164 | unsigned char* SZ_compress_args(int dataType, void *data, size_t *outSize, int errBoundMode, double absErrBound, |
---|
| 165 | double relBoundRatio, double pwrBoundRatio, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 166 | { |
---|
| 167 | //TODO |
---|
| 168 | confparams_cpr->dataType = dataType; |
---|
| 169 | if(dataType==SZ_FLOAT) |
---|
| 170 | { |
---|
| 171 | unsigned char *newByteData = NULL; |
---|
| 172 | |
---|
| 173 | SZ_compress_args_float(&newByteData, (float *)data, r5, r4, r3, r2, r1, |
---|
| 174 | outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio); |
---|
| 175 | |
---|
| 176 | return newByteData; |
---|
| 177 | } |
---|
| 178 | else if(dataType==SZ_DOUBLE) |
---|
| 179 | { |
---|
| 180 | unsigned char *newByteData; |
---|
| 181 | SZ_compress_args_double(&newByteData, (double *)data, r5, r4, r3, r2, r1, |
---|
| 182 | outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio); |
---|
| 183 | |
---|
| 184 | return newByteData; |
---|
| 185 | } |
---|
| 186 | else if(dataType==SZ_INT64) |
---|
| 187 | { |
---|
| 188 | unsigned char *newByteData; |
---|
| 189 | SZ_compress_args_int64(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 190 | return newByteData; |
---|
| 191 | } |
---|
| 192 | else if(dataType==SZ_INT32) //int type |
---|
| 193 | { |
---|
| 194 | unsigned char *newByteData; |
---|
| 195 | SZ_compress_args_int32(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 196 | return newByteData; |
---|
| 197 | } |
---|
| 198 | else if(dataType==SZ_INT16) |
---|
| 199 | { |
---|
| 200 | unsigned char *newByteData; |
---|
| 201 | SZ_compress_args_int16(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 202 | return newByteData; |
---|
| 203 | } |
---|
| 204 | else if(dataType==SZ_INT8) |
---|
| 205 | { |
---|
| 206 | unsigned char *newByteData; |
---|
| 207 | SZ_compress_args_int8(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 208 | return newByteData; |
---|
| 209 | } |
---|
| 210 | else if(dataType==SZ_UINT64) |
---|
| 211 | { |
---|
| 212 | unsigned char *newByteData; |
---|
| 213 | SZ_compress_args_uint64(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 214 | return newByteData; |
---|
| 215 | } |
---|
| 216 | else if(dataType==SZ_UINT32) //int type |
---|
| 217 | { |
---|
| 218 | unsigned char *newByteData; |
---|
| 219 | SZ_compress_args_uint32(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 220 | return newByteData; |
---|
| 221 | } |
---|
| 222 | else if(dataType==SZ_UINT16) |
---|
| 223 | { |
---|
| 224 | unsigned char *newByteData; |
---|
| 225 | SZ_compress_args_uint16(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 226 | return newByteData; |
---|
| 227 | } |
---|
| 228 | else if(dataType==SZ_UINT8) |
---|
| 229 | { |
---|
| 230 | unsigned char *newByteData; |
---|
| 231 | SZ_compress_args_uint8(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 232 | return newByteData; |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | printf("Error: dataType can only be SZ_FLOAT, SZ_DOUBLE, SZ_INT8/16/32/64 or SZ_UINT8/16/32/64.\n"); |
---|
| 237 | return NULL; |
---|
| 238 | } |
---|
| 239 | } |
---|
| 240 | |
---|
| 241 | int SZ_compress_args2(int dataType, void *data, unsigned char* compressed_bytes, size_t *outSize, |
---|
| 242 | int errBoundMode, double absErrBound, double relBoundRatio, double pwrBoundRatio, |
---|
| 243 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 244 | { |
---|
| 245 | unsigned char* bytes = SZ_compress_args(dataType, data, outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio, r5, r4, r3, r2, r1); |
---|
| 246 | memcpy(compressed_bytes, bytes, *outSize); |
---|
| 247 | free(bytes); |
---|
| 248 | return SZ_SCES; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | int SZ_compress_args3(int dataType, void *data, unsigned char* compressed_bytes, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 252 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, |
---|
| 253 | size_t s5, size_t s4, size_t s3, size_t s2, size_t s1, |
---|
| 254 | size_t e5, size_t e4, size_t e3, size_t e2, size_t e1) |
---|
| 255 | { |
---|
| 256 | confparams_cpr->dataType = dataType; |
---|
| 257 | if(dataType==SZ_FLOAT) |
---|
| 258 | { |
---|
| 259 | SZ_compress_args_float_subblock(compressed_bytes, (float *)data, |
---|
| 260 | r5, r4, r3, r2, r1, |
---|
| 261 | s5, s4, s3, s2, s1, |
---|
| 262 | e5, e4, e3, e2, e1, |
---|
| 263 | outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 264 | |
---|
| 265 | return SZ_SCES; |
---|
| 266 | } |
---|
| 267 | else if(dataType==SZ_DOUBLE) |
---|
| 268 | { |
---|
| 269 | SZ_compress_args_double_subblock(compressed_bytes, (double *)data, |
---|
| 270 | r5, r4, r3, r2, r1, |
---|
| 271 | s5, s4, s3, s2, s1, |
---|
| 272 | e5, e4, e3, e2, e1, |
---|
| 273 | outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 274 | |
---|
| 275 | return SZ_SCES; |
---|
| 276 | } |
---|
| 277 | else |
---|
| 278 | { |
---|
| 279 | printf("Error (in SZ_compress_args3): dataType can only be SZ_FLOAT or SZ_DOUBLE.\n"); |
---|
| 280 | return SZ_NSCS; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | unsigned char *SZ_compress(int dataType, void *data, size_t *outSize, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 285 | { |
---|
| 286 | unsigned char *newByteData = SZ_compress_args(dataType, data, outSize, confparams_cpr->errorBoundMode, confparams_cpr->absErrBound, confparams_cpr->relBoundRatio, |
---|
| 287 | confparams_cpr->pw_relBoundRatio, r5, r4, r3, r2, r1); |
---|
| 288 | return newByteData; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | ////////////////// |
---|
| 292 | /*-------------------------------------------------------------------------*/ |
---|
| 293 | /** |
---|
| 294 | @brief Perform Compression |
---|
| 295 | @param data data to be compressed |
---|
| 296 | @param reservedValue the reserved value |
---|
| 297 | @param outSize the size (in bytes) after compression |
---|
| 298 | @param r5,r4,r3,r2,r1 the sizes of each dimension (supporting only 5 dimensions at most in this version. |
---|
| 299 | @return compressed data (in binary stream) |
---|
| 300 | |
---|
| 301 | **/ |
---|
| 302 | /*-------------------------------------------------------------------------*/ |
---|
| 303 | unsigned char *SZ_compress_rev_args(int dataType, void *data, void *reservedValue, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 304 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 305 | { |
---|
| 306 | unsigned char *newByteData; |
---|
| 307 | //TODO |
---|
| 308 | printf("SZ compression with reserved data is TO BE DONE LATER.\n"); |
---|
| 309 | exit(0); |
---|
| 310 | |
---|
| 311 | return newByteData; |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | int SZ_compress_rev_args2(int dataType, void *data, void *reservedValue, unsigned char* compressed_bytes, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 315 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 316 | { |
---|
| 317 | confparams_cpr->dataType = dataType; |
---|
| 318 | unsigned char* bytes = SZ_compress_rev_args(dataType, data, reservedValue, outSize, errBoundMode, absErrBound, relBoundRatio, r5, r4, r3, r2, r1); |
---|
| 319 | memcpy(compressed_bytes, bytes, *outSize); |
---|
| 320 | free(bytes); //free(bytes) is removed , because of dump error at MIRA system (PPC architecture), fixed? |
---|
| 321 | return 0; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | unsigned char *SZ_compress_rev(int dataType, void *data, void *reservedValue, size_t *outSize, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 325 | { |
---|
| 326 | unsigned char *newByteData; |
---|
| 327 | //TODO |
---|
| 328 | printf("SZ compression with reserved data is TO BE DONE LATER.\n"); |
---|
| 329 | exit(0); |
---|
| 330 | |
---|
| 331 | return newByteData; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | void *SZ_decompress(int dataType, unsigned char *bytes, size_t byteLength, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 335 | { |
---|
| 336 | if(confparams_dec==NULL) |
---|
| 337 | confparams_dec = (sz_params*)malloc(sizeof(sz_params)); |
---|
| 338 | memset(confparams_dec, 0, sizeof(sz_params)); |
---|
| 339 | if(exe_params==NULL) |
---|
| 340 | exe_params = (sz_exedata*)malloc(sizeof(sz_exedata)); |
---|
| 341 | memset(exe_params, 0, sizeof(sz_exedata)); |
---|
| 342 | |
---|
| 343 | int x = 1; |
---|
| 344 | char *y = (char*)&x; |
---|
| 345 | if(*y==1) |
---|
| 346 | sysEndianType = LITTLE_ENDIAN_SYSTEM; |
---|
| 347 | else //=0 |
---|
| 348 | sysEndianType = BIG_ENDIAN_SYSTEM; |
---|
| 349 | |
---|
| 350 | if(dataType == SZ_FLOAT) |
---|
| 351 | { |
---|
| 352 | float *newFloatData; |
---|
| 353 | SZ_decompress_args_float(&newFloatData, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 354 | return newFloatData; |
---|
| 355 | } |
---|
| 356 | else if(dataType == SZ_DOUBLE) |
---|
| 357 | { |
---|
| 358 | double *newDoubleData; |
---|
| 359 | SZ_decompress_args_double(&newDoubleData, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 360 | return newDoubleData; |
---|
| 361 | } |
---|
| 362 | else if(dataType == SZ_INT8) |
---|
| 363 | { |
---|
| 364 | int8_t *newInt8Data; |
---|
| 365 | SZ_decompress_args_int8(&newInt8Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 366 | return newInt8Data; |
---|
| 367 | } |
---|
| 368 | else if(dataType == SZ_INT16) |
---|
| 369 | { |
---|
| 370 | int16_t *newInt16Data; |
---|
| 371 | SZ_decompress_args_int16(&newInt16Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 372 | return newInt16Data; |
---|
| 373 | } |
---|
| 374 | else if(dataType == SZ_INT32) |
---|
| 375 | { |
---|
| 376 | int32_t *newInt32Data; |
---|
| 377 | SZ_decompress_args_int32(&newInt32Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 378 | return newInt32Data; |
---|
| 379 | } |
---|
| 380 | else if(dataType == SZ_INT64) |
---|
| 381 | { |
---|
| 382 | int64_t *newInt64Data; |
---|
| 383 | SZ_decompress_args_int64(&newInt64Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 384 | return newInt64Data; |
---|
| 385 | } |
---|
| 386 | else if(dataType == SZ_UINT8) |
---|
| 387 | { |
---|
| 388 | uint8_t *newUInt8Data; |
---|
| 389 | SZ_decompress_args_uint8(&newUInt8Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 390 | return newUInt8Data; |
---|
| 391 | } |
---|
| 392 | else if(dataType == SZ_UINT16) |
---|
| 393 | { |
---|
| 394 | uint16_t *newUInt16Data; |
---|
| 395 | SZ_decompress_args_uint16(&newUInt16Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 396 | return newUInt16Data; |
---|
| 397 | } |
---|
| 398 | else if(dataType == SZ_UINT32) |
---|
| 399 | { |
---|
| 400 | uint32_t *newUInt32Data; |
---|
| 401 | SZ_decompress_args_uint32(&newUInt32Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 402 | return newUInt32Data; |
---|
| 403 | } |
---|
| 404 | else if(dataType == SZ_UINT64) |
---|
| 405 | { |
---|
| 406 | uint64_t *newUInt64Data; |
---|
| 407 | SZ_decompress_args_uint64(&newUInt64Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 408 | return newUInt64Data; |
---|
| 409 | } |
---|
| 410 | else |
---|
| 411 | { |
---|
| 412 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 413 | return NULL; |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | /** |
---|
| 418 | * |
---|
| 419 | * |
---|
| 420 | * return number of elements or -1 if any errors |
---|
| 421 | * */ |
---|
| 422 | size_t SZ_decompress_args(int dataType, unsigned char *bytes, size_t byteLength, void* decompressed_array, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 423 | { |
---|
| 424 | //size_t i; |
---|
| 425 | size_t nbEle = computeDataLength(r5,r4,r3,r2,r1); |
---|
| 426 | |
---|
| 427 | if(dataType == SZ_FLOAT) |
---|
| 428 | { |
---|
| 429 | float* data = (float *)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 430 | float* data_array = (float *)decompressed_array; |
---|
| 431 | memcpy(data_array, data, nbEle*sizeof(float)); |
---|
| 432 | //for(i=0;i<nbEle;i++) |
---|
| 433 | // data_array[i] = data[i]; |
---|
| 434 | free(data); //this free operation seems to not work with BlueG/Q system. |
---|
| 435 | } |
---|
| 436 | else if (dataType == SZ_DOUBLE) |
---|
| 437 | { |
---|
| 438 | double* data = (double *)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 439 | double* data_array = (double *)decompressed_array; |
---|
| 440 | memcpy(data_array, data, nbEle*sizeof(double)); |
---|
| 441 | //for(i=0;i<nbEle;i++) |
---|
| 442 | // data_array[i] = data[i]; |
---|
| 443 | free(data); //this free operation seems to not work with BlueG/Q system. |
---|
| 444 | } |
---|
| 445 | else if(dataType == SZ_INT8) |
---|
| 446 | { |
---|
| 447 | int8_t* data = (int8_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 448 | int8_t* data_array = (int8_t *)decompressed_array; |
---|
| 449 | memcpy(data_array, data, nbEle*sizeof(int8_t)); |
---|
| 450 | free(data); |
---|
| 451 | } |
---|
| 452 | else if(dataType == SZ_INT16) |
---|
| 453 | { |
---|
| 454 | int16_t* data = (int16_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 455 | int16_t* data_array = (int16_t *)decompressed_array; |
---|
| 456 | memcpy(data_array, data, nbEle*sizeof(int16_t)); |
---|
| 457 | free(data); |
---|
| 458 | } |
---|
| 459 | else if(dataType == SZ_INT32) |
---|
| 460 | { |
---|
| 461 | int32_t* data = (int32_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 462 | int32_t* data_array = (int32_t *)decompressed_array; |
---|
| 463 | memcpy(data_array, data, nbEle*sizeof(int32_t)); |
---|
| 464 | free(data); |
---|
| 465 | } |
---|
| 466 | else if(dataType == SZ_INT64) |
---|
| 467 | { |
---|
| 468 | int64_t* data = (int64_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 469 | int64_t* data_array = (int64_t *)decompressed_array; |
---|
| 470 | memcpy(data_array, data, nbEle*sizeof(int64_t)); |
---|
| 471 | free(data); |
---|
| 472 | } |
---|
| 473 | else if(dataType == SZ_UINT8) |
---|
| 474 | { |
---|
| 475 | uint8_t* data = (uint8_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 476 | uint8_t* data_array = (uint8_t *)decompressed_array; |
---|
| 477 | memcpy(data_array, data, nbEle*sizeof(uint8_t)); |
---|
| 478 | free(data); |
---|
| 479 | } |
---|
| 480 | else if(dataType == SZ_UINT16) |
---|
| 481 | { |
---|
| 482 | uint16_t* data = (uint16_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 483 | uint16_t* data_array = (uint16_t *)decompressed_array; |
---|
| 484 | memcpy(data_array, data, nbEle*sizeof(uint16_t)); |
---|
| 485 | free(data); |
---|
| 486 | } |
---|
| 487 | else if(dataType == SZ_UINT32) |
---|
| 488 | { |
---|
| 489 | uint32_t* data = (uint32_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 490 | uint32_t* data_array = (uint32_t *)decompressed_array; |
---|
| 491 | memcpy(data_array, data, nbEle*sizeof(uint32_t)); |
---|
| 492 | free(data); |
---|
| 493 | } |
---|
| 494 | else if(dataType == SZ_UINT64) |
---|
| 495 | { |
---|
| 496 | uint64_t* data = (uint64_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 497 | uint64_t* data_array = (uint64_t *)decompressed_array; |
---|
| 498 | memcpy(data_array, data, nbEle*sizeof(uint64_t)); |
---|
| 499 | free(data); |
---|
| 500 | } |
---|
| 501 | else |
---|
| 502 | { |
---|
| 503 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 504 | return SZ_NSCS; //indicating error |
---|
| 505 | } |
---|
| 506 | |
---|
| 507 | return nbEle; |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | |
---|
| 511 | sz_metadata* SZ_getMetadata(unsigned char* bytes) |
---|
| 512 | { |
---|
| 513 | int index = 0, i, isConstant, isLossless; |
---|
| 514 | size_t dataSeriesLength = 0; |
---|
| 515 | int versions[3] = {0,0,0}; |
---|
| 516 | for (i = 0; i < 3; i++) |
---|
| 517 | versions[i] = bytes[index++]; //3 |
---|
| 518 | unsigned char sameRByte = bytes[index++]; //1 |
---|
| 519 | isConstant = sameRByte & 0x01; |
---|
| 520 | //confparams_dec->szMode = (sameRByte & 0x06)>>1; |
---|
| 521 | isLossless = (sameRByte & 0x10)>>4; |
---|
[9ee2ce3] | 522 | |
---|
| 523 | int isRandomAccess = (sameRByte >> 7) & 0x01; |
---|
| 524 | |
---|
| 525 | if(exe_params==NULL) |
---|
| 526 | { |
---|
| 527 | exe_params = (sz_exedata *)malloc(sizeof(struct sz_exedata)); |
---|
| 528 | memset(exe_params, 0, sizeof(struct sz_exedata)); |
---|
| 529 | } |
---|
[2c47b73] | 530 | exe_params->SZ_SIZE_TYPE = ((sameRByte & 0x40)>>6)==1?8:4; |
---|
| 531 | |
---|
| 532 | sz_params* params = convertBytesToSZParams(&(bytes[index])); |
---|
| 533 | if(confparams_dec!=NULL) |
---|
| 534 | free(confparams_dec); |
---|
| 535 | confparams_dec = params; |
---|
| 536 | index += MetaDataByteLength; |
---|
| 537 | |
---|
| 538 | if(params->dataType!=SZ_FLOAT && params->dataType!= SZ_DOUBLE) //if this type is an Int type |
---|
| 539 | index++; //jump to the dataLength info byte address |
---|
| 540 | dataSeriesLength = bytesToSize(&(bytes[index]));// 4 or 8 |
---|
| 541 | index += exe_params->SZ_SIZE_TYPE; |
---|
[9ee2ce3] | 542 | //index += 4; //max_quant_intervals |
---|
| 543 | |
---|
[2c47b73] | 544 | sz_metadata* metadata = (sz_metadata*)malloc(sizeof(struct sz_metadata)); |
---|
| 545 | |
---|
| 546 | metadata->versionNumber[0] = versions[0]; |
---|
| 547 | metadata->versionNumber[1] = versions[1]; |
---|
| 548 | metadata->versionNumber[2] = versions[2]; |
---|
| 549 | metadata->isConstant = isConstant; |
---|
| 550 | metadata->isLossless = isLossless; |
---|
| 551 | metadata->sizeType = exe_params->SZ_SIZE_TYPE; |
---|
| 552 | metadata->dataSeriesLength = dataSeriesLength; |
---|
| 553 | |
---|
| 554 | metadata->conf_params = confparams_dec; |
---|
| 555 | |
---|
| 556 | int defactoNBBins = 0; //real # bins |
---|
| 557 | if(isConstant==0 && isLossless==0) |
---|
| 558 | { |
---|
[9ee2ce3] | 559 | if(isRandomAccess==1) |
---|
[2c47b73] | 560 | { |
---|
[9ee2ce3] | 561 | unsigned char* raBytes = &(bytes[index]); |
---|
| 562 | defactoNBBins = bytesToInt_bigEndian(raBytes + sizeof(int) + sizeof(double)); |
---|
[2c47b73] | 563 | } |
---|
[9ee2ce3] | 564 | else |
---|
| 565 | { |
---|
| 566 | int radExpoL = 0, segmentL = 0, pwrErrBoundBytesL = 0; |
---|
| 567 | if(metadata->conf_params->errorBoundMode >= PW_REL) |
---|
| 568 | { |
---|
| 569 | radExpoL = 1; |
---|
| 570 | segmentL = exe_params->SZ_SIZE_TYPE; |
---|
| 571 | pwrErrBoundBytesL = 4; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | int offset_typearray = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrErrBoundBytesL + 4 + (4 + params->dataType*4) + 1 + 8 |
---|
| 575 | + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + 4; |
---|
| 576 | defactoNBBins = bytesToInt_bigEndian(bytes+offset_typearray); |
---|
| 577 | } |
---|
| 578 | |
---|
| 579 | } |
---|
[2c47b73] | 580 | |
---|
| 581 | metadata->defactoNBBins = defactoNBBins; |
---|
| 582 | return metadata; |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | void SZ_printMetadata(sz_metadata* metadata) |
---|
| 586 | { |
---|
| 587 | printf("=================SZ Compression Meta Data=================\n"); |
---|
| 588 | printf("Version: \t %d.%d.%d\n", metadata->versionNumber[0], metadata->versionNumber[1], metadata->versionNumber[2]); |
---|
| 589 | printf("Constant data?: \t %s\n", metadata->isConstant==1?"YES":"NO"); |
---|
| 590 | printf("Lossless?: \t %s\n", metadata->isLossless==1?"YES":"NO"); |
---|
| 591 | printf("Size type (size of # elements): \t %d bytes\n", metadata->sizeType); |
---|
| 592 | printf("Num of elements: \t %zu\n", metadata->dataSeriesLength); |
---|
| 593 | |
---|
| 594 | sz_params* params = metadata->conf_params; |
---|
| 595 | |
---|
| 596 | switch(params->dataType) |
---|
| 597 | { |
---|
| 598 | case SZ_FLOAT: |
---|
| 599 | printf("Data type: \t FLOAT\n"); |
---|
| 600 | break; |
---|
| 601 | case SZ_DOUBLE: |
---|
| 602 | printf("Data type: \t DOUBLE\n"); |
---|
| 603 | break; |
---|
| 604 | case SZ_INT8: |
---|
| 605 | printf("Data type: \t INT8\n"); |
---|
| 606 | break; |
---|
| 607 | case SZ_INT16: |
---|
| 608 | printf("Data type: \t INT16\n"); |
---|
| 609 | break; |
---|
| 610 | case SZ_INT32: |
---|
| 611 | printf("Data type: \t INT32\n"); |
---|
| 612 | break; |
---|
| 613 | case SZ_INT64: |
---|
| 614 | printf("Data type: \t INT64\n"); |
---|
| 615 | break; |
---|
| 616 | case SZ_UINT8: |
---|
| 617 | printf("Data type: \t UINT8\n"); |
---|
| 618 | break; |
---|
| 619 | case SZ_UINT16: |
---|
| 620 | printf("Data type: \t UINT16\n"); |
---|
| 621 | break; |
---|
| 622 | case SZ_UINT32: |
---|
| 623 | printf("Data type: \t UINT32\n"); |
---|
| 624 | break; |
---|
| 625 | case SZ_UINT64: |
---|
| 626 | printf("Data type: \t UINT64\n"); |
---|
| 627 | break; |
---|
| 628 | } |
---|
| 629 | |
---|
| 630 | if(exe_params->optQuantMode==1) |
---|
| 631 | { |
---|
| 632 | printf("quantization_intervals: \t 0\n"); |
---|
| 633 | printf("max_quant_intervals: \t %d\n", params->max_quant_intervals); |
---|
| 634 | printf("actual used # intervals: \t %d\n", metadata->defactoNBBins); |
---|
| 635 | } |
---|
| 636 | else |
---|
| 637 | { |
---|
| 638 | printf("quantization_intervals: \t %d\n", params->quantization_intervals); |
---|
| 639 | printf("max_quant_intervals: \t - %d\n", params->max_quant_intervals); |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | printf("dataEndianType (prior raw data):\t %s\n", dataEndianType==BIG_ENDIAN_DATA?"BIG_ENDIAN":"LITTLE_ENDIAN"); |
---|
| 643 | printf("sysEndianType (at compression): \t %s\n", sysEndianType==1?"BIG_ENDIAN":"LITTLE_ENDIAN"); |
---|
| 644 | printf("sampleDistance: \t %d\n", params->sampleDistance); |
---|
| 645 | printf("predThreshold: \t %f\n", params->predThreshold); |
---|
| 646 | switch(params->szMode) |
---|
| 647 | { |
---|
| 648 | case SZ_BEST_SPEED: |
---|
| 649 | printf("szMode: \t SZ_BEST_SPEED (without Gzip)\n"); |
---|
| 650 | break; |
---|
| 651 | case SZ_BEST_COMPRESSION: |
---|
| 652 | printf("szMode: \t SZ_BEST_COMPRESSION (with Gzip)\n"); |
---|
| 653 | break; |
---|
| 654 | } |
---|
| 655 | switch(params->gzipMode) |
---|
| 656 | { |
---|
| 657 | case Z_BEST_SPEED: |
---|
| 658 | printf("gzipMode: \t Z_BEST_SPEED\n"); |
---|
| 659 | break; |
---|
| 660 | case Z_DEFAULT_COMPRESSION: |
---|
| 661 | printf("gzipMode: \t Z_BEST_SPEED\n"); |
---|
| 662 | break; |
---|
| 663 | case Z_BEST_COMPRESSION: |
---|
| 664 | printf("gzipMode: \t Z_BEST_COMPRESSION\n"); |
---|
| 665 | break; |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | switch(params->errorBoundMode) |
---|
| 669 | { |
---|
| 670 | case ABS: |
---|
| 671 | printf("errBoundMode: \t ABS\n"); |
---|
| 672 | printf("absErrBound: \t %f\n", params->absErrBound); |
---|
| 673 | break; |
---|
| 674 | case REL: |
---|
| 675 | printf("errBoundMode: \t REL (based on value_range extent)\n"); |
---|
| 676 | printf("relBoundRatio: \t %f\n", params->relBoundRatio); |
---|
| 677 | break; |
---|
| 678 | case ABS_AND_REL: |
---|
| 679 | printf("errBoundMode: \t ABS_AND_REL\n"); |
---|
| 680 | printf("absErrBound: \t %f\n", params->absErrBound); |
---|
| 681 | printf("relBoundRatio: \t %f\n", params->relBoundRatio); |
---|
| 682 | break; |
---|
| 683 | case ABS_OR_REL: |
---|
| 684 | printf("errBoundMode: \t ABS_OR_REL\n"); |
---|
| 685 | printf("absErrBound: \t %f\n", params->absErrBound); |
---|
| 686 | printf("relBoundRatio: \t %f\n", params->relBoundRatio); |
---|
| 687 | break; |
---|
| 688 | case PSNR: |
---|
| 689 | printf("errBoundMode: \t PSNR\n"); |
---|
| 690 | printf("psnr: \t %f\n", params->psnr); |
---|
| 691 | break; |
---|
| 692 | case PW_REL: |
---|
| 693 | printf("errBoundMode: \t PW_REL\n"); |
---|
| 694 | break; |
---|
| 695 | case ABS_AND_PW_REL: |
---|
| 696 | printf("errBoundMode: \t ABS_AND_PW_REL\n"); |
---|
| 697 | printf("absErrBound: \t %f\n", params->absErrBound); |
---|
| 698 | break; |
---|
| 699 | case ABS_OR_PW_REL: |
---|
| 700 | printf("errBoundMode: \t ABS_OR_PW_REL\n"); |
---|
| 701 | printf("absErrBound: \t %f\n", params->absErrBound); |
---|
| 702 | break; |
---|
| 703 | case REL_AND_PW_REL: |
---|
| 704 | printf("errBoundMode: \t REL_AND_PW_REL\n"); |
---|
| 705 | printf("range_relBoundRatio: \t %f\n", params->relBoundRatio); |
---|
| 706 | break; |
---|
| 707 | case REL_OR_PW_REL: |
---|
| 708 | printf("errBoundMode: \t REL_OR_PW_REL\n"); |
---|
| 709 | printf("range_relBoundRatio: \t %f\n", params->relBoundRatio); |
---|
| 710 | break; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | if(params->errorBoundMode>=PW_REL && params->errorBoundMode<=REL_OR_PW_REL) |
---|
| 714 | { |
---|
| 715 | printf("pw_relBoundRatio: \t %f\n", params->pw_relBoundRatio); |
---|
| 716 | printf("segment_size: \t %d\n", params->segment_size); |
---|
| 717 | switch(params->pwr_type) |
---|
| 718 | { |
---|
| 719 | case SZ_PWR_MIN_TYPE: |
---|
| 720 | printf("pwrType: \t SZ_PWR_MIN_TYPE\n"); |
---|
| 721 | break; |
---|
| 722 | case SZ_PWR_AVG_TYPE: |
---|
| 723 | printf("pwrType: \t SZ_PWR_AVG_TYPE\n"); |
---|
| 724 | break; |
---|
| 725 | case SZ_PWR_MAX_TYPE: |
---|
| 726 | printf("pwrType: \t SZ_PWR_MAX_TYPE\n"); |
---|
| 727 | break; |
---|
| 728 | } |
---|
| 729 | } |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | /*-----------------------------------batch data compression--------------------------------------*/ |
---|
| 733 | |
---|
| 734 | void filloutDimArray(size_t* dim, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 735 | { |
---|
| 736 | if(r2==0) |
---|
| 737 | dim[0] = r1; |
---|
| 738 | else if(r3==0) |
---|
| 739 | { |
---|
| 740 | dim[0] = r2; |
---|
| 741 | dim[1] = r1; |
---|
| 742 | } |
---|
| 743 | else if(r4==0) |
---|
| 744 | { |
---|
| 745 | dim[0] = r3; |
---|
| 746 | dim[1] = r2; |
---|
| 747 | dim[2] = r1; |
---|
| 748 | } |
---|
| 749 | else if(r5==0) |
---|
| 750 | { |
---|
| 751 | dim[0] = r4; |
---|
| 752 | dim[1] = r3; |
---|
| 753 | dim[2] = r2; |
---|
| 754 | dim[3] = r1; |
---|
| 755 | } |
---|
| 756 | else |
---|
| 757 | { |
---|
| 758 | dim[0] = r5; |
---|
| 759 | dim[1] = r4; |
---|
| 760 | dim[2] = r3; |
---|
| 761 | dim[3] = r2; |
---|
| 762 | dim[4] = r1; |
---|
| 763 | } |
---|
| 764 | } |
---|
| 765 | |
---|
| 766 | size_t compute_total_batch_size() |
---|
| 767 | { |
---|
| 768 | size_t eleNum = 0, totalSize = 0; |
---|
| 769 | SZ_Variable* p = sz_varset->header; |
---|
| 770 | while(p->next!=NULL) |
---|
| 771 | { |
---|
| 772 | eleNum = computeDataLength(p->next->r5, p->next->r4, p->next->r3, p->next->r2, p->next->r1); |
---|
| 773 | if(p->next->dataType==SZ_FLOAT) |
---|
| 774 | totalSize += (eleNum*4); |
---|
| 775 | else |
---|
| 776 | totalSize += (eleNum*8); |
---|
| 777 | p=p->next; |
---|
| 778 | } |
---|
| 779 | return totalSize; |
---|
| 780 | } |
---|
| 781 | |
---|
| 782 | void SZ_registerVar(char* varName, int dataType, void* data, |
---|
| 783 | int errBoundMode, double absErrBound, double relBoundRatio, double pwRelBoundRatio, |
---|
| 784 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 785 | { |
---|
| 786 | if(sz_tsc==NULL) |
---|
| 787 | initSZ_TSC(); |
---|
| 788 | |
---|
| 789 | char str[256]; |
---|
| 790 | SZ_batchAddVar(varName, dataType, data, |
---|
| 791 | errBoundMode, absErrBound, relBoundRatio, pwRelBoundRatio, r5, r4, r3, r2, r1); |
---|
| 792 | sprintf(str, "%d: %s : %zuX%zuX%zuX%zu%zu : %d : %f : %f : %f\n", sz_varset->count - 1, varName, r5, r4, r3, r2, r1, errBoundMode, absErrBound, relBoundRatio, pwRelBoundRatio); |
---|
| 793 | fputs(str, sz_tsc->metadata_file); |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | int SZ_deregisterVar(char* varName) |
---|
| 797 | { |
---|
| 798 | int state = SZ_batchDelVar(varName); |
---|
| 799 | return state; |
---|
| 800 | } |
---|
| 801 | |
---|
| 802 | #ifdef HAVE_TIMECMPR |
---|
| 803 | int SZ_compress_ts(unsigned char** newByteData, size_t *outSize) |
---|
| 804 | { |
---|
| 805 | confparams_cpr->szMode = SZ_TEMPORAL_COMPRESSION; |
---|
| 806 | confparams_cpr->predictionMode = SZ_PREVIOUS_VALUE_ESTIMATE; |
---|
| 807 | |
---|
| 808 | SZ_VarSet* vset = sz_varset; |
---|
| 809 | size_t *outSize_ = (size_t*)malloc(sizeof(size_t)*vset->count); |
---|
| 810 | memset(outSize_, 0, sizeof(size_t)*vset->count); |
---|
| 811 | unsigned char** compressBuffer = (unsigned char**)malloc(vset->count*sizeof(unsigned char*));//to store compressed bytes |
---|
| 812 | |
---|
| 813 | char *metadata_str = (char*)malloc(vset->count*256); |
---|
| 814 | memset(metadata_str, 0, vset->count*256); |
---|
| 815 | sprintf(metadata_str, "step %d", sz_tsc->currentStep); |
---|
| 816 | |
---|
| 817 | int i = 0, totalSize = 0; |
---|
| 818 | for(i=0;i<vset->count;i++) |
---|
| 819 | { |
---|
| 820 | SZ_Variable* v = vset->header->next; |
---|
| 821 | multisteps = v->multisteps; //assign the v's multisteps to the global variable 'multisteps', which will be used in the following compression. |
---|
| 822 | |
---|
| 823 | if(v->dataType==SZ_FLOAT) |
---|
| 824 | { |
---|
| 825 | SZ_compress_args_float(&(compressBuffer[i]), (float*)v->data, v->r5, v->r4, v->r3, v->r2, v->r1, &outSize_[i], v->errBoundMode, v->absErrBound, v->relBoundRatio, v->pwRelBoundRatio); |
---|
| 826 | } |
---|
| 827 | else if(v->dataType==SZ_DOUBLE) |
---|
| 828 | { |
---|
| 829 | SZ_compress_args_double(&(compressBuffer[i]), (double*)v->data, v->r5, v->r4, v->r3, v->r2, v->r1, &outSize_[i], v->errBoundMode, v->absErrBound, v->relBoundRatio, v->pwRelBoundRatio); |
---|
| 830 | } |
---|
| 831 | sprintf(metadata_str, "%s:%d,%d,%zu", metadata_str, i, multisteps->lastSnapshotStep, outSize_[i]); |
---|
| 832 | |
---|
| 833 | totalSize += outSize_[i]; |
---|
| 834 | v->compressType = multisteps->compressionType; |
---|
| 835 | v = v->next; |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | sprintf(metadata_str, "%s\n", metadata_str); |
---|
| 839 | fputs(metadata_str, sz_tsc->metadata_file); |
---|
| 840 | free(metadata_str); |
---|
| 841 | |
---|
| 842 | //sizeof(int)==current time step; 2*sizeof(char)+sizeof(size_t)=={compressionType + datatype + compression_data_size}; |
---|
| 843 | //sizeof(char)==# variables |
---|
| 844 | *outSize = sizeof(int) + sizeof(unsigned short) + totalSize + vset->count*(2*sizeof(unsigned char)+sizeof(size_t)); |
---|
| 845 | *newByteData = (unsigned char*)malloc(*outSize); |
---|
| 846 | unsigned char* p = *newByteData; |
---|
| 847 | |
---|
| 848 | intToBytes_bigEndian(p, sz_tsc->currentStep); |
---|
| 849 | p+=4; |
---|
| 850 | shortToBytes(p, vset->count); |
---|
| 851 | p+=2; |
---|
| 852 | |
---|
| 853 | for(i=0;i<vset->count;i++) |
---|
| 854 | { |
---|
| 855 | SZ_Variable* v = vset->header->next; |
---|
| 856 | |
---|
| 857 | *p = (unsigned char)v->compressType; //1 byte |
---|
| 858 | p++; |
---|
| 859 | *p = (unsigned char)v->dataType; //1 byte |
---|
| 860 | p++; |
---|
| 861 | sizeToBytes(p, outSize_[i]); //size_t |
---|
| 862 | p += sizeof(size_t); |
---|
| 863 | //sizeToBytes(p, v->r5); //size_t |
---|
| 864 | //p += sizeof(size_t); |
---|
| 865 | //sizeToBytes(p, v->r4); //size_t |
---|
| 866 | //p += sizeof(size_t); |
---|
| 867 | //sizeToBytes(p, v->r3); //size_t |
---|
| 868 | //p += sizeof(size_t); |
---|
| 869 | //sizeToBytes(p, v->r2); //size_t |
---|
| 870 | //p += sizeof(size_t); |
---|
| 871 | //sizeToBytes(p, v->r1); //size_t |
---|
| 872 | //p += sizeof(size_t); |
---|
| 873 | memcpy(p, compressBuffer[i], outSize_[i]); //outSize_[i] |
---|
| 874 | p += outSize_[i]; |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | sz_tsc->currentStep ++; |
---|
| 878 | free(outSize_); |
---|
| 879 | |
---|
| 880 | return SZ_SCES; |
---|
| 881 | } |
---|
| 882 | |
---|
| 883 | void SZ_decompress_ts(unsigned char *bytes, size_t byteLength) |
---|
| 884 | { |
---|
| 885 | if(confparams_dec==NULL) |
---|
| 886 | confparams_dec = (sz_params*)malloc(sizeof(sz_params)); |
---|
| 887 | memset(confparams_dec, 0, sizeof(sz_params)); |
---|
| 888 | confparams_dec->szMode = SZ_TEMPORAL_COMPRESSION; |
---|
| 889 | confparams_dec->predictionMode = SZ_PREVIOUS_VALUE_ESTIMATE; |
---|
| 890 | |
---|
| 891 | if(exe_params==NULL) |
---|
| 892 | exe_params = (sz_exedata*)malloc(sizeof(sz_exedata)); |
---|
| 893 | memset(exe_params, 0, sizeof(sz_exedata)); |
---|
| 894 | |
---|
| 895 | int x = 1; |
---|
| 896 | char *y = (char*)&x; |
---|
| 897 | if(*y==1) |
---|
| 898 | sysEndianType = LITTLE_ENDIAN_SYSTEM; |
---|
| 899 | else //=0 |
---|
| 900 | sysEndianType = BIG_ENDIAN_SYSTEM; |
---|
| 901 | |
---|
| 902 | int i = 0; |
---|
| 903 | size_t r5 = 0, r4 = 0, r3 = 0, r2 = 0, r1 = 0; |
---|
| 904 | unsigned char* q = bytes; |
---|
| 905 | sz_tsc->currentStep = bytesToInt_bigEndian(q); |
---|
| 906 | q += 4; |
---|
| 907 | unsigned short nbVars = (unsigned short)bytesToShort(q); |
---|
| 908 | q += 2; |
---|
| 909 | |
---|
| 910 | if(nbVars != sz_varset->count) |
---|
| 911 | { |
---|
| 912 | printf("Error: the number of variables in the compressed data file is inconsistent with the registered # variables.\n"); |
---|
| 913 | printf("Specifically, nbVars = %d, sz_varset->count = %d\n", nbVars, sz_varset->count); |
---|
| 914 | return; |
---|
| 915 | } |
---|
| 916 | |
---|
| 917 | float *newFloatData = NULL; |
---|
| 918 | double *newDoubleData = NULL; |
---|
| 919 | |
---|
| 920 | SZ_Variable* p = sz_varset->header->next; // p is pointed to the first variable. |
---|
| 921 | for(i=0;i<sz_varset->count;i++) |
---|
| 922 | { |
---|
| 923 | multisteps = p->multisteps; |
---|
| 924 | r5 = p->r5; |
---|
| 925 | r4 = p->r4; |
---|
| 926 | r3 = p->r3; |
---|
| 927 | r2 = p->r2; |
---|
| 928 | r1 = p->r1; |
---|
| 929 | size_t dataLen = computeDataLength(r5, r4, r3, r2, r1); |
---|
| 930 | multisteps->compressionType = *(q++); |
---|
| 931 | unsigned char dataType = *(q++); |
---|
| 932 | size_t cmpSize = bytesToSize(q); |
---|
| 933 | q += sizeof(size_t); |
---|
| 934 | unsigned char* cmpBytes = q; |
---|
| 935 | switch(dataType) |
---|
| 936 | { |
---|
| 937 | case SZ_FLOAT: |
---|
| 938 | SZ_decompress_args_float(&newFloatData, r5, r4, r3, r2, r1, cmpBytes, cmpSize); |
---|
| 939 | memcpy(p->data, newFloatData, dataLen*sizeof(float)); |
---|
| 940 | free(newFloatData); |
---|
| 941 | break; |
---|
| 942 | case SZ_DOUBLE: |
---|
| 943 | SZ_decompress_args_double(&newDoubleData, r5, r4, r3, r2, r1, cmpBytes, cmpSize); |
---|
| 944 | memcpy(p->data, newDoubleData, dataLen*sizeof(double)); |
---|
| 945 | free(newDoubleData); |
---|
| 946 | break; |
---|
| 947 | default: |
---|
| 948 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 949 | return; |
---|
| 950 | } |
---|
| 951 | |
---|
| 952 | q += cmpSize; |
---|
| 953 | p = p->next; |
---|
| 954 | } |
---|
| 955 | } |
---|
| 956 | #endif |
---|
| 957 | |
---|
| 958 | |
---|
| 959 | void SZ_Finalize() |
---|
| 960 | { |
---|
| 961 | #ifdef HAVE_TIMECMPR |
---|
| 962 | if(sz_varset!=NULL) |
---|
| 963 | SZ_freeVarSet(SZ_MAINTAIN_VAR_DATA); |
---|
| 964 | #endif |
---|
| 965 | |
---|
| 966 | if(confparams_dec!=NULL) |
---|
| 967 | { |
---|
| 968 | free(confparams_dec); |
---|
| 969 | confparams_dec = NULL; |
---|
| 970 | } |
---|
| 971 | if(confparams_cpr!=NULL) |
---|
| 972 | { |
---|
| 973 | free(confparams_cpr); |
---|
| 974 | confparams_cpr = NULL; |
---|
| 975 | } |
---|
| 976 | if(exe_params!=NULL) |
---|
| 977 | { |
---|
| 978 | free(exe_params); |
---|
| 979 | exe_params = NULL; |
---|
| 980 | } |
---|
| 981 | |
---|
| 982 | #ifdef HAVE_TIMECMPR |
---|
| 983 | if(sz_tsc!=NULL && sz_tsc->metadata_file!=NULL) |
---|
| 984 | fclose(sz_tsc->metadata_file); |
---|
| 985 | #endif |
---|
| 986 | } |
---|