noinit.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (C) 2016 Francesc Alted
  3. http://blosc.org
  4. License: MIT (see LICENSE.txt)
  5. Example program demonstrating that from 1.9.0 on, Blosc does not
  6. need to be initialized (although it is recommended).
  7. To compile this program:
  8. $ gcc noinit.c -o noinit -lblosc
  9. or, if you don't have the blosc library installed yet:
  10. $ gcc -O3 -msse2 noinit.c -I../blosc -o noinit -L../build/blosc
  11. $ export LD_LIBRARY_PATH=../build/blosc
  12. Using MSVC on Windows:
  13. $ cl /arch:SSE2 /Ox /Fenoinit.exe /Iblosc examples\noinit.c blosc\blosc.c blosc\blosclz.c blosc\shuffle.c blosc\shuffle-sse2.c blosc\shuffle-generic.c blosc\bitshuffle-generic.c blosc\bitshuffle-sse2.c
  14. To run:
  15. $ ./noinit
  16. Blosc version info: 1.8.2.dev ($Date:: 2016-04-08 #$)
  17. Compression: 4000000 -> 158788 (25.2x)
  18. Decompression succesful!
  19. Succesful roundtrip!
  20. */
  21. #include <stdio.h>
  22. #include <blosc.h>
  23. #define SIZE 100*100*100
  24. int main(){
  25. static float data[SIZE];
  26. static float data_out[SIZE];
  27. static float data_dest[SIZE];
  28. int isize = SIZE*sizeof(float), osize = SIZE*sizeof(float);
  29. int dsize = SIZE*sizeof(float), csize;
  30. int i;
  31. for(i=0; i<SIZE; i++){
  32. data[i] = i;
  33. }
  34. /* Register the filter with the library */
  35. printf("Blosc version info: %s (%s)\n",
  36. BLOSC_VERSION_STRING, BLOSC_VERSION_DATE);
  37. /* From 1.9 on, we don't need to initialize the Blosc compressor anymore */
  38. /* blosc_init(); */
  39. /* Compress with clevel=5 and shuffle active */
  40. csize = blosc_compress(5, 1, sizeof(float), isize, data, data_out, osize);
  41. if (csize == 0) {
  42. printf("Buffer is uncompressible. Giving up.\n");
  43. return 1;
  44. }
  45. else if (csize < 0) {
  46. printf("Compression error. Error code: %d\n", csize);
  47. return csize;
  48. }
  49. printf("Compression: %d -> %d (%.1fx)\n", isize, csize, (1.*isize) / csize);
  50. /* Decompress */
  51. dsize = blosc_decompress(data_out, data_dest, dsize);
  52. if (dsize < 0) {
  53. printf("Decompression error. Error code: %d\n", dsize);
  54. return dsize;
  55. }
  56. printf("Decompression succesful!\n");
  57. for(i=0;i<SIZE;i++){
  58. if(data[i] != data_dest[i]) {
  59. printf("Decompressed data differs from original!\n");
  60. return -1;
  61. }
  62. }
  63. printf("Succesful roundtrip!\n");
  64. return 0;
  65. }