1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * All rights reserved. *
4 * *
5 * This file is part of HDF5. The full HDF5 copyright notice, including *
6 * terms governing use, modification, and redistribution, is contained in *
7 * the COPYING file, which can be found at the root of the source code *
8 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
9 * If you do not have access to either file, you may request a copy from *
10 * help@hdfgroup.org. *
11 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13 /*
14 * Purpose: Test dataset filter plugin for the filter_pluging.c test.
15 */
16
17
18 #include <stdlib.h>
19 #include <stdio.h>
20
21 #include "H5PLextern.h"
22
23 #define FILTER1_ID 257
24
25 static size_t add_sub_value(unsigned int flags, size_t cd_nelmts,
26 const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf);
27
28 /* Filter class struct */
29 const H5Z_class2_t FILTER_INFO[1] = {{
30 H5Z_CLASS_T_VERS, /* H5Z_class_t version */
31 FILTER1_ID, /* Filter ID number */
32 1, /* Encoding enabled */
33 1, /* Decoding enabled */
34 "test filter plugin 1", /* Filter name for debugging */
35 NULL, /* The "can apply" callback */
36 NULL, /* The "set local" callback */
37 (H5Z_func_t)add_sub_value, /* The actual filter function */
38 }};
39
H5PLget_plugin_type(void)40 H5PL_type_t H5PLget_plugin_type(void) {return H5PL_TYPE_FILTER;}
H5PLget_plugin_info(void)41 const void *H5PLget_plugin_info(void) {return FILTER_INFO;}
42
43
44 /*-------------------------------------------------------------------------
45 * Function: add_sub_value
46 *
47 * Purpose: On write:
48 * Adds a caller-supplied value to the element
49 * On read:
50 * Subtracts a caller-supplied value from the element
51 *
52 * Return: Success: Data chunk size in bytes
53 * Failure: 0
54 *
55 *-------------------------------------------------------------------------
56 */
57 static size_t
add_sub_value(unsigned int flags,size_t cd_nelmts,const unsigned int * cd_values,size_t nbytes,size_t * buf_size,void ** buf)58 add_sub_value(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values,
59 size_t nbytes, size_t *buf_size, void **buf)
60 {
61 int *int_ptr = (int *)*buf; /* Pointer to the data values */
62 size_t buf_left = *buf_size; /* Amount of data buffer left to process */
63 int value = 0; /* Data value to add/subtract */
64
65 /* Check for the correct number of parameters */
66 if (0 == cd_nelmts)
67 return 0;
68
69 /* Check that permanent parameters are set correctly */
70 if (cd_values[0] > 9)
71 return 0;
72
73 value = (int)cd_values[0];
74
75 if (flags & H5Z_FLAG_REVERSE) {
76 /* READ - Substract the given value from all the data values */
77 while (buf_left > 0) {
78 *int_ptr++ -= value;
79 buf_left -= sizeof(int);
80 }
81 }
82 else {
83 /* WRITE - Add the given value to all the data values */
84 while (buf_left > 0) {
85 *int_ptr++ += value;
86 buf_left -= sizeof(int);
87 }
88 }
89
90 return nbytes;
91
92 } /* end add_sub_value() */
93
94