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..43f6808 --- /dev/null +++ b/test_attributes.c @@ -0,0 +1,109 @@ +#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" @@ -10,6 +11,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; @@ -124,6 +133,129 @@ 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 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 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 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 9713bd0..71cc6d5 100644 --- a/z5wrapper.h +++ b/z5wrapper.h @@ -11,7 +11,9 @@ #ifdef __cplusplus #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 @@ -20,7 +22,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); @@ -37,7 +40,29 @@ 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 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 } }