[2c47b73] | 1 | #include "pastri.h" |
---|
| 2 | #include "pastriD.h" |
---|
| 3 | #include "pastriF.h" |
---|
| 4 | |
---|
| 5 | void SZ_pastriReadParameters(char paramsFilename[512],pastri_params *paramsPtr){ |
---|
| 6 | FILE *paramsF; |
---|
| 7 | paramsF=fopen(paramsFilename,"r"); |
---|
| 8 | |
---|
| 9 | if(paramsF==NULL){ |
---|
| 10 | printf("ERROR: Parameters file cannot be opened.\n"); |
---|
| 11 | printf("Filename: %s\n",paramsFilename); |
---|
| 12 | assert(0); |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | fscanf(paramsF,"%d %d %d %d %lf %d %d",¶msPtr->bf[0],¶msPtr->bf[1],¶msPtr->bf[2],¶msPtr->bf[3],¶msPtr->originalEb,¶msPtr->dataSize,¶msPtr->numBlocks); |
---|
| 16 | //printf("Params: %d %d %d %d %.3e %d\n",paramsPtr->bf[0],paramsPtr->bf[1],paramsPtr->bf[2],paramsPtr->bf[3],paramsPtr->originalEb,paramsPtr->numBlocks); |
---|
| 17 | fclose(paramsF); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | void SZ_pastriPreprocessParameters(pastri_params *p){ |
---|
| 21 | //Preprocess by calculating some pastri_params: |
---|
| 22 | //Calculate sbSize, sbNum, etc.: |
---|
| 23 | p->idxRange[0]=(p->bf[0]+1)*(p->bf[0]+2)/2; |
---|
| 24 | p->idxRange[1]=(p->bf[1]+1)*(p->bf[1]+2)/2; |
---|
| 25 | p->idxRange[2]=(p->bf[2]+1)*(p->bf[2]+2)/2; |
---|
| 26 | p->idxRange[3]=(p->bf[3]+1)*(p->bf[3]+2)/2; |
---|
| 27 | p->sbSize=p->idxRange[2]*p->idxRange[3]; |
---|
| 28 | p->sbNum=p->idxRange[0]*p->idxRange[1]; |
---|
| 29 | p->bSize=p->sbSize*p->sbNum; |
---|
| 30 | p->usedEb=p->originalEb*0.999; //This is needed just to eliminate some rounding errors. It has almost no effect on compression rate/ratios. |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | void SZ_pastriCompressBatch(pastri_params *p,unsigned char *originalBuf, unsigned char** compressedBufP,size_t *compressedBytes){ |
---|
| 34 | (*compressedBufP) = (unsigned char*)calloc(p->numBlocks*p->bSize*p->dataSize,sizeof(char)); |
---|
| 35 | int bytes; //bytes for this block |
---|
| 36 | int i; |
---|
| 37 | size_t bytePos=0; //Current byte pos in the outBuf |
---|
| 38 | |
---|
| 39 | memcpy(*compressedBufP, p, sizeof(pastri_params)); |
---|
| 40 | bytePos+=sizeof(pastri_params); |
---|
| 41 | |
---|
| 42 | for(i=0;i<p->numBlocks;i++){ |
---|
| 43 | if(p->dataSize==8){ |
---|
| 44 | pastri_double_Compress(originalBuf + (i*p->bSize*p->dataSize),p,(*compressedBufP) + bytePos,&bytes); |
---|
| 45 | }else if(p->dataSize==4){ |
---|
| 46 | pastri_float_Compress(originalBuf + (i*p->bSize*p->dataSize),p,(*compressedBufP) + bytePos,&bytes); |
---|
| 47 | } |
---|
| 48 | bytePos+=bytes; |
---|
| 49 | //printf("bytes:%d\n",bytes); |
---|
| 50 | } |
---|
| 51 | *compressedBytes=bytePos; |
---|
| 52 | //printf("totalBytesWritten:%d\n",*compressedBytes); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | void SZ_pastriDecompressBatch(unsigned char*compressedBuf, pastri_params *p, unsigned char** decompressedBufP ,size_t *decompressedBytes){ |
---|
| 56 | int bytePos=0; //Current byte pos in the outBuf |
---|
| 57 | memcpy(p, compressedBuf, sizeof(pastri_params)); |
---|
| 58 | bytePos+=sizeof(pastri_params); |
---|
| 59 | |
---|
| 60 | (*decompressedBufP) = (unsigned char*)malloc(p->numBlocks*p->bSize*p->dataSize*sizeof(char)); |
---|
| 61 | int bytes; //bytes for this block |
---|
| 62 | int i; |
---|
| 63 | |
---|
| 64 | for(i=0;i<p->numBlocks;i++){ |
---|
| 65 | if(p->dataSize==8){ |
---|
| 66 | pastri_double_Decompress(compressedBuf + bytePos,p->dataSize,p,(*decompressedBufP) + (i*p->bSize*p->dataSize),&bytes); |
---|
| 67 | }else if(p->dataSize==4){ |
---|
| 68 | pastri_float_Decompress(compressedBuf + bytePos,p->dataSize,p,(*decompressedBufP) + (i*p->bSize*p->dataSize),&bytes); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | bytePos += bytes; |
---|
| 72 | //printf("bytes:%d\n",bytes); |
---|
| 73 | } |
---|
| 74 | //printf("totalBytesRead:%d\n",bytePos); |
---|
| 75 | *decompressedBytes=p->numBlocks*p->bSize*p->dataSize; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void SZ_pastriCheckBatch(pastri_params *p,unsigned char*originalBuf,unsigned char*decompressedBuf){ |
---|
| 79 | int i; |
---|
| 80 | for(i=0;i<p->numBlocks;i++){ |
---|
| 81 | if(p->dataSize==8){ |
---|
| 82 | pastri_double_Check(originalBuf+(i*p->bSize*p->dataSize),p->dataSize,decompressedBuf+(i*p->bSize*p->dataSize),p); |
---|
| 83 | }else if(p->dataSize==4){ |
---|
| 84 | pastri_float_Check(originalBuf+(i*p->bSize*p->dataSize),p->dataSize,decompressedBuf+(i*p->bSize*p->dataSize),p); |
---|
| 85 | } |
---|
| 86 | } |
---|
| 87 | } |
---|