Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hdf5plugins
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
goebbert
hdf5plugins
Commits
2ed9d7a4
Commit
2ed9d7a4
authored
Aug 26, 2016
by
Jens Henrik Goebbert
Browse files
Options
Downloads
Patches
Plain Diff
finalize compress function
parent
377a2f35
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hdf5plugin_sz/src/sz_h5filter.cpp
+80
-77
80 additions, 77 deletions
hdf5plugin_sz/src/sz_h5filter.cpp
hdf5plugin_sz/src/sz_h5filter.h
+6
-0
6 additions, 0 deletions
hdf5plugin_sz/src/sz_h5filter.h
with
86 additions
and
77 deletions
hdf5plugin_sz/src/sz_h5filter.cpp
+
80
−
77
View file @
2ed9d7a4
...
@@ -72,12 +72,18 @@ const H5Z_class2_t SZ_H5Filter[1] = {{
...
@@ -72,12 +72,18 @@ const H5Z_class2_t SZ_H5Filter[1] = {{
H5PL_type_t
H5PL_type_t
H5PLget_plugin_type
(
void
)
H5PLget_plugin_type
(
void
)
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5PLget_plugin_type()."
);
#endif
return
H5PL_TYPE_FILTER
;
return
H5PL_TYPE_FILTER
;
}
}
const
void
*
const
void
*
H5PLget_plugin_info
(
void
)
H5PLget_plugin_info
(
void
)
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5PLget_plugin_info()."
);
#endif
return
SZ_H5Filter
;
return
SZ_H5Filter
;
}
}
...
@@ -98,6 +104,10 @@ H5PLget_plugin_info(void)
...
@@ -98,6 +104,10 @@ H5PLget_plugin_info(void)
herr_t
herr_t
H5Z_can_apply_sz
(
hid_t
dcpl_id
,
hid_t
type_id
,
hid_t
space_id
)
H5Z_can_apply_sz
(
hid_t
dcpl_id
,
hid_t
type_id
,
hid_t
space_id
)
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5Z_can_apply_sz()."
);
#endif
hid_t
dclass
;
hid_t
dclass
;
size_t
dsize
;
size_t
dsize
;
hid_t
dntype
;
hid_t
dntype
;
...
@@ -263,6 +273,10 @@ H5Z_can_apply_sz(hid_t dcpl_id, hid_t type_id, hid_t space_id)
...
@@ -263,6 +273,10 @@ H5Z_can_apply_sz(hid_t dcpl_id, hid_t type_id, hid_t space_id)
herr_t
herr_t
H5Z_set_local_sz
(
hid_t
dcpl_id
,
hid_t
type_id
,
hid_t
space_id
)
H5Z_set_local_sz
(
hid_t
dcpl_id
,
hid_t
type_id
,
hid_t
space_id
)
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5Z_set_local_sz()."
);
#endif
size_t
dsize
;
size_t
dsize
;
size_t
ndims
;
size_t
ndims
;
...
@@ -371,12 +385,16 @@ H5Z_filter_sz(unsigned int flags,
...
@@ -371,12 +385,16 @@ H5Z_filter_sz(unsigned int flags,
size_t
*
buf_size
,
// buffer size
size_t
*
buf_size
,
// buffer size
void
**
buf
)
// buffer
void
**
buf
)
// buffer
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5Z_filter_sz()."
);
#endif
unsigned
int
sz_major_ver
,
sz_minor_ver
;
unsigned
int
sz_major_ver
,
sz_minor_ver
;
size_t
dsize
;
size_t
dsize
;
size_t
ndims
;
size_t
ndims
;
size_t
buf_size_out
=
-
1
;
size_t
buf_size_out
=
-
1
;
size_
t
nbytes_out
=
-
1
;
in
t
nbytes_out
=
-
1
;
bool
dp
=
false
;
bool
dp
=
false
;
void
*
tmp_buf
=
NULL
;
void
*
tmp_buf
=
NULL
;
...
@@ -466,20 +484,19 @@ H5Z_filter_sz(unsigned int flags,
...
@@ -466,20 +484,19 @@ H5Z_filter_sz(unsigned int flags,
}
}
#ifndef NDEBUG
#ifndef NDEBUG
// fprintf(stdout, " H5Z_filter_sz: decompress: [%d, (%d, %d, %d), %d, %d, %d, %d,%d,%d,%d,%d,%lf,%lf] = %d \n",
fprintf
(
stdout
,
" H5Z_filter_sz: decompress: [%d, (%d, %d, %d, %d, %d), %d, %d, %d, %d,%d,%d,%d,%d,%lf,%lf] = %d
\n
"
,
// dp, nx, ny, nz,
dp
,
n
[
0
],
n
[
1
],
n
[
2
],
n
[
3
],
n
[
4
],
// params.dataEndianType,
params
.
dataEndianType
,
// params.sol_ID,
params
.
sol_ID
,
// params.offset,
params
.
offset
,
// params.gzipMode,
params
.
gzipMode
,
// params.maxSegmentNum,
params
.
maxSegmentNum
,
// params.spaceFillingCurveTransform,
params
.
spaceFillingCurveTransform
,
// params.reOrgSize,
params
.
reOrgSize
,
// params.errorBoundMode,
params
.
errorBoundMode
,
// params.absErrBound,
params
.
absErrBound
,
// params.relBoundRatio,
params
.
relBoundRatio
,
// (int)buf_size_in);
(
int
)
buf_size_in
);
#endif
#endif
// buf[header_bytes+] -> out_buf
// buf[header_bytes+] -> out_buf
...
@@ -509,23 +526,6 @@ H5Z_filter_sz(unsigned int flags,
...
@@ -509,23 +526,6 @@ H5Z_filter_sz(unsigned int flags,
// compress data
// compress data
}
else
{
}
else
{
// 00 - version >> 4; /* major version */
// 01 - version & 0x000f; /* minor version */
// 02 - dsize; /* bytes per element */
// 03 - ndims; /* number of dimensions */
// -------------
// 04 - size of dim 1
// 05 - size of dim 2
// 06 - size of dim 3
// 07 - size of dim 4
// 08 - size of dim 5
// -------------
// x+00 - params.errorBoundMode = REL;
// x+01 - params.absErrBound_ppm
// x+02 - params.relBoundRatio_ppm
// x+03 - params.gzipMode
// x+04 - threshold = 64 (no compression below 64 byte)
// compression parameter (0 == no compression)
// compression parameter (0 == no compression)
sz_params
params
;
sz_params
params
;
params
.
errorBoundMode
=
cd_values
[
4
+
ndims
+
0
];
params
.
errorBoundMode
=
cd_values
[
4
+
ndims
+
0
];
...
@@ -550,62 +550,62 @@ H5Z_filter_sz(unsigned int flags,
...
@@ -550,62 +550,62 @@ H5Z_filter_sz(unsigned int flags,
}
}
// ptr to data (skipping header)
// ptr to data (skipping header)
sz_buf
=
(
char
*
)
tmp_buf
+
header_bytes
;
sz_buf
=
(
char
*
)
tmp_buf
+
header_bytes
;
/* skip header */
int
SZ_compress_args2
(
int
dataType
,
void
*
data
,
char
*
compressed_bytes
,
int
*
outSize
,
int
errBoundMode
,
double
absErrBound
,
double
relBoundRatio
,
int
r5
,
int
r4
,
int
r3
,
int
r2
,
int
r1
);
// int SZ_compress_args(
if
(
SZ_compress_args2
(
// int dataType, SZ_FLOAT or SZ_DOUBLE (float not supported, yet)
// void *data,
// char* compressed_bytes,
// int *outSize,
// int errBoundMode, ABS, REL, ABS_AND_REL, ABS_OR_REL
// double absErrBound,
// double relBoundRatio,
// int r5, int r4, int r3, int r2, int r1); =0 if dim not required
// return 1 on failure, 0 on success
// if(SZ_compress_args() != 0) {
((
typesize
==
8
)
?
SZ_DOUBLE
:
SZ_FLOAT
),
/* dataType */
((
typesize
==
8
)
?
SZ_DOUBLE
:
SZ_FLOAT
),
/* dataType */
(
char
*
)
sz_buf
,
/* compressed data */
*
buf
,
/* data */
nbytes
header_bytes
,
/* length of the compressed data stream */
(
char
*
)
sz_buf
,
/* compressed floating-point data */
out_buf
,
/* decompressed floating-point data */
&
nbytes_out
,
/* data stream size (in bytes) after compression */
params
.
errorBoundMode
,
params
.
absErrBound
,
params
.
relBoundRatio
,
n
[
4
],
n
[
3
],
n
[
2
],
n
[
1
],
n
[
0
]
/* size of dimension 5-1 */
n
[
4
],
n
[
3
],
n
[
2
],
n
[
1
],
n
[
0
]
/* size of dimension 5-1 */
)
!=
0
)
{
/* 1 (failure) or 0 (success) */
//
PUSH_ERR("H5Z_filter_sz", H5E_CALLBACK, "compression failed");
PUSH_ERR
(
"H5Z_filter_sz"
,
H5E_CALLBACK
,
"compression failed"
);
//
free(out_buf);
free
(
out_buf
);
//
return 0;
return
0
;
//
}
}
#ifndef NDEBUG
#ifndef NDEBUG
// fprintf(stdout, " H5Z_filter_sz: compress(out): [%d, (%d, %d, %d), %d, %d, %d, %d] = %d \n",
fprintf
(
stdout
,
" H5Z_filter_sz: compress: [%d, (%d, %d, %d, %d, %d), %d, %d, %d, %d,%d,%d,%d,%d,%lf,%lf] = %d
\n
"
,
// dp, nx, ny, nz,
dp
,
n
[
0
],
n
[
1
],
n
[
2
],
n
[
3
],
n
[
4
],
// params.minbits, params.maxbits, params.maxprec, params.minexp,
params
.
dataEndianType
,
// (int)buf_size_out);
params
.
sol_ID
,
params
.
offset
,
params
.
gzipMode
,
params
.
maxSegmentNum
,
params
.
spaceFillingCurveTransform
,
params
.
reOrgSize
,
params
.
errorBoundMode
,
params
.
absErrBound
,
params
.
relBoundRatio
,
(
int
)
buf_size_out
);
#endif
#endif
// add 22byte header
// add 22byte header
sz_write_uint8
((
char
*
)
tmp_buf
+
1
,
(
uint8_t
)
params
.
dataEndianType
);
sz_write_uint8
((
char
*
)
tmp_buf
+
2
,
(
uint8_t
)
params
.
errorBoundMode
);
sz_write_uint8
((
char
*
)
tmp_buf
+
1
,
(
uint8_t
)
params
.
dataEndianType
sz_write_int32
((
char
*
)
tmp_buf
+
3
,
(
int32_t
)
params
.
absErrBound
);
sz_write_uint8
((
char
*
)
tmp_buf
+
2
,
(
uint8_t
)
params
.
errorBoundMode
sz_write_int32
((
char
*
)
tmp_buf
+
7
,
(
int32_t
)
params
.
relBoundRatio
);
sz_write_int32
((
char
*
)
tmp_buf
+
3
,
(
int32_t
)
params
.
absErrBound
sz_write_uint8
((
char
*
)
tmp_buf
+
11
,
(
uint8_t
)
params
.
gzipMode
);
sz_write_int32
((
char
*
)
tmp_buf
+
7
,
(
int32_t
)
params
.
relBoundRatio
sz_write_uint8
((
char
*
)
tmp_buf
+
12
,
(
uint8_t
)
params
.
offset
);
sz_write_uint8
((
char
*
)
tmp_buf
+
11
,
(
uint8_t
)
params
.
gzipMode
sz_write_int32
((
char
*
)
tmp_buf
+
13
,
(
int32_t
)
params
.
maxSegmentNum
);
sz_write_uint8
((
char
*
)
tmp_buf
+
12
,
(
uint8_t
)
params
.
offset
sz_write_uint8
((
char
*
)
tmp_buf
+
17
,
(
uint8_t
)
params
.
spaceFillingCurveTransform
);
sz_write_int32
((
char
*
)
tmp_buf
+
13
,
(
int32_t
)
params
.
maxSegmentNum
sz_write_int32
((
char
*
)
tmp_buf
+
18
,
(
int32_t
)
params
.
reOrgSize
);
sz_write_uint8
((
char
*
)
tmp_buf
+
17
,
(
uint8_t
)
params
.
spaceFillingCurveTransform
sz_write_int32
((
char
*
)
tmp_buf
+
18
,
(
int32_t
)
params
.
reOrgSize
nbytes_out
=
buf_size_out
+
header_bytes
;
nbytes_out
=
buf_size_out
+
header_bytes
;
// realloc (free partly) if required
// realloc (free partly) if required
//
if(buf_size_out < buf_size_maxout) {
if
(
buf_size_out
<
buf_size_maxout
)
{
//
out_buf = realloc(tmp_buf, nbytes_out); // free out_buf partly (which was not used by SZ::compress(..))
out_buf
=
realloc
(
tmp_buf
,
nbytes_out
);
// free out_buf partly (which was not used by SZ::compress(..))
//
if (out_buf == NULL) {
if
(
out_buf
==
NULL
)
{
//
PUSH_ERR("H5Z_filter_sz", H5E_CALLBACK, "Could not reallocate output buffer.");
PUSH_ERR
(
"H5Z_filter_sz"
,
H5E_CALLBACK
,
"Could not reallocate output buffer."
);
//
return 0;
return
0
;
//
}
}
//
} else {
}
else
{
//
out_buf = tmp_buf;
out_buf
=
tmp_buf
;
//
}
}
}
}
/* flip buffer and return
/* flip buffer and return
...
@@ -630,4 +630,7 @@ H5Z_filter_sz(unsigned int flags,
...
@@ -630,4 +630,7 @@ H5Z_filter_sz(unsigned int flags,
int
int
H5Z_register_sz
(
void
)
H5Z_register_sz
(
void
)
{
{
#ifndef NDEBUG
fprintf
(
stdout
,
" H5Z_filter_sz: called H5Z_register_sz()."
);
#endif
}
}
This diff is collapsed.
Click to expand it.
hdf5plugin_sz/src/sz_h5filter.h
+
6
−
0
View file @
2ed9d7a4
...
@@ -150,4 +150,10 @@ uint8_t sz_read_uint8(void* buf) {
...
@@ -150,4 +150,10 @@ uint8_t sz_read_uint8(void* buf) {
return
num
;
return
num
;
}
}
/* write a 8 bit unsigned integer to a buffer in big endian order. */
void
sz_write_uint8
(
void
*
buf
,
uint8_t
num
)
{
uint8_t
*
b
=
static_cast
<
uint8_t
*>
(
buf
);
b
[
0
]
=
num
;
}
#endif // SZ_H5FILTER_H
#endif // SZ_H5FILTER_H
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment