example.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdio.h>
  2. #include <blosc.h>
  3. #define SIZE 100*100*100
  4. int main(){
  5. static float data[SIZE];
  6. static float data_out[SIZE];
  7. static float data_dest[SIZE];
  8. int isize = SIZE*sizeof(float), osize = SIZE*sizeof(float);
  9. int dsize = SIZE*sizeof(float), csize;
  10. int i;
  11. for(i=0; i<SIZE; i++){
  12. data[i] = i;
  13. }
  14. /* Register the filter with the library */
  15. printf("Blosc version info: %s (%s)\n",
  16. BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);
  17. /* Initialize the Blosc compressor */
  18. blosc_init();
  19. /* Compress with clevel=5 and shuffle active */
  20. csize = blosc_compress(5, 1, sizeof(float), isize, data, data_out, osize);
  21. if (csize == 0) {
  22. printf("Buffer is uncompressible. Giving up.\n");
  23. return 1;
  24. }
  25. else if (csize < 0) {
  26. printf("Compression error. Error code: %d\n", csize);
  27. return csize;
  28. }
  29. printf("Compression: %d -> %d (%.1fx)\n", isize, csize, (1.*isize) / csize);
  30. /* Decompress */
  31. dsize = blosc_decompress(data_out, data_dest, dsize);
  32. if (dsize < 0) {
  33. printf("Decompression error. Error code: %d\n", dsize);
  34. return dsize;
  35. }
  36. printf("Decompression succesful!\n");
  37. /* After using it, destroy the Blosc environment */
  38. blosc_destroy();
  39. for(i=0;i<SIZE;i++){
  40. if(data[i] != data_dest[i]) {
  41. printf("Decompressed data differs from original!\n");
  42. return -1;
  43. }
  44. }
  45. printf("Succesful roundtrip!\n");
  46. return 0;
  47. }