[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" |
---|
| 25 | //#include "CurveFillingCompressStorage.h" |
---|
| 26 | |
---|
| 27 | int versionNumber[4] = {SZ_VER_MAJOR,SZ_VER_MINOR,SZ_VER_BUILD,SZ_VER_REVISION}; |
---|
| 28 | //int SZ_SIZE_TYPE = 8; |
---|
| 29 | |
---|
| 30 | int dataEndianType = LITTLE_ENDIAN_DATA; //*endian type of the data read from disk |
---|
| 31 | int sysEndianType; //*sysEndianType is actually set automatically. |
---|
| 32 | |
---|
| 33 | //the confparams should be separate between compression and decopmression, in case of mutual-affection when calling compression/decompression alternatively |
---|
| 34 | sz_params *confparams_cpr = NULL; //used for compression |
---|
| 35 | sz_params *confparams_dec = NULL; //used for decompression |
---|
| 36 | |
---|
| 37 | sz_exedata *exe_params = NULL; |
---|
| 38 | |
---|
| 39 | /*following global variables are desgined for time-series based compression*/ |
---|
| 40 | /*sz_varset is not used in the single-snapshot data compression*/ |
---|
| 41 | SZ_VarSet* sz_varset = NULL; |
---|
| 42 | sz_multisteps *multisteps = NULL; |
---|
| 43 | sz_tsc_metadata *sz_tsc = NULL; |
---|
| 44 | |
---|
| 45 | //only for Pastri compressor |
---|
| 46 | #ifdef PASTRI |
---|
| 47 | pastri_params pastri_par; |
---|
| 48 | #endif |
---|
| 49 | |
---|
| 50 | HuffmanTree* SZ_Reset() |
---|
| 51 | { |
---|
| 52 | return createDefaultHuffmanTree(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | int SZ_Init(const char *configFilePath) |
---|
| 56 | { |
---|
| 57 | int loadFileResult = SZ_LoadConf(configFilePath); |
---|
| 58 | if(loadFileResult==SZ_NSCS) |
---|
| 59 | return SZ_NSCS; |
---|
| 60 | |
---|
| 61 | exe_params->SZ_SIZE_TYPE = sizeof(size_t); |
---|
| 62 | |
---|
| 63 | if(confparams_cpr->szMode == SZ_TEMPORAL_COMPRESSION) |
---|
| 64 | { |
---|
| 65 | initSZ_TSC(); |
---|
| 66 | } |
---|
| 67 | return SZ_SCES; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | int SZ_Init_Params(sz_params *params) |
---|
| 71 | { |
---|
| 72 | int x = 1; |
---|
| 73 | char *y = (char*)&x; |
---|
| 74 | int endianType = BIG_ENDIAN_SYSTEM; |
---|
| 75 | if(*y==1) endianType = LITTLE_ENDIAN_SYSTEM; |
---|
| 76 | |
---|
| 77 | sysEndianType = endianType; |
---|
| 78 | exe_params->SZ_SIZE_TYPE = sizeof(size_t); |
---|
| 79 | |
---|
| 80 | // set default values |
---|
| 81 | if(params->max_quant_intervals > 0) |
---|
| 82 | params->maxRangeRadius = params->max_quant_intervals/2; |
---|
| 83 | else |
---|
| 84 | params->max_quant_intervals = params->maxRangeRadius*2; |
---|
| 85 | |
---|
| 86 | exe_params->intvCapacity = params->maxRangeRadius*2; |
---|
| 87 | exe_params->intvRadius = params->maxRangeRadius; |
---|
| 88 | |
---|
| 89 | if(params->quantization_intervals>0) |
---|
| 90 | { |
---|
| 91 | updateQuantizationInfo(params->quantization_intervals); |
---|
| 92 | exe_params->optQuantMode = 0; |
---|
| 93 | } |
---|
| 94 | else |
---|
| 95 | exe_params->optQuantMode = 1; |
---|
| 96 | |
---|
| 97 | |
---|
| 98 | if(params->quantization_intervals%2!=0) |
---|
| 99 | { |
---|
| 100 | printf("Error: quantization_intervals must be an even number!\n"); |
---|
| 101 | return SZ_NSCS; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | confparams_cpr = (sz_params*)malloc(sizeof(sz_params)); |
---|
| 105 | memcpy(confparams_cpr, params, sizeof(sz_params)); |
---|
| 106 | |
---|
| 107 | return SZ_SCES; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | int computeDimension(size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 111 | { |
---|
| 112 | int dimension; |
---|
| 113 | if(r1==0) |
---|
| 114 | { |
---|
| 115 | dimension = 0; |
---|
| 116 | } |
---|
| 117 | else if(r2==0) |
---|
| 118 | { |
---|
| 119 | dimension = 1; |
---|
| 120 | } |
---|
| 121 | else if(r3==0) |
---|
| 122 | { |
---|
| 123 | dimension = 2; |
---|
| 124 | } |
---|
| 125 | else if(r4==0) |
---|
| 126 | { |
---|
| 127 | dimension = 3; |
---|
| 128 | } |
---|
| 129 | else if(r5==0) |
---|
| 130 | { |
---|
| 131 | dimension = 4; |
---|
| 132 | } |
---|
| 133 | else |
---|
| 134 | { |
---|
| 135 | dimension = 5; |
---|
| 136 | } |
---|
| 137 | return dimension; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | size_t computeDataLength(size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 141 | { |
---|
| 142 | size_t dataLength; |
---|
| 143 | if(r1==0) |
---|
| 144 | { |
---|
| 145 | dataLength = 0; |
---|
| 146 | } |
---|
| 147 | else if(r2==0) |
---|
| 148 | { |
---|
| 149 | dataLength = r1; |
---|
| 150 | } |
---|
| 151 | else if(r3==0) |
---|
| 152 | { |
---|
| 153 | dataLength = r1*r2; |
---|
| 154 | } |
---|
| 155 | else if(r4==0) |
---|
| 156 | { |
---|
| 157 | dataLength = r1*r2*r3; |
---|
| 158 | } |
---|
| 159 | else if(r5==0) |
---|
| 160 | { |
---|
| 161 | dataLength = r1*r2*r3*r4; |
---|
| 162 | } |
---|
| 163 | else |
---|
| 164 | { |
---|
| 165 | dataLength = r1*r2*r3*r4*r5; |
---|
| 166 | } |
---|
| 167 | return dataLength; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | /*-------------------------------------------------------------------------*/ |
---|
| 171 | /** |
---|
| 172 | @brief Perform Compression |
---|
| 173 | @param data data to be compressed |
---|
| 174 | @param outSize the size (in bytes) after compression |
---|
| 175 | @param r5,r4,r3,r2,r1 the sizes of each dimension (supporting only 5 dimensions at most in this version. |
---|
| 176 | @return compressed data (in binary stream) or NULL(0) if any errors |
---|
| 177 | |
---|
| 178 | **/ |
---|
| 179 | /*-------------------------------------------------------------------------*/ |
---|
| 180 | unsigned char* SZ_compress_args(int dataType, void *data, size_t *outSize, int errBoundMode, double absErrBound, |
---|
| 181 | double relBoundRatio, double pwrBoundRatio, size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 182 | { |
---|
| 183 | //TODO |
---|
| 184 | confparams_cpr->dataType = dataType; |
---|
| 185 | if(dataType==SZ_FLOAT) |
---|
| 186 | { |
---|
| 187 | unsigned char *newByteData = NULL; |
---|
| 188 | |
---|
| 189 | SZ_compress_args_float(&newByteData, (float *)data, r5, r4, r3, r2, r1, |
---|
| 190 | outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio); |
---|
| 191 | |
---|
| 192 | return newByteData; |
---|
| 193 | } |
---|
| 194 | else if(dataType==SZ_DOUBLE) |
---|
| 195 | { |
---|
| 196 | unsigned char *newByteData; |
---|
| 197 | SZ_compress_args_double(&newByteData, (double *)data, r5, r4, r3, r2, r1, |
---|
| 198 | outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio); |
---|
| 199 | |
---|
| 200 | return newByteData; |
---|
| 201 | } |
---|
| 202 | else if(dataType==SZ_INT64) |
---|
| 203 | { |
---|
| 204 | unsigned char *newByteData; |
---|
| 205 | SZ_compress_args_int64(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 206 | return newByteData; |
---|
| 207 | } |
---|
| 208 | else if(dataType==SZ_INT32) //int type |
---|
| 209 | { |
---|
| 210 | unsigned char *newByteData; |
---|
| 211 | SZ_compress_args_int32(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 212 | return newByteData; |
---|
| 213 | } |
---|
| 214 | else if(dataType==SZ_INT16) |
---|
| 215 | { |
---|
| 216 | unsigned char *newByteData; |
---|
| 217 | SZ_compress_args_int16(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 218 | return newByteData; |
---|
| 219 | } |
---|
| 220 | else if(dataType==SZ_INT8) |
---|
| 221 | { |
---|
| 222 | unsigned char *newByteData; |
---|
| 223 | SZ_compress_args_int8(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 224 | return newByteData; |
---|
| 225 | } |
---|
| 226 | else if(dataType==SZ_UINT64) |
---|
| 227 | { |
---|
| 228 | unsigned char *newByteData; |
---|
| 229 | SZ_compress_args_uint64(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 230 | return newByteData; |
---|
| 231 | } |
---|
| 232 | else if(dataType==SZ_UINT32) //int type |
---|
| 233 | { |
---|
| 234 | unsigned char *newByteData; |
---|
| 235 | SZ_compress_args_uint32(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 236 | return newByteData; |
---|
| 237 | } |
---|
| 238 | else if(dataType==SZ_UINT16) |
---|
| 239 | { |
---|
| 240 | unsigned char *newByteData; |
---|
| 241 | SZ_compress_args_uint16(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 242 | return newByteData; |
---|
| 243 | } |
---|
| 244 | else if(dataType==SZ_UINT8) |
---|
| 245 | { |
---|
| 246 | unsigned char *newByteData; |
---|
| 247 | SZ_compress_args_uint8(&newByteData, data, r5, r4, r3, r2, r1, outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 248 | return newByteData; |
---|
| 249 | } |
---|
| 250 | else |
---|
| 251 | { |
---|
| 252 | printf("Error: dataType can only be SZ_FLOAT, SZ_DOUBLE, SZ_INT8/16/32/64 or SZ_UINT8/16/32/64.\n"); |
---|
| 253 | return NULL; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
| 257 | int SZ_compress_args2(int dataType, void *data, unsigned char* compressed_bytes, size_t *outSize, |
---|
| 258 | int errBoundMode, double absErrBound, double relBoundRatio, double pwrBoundRatio, |
---|
| 259 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 260 | { |
---|
| 261 | unsigned char* bytes = SZ_compress_args(dataType, data, outSize, errBoundMode, absErrBound, relBoundRatio, pwrBoundRatio, r5, r4, r3, r2, r1); |
---|
| 262 | memcpy(compressed_bytes, bytes, *outSize); |
---|
| 263 | free(bytes); |
---|
| 264 | return SZ_SCES; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | int SZ_compress_args3(int dataType, void *data, unsigned char* compressed_bytes, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 268 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1, |
---|
| 269 | size_t s5, size_t s4, size_t s3, size_t s2, size_t s1, |
---|
| 270 | size_t e5, size_t e4, size_t e3, size_t e2, size_t e1) |
---|
| 271 | { |
---|
| 272 | confparams_cpr->dataType = dataType; |
---|
| 273 | if(dataType==SZ_FLOAT) |
---|
| 274 | { |
---|
| 275 | SZ_compress_args_float_subblock(compressed_bytes, (float *)data, |
---|
| 276 | r5, r4, r3, r2, r1, |
---|
| 277 | s5, s4, s3, s2, s1, |
---|
| 278 | e5, e4, e3, e2, e1, |
---|
| 279 | outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 280 | |
---|
| 281 | return SZ_SCES; |
---|
| 282 | } |
---|
| 283 | else if(dataType==SZ_DOUBLE) |
---|
| 284 | { |
---|
| 285 | SZ_compress_args_double_subblock(compressed_bytes, (double *)data, |
---|
| 286 | r5, r4, r3, r2, r1, |
---|
| 287 | s5, s4, s3, s2, s1, |
---|
| 288 | e5, e4, e3, e2, e1, |
---|
| 289 | outSize, errBoundMode, absErrBound, relBoundRatio); |
---|
| 290 | |
---|
| 291 | return SZ_SCES; |
---|
| 292 | } |
---|
| 293 | else |
---|
| 294 | { |
---|
| 295 | printf("Error (in SZ_compress_args3): dataType can only be SZ_FLOAT or SZ_DOUBLE.\n"); |
---|
| 296 | return SZ_NSCS; |
---|
| 297 | } |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | 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) |
---|
| 301 | { |
---|
| 302 | unsigned char *newByteData = SZ_compress_args(dataType, data, outSize, confparams_cpr->errorBoundMode, confparams_cpr->absErrBound, confparams_cpr->relBoundRatio, |
---|
| 303 | confparams_cpr->pw_relBoundRatio, r5, r4, r3, r2, r1); |
---|
| 304 | return newByteData; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | ////////////////// |
---|
| 308 | /*-------------------------------------------------------------------------*/ |
---|
| 309 | /** |
---|
| 310 | @brief Perform Compression |
---|
| 311 | @param data data to be compressed |
---|
| 312 | @param reservedValue the reserved value |
---|
| 313 | @param outSize the size (in bytes) after compression |
---|
| 314 | @param r5,r4,r3,r2,r1 the sizes of each dimension (supporting only 5 dimensions at most in this version. |
---|
| 315 | @return compressed data (in binary stream) |
---|
| 316 | |
---|
| 317 | **/ |
---|
| 318 | /*-------------------------------------------------------------------------*/ |
---|
| 319 | unsigned char *SZ_compress_rev_args(int dataType, void *data, void *reservedValue, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 320 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 321 | { |
---|
| 322 | unsigned char *newByteData; |
---|
| 323 | //TODO |
---|
| 324 | printf("SZ compression with reserved data is TO BE DONE LATER.\n"); |
---|
| 325 | exit(0); |
---|
| 326 | |
---|
| 327 | return newByteData; |
---|
| 328 | } |
---|
| 329 | |
---|
| 330 | int SZ_compress_rev_args2(int dataType, void *data, void *reservedValue, unsigned char* compressed_bytes, size_t *outSize, int errBoundMode, double absErrBound, double relBoundRatio, |
---|
| 331 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 332 | { |
---|
| 333 | confparams_cpr->dataType = dataType; |
---|
| 334 | unsigned char* bytes = SZ_compress_rev_args(dataType, data, reservedValue, outSize, errBoundMode, absErrBound, relBoundRatio, r5, r4, r3, r2, r1); |
---|
| 335 | memcpy(compressed_bytes, bytes, *outSize); |
---|
| 336 | free(bytes); //free(bytes) is removed , because of dump error at MIRA system (PPC architecture), fixed? |
---|
| 337 | return 0; |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | 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) |
---|
| 341 | { |
---|
| 342 | unsigned char *newByteData; |
---|
| 343 | //TODO |
---|
| 344 | printf("SZ compression with reserved data is TO BE DONE LATER.\n"); |
---|
| 345 | exit(0); |
---|
| 346 | |
---|
| 347 | return newByteData; |
---|
| 348 | } |
---|
| 349 | |
---|
| 350 | 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) |
---|
| 351 | { |
---|
| 352 | if(confparams_dec==NULL) |
---|
| 353 | confparams_dec = (sz_params*)malloc(sizeof(sz_params)); |
---|
| 354 | memset(confparams_dec, 0, sizeof(sz_params)); |
---|
| 355 | if(exe_params==NULL) |
---|
| 356 | exe_params = (sz_exedata*)malloc(sizeof(sz_exedata)); |
---|
| 357 | memset(exe_params, 0, sizeof(sz_exedata)); |
---|
| 358 | |
---|
| 359 | int x = 1; |
---|
| 360 | char *y = (char*)&x; |
---|
| 361 | if(*y==1) |
---|
| 362 | sysEndianType = LITTLE_ENDIAN_SYSTEM; |
---|
| 363 | else //=0 |
---|
| 364 | sysEndianType = BIG_ENDIAN_SYSTEM; |
---|
| 365 | |
---|
| 366 | if(dataType == SZ_FLOAT) |
---|
| 367 | { |
---|
| 368 | float *newFloatData; |
---|
| 369 | SZ_decompress_args_float(&newFloatData, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 370 | return newFloatData; |
---|
| 371 | } |
---|
| 372 | else if(dataType == SZ_DOUBLE) |
---|
| 373 | { |
---|
| 374 | double *newDoubleData; |
---|
| 375 | SZ_decompress_args_double(&newDoubleData, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 376 | return newDoubleData; |
---|
| 377 | } |
---|
| 378 | else if(dataType == SZ_INT8) |
---|
| 379 | { |
---|
| 380 | int8_t *newInt8Data; |
---|
| 381 | SZ_decompress_args_int8(&newInt8Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 382 | return newInt8Data; |
---|
| 383 | } |
---|
| 384 | else if(dataType == SZ_INT16) |
---|
| 385 | { |
---|
| 386 | int16_t *newInt16Data; |
---|
| 387 | SZ_decompress_args_int16(&newInt16Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 388 | return newInt16Data; |
---|
| 389 | } |
---|
| 390 | else if(dataType == SZ_INT32) |
---|
| 391 | { |
---|
| 392 | int32_t *newInt32Data; |
---|
| 393 | SZ_decompress_args_int32(&newInt32Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 394 | return newInt32Data; |
---|
| 395 | } |
---|
| 396 | else if(dataType == SZ_INT64) |
---|
| 397 | { |
---|
| 398 | int64_t *newInt64Data; |
---|
| 399 | SZ_decompress_args_int64(&newInt64Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 400 | return newInt64Data; |
---|
| 401 | } |
---|
| 402 | else if(dataType == SZ_UINT8) |
---|
| 403 | { |
---|
| 404 | uint8_t *newUInt8Data; |
---|
| 405 | SZ_decompress_args_uint8(&newUInt8Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 406 | return newUInt8Data; |
---|
| 407 | } |
---|
| 408 | else if(dataType == SZ_UINT16) |
---|
| 409 | { |
---|
| 410 | uint16_t *newUInt16Data; |
---|
| 411 | SZ_decompress_args_uint16(&newUInt16Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 412 | return newUInt16Data; |
---|
| 413 | } |
---|
| 414 | else if(dataType == SZ_UINT32) |
---|
| 415 | { |
---|
| 416 | uint32_t *newUInt32Data; |
---|
| 417 | SZ_decompress_args_uint32(&newUInt32Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 418 | return newUInt32Data; |
---|
| 419 | } |
---|
| 420 | else if(dataType == SZ_UINT64) |
---|
| 421 | { |
---|
| 422 | uint64_t *newUInt64Data; |
---|
| 423 | SZ_decompress_args_uint64(&newUInt64Data, r5, r4, r3, r2, r1, bytes, byteLength); |
---|
| 424 | return newUInt64Data; |
---|
| 425 | } |
---|
| 426 | else |
---|
| 427 | { |
---|
| 428 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 429 | return NULL; |
---|
| 430 | } |
---|
| 431 | } |
---|
| 432 | |
---|
| 433 | /** |
---|
| 434 | * |
---|
| 435 | * |
---|
| 436 | * return number of elements or -1 if any errors |
---|
| 437 | * */ |
---|
| 438 | 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) |
---|
| 439 | { |
---|
| 440 | //size_t i; |
---|
| 441 | size_t nbEle = computeDataLength(r5,r4,r3,r2,r1); |
---|
| 442 | |
---|
| 443 | if(dataType == SZ_FLOAT) |
---|
| 444 | { |
---|
| 445 | float* data = (float *)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 446 | float* data_array = (float *)decompressed_array; |
---|
| 447 | memcpy(data_array, data, nbEle*sizeof(float)); |
---|
| 448 | //for(i=0;i<nbEle;i++) |
---|
| 449 | // data_array[i] = data[i]; |
---|
| 450 | free(data); //this free operation seems to not work with BlueG/Q system. |
---|
| 451 | } |
---|
| 452 | else if (dataType == SZ_DOUBLE) |
---|
| 453 | { |
---|
| 454 | double* data = (double *)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 455 | double* data_array = (double *)decompressed_array; |
---|
| 456 | memcpy(data_array, data, nbEle*sizeof(double)); |
---|
| 457 | //for(i=0;i<nbEle;i++) |
---|
| 458 | // data_array[i] = data[i]; |
---|
| 459 | free(data); //this free operation seems to not work with BlueG/Q system. |
---|
| 460 | } |
---|
| 461 | else if(dataType == SZ_INT8) |
---|
| 462 | { |
---|
| 463 | int8_t* data = (int8_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 464 | int8_t* data_array = (int8_t *)decompressed_array; |
---|
| 465 | memcpy(data_array, data, nbEle*sizeof(int8_t)); |
---|
| 466 | free(data); |
---|
| 467 | } |
---|
| 468 | else if(dataType == SZ_INT16) |
---|
| 469 | { |
---|
| 470 | int16_t* data = (int16_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 471 | int16_t* data_array = (int16_t *)decompressed_array; |
---|
| 472 | memcpy(data_array, data, nbEle*sizeof(int16_t)); |
---|
| 473 | free(data); |
---|
| 474 | } |
---|
| 475 | else if(dataType == SZ_INT32) |
---|
| 476 | { |
---|
| 477 | int32_t* data = (int32_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 478 | int32_t* data_array = (int32_t *)decompressed_array; |
---|
| 479 | memcpy(data_array, data, nbEle*sizeof(int32_t)); |
---|
| 480 | free(data); |
---|
| 481 | } |
---|
| 482 | else if(dataType == SZ_INT64) |
---|
| 483 | { |
---|
| 484 | int64_t* data = (int64_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 485 | int64_t* data_array = (int64_t *)decompressed_array; |
---|
| 486 | memcpy(data_array, data, nbEle*sizeof(int64_t)); |
---|
| 487 | free(data); |
---|
| 488 | } |
---|
| 489 | else if(dataType == SZ_UINT8) |
---|
| 490 | { |
---|
| 491 | uint8_t* data = (uint8_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 492 | uint8_t* data_array = (uint8_t *)decompressed_array; |
---|
| 493 | memcpy(data_array, data, nbEle*sizeof(uint8_t)); |
---|
| 494 | free(data); |
---|
| 495 | } |
---|
| 496 | else if(dataType == SZ_UINT16) |
---|
| 497 | { |
---|
| 498 | uint16_t* data = (uint16_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 499 | uint16_t* data_array = (uint16_t *)decompressed_array; |
---|
| 500 | memcpy(data_array, data, nbEle*sizeof(uint16_t)); |
---|
| 501 | free(data); |
---|
| 502 | } |
---|
| 503 | else if(dataType == SZ_UINT32) |
---|
| 504 | { |
---|
| 505 | uint32_t* data = (uint32_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 506 | uint32_t* data_array = (uint32_t *)decompressed_array; |
---|
| 507 | memcpy(data_array, data, nbEle*sizeof(uint32_t)); |
---|
| 508 | free(data); |
---|
| 509 | } |
---|
| 510 | else if(dataType == SZ_UINT64) |
---|
| 511 | { |
---|
| 512 | uint64_t* data = (uint64_t*)SZ_decompress(dataType, bytes, byteLength, r5, r4, r3, r2, r1); |
---|
| 513 | uint64_t* data_array = (uint64_t *)decompressed_array; |
---|
| 514 | memcpy(data_array, data, nbEle*sizeof(uint64_t)); |
---|
| 515 | free(data); |
---|
| 516 | } |
---|
| 517 | else |
---|
| 518 | { |
---|
| 519 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 520 | return SZ_NSCS; //indicating error |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | return nbEle; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | |
---|
| 527 | sz_metadata* SZ_getMetadata(unsigned char* bytes) |
---|
| 528 | { |
---|
| 529 | int index = 0, i, isConstant, isLossless; |
---|
| 530 | size_t dataSeriesLength = 0; |
---|
| 531 | int versions[3] = {0,0,0}; |
---|
| 532 | for (i = 0; i < 3; i++) |
---|
| 533 | versions[i] = bytes[index++]; //3 |
---|
| 534 | unsigned char sameRByte = bytes[index++]; //1 |
---|
| 535 | isConstant = sameRByte & 0x01; |
---|
| 536 | //confparams_dec->szMode = (sameRByte & 0x06)>>1; |
---|
| 537 | isLossless = (sameRByte & 0x10)>>4; |
---|
| 538 | exe_params->SZ_SIZE_TYPE = ((sameRByte & 0x40)>>6)==1?8:4; |
---|
| 539 | |
---|
| 540 | sz_params* params = convertBytesToSZParams(&(bytes[index])); |
---|
| 541 | if(confparams_dec!=NULL) |
---|
| 542 | free(confparams_dec); |
---|
| 543 | confparams_dec = params; |
---|
| 544 | index += MetaDataByteLength; |
---|
| 545 | |
---|
| 546 | if(params->dataType!=SZ_FLOAT && params->dataType!= SZ_DOUBLE) //if this type is an Int type |
---|
| 547 | index++; //jump to the dataLength info byte address |
---|
| 548 | dataSeriesLength = bytesToSize(&(bytes[index]));// 4 or 8 |
---|
| 549 | index += exe_params->SZ_SIZE_TYPE; |
---|
| 550 | index += 4; //max_quant_intervals |
---|
| 551 | |
---|
| 552 | sz_metadata* metadata = (sz_metadata*)malloc(sizeof(struct sz_metadata)); |
---|
| 553 | |
---|
| 554 | metadata->versionNumber[0] = versions[0]; |
---|
| 555 | metadata->versionNumber[1] = versions[1]; |
---|
| 556 | metadata->versionNumber[2] = versions[2]; |
---|
| 557 | metadata->isConstant = isConstant; |
---|
| 558 | metadata->isLossless = isLossless; |
---|
| 559 | metadata->sizeType = exe_params->SZ_SIZE_TYPE; |
---|
| 560 | metadata->dataSeriesLength = dataSeriesLength; |
---|
| 561 | |
---|
| 562 | metadata->conf_params = confparams_dec; |
---|
| 563 | |
---|
| 564 | int defactoNBBins = 0; //real # bins |
---|
| 565 | if(isConstant==0 && isLossless==0) |
---|
| 566 | { |
---|
| 567 | int radExpoL = 0, segmentL = 0, pwrErrBoundBytesL = 0; |
---|
| 568 | if(metadata->conf_params->errorBoundMode >= PW_REL) |
---|
| 569 | { |
---|
| 570 | radExpoL = 1; |
---|
| 571 | segmentL = exe_params->SZ_SIZE_TYPE; |
---|
| 572 | pwrErrBoundBytesL = 4; |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | int offset_typearray = 3 + 1 + MetaDataByteLength + exe_params->SZ_SIZE_TYPE + 4 + radExpoL + segmentL + pwrErrBoundBytesL + 4 + 4 + 1 + 8 |
---|
| 576 | + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE + exe_params->SZ_SIZE_TYPE; |
---|
| 577 | size_t nodeCount = bytesToInt_bigEndian(bytes+offset_typearray); |
---|
| 578 | defactoNBBins = (nodeCount+1)/2; |
---|
| 579 | } |
---|
| 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 | int isZlibFormat(unsigned char magic1, unsigned char magic2) |
---|
| 783 | { |
---|
| 784 | if(magic1==104&&magic2==5) //DC+BS |
---|
| 785 | return 1; |
---|
| 786 | if(magic1==104&&magic2==129) //DC+DC |
---|
| 787 | return 1; |
---|
| 788 | if(magic1==104&&magic2==222) //DC+BC |
---|
| 789 | return 1; |
---|
| 790 | if(magic1==120&&magic2==1) //BC+BS |
---|
| 791 | return 1; |
---|
| 792 | if(magic1==120&&magic2==156) //BC+DC |
---|
| 793 | return 1; |
---|
| 794 | if(magic1==120&&magic2==218) //BC+BS |
---|
| 795 | return 1; |
---|
| 796 | return 0; |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | void SZ_registerVar(char* varName, int dataType, void* data, |
---|
| 800 | int errBoundMode, double absErrBound, double relBoundRatio, double pwRelBoundRatio, |
---|
| 801 | size_t r5, size_t r4, size_t r3, size_t r2, size_t r1) |
---|
| 802 | { |
---|
| 803 | if(sz_tsc==NULL) |
---|
| 804 | initSZ_TSC(); |
---|
| 805 | |
---|
| 806 | char str[256]; |
---|
| 807 | SZ_batchAddVar(varName, dataType, data, |
---|
| 808 | errBoundMode, absErrBound, relBoundRatio, pwRelBoundRatio, r5, r4, r3, r2, r1); |
---|
| 809 | 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); |
---|
| 810 | fputs(str, sz_tsc->metadata_file); |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | int SZ_deregisterVar(char* varName) |
---|
| 814 | { |
---|
| 815 | int state = SZ_batchDelVar(varName); |
---|
| 816 | return state; |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | #ifdef HAVE_TIMECMPR |
---|
| 820 | int SZ_compress_ts(unsigned char** newByteData, size_t *outSize) |
---|
| 821 | { |
---|
| 822 | confparams_cpr->szMode = SZ_TEMPORAL_COMPRESSION; |
---|
| 823 | confparams_cpr->predictionMode = SZ_PREVIOUS_VALUE_ESTIMATE; |
---|
| 824 | |
---|
| 825 | SZ_VarSet* vset = sz_varset; |
---|
| 826 | size_t *outSize_ = (size_t*)malloc(sizeof(size_t)*vset->count); |
---|
| 827 | memset(outSize_, 0, sizeof(size_t)*vset->count); |
---|
| 828 | unsigned char** compressBuffer = (unsigned char**)malloc(vset->count*sizeof(unsigned char*));//to store compressed bytes |
---|
| 829 | |
---|
| 830 | char *metadata_str = (char*)malloc(vset->count*256); |
---|
| 831 | memset(metadata_str, 0, vset->count*256); |
---|
| 832 | sprintf(metadata_str, "step %d", sz_tsc->currentStep); |
---|
| 833 | |
---|
| 834 | int i = 0, totalSize = 0; |
---|
| 835 | for(i=0;i<vset->count;i++) |
---|
| 836 | { |
---|
| 837 | SZ_Variable* v = vset->header->next; |
---|
| 838 | multisteps = v->multisteps; //assign the v's multisteps to the global variable 'multisteps', which will be used in the following compression. |
---|
| 839 | |
---|
| 840 | if(v->dataType==SZ_FLOAT) |
---|
| 841 | { |
---|
| 842 | 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); |
---|
| 843 | } |
---|
| 844 | else if(v->dataType==SZ_DOUBLE) |
---|
| 845 | { |
---|
| 846 | 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); |
---|
| 847 | } |
---|
| 848 | sprintf(metadata_str, "%s:%d,%d,%zu", metadata_str, i, multisteps->lastSnapshotStep, outSize_[i]); |
---|
| 849 | |
---|
| 850 | totalSize += outSize_[i]; |
---|
| 851 | v->compressType = multisteps->compressionType; |
---|
| 852 | v = v->next; |
---|
| 853 | } |
---|
| 854 | |
---|
| 855 | sprintf(metadata_str, "%s\n", metadata_str); |
---|
| 856 | fputs(metadata_str, sz_tsc->metadata_file); |
---|
| 857 | free(metadata_str); |
---|
| 858 | |
---|
| 859 | //sizeof(int)==current time step; 2*sizeof(char)+sizeof(size_t)=={compressionType + datatype + compression_data_size}; |
---|
| 860 | //sizeof(char)==# variables |
---|
| 861 | *outSize = sizeof(int) + sizeof(unsigned short) + totalSize + vset->count*(2*sizeof(unsigned char)+sizeof(size_t)); |
---|
| 862 | *newByteData = (unsigned char*)malloc(*outSize); |
---|
| 863 | unsigned char* p = *newByteData; |
---|
| 864 | |
---|
| 865 | intToBytes_bigEndian(p, sz_tsc->currentStep); |
---|
| 866 | p+=4; |
---|
| 867 | shortToBytes(p, vset->count); |
---|
| 868 | p+=2; |
---|
| 869 | |
---|
| 870 | for(i=0;i<vset->count;i++) |
---|
| 871 | { |
---|
| 872 | SZ_Variable* v = vset->header->next; |
---|
| 873 | |
---|
| 874 | *p = (unsigned char)v->compressType; //1 byte |
---|
| 875 | p++; |
---|
| 876 | *p = (unsigned char)v->dataType; //1 byte |
---|
| 877 | p++; |
---|
| 878 | sizeToBytes(p, outSize_[i]); //size_t |
---|
| 879 | p += sizeof(size_t); |
---|
| 880 | //sizeToBytes(p, v->r5); //size_t |
---|
| 881 | //p += sizeof(size_t); |
---|
| 882 | //sizeToBytes(p, v->r4); //size_t |
---|
| 883 | //p += sizeof(size_t); |
---|
| 884 | //sizeToBytes(p, v->r3); //size_t |
---|
| 885 | //p += sizeof(size_t); |
---|
| 886 | //sizeToBytes(p, v->r2); //size_t |
---|
| 887 | //p += sizeof(size_t); |
---|
| 888 | //sizeToBytes(p, v->r1); //size_t |
---|
| 889 | //p += sizeof(size_t); |
---|
| 890 | memcpy(p, compressBuffer[i], outSize_[i]); //outSize_[i] |
---|
| 891 | p += outSize_[i]; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | sz_tsc->currentStep ++; |
---|
| 895 | free(outSize_); |
---|
| 896 | |
---|
| 897 | return SZ_SCES; |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | void SZ_decompress_ts(unsigned char *bytes, size_t byteLength) |
---|
| 901 | { |
---|
| 902 | if(confparams_dec==NULL) |
---|
| 903 | confparams_dec = (sz_params*)malloc(sizeof(sz_params)); |
---|
| 904 | memset(confparams_dec, 0, sizeof(sz_params)); |
---|
| 905 | confparams_dec->szMode = SZ_TEMPORAL_COMPRESSION; |
---|
| 906 | confparams_dec->predictionMode = SZ_PREVIOUS_VALUE_ESTIMATE; |
---|
| 907 | |
---|
| 908 | if(exe_params==NULL) |
---|
| 909 | exe_params = (sz_exedata*)malloc(sizeof(sz_exedata)); |
---|
| 910 | memset(exe_params, 0, sizeof(sz_exedata)); |
---|
| 911 | |
---|
| 912 | int x = 1; |
---|
| 913 | char *y = (char*)&x; |
---|
| 914 | if(*y==1) |
---|
| 915 | sysEndianType = LITTLE_ENDIAN_SYSTEM; |
---|
| 916 | else //=0 |
---|
| 917 | sysEndianType = BIG_ENDIAN_SYSTEM; |
---|
| 918 | |
---|
| 919 | int i = 0; |
---|
| 920 | size_t r5 = 0, r4 = 0, r3 = 0, r2 = 0, r1 = 0; |
---|
| 921 | unsigned char* q = bytes; |
---|
| 922 | sz_tsc->currentStep = bytesToInt_bigEndian(q); |
---|
| 923 | q += 4; |
---|
| 924 | unsigned short nbVars = (unsigned short)bytesToShort(q); |
---|
| 925 | q += 2; |
---|
| 926 | |
---|
| 927 | if(nbVars != sz_varset->count) |
---|
| 928 | { |
---|
| 929 | printf("Error: the number of variables in the compressed data file is inconsistent with the registered # variables.\n"); |
---|
| 930 | printf("Specifically, nbVars = %d, sz_varset->count = %d\n", nbVars, sz_varset->count); |
---|
| 931 | return; |
---|
| 932 | } |
---|
| 933 | |
---|
| 934 | float *newFloatData = NULL; |
---|
| 935 | double *newDoubleData = NULL; |
---|
| 936 | |
---|
| 937 | SZ_Variable* p = sz_varset->header->next; // p is pointed to the first variable. |
---|
| 938 | for(i=0;i<sz_varset->count;i++) |
---|
| 939 | { |
---|
| 940 | multisteps = p->multisteps; |
---|
| 941 | r5 = p->r5; |
---|
| 942 | r4 = p->r4; |
---|
| 943 | r3 = p->r3; |
---|
| 944 | r2 = p->r2; |
---|
| 945 | r1 = p->r1; |
---|
| 946 | size_t dataLen = computeDataLength(r5, r4, r3, r2, r1); |
---|
| 947 | multisteps->compressionType = *(q++); |
---|
| 948 | unsigned char dataType = *(q++); |
---|
| 949 | size_t cmpSize = bytesToSize(q); |
---|
| 950 | q += sizeof(size_t); |
---|
| 951 | unsigned char* cmpBytes = q; |
---|
| 952 | switch(dataType) |
---|
| 953 | { |
---|
| 954 | case SZ_FLOAT: |
---|
| 955 | SZ_decompress_args_float(&newFloatData, r5, r4, r3, r2, r1, cmpBytes, cmpSize); |
---|
| 956 | memcpy(p->data, newFloatData, dataLen*sizeof(float)); |
---|
| 957 | free(newFloatData); |
---|
| 958 | break; |
---|
| 959 | case SZ_DOUBLE: |
---|
| 960 | SZ_decompress_args_double(&newDoubleData, r5, r4, r3, r2, r1, cmpBytes, cmpSize); |
---|
| 961 | memcpy(p->data, newDoubleData, dataLen*sizeof(double)); |
---|
| 962 | free(newDoubleData); |
---|
| 963 | break; |
---|
| 964 | default: |
---|
| 965 | printf("Error: data type cannot be the types other than SZ_FLOAT or SZ_DOUBLE\n"); |
---|
| 966 | return; |
---|
| 967 | } |
---|
| 968 | |
---|
| 969 | q += cmpSize; |
---|
| 970 | p = p->next; |
---|
| 971 | } |
---|
| 972 | } |
---|
| 973 | #endif |
---|
| 974 | |
---|
| 975 | |
---|
| 976 | void SZ_Finalize() |
---|
| 977 | { |
---|
| 978 | #ifdef HAVE_TIMECMPR |
---|
| 979 | if(sz_varset!=NULL) |
---|
| 980 | SZ_freeVarSet(SZ_MAINTAIN_VAR_DATA); |
---|
| 981 | #endif |
---|
| 982 | |
---|
| 983 | if(confparams_dec!=NULL) |
---|
| 984 | { |
---|
| 985 | free(confparams_dec); |
---|
| 986 | confparams_dec = NULL; |
---|
| 987 | } |
---|
| 988 | if(confparams_cpr!=NULL) |
---|
| 989 | { |
---|
| 990 | free(confparams_cpr); |
---|
| 991 | confparams_cpr = NULL; |
---|
| 992 | } |
---|
| 993 | if(exe_params!=NULL) |
---|
| 994 | { |
---|
| 995 | free(exe_params); |
---|
| 996 | exe_params = NULL; |
---|
| 997 | } |
---|
| 998 | |
---|
| 999 | #ifdef HAVE_TIMECMPR |
---|
| 1000 | if(sz_tsc!=NULL && sz_tsc->metadata_file!=NULL) |
---|
| 1001 | fclose(sz_tsc->metadata_file); |
---|
| 1002 | #endif |
---|
| 1003 | } |
---|