@@ -82,6 +82,50 @@ integer(c_int) function zmat_run(inputsize, inputbuf, outputsize, outputbuf, zip
8282 type (c_ptr),intent (out ) :: outputbuf
8383 end function zmat_run
8484
85+ !- -----------------------------------------------------------------------------
86+ ! > @brief Compression/decompression with an optional block index
87+ !
88+ ! > Identical to zmat_run except that zlib and gzip gain a threaded path. The
89+ ! > thread count is packed into the low bytes of "level" the same way the MATLAB
90+ ! > and Python bindings do: byte 0 is the compression level, byte 1 the thread
91+ ! > count. A thread count of 0 lets the library choose (ZMAT_DEFAULT_NTHREAD for
92+ ! > zlib and gzip); a negative one forces the historical single deflate stream.
93+ !
94+ ! > On compression the blocks are closed with Z_FULL_FLUSH so the result stays an
95+ ! > ordinary zlib/gzip stream any decompressor can read, and "offsets" receives a
96+ ! > malloc'ed index of "noffsets" size_t values, laid out as compressed0,
97+ ! > uncompressed0, compressed1, ... with a final sentinel pair. Release it with
98+ ! > zmat_free once done. Pass a c_ptr holding C_NULL_PTR to decline the index.
99+ !
100+ ! > On decompression, handing back that index inflates the blocks concurrently.
101+ ! > An index that does not describe the stream is rejected in favour of a serial
102+ ! > inflate, so a stale one costs time but never correctness.
103+ !
104+ ! > @param[in] inputsize: input stream buffer length
105+ ! > @param[in] inputbuf: input stream buffer pointer
106+ ! > @param[out] outputsize: output stream buffer length
107+ ! > @param[out] outputbuf: output stream buffer pointer
108+ ! > @param[in] zipid: compression method id
109+ ! > @param[out] ret: encoder/decoder specific detailed error code (if error occurs)
110+ ! > @param[in] level: packed compression level and thread count
111+ ! > @param[in,out] offsets: block index, see above
112+ ! > @param[in,out] noffsets: number of size_t entries in offsets
113+ ! > @return return the coarse grained zmat error code; detailed error code is in ret.
114+ !- -----------------------------------------------------------------------------
115+
116+ integer (c_int) function zmat_run_indexed(inputsize, inputbuf, outputsize, outputbuf, zipid, ret, level, &
117+ offsets, noffsets) bind(C)
118+ use iso_c_binding, only: c_char,c_size_t,c_int,c_ptr
119+ integer (c_size_t), value :: inputsize
120+ integer (c_int), value :: zipid, level
121+ integer (c_size_t), intent (out ) :: outputsize
122+ integer (c_int), intent (out ) :: ret
123+ type (c_ptr), value, intent (in ) :: inputbuf
124+ type (c_ptr),intent (out ) :: outputbuf
125+ type (c_ptr),intent (inout ) :: offsets
126+ integer (c_size_t),intent (inout ) :: noffsets
127+ end function zmat_run_indexed
128+
85129!- -----------------------------------------------------------------------------
86130! > @brief Simplified interface to perform compression, same as zmat_run(...,1)
87131!
0 commit comments