5
5
*/
6
6
7
7
#include <assert.h>
8
- #include <binsparse/binsparse .h>
8
+ #include <binsparse/binsparse_all .h>
9
9
#include <binsparse/matrix.h>
10
10
#include <cJSON/cJSON.h>
11
11
#include <unistd.h>
@@ -87,8 +87,9 @@ char* bsp_generate_json(bsp_matrix_t matrix, cJSON* user_json) {
87
87
return string ;
88
88
}
89
89
90
- bsp_error_t bsp_write_matrix_to_group (hid_t f , bsp_matrix_t matrix ,
91
- cJSON * user_json , int compression_level ) {
90
+ bsp_error_t bsp_write_matrix_to_group_cjson (hid_t f , bsp_matrix_t matrix ,
91
+ cJSON * user_json ,
92
+ int compression_level ) {
92
93
bsp_error_t error =
93
94
bsp_write_array (f , (char * ) "values" , matrix .values , compression_level );
94
95
if (error != BSP_SUCCESS ) {
@@ -131,13 +132,26 @@ bsp_error_t bsp_write_matrix_to_group(hid_t f, bsp_matrix_t matrix,
131
132
return BSP_SUCCESS ;
132
133
}
133
134
134
- bsp_error_t bsp_write_matrix (const char * fname , bsp_matrix_t matrix ,
135
- const char * group , cJSON * user_json ,
136
- int compression_level ) {
135
+ bsp_error_t bsp_write_matrix_to_group (hid_t f , bsp_matrix_t matrix ,
136
+ const char * user_json ,
137
+ int compression_level ) {
138
+ cJSON * user_json_cjson = cJSON_Parse (user_json );
139
+ if (user_json_cjson == NULL ) {
140
+ return BSP_ERROR_FORMAT ;
141
+ }
142
+ bsp_error_t error = bsp_write_matrix_to_group_cjson (
143
+ f , matrix , user_json_cjson , compression_level );
144
+ cJSON_Delete (user_json_cjson );
145
+ return error ;
146
+ }
147
+
148
+ bsp_error_t bsp_write_matrix_cjson (const char * fname , bsp_matrix_t matrix ,
149
+ const char * group , cJSON * user_json ,
150
+ int compression_level ) {
137
151
if (group == NULL ) {
138
152
hid_t f = H5Fcreate (fname , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT );
139
- bsp_error_t error =
140
- bsp_write_matrix_to_group ( f , matrix , user_json , compression_level );
153
+ bsp_error_t error = bsp_write_matrix_to_group_cjson ( f , matrix , user_json ,
154
+ compression_level );
141
155
if (error != BSP_SUCCESS ) {
142
156
H5Fclose (f );
143
157
return error ;
@@ -151,8 +165,8 @@ bsp_error_t bsp_write_matrix(const char* fname, bsp_matrix_t matrix,
151
165
f = H5Fcreate (fname , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT );
152
166
}
153
167
hid_t g = H5Gcreate1 (f , group , H5P_DEFAULT );
154
- bsp_error_t error =
155
- bsp_write_matrix_to_group ( g , matrix , user_json , compression_level );
168
+ bsp_error_t error = bsp_write_matrix_to_group_cjson ( g , matrix , user_json ,
169
+ compression_level );
156
170
if (error != BSP_SUCCESS ) {
157
171
H5Gclose (g );
158
172
H5Fclose (f );
@@ -163,3 +177,16 @@ bsp_error_t bsp_write_matrix(const char* fname, bsp_matrix_t matrix,
163
177
}
164
178
return BSP_SUCCESS ;
165
179
}
180
+
181
+ bsp_error_t bsp_write_matrix (const char * fname , bsp_matrix_t matrix ,
182
+ const char * group , const char * user_json ,
183
+ int compression_level ) {
184
+ cJSON * user_json_cjson = cJSON_Parse (user_json );
185
+ if (user_json_cjson == NULL ) {
186
+ return BSP_ERROR_FORMAT ;
187
+ }
188
+ bsp_error_t error = bsp_write_matrix_cjson (
189
+ fname , matrix , group , user_json_cjson , compression_level );
190
+ cJSON_Delete (user_json_cjson );
191
+ return error ;
192
+ }
0 commit comments