From 274bc379faca9ba48a1b98e4f2b8a7514567e7b3 Mon Sep 17 00:00:00 2001 From: Weile Wei Date: Tue, 4 Jun 2019 15:50:26 -0600 Subject: [PATCH 1/3] add write file support --- z5wrapper.cc | 8 ++++++++ z5wrapper.h | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/z5wrapper.cc b/z5wrapper.cc index fccd30f..ff5dadb 100644 --- a/z5wrapper.cc +++ b/z5wrapper.cc @@ -10,6 +10,14 @@ namespace fs = boost::filesystem; namespace z5 { extern "C" { + void z5CreateFile(char* path) + { + std::string path_s(path); + bool asZarr = true; + handle::File cFile(path_s); + createFile(cFile, asZarr); + } + void z5CreateGroup(char* path) { std::string path_s(path); bool asZarr = true; diff --git a/z5wrapper.h b/z5wrapper.h index 9713bd0..a4a50b9 100644 --- a/z5wrapper.h +++ b/z5wrapper.h @@ -11,6 +11,7 @@ #ifdef __cplusplus #include "z5/dataset_factory.hxx" +#include "z5/file.hxx" #include "z5/groups.hxx" #include "z5/compression/zlib_compressor.hxx" #include "z5/types/types.hxx" @@ -20,7 +21,8 @@ namespace z5 { extern "C" { #endif - + void z5CreateFile(char* path); + void z5CreateGroup(char* path); void z5CreateFloatDataset(char *path, unsigned int ndim, size_t *shape, size_t *chunks, int cuseZlib, int level); From 299dc32b0efb301310ab04bfea71e04d479ff237 Mon Sep 17 00:00:00 2001 From: Weile Wei Date: Wed, 5 Jun 2019 15:44:52 -0600 Subject: [PATCH 2/3] add write attributes --- CMakeLists.txt | 3 ++ test_attributes.c | 94 ++++++++++++++++++++++++++++++++++++++ z5wrapper.cc | 113 ++++++++++++++++++++++++++++++++++++++++++++++ z5wrapper.h | 23 +++++++++- 4 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 test_attributes.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e675305..e7f1195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,9 @@ target_link_libraries(test_cpp LINK_PUBLIC ${TEST_LIBS} ${COMPRESSION_LIBRARIES} add_executable(test_c main.c z5wrapper.cc) target_link_libraries(test_c LINK_PUBLIC ${TEST_LIBS} ${COMPRESSION_LIBRARIES}) +add_executable(test_attributes test_attributes.c z5wrapper.cc) +target_link_libraries(test_attributes LINK_PUBLIC ${TEST_LIBS} ${COMPRESSION_LIBRARIES}) + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/z5wrapper.h" DESTINATION "${CMAKE_INSTALL_PREFIX}/include") diff --git a/test_attributes.c b/test_attributes.c new file mode 100644 index 0000000..b4fc0c1 --- /dev/null +++ b/test_attributes.c @@ -0,0 +1,94 @@ +#include +#include +#include "z5wrapper.h" + +void my_create_dataset(char* arrayName) +{ + size_t shape[] = {20, 20, 20}; + size_t chunks[] = {10, 10, 10}; + size_t offset[] = {0, 0, 0}; + size_t offset2[] = {10, 10, 10}; + float data1[10][10][10]; + float data2[10][10][10]; + float rdata[10][10][10]; + long long int idata1[10][10][10]; + long long int idata2[10][10][10]; + long long int irdata[10][10][10]; + unsigned int ndim = 3; + for (int i = 0; i < chunks[0]; i++){ + for (int j = 0; j < chunks[1]; j++){ + for (int k = 0; k +#include #include #include #include "z5wrapper.h" @@ -132,6 +133,118 @@ namespace z5 { file.close(); return fileSize; } + + void z5writeAttributesString(char *path, const char *name, const char *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + std::string value_s(value); + j[name_s] = value_s; + writeAttributes(cHandle, j); + } + + void z5writeAttributesshort(char *path, const char *name, const short *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesint(char *path, const char *name, const int *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributeslong(char *path, const char *name, const long *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesfloat(char *path, const char *name, const float *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (double) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesdouble(char *path, const char *name, const double *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesushort(char *path, const char *name, const unsigned short *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesusint(char *path, const char *name, const unsigned int *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributeslonglong(char *path, const char *name, const long long *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + + void z5writeAttributesulonglong(char *path, const char *name, const unsigned long long *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + void z5Delete(char *path ){ std::string path_s(path); fs::path filename(path_s); diff --git a/z5wrapper.h b/z5wrapper.h index a4a50b9..0aff078 100644 --- a/z5wrapper.h +++ b/z5wrapper.h @@ -13,6 +13,7 @@ #include "z5/dataset_factory.hxx" #include "z5/file.hxx" #include "z5/groups.hxx" +#include "z5/attributes.hxx" #include "z5/compression/zlib_compressor.hxx" #include "z5/types/types.hxx" #endif @@ -39,7 +40,27 @@ namespace z5 { size_t z5GetFileSize(char *path); - void z5Delete(char *path ); + void z5writeAttributesString(char *path, const char *name, const char *value); + + void z5writeAttributesshort(char *path, const char *name, const short *value); + + void z5writeAttributesint(char *path, const char *name, const int *value); + + void z5writeAttributeslong(char *path, const char *name, const long *value); + + void z5writeAttributesfloat(char *path, const char *name, const float *value); + + void z5writeAttributesdouble(char *path, const char *name, const double *value); + + void z5writeAttributesushort(char *path, const char *name, const unsigned short *value); + + void z5writeAttributesusint(char *path, const char *name, const unsigned int *value); + + void z5writeAttributeslonglong(char *path, const char *name, const long long *value); + + void z5writeAttributesulonglong(char *path, const char *name, const unsigned long long *value); + + void z5Delete(char *path ); #ifdef __cplusplus } } From 2baa5a035237899cab64e6e38d3632a25042da07 Mon Sep 17 00:00:00 2001 From: Weile Wei Date: Wed, 5 Jun 2019 16:20:20 -0600 Subject: [PATCH 3/3] add more tests for write attributes --- test_attributes.c | 17 ++++++++++++++++- z5wrapper.cc | 13 ++++++++++++- z5wrapper.h | 4 +++- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/test_attributes.c b/test_attributes.c index b4fc0c1..43f6808 100644 --- a/test_attributes.c +++ b/test_attributes.c @@ -66,9 +66,24 @@ void my_create_dataset(char* arrayName) long int longval = 42; z5writeAttributeslong(arrayName, "long", &longval); + long long longlongval = 42; + z5writeAttributeslonglong(arrayName, "longlong", &longlongval); + + unsigned long long ulonglongval = 42; + z5writeAttributesulonglong(arrayName, "ulonglong", &ulonglongval); + unsigned short ushortval = 42; z5writeAttributesushort(arrayName, "unshort", &ushortval); - + + unsigned int uint = 42; + z5writeAttributesuint(arrayName, "uint", &uint); + + unsigned short usint = 42; + z5writeAttributesusint(arrayName, "usint", &usint); + + short shortint = 42; + z5writeAttributesshort(arrayName, "short", &shortint); + printf("after assert\n"); } diff --git a/z5wrapper.cc b/z5wrapper.cc index ed5d4a7..fd0f7b9 100644 --- a/z5wrapper.cc +++ b/z5wrapper.cc @@ -212,7 +212,7 @@ namespace z5 { writeAttributes(cHandle, j); } - void z5writeAttributesusint(char *path, const char *name, const unsigned int *value) + void z5writeAttributesusint(char *path, const char *name, const unsigned short *value) { std::string path_s(path); bool asZarr = true; @@ -245,6 +245,17 @@ namespace z5 { writeAttributes(cHandle, j); } + void z5writeAttributesuint(char *path, const char *name, const unsigned int *value) + { + std::string path_s(path); + bool asZarr = true; + handle::Handle cHandle(path_s); + nlohmann::json j; + std::string name_s(name); + j[name_s] = (int64_t) *value; + writeAttributes(cHandle, j); + } + void z5Delete(char *path ){ std::string path_s(path); fs::path filename(path_s); diff --git a/z5wrapper.h b/z5wrapper.h index 0aff078..71cc6d5 100644 --- a/z5wrapper.h +++ b/z5wrapper.h @@ -54,12 +54,14 @@ namespace z5 { void z5writeAttributesushort(char *path, const char *name, const unsigned short *value); - void z5writeAttributesusint(char *path, const char *name, const unsigned int *value); + void z5writeAttributesusint(char *path, const char *name, const unsigned short int *value); void z5writeAttributeslonglong(char *path, const char *name, const long long *value); void z5writeAttributesulonglong(char *path, const char *name, const unsigned long long *value); + void z5writeAttributesuint(char *path, const char *name, const unsigned int *value); + void z5Delete(char *path ); #ifdef __cplusplus }