#include "zarrs.h" #include #include int main() { const char *tmp_path = getenv("TMP_PATH_WRITE_RUST_READ_C"); ZarrsStorage storage = nullptr; zarrs_assert(zarrsCreateStorageFilesystem(tmp_path, &storage)); assert(storage); ZarrsArray array = nullptr; zarrs_assert(zarrsOpenArrayRW(storage, "/array", &array)); assert(array); // Update a subset size_t subset_start[] = {1, 1}; size_t subset_shape[] = {2, 2}; float subset_elements[] = {-1.0f, -2.0f, -3.0f, -4.0f}; uint8_t *subset_bytes = reinterpret_cast(subset_elements); zarrs_assert(zarrsArrayStoreSubset(array, 2, subset_start, subset_shape, 4 * sizeof(float), subset_bytes)); // Get the chunk size size_t indices[] = {0, 0}; size_t chunk_size; zarrs_assert(zarrsArrayGetChunkSize(array, 2, indices, &chunk_size)); std::cout << chunk_size << std::endl; // Get chunk bytes std::unique_ptr chunk_bytes(new uint8_t[chunk_size]); zarrs_assert(zarrsArrayRetrieveChunk(array, 2, indices, chunk_size, chunk_bytes.get())); // Print the elements auto chunk_elements = reinterpret_cast(chunk_bytes.get()); for (size_t i = 0; i < chunk_size / sizeof(float); ++i) { std::cout << (i == 0 ? "" : " ") << chunk_elements[i]; } std::cout << std::endl; chunk_bytes.reset(); // Cleanup zarrs_assert(zarrsDestroyArray(array)); zarrs_assert(zarrsDestroyStorage(storage)); }