[h5py] 209/455: Example C program for LZF, fix issue with -ansi compiler switch

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:33 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit aad91a67454c083cfefcf9fc8420d7c218d87e07
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Thu Jan 29 05:53:44 2009 +0000

    Example C program for LZF, fix issue with -ansi compiler switch
---
 lzf/example.c    | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lzf/lzf/lzf_d.c  |   2 ++
 lzf/lzf_filter.h |   3 ++
 3 files changed, 107 insertions(+)

diff --git a/lzf/example.c b/lzf/example.c
new file mode 100644
index 0000000..fe05c51
--- /dev/null
+++ b/lzf/example.c
@@ -0,0 +1,102 @@
+/*
+    Copyright (C) 2009 Andrew Collette
+    http://h5py.alfven.org
+    License: BSD (see LICENSE.txt)
+
+    Example program demonstrating use of the LZF filter from C code.
+    The filter is completely stateless, and so is safe to statically
+    link into the final program.
+
+    The LZF filter provides high-speed compression with acceptable compression
+    performance, resulting in much faster performance than DEFLATE, at the
+    cost of a slightly worse compression ratio. It's appropriate for large
+    datasets of low to moderate complexity, for which some compression is
+    much better than none, but for which the speed of DEFLATE is unacceptable.
+
+    It's recommended to use the SHUFFLE filter with LZF, as it's virtually
+    free, supported by all current versions of HDF5, and can significantly
+    improve the compression ratio.
+
+    To compile:
+
+    h5cc lzf/*.c lzf_filter.c example.c -o example
+
+    To run:
+
+    $ ./example
+    $ h5ls -v test_lzf.hdf5 
+    Opened "test_lzf.hdf5" with sec2 driver.
+    dset                     Dataset {100/100, 100/100, 100/100}
+        Location:  0:1:0:976
+        Links:     1
+        Modified:  2009-01-28 21:51:20 PST
+        Chunks:    {1, 100, 100} 40000 bytes
+        Storage:   4000000 logical bytes, 529745 allocated bytes, 755.08% utilization
+        Filter-0:  shuffle-2 OPT {4}
+        Filter-1:  lzf-315 OPT {}
+        Type:      native float
+*/
+
+#define H5_USE_16_API
+
+#include "hdf5.h"
+#include "lzf_filter.h"
+
+int main(){
+
+    float data[100*100*100];
+    const hsize_t shape[] = {100,100,100};
+    const hsize_t chunkshape[] = {1,100,100};
+    int r, i;
+
+    hid_t fid, sid, dset, plist;
+
+    for(i=0; i<100*100*100; i++){
+        data[i] = i;
+    }
+
+    /* Register the filter with the library */
+    r = register_lzf();
+    if(r<0) goto failed;
+
+    sid = H5Screate_simple(3, &shape, NULL);
+    if(sid<0) goto failed;
+
+    fid = H5Fcreate("test_lzf.hdf5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+    if(fid<0) goto failed;
+
+    plist = H5Pcreate(H5P_DATASET_CREATE);
+    if(plist<0) goto failed;
+
+    /* Chunked layout required for filters */
+    r = H5Pset_chunk(plist, 3, &chunkshape);
+    if(r<0) goto failed;
+
+    /* Use of the shuffle filter VASTLY improves performance of this
+       and other block-oriented compression filters.  Be sure to add
+       this before the compression filter!
+    */
+    r = H5Pset_shuffle(plist);
+    if(r<0) goto failed;
+
+    /* Note the "optional" flag is necessary, as with the DEFLATE filter */
+    r = H5Pset_filter(plist, H5PY_FILTER_LZF, H5Z_FLAG_OPTIONAL, 0, NULL);
+    if(r<0) goto failed;
+
+    dset = H5Dcreate(fid, "dset", H5T_NATIVE_FLOAT, sid, plist);
+    if(dset<0) goto failed;
+    
+    r = H5Dwrite(dset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &data);
+    if(r<0) goto failed;
+
+    H5Dclose(dset);
+    H5Sclose(sid);
+    H5Pclose(plist);
+    H5Fclose(fid);
+
+    return 0;
+
+    failed:
+    return 1;
+}
+
diff --git a/lzf/lzf/lzf_d.c b/lzf/lzf/lzf_d.c
index 9e2cd82..562e188 100644
--- a/lzf/lzf/lzf_d.c
+++ b/lzf/lzf/lzf_d.c
@@ -43,12 +43,14 @@
 # define SET_ERRNO(n) errno = (n)
 #endif
 
+#ifndef __STRICT_ANSI__
 #if (__i386 || __amd64) && __GNUC__ >= 3
 # define lzf_movsb(dst, src, len)                \
    asm ("rep movsb"                              \
         : "=D" (dst), "=S" (src), "=c" (len)     \
         :  "0" (dst),  "1" (src),  "2" (len));
 #endif
+#endif
 
 unsigned int 
 lzf_decompress (const void *const in_data,  unsigned int in_len,
diff --git a/lzf/lzf_filter.h b/lzf/lzf_filter.h
index d24601f..7c3f54c 100644
--- a/lzf/lzf_filter.h
+++ b/lzf/lzf_filter.h
@@ -20,6 +20,9 @@
 
 #define H5PY_FILTER_LZF 315
 
+/* Register the filter with the library. Returns a negative value on failure, 
+   and a non-negative value on success.
+*/
 int register_lzf(void);
 
 #endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list