diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..1b8aa883ff --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..bcea48e8bd --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,97 @@ +{ + "cmake.configureSettings": { + "CMAKE_INSTALL_PREFIX": "/Users/eschnett/openpmd-api", + "CMAKE_OSX_DEPLOYMENT_TARGET": "14.0", + "openPMD_USE_ADIOS2": "OFF", + "openPMD_USE_JULIA": "OFF", + "openPMD_USE_PYTHON": "OFF" + }, + "files.associations": { + "*.tpp": "cpp", + "__bit_reference": "cpp", + "__config": "cpp", + "__debug": "cpp", + "__errc": "cpp", + "__hash_table": "cpp", + "__locale": "cpp", + "__mutex_base": "cpp", + "__node_handle": "cpp", + "__split_buffer": "cpp", + "__threading_support": "cpp", + "__tree": "cpp", + "__verbose_abort": "cpp", + "array": "cpp", + "atomic": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "charconv": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "complex": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "exception": "cpp", + "forward_list": "cpp", + "fstream": "cpp", + "future": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "ios": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "mutex": "cpp", + "new": "cpp", + "numbers": "cpp", + "optional": "cpp", + "ostream": "cpp", + "queue": "cpp", + "ratio": "cpp", + "regex": "cpp", + "set": "cpp", + "sstream": "cpp", + "stack": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "thread": "cpp", + "tuple": "cpp", + "typeindex": "cpp", + "typeinfo": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "valarray": "cpp", + "variant": "cpp", + "vector": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "chrono": "cpp", + "compare": "cpp", + "concepts": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "format": "cpp" + } +} diff --git a/BUILD.sh b/BUILD.sh new file mode 100644 index 0000000000..6cf890bf3b --- /dev/null +++ b/BUILD.sh @@ -0,0 +1,35 @@ +# Build locally (just to test) +( + cd ~/src/openPMD-api + cmake --build config --verbose && cmake --install config --verbose +) + +# Commit +( + cd ~/src/openPMD-api + git add src && git commit -m 'Make changes' && git push + commit=$(git log | head -n 1 | awk '{ print $2; }') + sha256=$(echo $(wget https://github.com/eschnett/openPMD-api/archive/$commit.tar.gz && sha256sum $commit.tar.gz | awk '{ print $1; }' && rm $commit.tar.gz)) + echo $commit + echo $sha256 +) + +# Build in Yggdrasil +( + cd ~/src/Yggdrasil/O/openPMD_api + julia --color=yes build_tarballs.jl --debug --verbose --deploy=local x86_64-apple-darwin-libgfortran5 +) + +# Commit in local repo +( + cd ~/.julia/dev/openPMD_api_jll + git add . && git commit -m 'Update generated package' +) + +# Test in Julia +# julia +1.6 --eval 'using openPMD' +julia +1.7 --eval 'using openPMD' +julia +1.8 --eval 'using openPMD' +julia +1.9 --eval 'using openPMD' +julia +1.10 --eval 'using openPMD' +julia +dev --eval 'using openPMD' diff --git a/BUILD.txt b/BUILD.txt new file mode 100644 index 0000000000..d769c26e3d --- /dev/null +++ b/BUILD.txt @@ -0,0 +1,21 @@ +cd $HOME/src/ADIOS2 +rm -rf config $HOME/ADIOS2 +cmake -S . -B config -G Ninja -DCMAKE_C_COMPILER=mpicc-openmpi-mp -DCMAKE_CXX_COMPILER=mpicxx-openmpi-mp -DCMAKE_Fortran_COMPILER=mpif90-openmpi-mp -DADIOS2_USE_HDF5=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/ADIOS2 +cmake --build config --verbose && cmake --install config --verbose + +cd $HOME/src/libcxxwrap-julia +rm -rf config $HOME/libcxxwrap-julia +cmake -S . -B config -G Ninja -DCMAKE_C_COMPILER=mpicc-openmpi-mp -DCMAKE_CXX_COMPILER=mpicxx-openmpi-mp -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/libcxxwrap-julia +cmake --build config --verbose && cmake --install config --verbose + +cd $HOME/src/openPMD-api +rm -rf config $HOME/openPMD-api +cmake -S . -B config -G Ninja -DCMAKE_C_COMPILER=mpicc-openmpi-mp -DCMAKE_CXX_COMPILER=mpicxx-openmpi-mp -DCMAKE_PREFIX_PATH="$HOME/ADIOS2;$HOME/libcxxwrap-julia" -DopenPMD_USE_ADIOS2=ON -DopenPMD_USE_JULIA=ON -DopenPMD_USE_HDF5=OFF -DopenPMD_USE_PYTHON=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/openPMD-api +cmake --build config --verbose && cmake --install config --verbose + + + +cd $HOME/src/openPMD-api +rm -rf config $HOME/openPMD-api +cmake -S . -B config -G Ninja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_PREFIX_PATH="$HOME/ADIOS2;$HOME/libcxxwrap-julia" -DopenPMD_USE_HDF5=OFF -DopenPMD_USE_JULIA=ON -DopenPMD_USE_PYTHON=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=$HOME/openPMD-api +cmake --build config --verbose && cmake --install config --verbose diff --git a/CMakeLists.txt b/CMakeLists.txt index c57e3b7fe6..94325778db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,7 @@ endfunction() openpmd_option(MPI "Parallel, Multi-Node I/O for clusters" AUTO) openpmd_option(HDF5 "HDF5 backend (.h5 files)" AUTO) openpmd_option(ADIOS2 "ADIOS2 backend (.bp files)" AUTO) +openpmd_option(C "Enable C bindings" ON) openpmd_option(PYTHON "Enable Python bindings" AUTO) option(openPMD_INSTALL "Add installation targets" ON) @@ -379,6 +380,12 @@ else() endif() unset(openPMD_REQUIRED_ADIOS2_COMPONENTS) +if(openPMD_USE_C) + set(openPMD_HAVE_C TRUE) +else() + set(openPMD_HAVE_C FALSE) +endif() + # external library: pybind11 (optional) include(${openPMD_SOURCE_DIR}/cmake/dependencies/pybind11.cmake) @@ -538,6 +545,64 @@ else() target_compile_definitions(openPMD PRIVATE openPMD_USE_VERIFY=0) endif() +# C bindings +if(openPMD_HAVE_C) + add_library(openPMD.c ${_openpmd_lib_type} + src/binding/c/ChunkInfo.cpp + src/binding/c/Container_Iteration.cpp + src/binding/c/Container_Mesh.cpp + src/binding/c/Datatype.cpp + src/binding/c/IO/Access.cpp + src/binding/c/IO/Format.cpp + src/binding/c/Iteration.cpp + src/binding/c/Mesh.cpp + src/binding/c/ReadIterations.cpp + src/binding/c/RecordComponent.cpp + src/binding/c/Series.cpp + src/binding/c/UnitDimension.cpp + src/binding/c/WriteIterations.cpp + src/binding/c/backend/Attributable.c + src/binding/c/backend/Attributable.cpp + #TODO src/binding/c/backend/Attribute.cpp + src/binding/c/backend/BaseRecordComponent.cpp + src/binding/c/backend/Container_MeshRecordComponent.cpp + src/binding/c/backend/MeshRecordComponent.cpp + src/binding/c/version.cpp + ) + target_compile_features(openPMD.c PUBLIC c_std_99) + target_compile_features(openPMD.c PRIVATE cxx_std_17) + target_compile_options(openPMD.c PUBLIC ${_msvc_options}) + target_link_libraries(openPMD.c PRIVATE openPMD) + if(openPMD_HAVE_MPI) + target_link_libraries(openPMD.c PUBLIC ${openPMD_MPI_TARGETS}) + endif() + set_target_properties(openPMD.c PROPERTIES + C_EXTENSIONS OFF + C_STANDARD_VERSION 99 + C_STANDARD_REQUIRED ON + # # Allow C++ extensions since we read C header code into C++ + # # code and C99 `_Complex` counts as C++ extension + # CXX_EXTENSIONS ON + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON + + COMPILE_PDB_NAME openPMD + ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY} + RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY} + PDB_OUTPUT_DIRECTORY ${openPMD_PDB_OUTPUT_DIRECTORY} + COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_COMPILE_PDB_OUTPUT_DIRECTORY} + POSITION_INDEPENDENT_CODE ON + WINDOWS_EXPORT_ALL_SYMBOLS ON + ) + + target_include_directories(openPMD.c PUBLIC + $ + $ + $ + ) +endif() + # python bindings if(openPMD_HAVE_PYTHON) add_library(openPMD.py MODULE @@ -668,6 +733,10 @@ set(openPMD_TEST_NAMES ParallelIO JSON ) +set(openPMD_C_TEST_NAMES + C +) + # command line tools set(openPMD_CLI_TOOL_NAMES ls @@ -814,6 +883,25 @@ if(openPMD_BUILD_TESTING) $) endif() endforeach() + + if(openPMD_HAVE_C) + foreach(testname ${openPMD_C_TEST_NAMES}) + add_executable(${testname}Tests test/c/${testname}Test.c) + target_compile_features(${testname}Tests PUBLIC c_std_99) + target_link_libraries(${testname}Tests PRIVATE openPMD.c) + set_target_properties(${testname}Tests PROPERTIES + C_EXTENSIONS OFF + C_STANDARD_REQUIRED ON + + COMPILE_PDB_NAME ${testname}Tests + ARCHIVE_OUTPUT_DIRECTORY ${openPMD_ARCHIVE_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY ${openPMD_LIBRARY_OUTPUT_DIRECTORY} + RUNTIME_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY} + PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY} + COMPILE_PDB_OUTPUT_DIRECTORY ${openPMD_RUNTIME_OUTPUT_DIRECTORY} + ) + endforeach() + endif() endif() if(openPMD_BUILD_CLI_TOOLS) @@ -1026,6 +1114,9 @@ if(openPMD_INSTALL) RUNTIME DESTINATION ${openPMD_INSTALL_BINDIR} INCLUDES DESTINATION ${openPMD_INSTALL_INCLUDEDIR} ) + if(openPMD_HAVE_C) + install(TARGETS openPMD.c DESTINATION ${openPMD_INSTALL_LIBDIR}) + endif() if(openPMD_HAVE_PYTHON) install( DIRECTORY ${openPMD_SOURCE_DIR}/src/binding/python/openpmd_api @@ -1052,6 +1143,13 @@ if(openPMD_INSTALL) PATTERN "*.hpp" PATTERN "*.tpp" ) + if(openPMD_HAVE_C) + install(DIRECTORY "${openPMD_SOURCE_DIR}/include/openPMD" + DESTINATION ${openPMD_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) + endif() install( FILES ${openPMD_BINARY_DIR}/include/openPMD/config.hpp DESTINATION ${openPMD_INSTALL_INCLUDEDIR}/openPMD diff --git a/include/openPMD/binding/c/ChunkInfo.h b/include/openPMD/binding/c/ChunkInfo.h new file mode 100644 index 0000000000..7e24bb8544 --- /dev/null +++ b/include/openPMD/binding/c/ChunkInfo.h @@ -0,0 +1,43 @@ +#ifndef OPENPMD_CHUNKINFO_H +#define OPENPMD_CHUNKINFO_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_ChunkInfo + { + uint64_t *offset; + uint64_t *extent; + size_t size; + } openPMD_ChunkInfo; + + void openPMD_ChunkInfo_construct(openPMD_ChunkInfo *chunkInfo); + void openPMD_ChunkInfo_destruct(openPMD_ChunkInfo *chunkInfo); + + typedef struct openPMD_WrittenChunkInfo + { + openPMD_ChunkInfo chunkInfo; + unsigned int sourceID; + } openPMD_WrittenChunkInfo; + + void openPMD_WrittenChunkInfo_construct( + openPMD_WrittenChunkInfo *writtenChunkInfo); + void openPMD_WrittenChunkInfo_destruct( + openPMD_WrittenChunkInfo *writtenChunkInfo); + + typedef struct openPMD_ChunkTable + { + openPMD_WrittenChunkInfo *writtenChunkInfo; + size_t size; + } openPMD_ChunkTable; + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_CHUNKINFO_H diff --git a/include/openPMD/binding/c/Container_Iteration.h b/include/openPMD/binding/c/Container_Iteration.h new file mode 100644 index 0000000000..75268afeea --- /dev/null +++ b/include/openPMD/binding/c/Container_Iteration.h @@ -0,0 +1,54 @@ +#ifndef OPENPMD_CONTAINER_ITERATION_H +#define OPENPMD_CONTAINER_ITERATION_H + +#include + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Container_Iteration openPMD_Container_Iteration; + + // returns a non-owning pointer + const openPMD_Attributable * + openPMD_Container_Iteration_getConstAttributable( + const openPMD_Container_Iteration *container); + + // returns a non-owning pointer + openPMD_Attributable *openPMD_Container_Iteration_getAttributable( + openPMD_Container_Iteration *container); + + bool openPMD_Container_Iteration_empty( + const openPMD_Container_Iteration *container); + + size_t openPMD_Container_Iteration_size( + const openPMD_Container_Iteration *container); + + void + openPMD_Container_Iteration_clear(openPMD_Container_Iteration *container); + + openPMD_Iteration *openPMD_Container_Iteration_get( + openPMD_Container_Iteration *container, uint64_t key); + + void openPMD_Container_Iteration_set( + openPMD_Container_Iteration *container, + uint64_t key, + const openPMD_Iteration *component); + + bool openPMD_Container_Iteration_contains( + const openPMD_Container_Iteration *container, uint64_t key); + + void openPMD_Container_Iteration_erase( + openPMD_Container_Iteration *container, uint64_t key); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_CONTAINER_ITERATION_H diff --git a/include/openPMD/binding/c/Container_Mesh.h b/include/openPMD/binding/c/Container_Mesh.h new file mode 100644 index 0000000000..13e59c6cfb --- /dev/null +++ b/include/openPMD/binding/c/Container_Mesh.h @@ -0,0 +1,49 @@ +#ifndef OPENPMD_CONTAINER_MESH_H +#define OPENPMD_CONTAINER_MESH_H + +#include + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Container_Mesh openPMD_Container_Mesh; + + // returns a non-owning pointer + const openPMD_Attributable *openPMD_Container_Mesh_getConstAttributable( + const openPMD_Container_Mesh *container); + + // returns a non-owning pointer + openPMD_Attributable * + openPMD_Container_Mesh_getAttributable(openPMD_Container_Mesh *container); + + bool openPMD_Container_Mesh_empty(const openPMD_Container_Mesh *container); + + size_t openPMD_Container_Mesh_size(const openPMD_Container_Mesh *container); + + void openPMD_Container_Mesh_clear(openPMD_Container_Mesh *container); + + openPMD_Mesh *openPMD_Container_Mesh_get( + openPMD_Container_Mesh *container, const char *key); + + void openPMD_Container_Mesh_set( + openPMD_Container_Mesh *container, + const char *key, + const openPMD_Mesh *component); + + bool openPMD_Container_Mesh_contains( + const openPMD_Container_Mesh *container, const char *key); + + void openPMD_Container_Mesh_erase( + openPMD_Container_Mesh *container, const char *key); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_CONTAINER_MESH_H diff --git a/include/openPMD/binding/c/Datatype.h b/include/openPMD/binding/c/Datatype.h new file mode 100644 index 0000000000..cf59daf883 --- /dev/null +++ b/include/openPMD/binding/c/Datatype.h @@ -0,0 +1,76 @@ +#ifndef OPENPMD_DATATYPE_H +#define OPENPMD_DATATYPE_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_Datatype + { + openPMD_Datatype_CHAR, + openPMD_Datatype_UCHAR, + openPMD_Datatype_SCHAR, + openPMD_Datatype_SHORT, + openPMD_Datatype_INT, + openPMD_Datatype_LONG, + openPMD_Datatype_LONGLONG, + openPMD_Datatype_USHORT, + openPMD_Datatype_UINT, + openPMD_Datatype_ULONG, + openPMD_Datatype_ULONGLONG, + openPMD_Datatype_FLOAT, + openPMD_Datatype_DOUBLE, + openPMD_Datatype_LONG_DOUBLE, + openPMD_Datatype_CFLOAT, + openPMD_Datatype_CDOUBLE, + openPMD_Datatype_CLONG_DOUBLE, + openPMD_Datatype_STRING, + openPMD_Datatype_VEC_CHAR, + openPMD_Datatype_VEC_SHORT, + openPMD_Datatype_VEC_INT, + openPMD_Datatype_VEC_LONG, + openPMD_Datatype_VEC_LONGLONG, + openPMD_Datatype_VEC_UCHAR, + openPMD_Datatype_VEC_USHORT, + openPMD_Datatype_VEC_UINT, + openPMD_Datatype_VEC_ULONG, + openPMD_Datatype_VEC_ULONGLONG, + openPMD_Datatype_VEC_FLOAT, + openPMD_Datatype_VEC_DOUBLE, + openPMD_Datatype_VEC_LONG_DOUBLE, + openPMD_Datatype_VEC_CFLOAT, + openPMD_Datatype_VEC_CDOUBLE, + openPMD_Datatype_VEC_CLONG_DOUBLE, + openPMD_Datatype_VEC_SCHAR, + openPMD_Datatype_VEC_STRING, + openPMD_Datatype_ARR_DBL_7, + openPMD_Datatype_BOOL, + openPMD_Datatype_UNDEFINED + } openPMD_Datatype; + + const openPMD_Datatype *openPMD_Datatypes(); + size_t openPMD_DatatypesSize(); + + size_t openPMD_toBytes(openPMD_Datatype datatype); + size_t openPMD_toBits(openPMD_Datatype datatype); + bool openPMD_isVector(openPMD_Datatype datatype); + bool openPMD_isFloatingPoint(openPMD_Datatype datatype); + bool openPMD_isComplexFloatingPoint(openPMD_Datatype datatype); + bool openPMD_isInteger(openPMD_Datatype datatype); + bool openPMD_isSigned(openPMD_Datatype datatype); + bool openPMD_isChar(openPMD_Datatype datatype); + bool openPMD_isSame(openPMD_Datatype datatype1, openPMD_Datatype datatype2); + openPMD_Datatype openPMD_basicDatatype(openPMD_Datatype datatype); + openPMD_Datatype openPMD_toVectorType(openPMD_Datatype datatype); + const char *openPMD_datatypeToString(openPMD_Datatype datatype); + openPMD_Datatype openPMD_stringToDatatype(const char *string); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_DATATYPE_H diff --git a/include/openPMD/binding/c/IO/Access.h b/include/openPMD/binding/c/IO/Access.h new file mode 100644 index 0000000000..55d7667f37 --- /dev/null +++ b/include/openPMD/binding/c/IO/Access.h @@ -0,0 +1,30 @@ +#ifndef OPENPMD_ACCESS_H +#define OPENPMD_ACCESS_H + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_Access + { + openPMD_Access_READ_ONLY, + openPMD_Access_READ_RANDOM_ACCESS = openPMD_Access_READ_ONLY, + openPMD_Access_READ_LINEAR, + openPMD_Access_READ_WRITE, + openPMD_Access_CREATE, + openPMD_Access_APPEND + } openPMD_Access; + + bool openPMD_Access_readOnly(openPMD_Access access); + bool openPMD_Access_write(openPMD_Access access); + bool openPMD_Access_writeOnly(openPMD_Access access); + bool openPMD_Access_read(openPMD_Access access); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_ACCESS_H diff --git a/include/openPMD/binding/c/IO/Format.h b/include/openPMD/binding/c/IO/Format.h new file mode 100644 index 0000000000..eb116e8577 --- /dev/null +++ b/include/openPMD/binding/c/IO/Format.h @@ -0,0 +1,29 @@ +#ifndef OPENPMD_FORMAT_H +#define OPENPMD_FORMAT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_Format + { + openPMD_Format_HDF5, + openPMD_Format_ADIOS2_BP, + openPMD_Format_ADIOS2_BP4, + openPMD_Format_ADIOS2_BP5, + openPMD_Format_ADIOS2_SST, + openPMD_Format_ADIOS2_SSC, + openPMD_Format_JSON, + openPMD_Format_TOML, + openPMD_Format_DUMMY + } openPMD_Format; + + openPMD_Format openPMD_determineFormat(const char *filename); + const char *openPMD_suffix(openPMD_Format format); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_FORMAT_H diff --git a/include/openPMD/binding/c/Iteration.h b/include/openPMD/binding/c/Iteration.h new file mode 100644 index 0000000000..b00c2d835a --- /dev/null +++ b/include/openPMD/binding/c/Iteration.h @@ -0,0 +1,71 @@ +#ifndef OPENPMD_ITERATION_H +#define OPENPMD_ITERATION_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Iteration openPMD_Iteration; + + // returns a non-owning pointer + const openPMD_Attributable * + openPMD_Iteration_getConstAttributable(const openPMD_Iteration *iteration); + + // returns a non-owning pointer + openPMD_Attributable * + openPMD_Iteration_getAttributable(openPMD_Iteration *iteration); + + openPMD_Iteration * + openPMD_Iteration_copy(const openPMD_Iteration *iteration); + + double openPMD_Iteration_time(const openPMD_Iteration *iteration); + + void + openPMD_Iteration_setTime(openPMD_Iteration *iteration, double newTime); + + double openPMD_Iteration_dt(const openPMD_Iteration *iteration); + + void openPMD_Iteration_setDt(openPMD_Iteration *iteration, double newDt); + + double openPMD_Iteration_timeUnitSI(const openPMD_Iteration *iteration); + + void openPMD_Iteration_setTimeUnitSI( + openPMD_Iteration *iteration, double newTimeUnitSI); + + void openPMD_Iteration_close(openPMD_Iteration *iteration, bool flush); + + void openPMD_Iteration_open(openPMD_Iteration *iteration); + + bool openPMD_Iteration_closed(const openPMD_Iteration *iteration); + + const openPMD_Container_Mesh * + openPMD_Iteration_constMeshes(const openPMD_Iteration *iteration); + + openPMD_Container_Mesh * + openPMD_Iteration_meshes(openPMD_Iteration *iteration); + + void openPMD_Iteration_delete(openPMD_Iteration *iteration); + + typedef struct openPMD_IndexedIteration openPMD_IndexedIteration; + + const openPMD_Iteration *openPMD_IndexedIteration_getConstIteration( + const openPMD_IndexedIteration *indexed_iteration); + + openPMD_Iteration *openPMD_IndexedIteration_getIteration( + openPMD_IndexedIteration *indexed_iteration); + + uint64_t openPMD_IndexedIteration_iterationIndex( + const openPMD_IndexedIteration *indexed_iteration); + + void + openPMD_IndexedIteration_delete(openPMD_IndexedIteration *indexedIteration); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_ITERATION_H diff --git a/include/openPMD/binding/c/IterationEncoding.h b/include/openPMD/binding/c/IterationEncoding.h new file mode 100644 index 0000000000..2166c0c72e --- /dev/null +++ b/include/openPMD/binding/c/IterationEncoding.h @@ -0,0 +1,20 @@ +#ifndef OPENPMD_ITERATIONENCODING_H +#define OPENPMD_ITERATIONENCODING_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_IterationEncoding + { + openPMD_IterationEncoding_fileBased, + openPMD_IterationEncoding_groupBased, + openPMD_IterationEncoding_variableBased + } openPMD_IterationEncoding; + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_ITERATIONENCODING_H diff --git a/include/openPMD/binding/c/Mesh.h b/include/openPMD/binding/c/Mesh.h new file mode 100644 index 0000000000..9341601d01 --- /dev/null +++ b/include/openPMD/binding/c/Mesh.h @@ -0,0 +1,103 @@ +#ifndef OPENPMD_MESH_H +#define OPENPMD_MESH_H + +#include + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Mesh openPMD_Mesh; + + const openPMD_Container_MeshRecordComponent * + openPMD_Mesh_getConstContainer_MeshRecordComponent( + const openPMD_Mesh *mesh); + + openPMD_Container_MeshRecordComponent * + openPMD_Mesh_getContainer_MeshRecordComponent(openPMD_Mesh *mesh); + + // From BaseRecord (too lazy to wrap this class) + openPMD_ArrayDouble7 openPMD_Mesh_unitDimension(const openPMD_Mesh *mesh); + + bool openPMD_Mesh_scalar(const openPMD_Mesh *mesh); + + // From Mesh + openPMD_Mesh *openPMD_Mesh_copy(const openPMD_Mesh *mesh); + + void openPMD_Mesh_delete(openPMD_Mesh *mesh); + + typedef enum openPMD_Mesh_Geometry + { + openPMD_Mesh_Geometry_cartesian, + openPMD_Mesh_Geometry_thetaMode, + openPMD_Mesh_Geometry_cylindrical, + openPMD_Mesh_Geometry_spherical, + openPMD_Mesh_Geometry_other + } openPMD_Mesh_Geometry; + + typedef enum openPMD_Mesh_DataOrder + { + openPMD_Mesh_DataOrder_C = 'C', + openPMD_Mesh_DataOrder_F = 'F' + } openPMD_Mesh_DataOrder; + + openPMD_Mesh_Geometry openPMD_Mesh_geometry(const openPMD_Mesh *mesh); + + const char *openPMD_Mesh_geometryString(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setGeometry( + openPMD_Mesh *mesh, openPMD_Mesh_Geometry geometry); + + char *openPMD_Mesh_geometryParameters(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setGeometryParameters( + openPMD_Mesh *mesh, const char *geometryParameters); + + openPMD_Mesh_DataOrder openPMD_Mesh_dataOrder(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setDataOrder( + openPMD_Mesh *mesh, openPMD_Mesh_DataOrder dataOrder); + + char **openPMD_Mesh_axisLabels(const openPMD_Mesh *mesh); + + size_t openPMD_Mesh_axisLabelsSize(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setAxisLabels( + openPMD_Mesh *mesh, const char *const *axisLabels, size_t size); + + double *openPMD_Mesh_gridSpacing(const openPMD_Mesh *mesh); + + size_t openPMD_Mesh_gridSpacingSize(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setgridSpacing( + openPMD_Mesh *mesh, const double *gridSpacing, size_t size); + + double *openPMD_Mesh_gridGlobalOffset(const openPMD_Mesh *mesh); + + size_t openPMD_Mesh_gridGlobalOffsetSize(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setgridGlobalOffset( + openPMD_Mesh *mesh, const double *gridGlobalOffset, size_t size); + + double openPMD_Mesh_gridUnitSI(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setGridUnitSI(openPMD_Mesh *mesh, double unitSI); + + void openPMD_Mesh_setUnitDimension( + openPMD_Mesh *mesh, const openPMD_ArrayDouble7 *unitDimension); + + double openPMD_Mesh_timeOffset(const openPMD_Mesh *mesh); + + void openPMD_Mesh_setTimeOffset(openPMD_Mesh *mesh, double timeOffset); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_MESH_H diff --git a/include/openPMD/binding/c/ReadIterations.h b/include/openPMD/binding/c/ReadIterations.h new file mode 100644 index 0000000000..cc3b8952de --- /dev/null +++ b/include/openPMD/binding/c/ReadIterations.h @@ -0,0 +1,44 @@ +#ifndef OPENPMD_READITERATIONS_H +#define OPENPMD_READITERATIONS_H + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Series openPMD_Series; + + // SeriesIterator + + typedef struct openPMD_SeriesIterator openPMD_SeriesIterator; + + openPMD_SeriesIterator *openPMD_SeriesIterator_new( + openPMD_Series *series, openPMD_ParsePreference parsePreference); + + void openPMD_SeriesIterator_delete(openPMD_SeriesIterator *seriesIterator); + + bool + openPMD_SeriesIterator_done(const openPMD_SeriesIterator *seriesIterator); + + void openPMD_SeriesIterator_advance(openPMD_SeriesIterator *seriesIterator); + + openPMD_IndexedIteration * + openPMD_SeriesIterator_get(openPMD_SeriesIterator *seriesIterator); + + // ReadIterations + + typedef struct openPMD_ReadIterations openPMD_ReadIterations; + + void openPMD_ReadIterations_delete(openPMD_ReadIterations *readIterations); + + openPMD_SeriesIterator *openPMD_ReadIterations_iterate( + const openPMD_ReadIterations *readIterations); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_READITERATIONS_H diff --git a/include/openPMD/binding/c/RecordComponent.h b/include/openPMD/binding/c/RecordComponent.h new file mode 100644 index 0000000000..673fd1413d --- /dev/null +++ b/include/openPMD/binding/c/RecordComponent.h @@ -0,0 +1,83 @@ +#ifndef OPENPMD_RECORDCOMPONENT_H +#define OPENPMD_RECORDCOMPONENT_H + +#include + +#include +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_RecordComponent openPMD_RecordComponent; + + const openPMD_BaseRecordComponent * + openPMD_RecordComponent_getConstBaseRecordComponent( + const openPMD_RecordComponent *component); + openPMD_BaseRecordComponent *openPMD_RecordComponent_getBaseRecordComponent( + openPMD_RecordComponent *component); + + typedef enum openPMD_RecordComponent_Allocation + { + openPMD_RecordComponent_Allocation_USER, + openPMD_RecordComponent_Allocation_API, + openPMD_RecordComponent_Allocation_AUTO + } openPMD_RecordComponent_Allocation; + + void openPMD_RecordComponent_setUnitSI( + openPMD_RecordComponent *component, double unit); + + void openPMD_RecordComponent_resetDataset( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + const uint64_t *extent, + size_t rank, + const char *options); + + uint8_t openPMD_RecordComponent_getDimensionality( + const openPMD_RecordComponent *component); + + uint64_t * + openPMD_RecordComponent_getExtent(const openPMD_RecordComponent *component); + size_t openPMD_RecordComponent_getExtentSize( + const openPMD_RecordComponent *component); + + void openPMD_RecordComponent_makeConstant( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + const void *data); + + void openPMD_RecordComponent_makeEmpty( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + uint8_t dimensions); + + bool + openPMD_RecordComponent_empty(const openPMD_RecordComponent *component); + + void openPMD_RecordComponent_loadChunkRaw( + openPMD_RecordComponent *component, + void *data, + openPMD_Datatype datatype, + const uint64_t *offset, + const uint64_t *extent, + size_t size); + + void openPMD_RecordComponent_storeChunkRaw( + openPMD_RecordComponent *component, + void *data, + openPMD_Datatype datatype, + const uint64_t *offset, + const uint64_t *extent, + size_t size); + + char const *openPMD_RecordComponent_SCALAR(); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_RECORDCOMPONENT_H diff --git a/include/openPMD/binding/c/Series.h b/include/openPMD/binding/c/Series.h new file mode 100644 index 0000000000..6d8c93c45d --- /dev/null +++ b/include/openPMD/binding/c/Series.h @@ -0,0 +1,137 @@ +#ifndef OPENPMD_SERIES_H +#define OPENPMD_SERIES_H + +#include + +#include +#include +#include +#include +#include +#include + +#if openPMD_HAVE_MPI +#include +#endif + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Series openPMD_Series; + + // returns a non-owning pointer + const openPMD_Attributable * + openPMD_Series_getConstAttributable(const openPMD_Series *series); + + // returns a non-owning pointer + openPMD_Attributable * + openPMD_Series_getAttributable(openPMD_Series *series); + + openPMD_Series *openPMD_Series_new(); + +#if openPMD_HAVE_MPI + openPMD_Series *openPMD_Series_new_parallel( + const char *filepath, + openPMD_Access at, + MPI_Comm comm, + const char *options); +#endif + + openPMD_Series *openPMD_Series_new_serial( + const char *filepath, openPMD_Access at, const char *options); + + void openPMD_Series_delete(openPMD_Series *series); + + // returns a non-owning pointer + const openPMD_Container_Iteration * + openPMD_Series_constIterations(const openPMD_Series *series); + + // returns a non-owning pointer + openPMD_Container_Iteration * + openPMD_Series_iterations(openPMD_Series *series); + + bool openPMD_Series_has_value(const openPMD_Series *series); + + char *openPMD_Series_openPMD(const openPMD_Series *series); + + void openPMD_Series_setOpenPMD(openPMD_Series *series, const char *openPMD); + + uint32_t openPMD_Series_openPMDextension(const openPMD_Series *series); + + void openPMD_Series_setOpenPMDextension( + openPMD_Series *series, uint32_t openPMDextension); + + char *openPMD_Series_basePath(const openPMD_Series *series); + + void + openPMD_Series_setBasePath(openPMD_Series *series, const char *basePath); + + char *openPMD_Series_meshesPath(const openPMD_Series *series); + + void openPMD_Series_setMeshesPath( + openPMD_Series *series, const char *meshesPath); + + char *openPMD_Series_particlesPath(const openPMD_Series *series); + + void openPMD_Series_setParticlesPath( + openPMD_Series *series, const char *particlesPath); + + char *openPMD_Series_author(const openPMD_Series *series); + + void openPMD_Series_setAuthor(openPMD_Series *series, const char *author); + + char *openPMD_Series_software(const openPMD_Series *series); + + void openPMD_Series_setSoftware( + openPMD_Series *series, const char *name, const char *version); + + char *openPMD_Series_date(const openPMD_Series *series); + + void openPMD_Series_setDate(openPMD_Series *series, const char *date); + + char *openPMD_Series_softwareDependencies(const openPMD_Series *series); + + void openPMD_Series_setSoftwareDependencies( + openPMD_Series *series, const char *SoftwareDependencies); + + char *openPMD_Series_machine(const openPMD_Series *series); + + void openPMD_Series_setMachine(openPMD_Series *series, const char *machine); + + openPMD_IterationEncoding + openPMD_Series_iterationEncoding(const openPMD_Series *series); + + void openPMD_Series_setIterationEncoding( + openPMD_Series *series, openPMD_IterationEncoding iterationEncoding); + + char *openPMD_Series_iterationFormat(const openPMD_Series *series); + + void openPMD_Series_setIterationFormat( + openPMD_Series *series, const char *iterationFormat); + + char *openPMD_Series_name(const openPMD_Series *series); + + void openPMD_Series_setName(openPMD_Series *series, const char *name); + + char *openPMD_Series_backend(const openPMD_Series *series); + + void + openPMD_Series_flush(openPMD_Series *series, const char *backendConfig); + + openPMD_ReadIterations * + openPMD_Series_readIteration(openPMD_Series *series); + + void openPMD_Series_parseBase(openPMD_Series *series); + + openPMD_WriteIterations * + openPMD_Series_writeIteration(openPMD_Series *series); + + void openPMD_Series_close(openPMD_Series *series); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_SERIES_H diff --git a/include/openPMD/binding/c/UnitDimension.h b/include/openPMD/binding/c/UnitDimension.h new file mode 100644 index 0000000000..e11144df5e --- /dev/null +++ b/include/openPMD/binding/c/UnitDimension.h @@ -0,0 +1,29 @@ +#ifndef OPENPMD_UNITDIMENSION_H +#define OPENPMD_UNITDIMENSION_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_UnitDimension + { + openPMD_UnitDimension_L = 0, + openPMD_UnitDimension_M, + openPMD_UnitDimension_T, + openPMD_UnitDimension_I, + openPMD_UnitDimension_theta, + openPMD_UnitDimension_N, + openPMD_UnitDimension_J + } openPMD_UnitDimension; + + typedef struct openPMD_ArrayDouble7 + { + double element[7]; + } openPMD_ArrayDouble7; + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_UNITDIMENSION_H diff --git a/include/openPMD/binding/c/WriteIterations.h b/include/openPMD/binding/c/WriteIterations.h new file mode 100644 index 0000000000..6a3beb26a2 --- /dev/null +++ b/include/openPMD/binding/c/WriteIterations.h @@ -0,0 +1,28 @@ +#ifndef OPENPMD_WRITEITERATIONS_H +#define OPENPMD_WRITEITERATIONS_H + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_WriteIterations openPMD_WriteIterations; + + void openPMD_WriteIterations_delete(openPMD_WriteIterations *iterations); + + openPMD_Iteration *openPMD_WriteIterations_get( + openPMD_WriteIterations *iterations, uint64_t key); + + openPMD_IndexedIteration *openPMD_WriteIterations_currentIteration( + openPMD_WriteIterations *iterations); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_WRITEITERATIONS_H diff --git a/include/openPMD/binding/c/auxiliary/deprecate.h b/include/openPMD/binding/c/auxiliary/deprecate.h new file mode 100644 index 0000000000..e6bc1f9328 --- /dev/null +++ b/include/openPMD/binding/c/auxiliary/deprecate.h @@ -0,0 +1,10 @@ +#ifndef OPENPMD_DEPRECATE_H +#define OPENPMD_DEPRECATE_H + +#ifndef _MSC_VER +#define OPENPMD_DEPRECATED __attribute__((deprecated)) +#else +#define OPENPMD_DEPRECATED +#endif + +#endif diff --git a/include/openPMD/binding/c/backend/Attributable.h b/include/openPMD/binding/c/backend/Attributable.h new file mode 100644 index 0000000000..1ef7ddc09c --- /dev/null +++ b/include/openPMD/binding/c/backend/Attributable.h @@ -0,0 +1,439 @@ +#ifndef OPENPMD_ATTRIBUTABLE_H +#define OPENPMD_ATTRIBUTABLE_H + +#include +#include + +#include +#undef I +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Attributable openPMD_Attributable; + + openPMD_Attributable *openPMD_Attributable_new(); + void openPMD_Attributable_delete(openPMD_Attributable *attributable); + + bool openPMD_Attributable_setAttribute_char( + openPMD_Attributable *attributable, const char *key, char value); + bool openPMD_Attributable_setAttribute_uchar( + openPMD_Attributable *attributable, + const char *key, + unsigned char value); + bool openPMD_Attributable_setAttribute_schar( + openPMD_Attributable *attributable, const char *key, signed char value); + bool openPMD_Attributable_setAttribute_short( + openPMD_Attributable *attributable, const char *key, short value); + bool openPMD_Attributable_setAttribute_int( + openPMD_Attributable *attributable, const char *key, int value); + bool openPMD_Attributable_setAttribute_long( + openPMD_Attributable *attributable, const char *key, long value); + bool openPMD_Attributable_setAttribute_longlong( + openPMD_Attributable *attributable, const char *key, long long value); + bool openPMD_Attributable_setAttribute_ushort( + openPMD_Attributable *attributable, + const char *key, + unsigned short value); + bool openPMD_Attributable_setAttribute_uint( + openPMD_Attributable *attributable, + const char *key, + unsigned int value); + bool openPMD_Attributable_setAttribute_ulong( + openPMD_Attributable *attributable, + const char *key, + unsigned long value); + bool openPMD_Attributable_setAttribute_ulonglong( + openPMD_Attributable *attributable, + const char *key, + unsigned long long value); + bool openPMD_Attributable_setAttribute_float( + openPMD_Attributable *attributable, const char *key, float value); + bool openPMD_Attributable_setAttribute_double( + openPMD_Attributable *attributable, const char *key, double value); + bool openPMD_Attributable_setAttribute_long_double( + openPMD_Attributable *attributable, const char *key, long double value); + bool openPMD_Attributable_setAttribute_cfloat2( + openPMD_Attributable *attributable, + const char *key, + float value_re, + float value_im); + bool openPMD_Attributable_setAttribute_cdouble2( + openPMD_Attributable *attributable, + const char *key, + double value_re, + double value_im); + bool openPMD_Attributable_setAttribute_clong_double2( + openPMD_Attributable *attributable, + const char *key, + long double value_re, + long double value_im); +#ifndef __cplusplus + bool openPMD_Attributable_setAttribute_cfloat( + openPMD_Attributable *attributable, + const char *key, + complex float value); + bool openPMD_Attributable_setAttribute_cdouble( + openPMD_Attributable *attributable, + const char *key, + complex double value); + bool openPMD_Attributable_setAttribute_clong_double( + openPMD_Attributable *attributable, + const char *key, + complex long double value); +#endif + bool openPMD_Attributable_setAttribute_string( + openPMD_Attributable *attributable, const char *key, const char *value); + bool openPMD_Attributable_setAttribute_vec_char( + openPMD_Attributable *attributable, + const char *key, + const char *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_uchar( + openPMD_Attributable *attributable, + const char *key, + const unsigned char *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_schar( + openPMD_Attributable *attributable, + const char *key, + const signed char *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_short( + openPMD_Attributable *attributable, + const char *key, + const short *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_int( + openPMD_Attributable *attributable, + const char *key, + const int *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_long( + openPMD_Attributable *attributable, + const char *key, + const long *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_longlong( + openPMD_Attributable *attributable, + const char *key, + const long long *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_ushort( + openPMD_Attributable *attributable, + const char *key, + const unsigned short *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_uint( + openPMD_Attributable *attributable, + const char *key, + const unsigned int *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_ulong( + openPMD_Attributable *attributable, + const char *key, + const unsigned long *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_ulonglong( + openPMD_Attributable *attributable, + const char *key, + const unsigned long long *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_float( + openPMD_Attributable *attributable, + const char *key, + const float *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_double( + openPMD_Attributable *attributable, + const char *key, + const double *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_long_double( + openPMD_Attributable *attributable, + const char *key, + const long double *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_cfloat2( + openPMD_Attributable *attributable, + const char *key, + const float *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_cdouble2( + openPMD_Attributable *attributable, + const char *key, + const double *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_clong_double2( + openPMD_Attributable *attributable, + const char *key, + const long double *values, + size_t size); +#ifndef __cplusplus + bool openPMD_Attributable_setAttribute_vec_cfloat( + openPMD_Attributable *attributable, + const char *key, + const complex float *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_cdouble( + openPMD_Attributable *attributable, + const char *key, + const complex double *values, + size_t size); + bool openPMD_Attributable_setAttribute_vec_clong_double( + openPMD_Attributable *attributable, + const char *key, + const complex long double *values, + size_t size); +#endif + bool openPMD_Attributable_setAttribute_vec_string( + openPMD_Attributable *attributable, + const char *key, + const char *const *values, + size_t size); + bool openPMD_Attributable_setAttribute_bool( + openPMD_Attributable *attributable, const char *key, bool value); + + openPMD_Datatype openPMD_Attributable_attributeDatatype( + const openPMD_Attributable *attributable, const char *key); + + bool openPMD_Attributable_getAttribute_char( + const openPMD_Attributable *attributable, const char *key, char *value); + bool openPMD_Attributable_getAttribute_uchar( + const openPMD_Attributable *attributable, + const char *key, + unsigned char *value); + bool openPMD_Attributable_getAttribute_schar( + const openPMD_Attributable *attributable, + const char *key, + signed char *value); + bool openPMD_Attributable_getAttribute_short( + const openPMD_Attributable *attributable, + const char *key, + short *value); + bool openPMD_Attributable_getAttribute_int( + const openPMD_Attributable *attributable, const char *key, int *value); + bool openPMD_Attributable_getAttribute_long( + const openPMD_Attributable *attributable, const char *key, long *value); + bool openPMD_Attributable_getAttribute_longlong( + const openPMD_Attributable *attributable, + const char *key, + long long *value); + bool openPMD_Attributable_getAttribute_ushort( + const openPMD_Attributable *attributable, + const char *key, + unsigned short *value); + bool openPMD_Attributable_getAttribute_uint( + const openPMD_Attributable *attributable, + const char *key, + unsigned int *value); + bool openPMD_Attributable_getAttribute_ulong( + const openPMD_Attributable *attributable, + const char *key, + unsigned long *value); + bool openPMD_Attributable_getAttribute_ulonglong( + const openPMD_Attributable *attributable, + const char *key, + unsigned long long *value); + bool openPMD_Attributable_getAttribute_float( + const openPMD_Attributable *attributable, + const char *key, + float *value); + bool openPMD_Attributable_getAttribute_double( + const openPMD_Attributable *attributable, + const char *key, + double *value); + bool openPMD_Attributable_getAttribute_long_double( + const openPMD_Attributable *attributable, + const char *key, + long double *value); + bool openPMD_Attributable_getAttribute_cfloat2( + const openPMD_Attributable *attributable, + const char *key, + float *value); + bool openPMD_Attributable_getAttribute_cdouble2( + const openPMD_Attributable *attributable, + const char *key, + double *value); + bool openPMD_Attributable_getAttribute_clong_double2( + const openPMD_Attributable *attributable, + const char *key, + long double *value); +#ifndef __cplusplus + bool openPMD_Attributable_getAttribute_cfloat( + const openPMD_Attributable *attributable, + const char *key, + complex float *value); + bool openPMD_Attributable_getAttribute_cdouble( + const openPMD_Attributable *attributable, + const char *key, + complex double *value); + bool openPMD_Attributable_getAttribute_clong_double( + const openPMD_Attributable *attributable, + const char *key, + complex long double *value); +#endif + bool openPMD_Attributable_getAttribute_string( + const openPMD_Attributable *attributable, + const char *key, + char **value); + bool openPMD_Attributable_getAttribute_vec_char( + const openPMD_Attributable *attributable, + const char *key, + char **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_uchar( + const openPMD_Attributable *attributable, + const char *key, + unsigned char **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_schar( + const openPMD_Attributable *attributable, + const char *key, + signed char **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_short( + const openPMD_Attributable *attributable, + const char *key, + short **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_int( + const openPMD_Attributable *attributable, + const char *key, + int **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_long( + const openPMD_Attributable *attributable, + const char *key, + long **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_longlong( + const openPMD_Attributable *attributable, + const char *key, + long long **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_ushort( + const openPMD_Attributable *attributable, + const char *key, + unsigned short **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_uint( + const openPMD_Attributable *attributable, + const char *key, + unsigned int **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_ulong( + const openPMD_Attributable *attributable, + const char *key, + long **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_ulonglong( + const openPMD_Attributable *attributable, + const char *key, + unsigned long long **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_float( + const openPMD_Attributable *attributable, + const char *key, + float **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_double( + const openPMD_Attributable *attributable, + const char *key, + double **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_long_double( + const openPMD_Attributable *attributable, + const char *key, + long double **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_cfloat2( + const openPMD_Attributable *attributable, + const char *key, + float **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_cdouble2( + const openPMD_Attributable *attributable, + const char *key, + double **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_clong_double2( + const openPMD_Attributable *attributable, + const char *key, + long double **values, + size_t *size); +#ifndef __cplusplus + bool openPMD_Attributable_getAttribute_vec_cfloat( + const openPMD_Attributable *attributable, + const char *key, + complex float **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_cdouble( + const openPMD_Attributable *attributable, + const char *key, + complex double **values, + size_t *size); + bool openPMD_Attributable_getAttribute_vec_clong_double( + const openPMD_Attributable *attributable, + const char *key, + complex long double **values, + size_t *size); +#endif + bool openPMD_Attributable_getAttribute_vec_string( + const openPMD_Attributable *attributable, + const char *key, + char ***values, + size_t *size); + bool openPMD_Attributable_getAttribute_bool( + const openPMD_Attributable *attributable, const char *key, bool *value); + + bool openPMD_Attributable_deleteAttribute( + openPMD_Attributable *attributable, const char *key); + + // result is a pointer to pointers, both layers must be freed + char ** + openPMD_Attributable_attributes(const openPMD_Attributable *attributable); + + size_t openPMD_Attributable_numAttributes( + const openPMD_Attributable *attributable); + + bool openPMD_Attributable_containsAttribute( + const openPMD_Attributable *attributable, const char *key); + + // result must be freed + char * + openPMD_Attributable_comment(const openPMD_Attributable *attributable); + + void openPMD_Attributable_setComment( + openPMD_Attributable *attributable, const char *comment); + + // backendConfig may be NULL + void openPMD_Attributable_seriesFlush( + openPMD_Attributable *attributable, const char *backendConfig); + + typedef struct openPMD_Attributable_MyPath + { + char *directory; + char *seriesName; + char *seriesExtension; + char **group; // NULL terminated + openPMD_Access access; + } openPMD_Attributable_MyPath; + + void openPMD_Attributable_MyPath_free(openPMD_Attributable_MyPath *myPath); + + char *openPMD_Attributable_MyPath_filePath( + const openPMD_Attributable_MyPath *myPath); + + openPMD_Attributable_MyPath * + openPMD_Attributable_myPath(const openPMD_Attributable *attributable); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_ATTRIBUTABLE_H diff --git a/include/openPMD/binding/c/backend/BaseRecordComponent.h b/include/openPMD/binding/c/backend/BaseRecordComponent.h new file mode 100644 index 0000000000..5b19d2f040 --- /dev/null +++ b/include/openPMD/binding/c/backend/BaseRecordComponent.h @@ -0,0 +1,39 @@ +#ifndef OPENPMD_BASERECORDCOMPONENT_H +#define OPENPMD_BASERECORDCOMPONENT_H + +#include +#include +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_BaseRecordComponent openPMD_BaseRecordComponent; + + const openPMD_Attributable * + openPMD_BaseRecordComponent_getConstAttributable( + const openPMD_BaseRecordComponent *component); + openPMD_Attributable *openPMD_BaseRecordComponent_getAttributable( + openPMD_BaseRecordComponent *component); + + void openPMD_BaseRecordComponent_resetDatatype( + openPMD_BaseRecordComponent *component, openPMD_Datatype datatype); + + openPMD_Datatype openPMD_BaseRecordComponent_getDatatype( + const openPMD_BaseRecordComponent *component); + + bool openPMD_BaseRecordComponent_constant( + const openPMD_BaseRecordComponent *component); + + openPMD_ChunkTable openPMD_BaseRecordComponent_availableChunks( + const openPMD_BaseRecordComponent *component); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_BASERECORDCOMPONENT_H diff --git a/include/openPMD/binding/c/backend/Container_MeshRecordComponent.h b/include/openPMD/binding/c/backend/Container_MeshRecordComponent.h new file mode 100644 index 0000000000..bd31fa3dae --- /dev/null +++ b/include/openPMD/binding/c/backend/Container_MeshRecordComponent.h @@ -0,0 +1,52 @@ +#ifndef OPENPMD_CONTAINER_MESHRECORDCOMPONENT_H +#define OPENPMD_CONTAINER_MESHRECORDCOMPONENT_H + +#include + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_Container_MeshRecordComponent + openPMD_Container_MeshRecordComponent; + + const openPMD_Attributable * + openPMD_Container_MeshRecordComponent_getConstAttributable( + const openPMD_Container_MeshRecordComponent *container); + openPMD_Attributable *openPMD_Container_MeshRecordComponent_getAttributable( + openPMD_Container_MeshRecordComponent *container); + + bool openPMD_Container_MeshRecordComponent_empty( + const openPMD_Container_MeshRecordComponent *container); + + size_t openPMD_Container_MeshRecordComponent_size( + const openPMD_Container_MeshRecordComponent *container); + + void openPMD_Container_MeshRecordComponent_clear( + openPMD_Container_MeshRecordComponent *container); + + openPMD_MeshRecordComponent *openPMD_Container_MeshRecordComponent_get( + openPMD_Container_MeshRecordComponent *container, const char *key); + + void openPMD_Container_MeshRecordComponent_set( + openPMD_Container_MeshRecordComponent *container, + const char *key, + const openPMD_MeshRecordComponent *component); + + bool openPMD_Container_MeshRecordComponent_contains( + const openPMD_Container_MeshRecordComponent *container, + const char *key); + + void openPMD_Container_MeshRecordComponent_erase( + openPMD_Container_MeshRecordComponent *container, const char *key); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_CONTAINER_MESHRECORDCOMPONENT_H diff --git a/include/openPMD/binding/c/backend/MeshRecordComponent.h b/include/openPMD/binding/c/backend/MeshRecordComponent.h new file mode 100644 index 0000000000..3817b170a0 --- /dev/null +++ b/include/openPMD/binding/c/backend/MeshRecordComponent.h @@ -0,0 +1,43 @@ +#ifndef OPENPMD_MESHRECORDCOMPONENT_H +#define OPENPMD_MESHRECORDCOMPONENT_H + +#include + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef struct openPMD_MeshRecordComponent openPMD_MeshRecordComponent; + + const openPMD_RecordComponent * + openPMD_MeshRecordComponent_getConstRecordComponent( + const openPMD_MeshRecordComponent *meshComponent); + openPMD_RecordComponent *openPMD_MeshRecordComponent_getRecordComponent( + openPMD_MeshRecordComponent *meshComponent); + + void + openPMD_MeshRecordComponent_delete(openPMD_MeshRecordComponent *component); + + double *openPMD_MeshRecordComponent_position( + const openPMD_MeshRecordComponent *component); + size_t openPMD_MeshRecordComponent_positionSize( + const openPMD_MeshRecordComponent *component); + + void openPMD_MeshRecordComponent_setPosition( + openPMD_MeshRecordComponent *component, + const double *position, + size_t size); + + void openPMD_MeshRecordComponent_makeConstant( + openPMD_MeshRecordComponent *component, + const void *data, + openPMD_Datatype datatype); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_MESHRECORDCOMPONENT_H diff --git a/include/openPMD/binding/c/backend/ParsePreference.h b/include/openPMD/binding/c/backend/ParsePreference.h new file mode 100644 index 0000000000..2b78168525 --- /dev/null +++ b/include/openPMD/binding/c/backend/ParsePreference.h @@ -0,0 +1,20 @@ +#ifndef OPENPMD_PARSEPREFERENCE_H +#define OPENPMD_PARSEPREFERENCE_H + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef enum openPMD_ParsePreference + { + openPMD_ParsePreference_None = -1, + openPMD_ParsePreference_UpFront, + openPMD_ParsePreference_PerStep, + } openPMD_ParsePreference; + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_PARSEPREFERENCE_H diff --git a/include/openPMD/binding/c/openPMD.h b/include/openPMD/binding/c/openPMD.h new file mode 100644 index 0000000000..9e7d6fc473 --- /dev/null +++ b/include/openPMD/binding/c/openPMD.h @@ -0,0 +1,25 @@ +#ifndef OPENPMD_H +#define OPENPMD_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* #include */ +#include +#include +#include +#include +#include + +#endif // #ifndef OPENPMD_H diff --git a/include/openPMD/binding/c/version.h b/include/openPMD/binding/c/version.h new file mode 100644 index 0000000000..e1f63dcf5a --- /dev/null +++ b/include/openPMD/binding/c/version.h @@ -0,0 +1,45 @@ +#ifndef OPENPMD_VERSION_H +#define OPENPMD_VERSION_H + +#include "openPMD/binding/c/auxiliary/deprecate.h" + +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + + extern const int openPMDapi_version_major; + extern const int openPMDapi_version_minor; + extern const int openPMDapi_version_patch; + extern const char *const openPMDapi_version_label; + + extern const int openPMD_standard_major; + extern const int openPMD_standard_minor; + extern const int openPMD_standard_patch; + + extern const int openPMD_standard_min_major; + extern const int openPMD_standard_min_minor; + extern const int openPMD_standard_min_patch; + + const char *openPMD_getVersion(); + const char *OPENPMD_DEPRECATED openPMD_getStandard(); + const char *openPMD_getStandardMinimum(); + const char *openPMD_getStandardDefault(); + const char *openPMD_getStandardMaximum(); + + typedef struct openPMD_Variant + { + const char *variant; + bool supported; + } openPMD_Variant; + const openPMD_Variant *openPMD_getVariants(); + + const char *const *openPMD_getFileExtensions(); + +#ifdef __cplusplus +} +#endif + +#endif // #ifndef OPENPMD_VERSION_H diff --git a/src/binding/c/ChunkInfo.cpp b/src/binding/c/ChunkInfo.cpp new file mode 100644 index 0000000000..13d9b61914 --- /dev/null +++ b/src/binding/c/ChunkInfo.cpp @@ -0,0 +1,33 @@ +#include + +#include + +#include + +void openPMD_ChunkInfo_construct(openPMD_ChunkInfo *chunkInfo) +{ + chunkInfo->offset = nullptr; + chunkInfo->extent = nullptr; + chunkInfo->size = 0; +} + +void openPMD_ChunkInfo_destruct(openPMD_ChunkInfo *chunkInfo) +{ + free(chunkInfo->offset); + free(chunkInfo->extent); + chunkInfo->offset = nullptr; + chunkInfo->extent = nullptr; +} + +void openPMD_WrittenChunkInfo_construct( + openPMD_WrittenChunkInfo *writtenChunkInfo) +{ + openPMD_ChunkInfo_construct(&writtenChunkInfo->chunkInfo); + writtenChunkInfo->sourceID = 0; +} + +void openPMD_WrittenChunkInfo_destruct( + openPMD_WrittenChunkInfo *writtenChunkInfo) +{ + openPMD_ChunkInfo_destruct(&writtenChunkInfo->chunkInfo); +} diff --git a/src/binding/c/Container_Iteration.cpp b/src/binding/c/Container_Iteration.cpp new file mode 100644 index 0000000000..9359b250a4 --- /dev/null +++ b/src/binding/c/Container_Iteration.cpp @@ -0,0 +1,88 @@ +#include + +#include +#include + +#include + +const openPMD_Attributable *openPMD_Container_Iteration_getConstAttributable( + const openPMD_Container_Iteration *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_container; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable *openPMD_Container_Iteration_getAttributable( + openPMD_Container_Iteration *container) +{ + const auto cxx_container = + (openPMD::Container *)container; + const auto cxx_attributable = (openPMD::Attributable *)cxx_container; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +bool openPMD_Container_Iteration_empty( + const openPMD_Container_Iteration *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->empty(); +} + +size_t +openPMD_Container_Iteration_size(const openPMD_Container_Iteration *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->size(); +} + +void openPMD_Container_Iteration_clear(openPMD_Container_Iteration *container) +{ + const auto cxx_container = + (openPMD::Container *)container; + cxx_container->clear(); +} + +openPMD_Iteration *openPMD_Container_Iteration_get( + openPMD_Container_Iteration *container, uint64_t key) +{ + const auto cxx_container = + (openPMD::Container *)container; + if (!cxx_container->contains(key)) + return nullptr; + const auto cxx_component = new openPMD::Iteration(cxx_container->at(key)); + const auto component = (openPMD_Iteration *)cxx_component; + return component; +} + +void openPMD_Container_Iteration_set( + openPMD_Container_Iteration *container, + uint64_t key, + const openPMD_Iteration *component) +{ + const auto cxx_container = + (openPMD::Container *)container; + const auto cxx_component = (const openPMD::Iteration *)component; + (*cxx_container)[key] = *cxx_component; +} + +bool openPMD_Container_Iteration_contains( + const openPMD_Container_Iteration *container, uint64_t key) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->contains(key); +} + +void openPMD_Container_Iteration_erase( + openPMD_Container_Iteration *container, uint64_t key) +{ + const auto cxx_container = + (openPMD::Container *)container; + cxx_container->erase(key); +} diff --git a/src/binding/c/Container_Mesh.cpp b/src/binding/c/Container_Mesh.cpp new file mode 100644 index 0000000000..19ab0e6f2f --- /dev/null +++ b/src/binding/c/Container_Mesh.cpp @@ -0,0 +1,83 @@ +#include + +#include +#include + +#include +#include + +const openPMD_Attributable *openPMD_Container_Mesh_getConstAttributable( + const openPMD_Container_Mesh *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_container; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable * +openPMD_Container_Mesh_getAttributable(openPMD_Container_Mesh *container) +{ + const auto cxx_container = (openPMD::Container *)container; + const auto cxx_attributable = (openPMD::Attributable *)cxx_container; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +bool openPMD_Container_Mesh_empty(const openPMD_Container_Mesh *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->empty(); +} + +size_t openPMD_Container_Mesh_size(const openPMD_Container_Mesh *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->size(); +} + +void openPMD_Container_Mesh_clear(openPMD_Container_Mesh *container) +{ + const auto cxx_container = (openPMD::Container *)container; + cxx_container->clear(); +} + +openPMD_Mesh * +openPMD_Container_Mesh_get(openPMD_Container_Mesh *container, const char *key) +{ + const auto cxx_container = (openPMD::Container *)container; + const auto cxx_key = std::string(key); + if (!cxx_container->contains(cxx_key)) + return nullptr; + const auto cxx_component = new openPMD::Mesh(cxx_container->at(cxx_key)); + const auto component = (openPMD_Mesh *)cxx_component; + return component; +} + +void openPMD_Container_Mesh_set( + openPMD_Container_Mesh *container, + const char *key, + const openPMD_Mesh *component) +{ + const auto cxx_container = (openPMD::Container *)container; + const auto cxx_component = (const openPMD::Mesh *)component; + (*cxx_container)[std::string(key)] = *cxx_component; +} + +bool openPMD_Container_Mesh_contains( + const openPMD_Container_Mesh *container, const char *key) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->contains(std::string(key)); +} + +void openPMD_Container_Mesh_erase( + openPMD_Container_Mesh *container, const char *key) +{ + const auto cxx_container = (openPMD::Container *)container; + cxx_container->erase(std::string(key)); +} diff --git a/src/binding/c/Datatype.cpp b/src/binding/c/Datatype.cpp new file mode 100644 index 0000000000..a1e64b2490 --- /dev/null +++ b/src/binding/c/Datatype.cpp @@ -0,0 +1,173 @@ +#include + +#include + +#include + +static const std::vector &getDatatypes() +{ + static const std::vector c_datatypes = []() { + const auto types = openPMD::openPMD_Datatypes(); + std::vector c_types(types.size()); + for (std::size_t n = 0; n < types.size(); ++n) + c_types[n] = openPMD_Datatype(types[n]); + return c_types; + }(); + return c_datatypes; +} +const openPMD_Datatype *openPMD_Datatypes() +{ + return getDatatypes().data(); +} +size_t openPMD_DatatypesSize() +{ + return getDatatypes().size(); +} + +size_t openPMD_toBytes(openPMD_Datatype datatype) +{ + return openPMD::toBytes(openPMD::Datatype(datatype)); +} + +size_t openPMD_toBits(openPMD_Datatype datatype) +{ + return openPMD::toBits(openPMD::Datatype(datatype)); +} + +bool openPMD_isVector(openPMD_Datatype datatype) +{ + return openPMD::isVector(openPMD::Datatype(datatype)); +} + +bool openPMD_isFloatingPoint(openPMD_Datatype datatype) +{ + return openPMD::isFloatingPoint(openPMD::Datatype(datatype)); +} + +bool openPMD_isComplexFloatingPoint(openPMD_Datatype datatype) +{ + return openPMD::isComplexFloatingPoint(openPMD::Datatype(datatype)); +} + +bool openPMD_isInteger(openPMD_Datatype datatype) +{ + return std::get<0>(openPMD::isInteger(openPMD::Datatype(datatype))); +} + +bool openPMD_isSigned(openPMD_Datatype datatype) +{ + return std::get<1>(openPMD::isInteger(openPMD::Datatype(datatype))); +} + +bool openPMD_isChar(openPMD_Datatype datatype) +{ + return openPMD::isChar(openPMD::Datatype(datatype)); +} + +bool openPMD_isSame(openPMD_Datatype datatype1, openPMD_Datatype datatype2) +{ + return openPMD::isSame( + openPMD::Datatype(datatype1), openPMD::Datatype(datatype2)); +} + +openPMD_Datatype openPMD_basicDatatype(openPMD_Datatype datatype) +{ + return openPMD_Datatype( + openPMD::basicDatatype(openPMD::Datatype(datatype))); +} + +openPMD_Datatype openPMD_toVectorType(openPMD_Datatype datatype) +{ + return openPMD_Datatype(openPMD::toVectorType(openPMD::Datatype(datatype))); +} + +const char *openPMD_datatypeToString(openPMD_Datatype datatype) +{ + switch (datatype) + { + case openPMD_Datatype_CHAR: + return "CHAR"; + case openPMD_Datatype_UCHAR: + return "UCHAR"; + case openPMD_Datatype_SCHAR: + return "SCHAR"; + case openPMD_Datatype_SHORT: + return "SHORT"; + case openPMD_Datatype_INT: + return "INT"; + case openPMD_Datatype_LONG: + return "LONG"; + case openPMD_Datatype_LONGLONG: + return "LONGLONG"; + case openPMD_Datatype_USHORT: + return "USHORT"; + case openPMD_Datatype_UINT: + return "UINT"; + case openPMD_Datatype_ULONG: + return "ULONG"; + case openPMD_Datatype_ULONGLONG: + return "ULONGLONG"; + case openPMD_Datatype_FLOAT: + return "FLOAT"; + case openPMD_Datatype_DOUBLE: + return "DOUBLE"; + case openPMD_Datatype_LONG_DOUBLE: + return "LONG_DOUBLE"; + case openPMD_Datatype_CFLOAT: + return "CFLOAT"; + case openPMD_Datatype_CDOUBLE: + return "CDOUBLE"; + case openPMD_Datatype_CLONG_DOUBLE: + return "CLONG_DOUBLE"; + case openPMD_Datatype_STRING: + return "STRING"; + case openPMD_Datatype_VEC_CHAR: + return "VEC_CHAR"; + case openPMD_Datatype_VEC_SHORT: + return "VEC_SHORT"; + case openPMD_Datatype_VEC_INT: + return "VEC_INT"; + case openPMD_Datatype_VEC_LONG: + return "VEC_LONG"; + case openPMD_Datatype_VEC_LONGLONG: + return "VEC_LONGLONG"; + case openPMD_Datatype_VEC_UCHAR: + return "VEC_UCHAR"; + case openPMD_Datatype_VEC_USHORT: + return "VEC_USHORT"; + case openPMD_Datatype_VEC_UINT: + return "VEC_UINT"; + case openPMD_Datatype_VEC_ULONG: + return "VEC_ULONG"; + case openPMD_Datatype_VEC_ULONGLONG: + return "VEC_ULONGLONG"; + case openPMD_Datatype_VEC_FLOAT: + return "VEC_FLOAT"; + case openPMD_Datatype_VEC_DOUBLE: + return "VEC_DOUBLE"; + case openPMD_Datatype_VEC_LONG_DOUBLE: + return "VEC_LONG_DOUBLE"; + case openPMD_Datatype_VEC_CFLOAT: + return "VEC_CFLOAT"; + case openPMD_Datatype_VEC_CDOUBLE: + return "VEC_CDOUBLE"; + case openPMD_Datatype_VEC_CLONG_DOUBLE: + return "VEC_CLONG_DOUBLE"; + case openPMD_Datatype_VEC_SCHAR: + return "VEC_SCHAR"; + case openPMD_Datatype_VEC_STRING: + return "VEC_STRING"; + case openPMD_Datatype_ARR_DBL_7: + return "ARR_DBL_7"; + case openPMD_Datatype_BOOL: + return "BOOL"; + case openPMD_Datatype_UNDEFINED: + return "UNDEFINED"; + } + abort(); +} + +openPMD_Datatype openPMD_stringToDatatype(const char *string) +{ + return openPMD_Datatype(openPMD::stringToDatatype(std::string(string))); +} diff --git a/src/binding/c/IO/Access.cpp b/src/binding/c/IO/Access.cpp new file mode 100644 index 0000000000..25e4251928 --- /dev/null +++ b/src/binding/c/IO/Access.cpp @@ -0,0 +1,23 @@ +#include + +#include + +bool openPMD_Access_readOnly(openPMD_Access access) +{ + return openPMD::access::readOnly(openPMD::Access(access)); +} + +bool openPMD_Access_write(openPMD_Access access) +{ + return openPMD::access::write(openPMD::Access(access)); +} + +bool openPMD_Access_writeOnly(openPMD_Access access) +{ + return openPMD::access::writeOnly(openPMD::Access(access)); +} + +bool openPMD_Access_read(openPMD_Access access) +{ + return openPMD::access::read(openPMD::Access(access)); +} diff --git a/src/binding/c/IO/Format.cpp b/src/binding/c/IO/Format.cpp new file mode 100644 index 0000000000..9beca73b7b --- /dev/null +++ b/src/binding/c/IO/Format.cpp @@ -0,0 +1,37 @@ +#include + +#include + +#include +#include + +openPMD_Format openPMD_determineFormat(const char *filename) +{ + return openPMD_Format(openPMD::determineFormat(std::string(filename))); +} + +const char *openPMD_suffix(openPMD_Format format) +{ + switch (format) + { + case openPMD_Format_HDF5: + return ".h5"; + case openPMD_Format_ADIOS2_BP: + return ".bp"; + case openPMD_Format_ADIOS2_BP4: + return ".bp4"; + case openPMD_Format_ADIOS2_BP5: + return ".bp5"; + case openPMD_Format_ADIOS2_SST: + return ".sst"; + case openPMD_Format_ADIOS2_SSC: + return ".ssc"; + case openPMD_Format_JSON: + return ".json"; + case openPMD_Format_TOML: + return ".toml"; + case openPMD_Format_DUMMY: + return ""; + } + abort(); +} diff --git a/src/binding/c/Iteration.cpp b/src/binding/c/Iteration.cpp new file mode 100644 index 0000000000..0a339aeef2 --- /dev/null +++ b/src/binding/c/Iteration.cpp @@ -0,0 +1,145 @@ +#include + +#include + +const openPMD_Attributable * +openPMD_Iteration_getConstAttributable(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_iteration; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable * +openPMD_Iteration_getAttributable(openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + const auto cxx_attributable = (openPMD::Attributable *)cxx_iteration; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Iteration *openPMD_Iteration_copy(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + const auto cxx_new_iteration = new openPMD::Iteration(*cxx_iteration); + const auto new_iteration = (openPMD_Iteration *)cxx_new_iteration; + return new_iteration; +} + +double openPMD_Iteration_time(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + return cxx_iteration->time(); +} + +void openPMD_Iteration_setTime(openPMD_Iteration *iteration, double newTime) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + cxx_iteration->setTime(newTime); +} + +double openPMD_Iteration_dt(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + return cxx_iteration->dt(); +} + +void openPMD_Iteration_setDt(openPMD_Iteration *iteration, double newDt) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + cxx_iteration->setDt(newDt); +} + +double openPMD_Iteration_timeUnitSI(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + return cxx_iteration->timeUnitSI(); +} + +void openPMD_Iteration_setTimeUnitSI( + openPMD_Iteration *iteration, double newTimeUnitSI) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + cxx_iteration->setTimeUnitSI(newTimeUnitSI); +} + +void openPMD_Iteration_close(openPMD_Iteration *iteration, bool flush) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + cxx_iteration->close(flush); +} + +void openPMD_Iteration_open(openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + cxx_iteration->open(); +} + +bool openPMD_Iteration_closed(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + return cxx_iteration->closed(); +} + +const openPMD_Container_Mesh * +openPMD_Iteration_constMeshes(const openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (const openPMD::Iteration *)iteration; + const auto cxx_meshes = &cxx_iteration->meshes; + const auto meshes = (const openPMD_Container_Mesh *)cxx_meshes; + return meshes; +} + +openPMD_Container_Mesh *openPMD_Iteration_meshes(openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + const auto cxx_meshes = &cxx_iteration->meshes; + const auto meshes = (openPMD_Container_Mesh *)cxx_meshes; + return meshes; +} + +void openPMD_Iteration_delete(openPMD_Iteration *iteration) +{ + const auto cxx_iteration = (openPMD::Iteration *)iteration; + delete cxx_iteration; +} + +const openPMD_Iteration *openPMD_IndexedIteration_getConstIteration( + const openPMD_IndexedIteration *indexed_iteration) +{ + const auto cxx_indexed_iteration = + (const openPMD::IndexedIteration *)indexed_iteration; + const auto cxx_iteration = + (const openPMD::Iteration *)cxx_indexed_iteration; + const auto cxx_new_iteration = new openPMD::Iteration(*cxx_iteration); + const auto new_iteration = (const openPMD_Iteration *)cxx_new_iteration; + return new_iteration; +} + +openPMD_Iteration *openPMD_IndexedIteration_getIteration( + openPMD_IndexedIteration *indexed_iteration) +{ + const auto cxx_indexed_iteration = + (openPMD::IndexedIteration *)indexed_iteration; + const auto cxx_iteration = (openPMD::Iteration *)cxx_indexed_iteration; + const auto cxx_new_iteration = new openPMD::Iteration(*cxx_iteration); + const auto new_iteration = (openPMD_Iteration *)cxx_new_iteration; + return new_iteration; +} + +uint64_t openPMD_IndexedIteration_iterationIndex( + const openPMD_IndexedIteration *indexed_iteration) +{ + const auto cxx_indexed_iteration = + (const openPMD::IndexedIteration *)indexed_iteration; + return cxx_indexed_iteration->iterationIndex; +} + +void openPMD_IndexedIteration_delete(openPMD_IndexedIteration *indexedIteration) +{ + const auto cxx_indexedIteration = + (openPMD::IndexedIteration *)indexedIteration; + delete cxx_indexedIteration; +} diff --git a/src/binding/c/Mesh.cpp b/src/binding/c/Mesh.cpp new file mode 100644 index 0000000000..ccca7baa8c --- /dev/null +++ b/src/binding/c/Mesh.cpp @@ -0,0 +1,250 @@ +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +const openPMD_Container_MeshRecordComponent * +openPMD_Mesh_getConstContainer_MeshRecordComponent(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_container = + (const openPMD::Container *)cxx_mesh; + const auto container = + (const openPMD_Container_MeshRecordComponent *)cxx_container; + return container; +} + +openPMD_Container_MeshRecordComponent * +openPMD_Mesh_getContainer_MeshRecordComponent(openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + const auto cxx_container = + (openPMD::Container *)cxx_mesh; + const auto container = + (openPMD_Container_MeshRecordComponent *)cxx_container; + return container; +} + +// From BaseRecord (too lazy to wrap this class) +openPMD_ArrayDouble7 openPMD_Mesh_unitDimension(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_unitDimension = cxx_mesh->unitDimension(); + openPMD_ArrayDouble7 unitDimension; + for (size_t n = 0; n < 7; ++n) + unitDimension.element[n] = cxx_unitDimension[n]; + return unitDimension; +} + +bool openPMD_Mesh_scalar(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + return cxx_mesh->scalar(); +} + +// From Mesh +openPMD_Mesh *openPMD_Mesh_copy(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_mesh_copy = new openPMD::Mesh(*cxx_mesh); + const auto mesh_copy = (openPMD_Mesh *)cxx_mesh_copy; + return mesh_copy; +} + +void openPMD_Mesh_delete(openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + delete cxx_mesh; +} + +openPMD_Mesh_Geometry openPMD_Mesh_geometry(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_geometry = cxx_mesh->geometry(); + const auto geometry = openPMD_Mesh_Geometry(cxx_geometry); + return geometry; +} + +const char *openPMD_Mesh_geometryString(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_geometry = cxx_mesh->geometry(); + const auto geometry = openPMD_Mesh_Geometry(cxx_geometry); + switch (geometry) + { + case openPMD_Mesh_Geometry_cartesian: + return "cartesian"; + case openPMD_Mesh_Geometry_thetaMode: + return "thetaMode"; + case openPMD_Mesh_Geometry_cylindrical: + return "cylindrical"; + case openPMD_Mesh_Geometry_spherical: + return "spherical"; + case openPMD_Mesh_Geometry_other: + return "other"; + } + abort(); +} + +void openPMD_Mesh_setGeometry( + openPMD_Mesh *mesh, openPMD_Mesh_Geometry geometry) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + const auto cxx_geometry = openPMD::Mesh::Geometry(geometry); + cxx_mesh->setGeometry(cxx_geometry); +} + +char *openPMD_Mesh_geometryParameters(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_parameters = cxx_mesh->geometryParameters(); + return strdup(cxx_parameters.c_str()); +} + +void openPMD_Mesh_setGeometryParameters( + openPMD_Mesh *mesh, const char *geometryParameters) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + cxx_mesh->setGeometryParameters(std::string(geometryParameters)); +} + +openPMD_Mesh_DataOrder openPMD_Mesh_dataOrder(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_dataOrder = cxx_mesh->dataOrder(); + const auto dataOrder = openPMD_Mesh_DataOrder(cxx_dataOrder); + return dataOrder; +} + +void openPMD_Mesh_setDataOrder( + openPMD_Mesh *mesh, openPMD_Mesh_DataOrder dataOrder) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + const auto cxx_dataOrder = openPMD::Mesh::DataOrder(dataOrder); + cxx_mesh->setDataOrder(cxx_dataOrder); +} + +char **openPMD_Mesh_axisLabels(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_axisLabels = cxx_mesh->axisLabels(); + const size_t size = cxx_axisLabels.size(); + char **axisLabels = (char **)malloc(size * sizeof *axisLabels); + for (size_t d = 0; d < cxx_axisLabels.size(); ++d) + axisLabels[d] = strdup(cxx_axisLabels[d].c_str()); + return axisLabels; +} + +size_t openPMD_Mesh_axisLabelsSize(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_axisLabels = cxx_mesh->axisLabels(); + return cxx_axisLabels.size(); +} + +void openPMD_Mesh_setAxisLabels( + openPMD_Mesh *mesh, const char *const *axisLabels, size_t size) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + std::vector cxx_axisLabels(size); + for (size_t d = 0; d < size; ++d) + cxx_axisLabels[d] = std::string(axisLabels[d]); + cxx_mesh->setAxisLabels(std::move(cxx_axisLabels)); +} + +double *openPMD_Mesh_gridSpacing(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_gridSpacing = cxx_mesh->gridSpacing(); + const size_t size = cxx_gridSpacing.size(); + double *gridSpacing = (double *)malloc(size * sizeof *gridSpacing); + for (size_t d = 0; d < size; ++d) + gridSpacing[d] = cxx_gridSpacing[d]; + return gridSpacing; +} + +size_t openPMD_Mesh_gridSpacingSize(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_gridSpacing = cxx_mesh->gridSpacing(); + return cxx_gridSpacing.size(); +} + +void openPMD_Mesh_setgridSpacing( + openPMD_Mesh *mesh, const double gridSpacing, size_t size) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + std::vector cxx_gridSpacing(gridSpacing, gridSpacing + size); + cxx_mesh->setGridSpacing(std::move(cxx_gridSpacing)); +} + +double *openPMD_Mesh_gridGlobalOffset(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_gridGlobalOffset = cxx_mesh->gridGlobalOffset(); + const size_t size = cxx_gridGlobalOffset.size(); + double *gridGlobalOffset = + (double *)malloc(size * sizeof *gridGlobalOffset); + for (size_t d = 0; d < size; ++d) + gridGlobalOffset[d] = cxx_gridGlobalOffset[d]; + return gridGlobalOffset; +} + +size_t openPMD_Mesh_gridGlobalOffsetSize(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + const auto cxx_gridGlobalOffset = cxx_mesh->gridGlobalOffset(); + return cxx_gridGlobalOffset.size(); +} + +void openPMD_Mesh_setgridGlobalOffset( + openPMD_Mesh *mesh, const double gridGlobalOffset, size_t size) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + std::vector cxx_gridGlobalOffset( + gridGlobalOffset, gridGlobalOffset + size); + cxx_mesh->setGridGlobalOffset(std::move(cxx_gridGlobalOffset)); +} + +double openPMD_Mesh_gridUnitSI(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + return cxx_mesh->gridUnitSI(); +} + +void openPMD_Mesh_setGridUnitSI(openPMD_Mesh *mesh, double unitSI) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + cxx_mesh->setGridUnitSI(unitSI); +} + +void openPMD_Mesh_setUnitDimension( + openPMD_Mesh *mesh, const openPMD_ArrayDouble7 *unitDimension) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + std::map cxx_unitDimension; + for (size_t n = 0; n < 7; ++n) + cxx_unitDimension[openPMD::UnitDimension(n)] = + unitDimension->element[n]; + cxx_mesh->setUnitDimension(std::move(cxx_unitDimension)); +} + +double openPMD_Mesh_timeOffset(const openPMD_Mesh *mesh) +{ + const auto cxx_mesh = (const openPMD::Mesh *)mesh; + return cxx_mesh->timeOffset(); +} + +void openPMD_Mesh_setTimeOffset(openPMD_Mesh *mesh, double timeOffset) +{ + const auto cxx_mesh = (openPMD::Mesh *)mesh; + cxx_mesh->setTimeOffset(timeOffset); +} diff --git a/src/binding/c/ReadIterations.cpp b/src/binding/c/ReadIterations.cpp new file mode 100644 index 0000000000..f388f9b782 --- /dev/null +++ b/src/binding/c/ReadIterations.cpp @@ -0,0 +1,68 @@ +#include + +#include +#include + +// SeriesIterator + +openPMD_SeriesIterator *openPMD_SeriesIterator_new( + openPMD_Series *series, openPMD_ParsePreference parsePreference) +{ + const auto cxx_series = (openPMD::Series *)series; + std::optional cxx_parsePreference; + if (parsePreference != openPMD_ParsePreference_None) + cxx_parsePreference = { + openPMD::internal::ParsePreference(parsePreference)}; + const auto cxx_seriesIterator = + new openPMD::SeriesIterator(*cxx_series, cxx_parsePreference); + const auto seriesIterator = (openPMD_SeriesIterator *)cxx_seriesIterator; + return seriesIterator; +} + +void openPMD_SeriesIterator_delete(openPMD_SeriesIterator *seriesIterator) +{ + const auto cxx_seriesIterator = (openPMD::SeriesIterator *)seriesIterator; + delete cxx_seriesIterator; +} + +bool openPMD_SeriesIterator_done(const openPMD_SeriesIterator *seriesIterator) +{ + const auto cxx_seriesIterator = + (const openPMD::SeriesIterator *)seriesIterator; + return *cxx_seriesIterator == openPMD::SeriesIterator::end(); +} + +void openPMD_SeriesIterator_advance(openPMD_SeriesIterator *seriesIterator) +{ + const auto cxx_seriesIterator = (openPMD::SeriesIterator *)seriesIterator; + ++*cxx_seriesIterator; +} + +openPMD_IndexedIteration * +openPMD_SeriesIterator_get(openPMD_SeriesIterator *seriesIterator) +{ + const auto cxx_seriesIterator = (openPMD::SeriesIterator *)seriesIterator; + const auto cxx_indexedIteration = + new openPMD::IndexedIteration(**cxx_seriesIterator); + const auto indexedIteration = + (openPMD_IndexedIteration *)cxx_indexedIteration; + return indexedIteration; +} + +// ReadIterations + +void openPMD_ReadIterations_delete(openPMD_ReadIterations *readIterations) +{ + const auto cxx_readIterations = (openPMD::ReadIterations *)readIterations; + delete cxx_readIterations; +} + +openPMD_SeriesIterator * +openPMD_ReadIterations_iterate(const openPMD_ReadIterations *readIterations) +{ + const auto cxx_readIterations = (openPMD::ReadIterations *)readIterations; + const auto cxx_seriesIterator = + new openPMD::SeriesIterator(cxx_readIterations->begin()); + const auto seriesIterator = (openPMD_SeriesIterator *)cxx_seriesIterator; + return seriesIterator; +} diff --git a/src/binding/c/RecordComponent.cpp b/src/binding/c/RecordComponent.cpp new file mode 100644 index 0000000000..279ab95da2 --- /dev/null +++ b/src/binding/c/RecordComponent.cpp @@ -0,0 +1,373 @@ +#include + +#include + +#include +#include +#include +#include +#include + +const openPMD_BaseRecordComponent * +openPMD_RecordComponent_getConstBaseRecordComponent( + const openPMD_RecordComponent *component) +{ + const auto cxx_component = (const openPMD::RecordComponent *)component; + const auto cxx_baseComponent = + (const openPMD::BaseRecordComponent *)cxx_component; + const auto baseComponent = + (const openPMD_BaseRecordComponent *)cxx_baseComponent; + return baseComponent; +} + +openPMD_BaseRecordComponent *openPMD_RecordComponent_getBaseRecordComponent( + openPMD_RecordComponent *component) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + const auto cxx_baseComponent = + (openPMD::BaseRecordComponent *)cxx_component; + const auto baseComponent = (openPMD_BaseRecordComponent *)cxx_baseComponent; + return baseComponent; +} + +void openPMD_RecordComponent_setUnitSI( + openPMD_RecordComponent *component, double unit) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + cxx_component->setUnitSI(unit); +} + +void openPMD_RecordComponent_resetDataset( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + const uint64_t *extent, + size_t rank, + const char *options) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + const openPMD::Dataset cxx_dataset( + openPMD::Datatype(datatype), + openPMD::Extent(extent, extent + rank), + std::string(options ? options : "{}")); + cxx_component->resetDataset(std::move(cxx_dataset)); +} + +uint8_t openPMD_RecordComponent_getDimensionality( + const openPMD_RecordComponent *component) +{ + const auto cxx_component = (const openPMD::RecordComponent *)component; + return cxx_component->getDimensionality(); +} + +uint64_t * +openPMD_RecordComponent_getExtent(const openPMD_RecordComponent *component) +{ + const auto cxx_component = (const openPMD::RecordComponent *)component; + const auto cxx_extent = cxx_component->getExtent(); + uint64_t *extent = (uint64_t *)malloc(cxx_extent.size() * sizeof *extent); + memcpy(extent, cxx_extent.data(), cxx_extent.size() * sizeof *extent); + return extent; +} + +size_t +openPMD_RecordComponent_getExtentSize(const openPMD_RecordComponent *component) +{ + const auto cxx_component = (const openPMD::RecordComponent *)component; + const auto cxx_extent = cxx_component->getExtent(); + return cxx_extent.size(); +} + +void openPMD_RecordComponent_makeConstant( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + const void *data) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + switch (datatype) + { + case openPMD_Datatype_CHAR: + cxx_component->makeConstant(*(const char *)data); + break; + case openPMD_Datatype_UCHAR: + cxx_component->makeConstant(*(const unsigned char *)data); + break; + case openPMD_Datatype_SCHAR: + cxx_component->makeConstant(*(const signed char *)data); + break; + case openPMD_Datatype_SHORT: + cxx_component->makeConstant(*(const short *)data); + break; + case openPMD_Datatype_INT: + cxx_component->makeConstant(*(const int *)data); + break; + case openPMD_Datatype_LONG: + cxx_component->makeConstant(*(const long *)data); + break; + case openPMD_Datatype_LONGLONG: + cxx_component->makeConstant(*(const long long *)data); + break; + case openPMD_Datatype_USHORT: + cxx_component->makeConstant(*(const unsigned short *)data); + break; + case openPMD_Datatype_UINT: + cxx_component->makeConstant(*(const unsigned int *)data); + break; + case openPMD_Datatype_ULONG: + cxx_component->makeConstant(*(const unsigned long *)data); + break; + case openPMD_Datatype_ULONGLONG: + cxx_component->makeConstant(*(const unsigned long long *)data); + break; + case openPMD_Datatype_FLOAT: + cxx_component->makeConstant(*(const float *)data); + break; + case openPMD_Datatype_DOUBLE: + cxx_component->makeConstant(*(const double *)data); + break; + case openPMD_Datatype_LONG_DOUBLE: + cxx_component->makeConstant(*(const long double *)data); + break; + case openPMD_Datatype_CFLOAT: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_CDOUBLE: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_CLONG_DOUBLE: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_BOOL: + cxx_component->makeConstant(*(const bool *)data); + break; + default: + abort(); + } +} + +void openPMD_RecordComponent_makeEmpty( + openPMD_RecordComponent *component, + openPMD_Datatype datatype, + uint8_t dimensions) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + cxx_component->makeEmpty(openPMD::Datatype(datatype), dimensions); +} + +bool openPMD_RecordComponent_empty(const openPMD_RecordComponent *component) +{ + const auto cxx_component = (const openPMD::RecordComponent *)component; + return cxx_component->empty(); +} + +void openPMD_RecordComponent_loadChunkRaw( + openPMD_RecordComponent *component, + void *data, + openPMD_Datatype datatype, + const uint64_t *offset, + const uint64_t *extent, + size_t size) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + const openPMD::Offset cxx_offset(offset, offset + size); + const openPMD::Extent cxx_extent(extent, extent + size); + switch (datatype) + { + case openPMD_Datatype_CHAR: + cxx_component->loadChunkRaw( + (char *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_UCHAR: + cxx_component->loadChunkRaw( + (unsigned char *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_SCHAR: + cxx_component->loadChunkRaw( + (signed char *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_SHORT: + cxx_component->loadChunkRaw( + (short *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_INT: + cxx_component->loadChunkRaw( + (int *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONG: + cxx_component->loadChunkRaw( + (long *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONGLONG: + cxx_component->loadChunkRaw( + (long long *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_USHORT: + cxx_component->loadChunkRaw( + (unsigned short *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_UINT: + cxx_component->loadChunkRaw( + (unsigned int *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_ULONG: + cxx_component->loadChunkRaw( + (unsigned long *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_ULONGLONG: + cxx_component->loadChunkRaw( + (unsigned long long *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_FLOAT: + cxx_component->loadChunkRaw( + (float *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_DOUBLE: + cxx_component->loadChunkRaw( + (double *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONG_DOUBLE: + cxx_component->loadChunkRaw( + (long double *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_CFLOAT: + cxx_component->loadChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_CDOUBLE: + cxx_component->loadChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_CLONG_DOUBLE: + cxx_component->loadChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_BOOL: + cxx_component->loadChunkRaw( + (bool *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + default: + abort(); + } +} + +void openPMD_RecordComponent_storeChunkRaw( + openPMD_RecordComponent *component, + void *data, + openPMD_Datatype datatype, + const uint64_t *offset, + const uint64_t *extent, + size_t size) +{ + const auto cxx_component = (openPMD::RecordComponent *)component; + const openPMD::Offset cxx_offset(offset, offset + size); + const openPMD::Extent cxx_extent(extent, extent + size); + switch (datatype) + { + case openPMD_Datatype_CHAR: + cxx_component->storeChunkRaw( + (char *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_UCHAR: + cxx_component->storeChunkRaw( + (unsigned char *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_SCHAR: + cxx_component->storeChunkRaw( + (signed char *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_SHORT: + cxx_component->storeChunkRaw( + (short *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_INT: + cxx_component->storeChunkRaw( + (int *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONG: + cxx_component->storeChunkRaw( + (long *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONGLONG: + cxx_component->storeChunkRaw( + (long long *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_USHORT: + cxx_component->storeChunkRaw( + (unsigned short *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_UINT: + cxx_component->storeChunkRaw( + (unsigned int *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_ULONG: + cxx_component->storeChunkRaw( + (unsigned long *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_ULONGLONG: + cxx_component->storeChunkRaw( + (unsigned long long *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_FLOAT: + cxx_component->storeChunkRaw( + (float *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_DOUBLE: + cxx_component->storeChunkRaw( + (double *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_LONG_DOUBLE: + cxx_component->storeChunkRaw( + (long double *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + case openPMD_Datatype_CFLOAT: + cxx_component->storeChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_CDOUBLE: + cxx_component->storeChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_CLONG_DOUBLE: + cxx_component->storeChunkRaw( + (std::complex *)data, + std::move(cxx_offset), + std::move(cxx_extent)); + break; + case openPMD_Datatype_BOOL: + cxx_component->storeChunkRaw( + (bool *)data, std::move(cxx_offset), std::move(cxx_extent)); + break; + default: + abort(); + } +} + +char const *openPMD_RecordComponent_SCALAR() +{ + return openPMD::RecordComponent::SCALAR; +} diff --git a/src/binding/c/Series.cpp b/src/binding/c/Series.cpp new file mode 100644 index 0000000000..b41d70f395 --- /dev/null +++ b/src/binding/c/Series.cpp @@ -0,0 +1,288 @@ +#include + +#include + +#include +#include + +const openPMD_Attributable * +openPMD_Series_getConstAttributable(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_series; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable *openPMD_Series_getAttributable(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + const auto cxx_attributable = (openPMD::Attributable *)cxx_series; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Series *openPMD_Series_new() +{ + const auto cxx_series = new openPMD::Series(); + const auto series = (openPMD_Series *)cxx_series; + return series; +} + +#if openPMD_HAVE_MPI +openPMD_Series *openPMD_Series_new_parallell( + const char *filepath, openPMD_Access at, MPI_Comm comm, const char *options) +{ + const auto cxx_series = new openPMD::Series( + std::string(filepath), + openPMD::Access(at), + comm, + std::string(options ? options : "{}")); + const auto series = (openPMD_Series *)cxx_series; + return series; +} +#endif + +openPMD_Series *openPMD_Series_new_serial( + const char *filepath, openPMD_Access at, const char *options) +{ + const auto cxx_series = new openPMD::Series( + std::string(filepath), + openPMD::Access(at), + std::string(options ? options : "{}")); + const auto series = (openPMD_Series *)cxx_series; + return series; +} + +void openPMD_Series_delete(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + delete cxx_series; +} + +const openPMD_Container_Iteration * +openPMD_Series_constIterations(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return (const openPMD_Container_Iteration *)&cxx_series->iterations; +} + +openPMD_Container_Iteration *openPMD_Series_iterations(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + return (openPMD_Container_Iteration *)&cxx_series->iterations; +} + +bool openPMD_Series_has_value(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return (bool)*cxx_series; +} + +char *openPMD_Series_openPMD(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->openPMD().c_str()); +} + +void openPMD_Series_setOpenPMD(openPMD_Series *series, const char *openPMD) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setOpenPMD(std::string(openPMD)); +} + +uint32_t openPMD_Series_openPMDextension(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return cxx_series->openPMDextension(); +} + +void openPMD_Series_setOpenPMDextension( + openPMD_Series *series, uint32_t openPMDextension) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setOpenPMDextension(openPMDextension); +} + +char *openPMD_Series_basePath(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->basePath().c_str()); +} + +void openPMD_Series_setBasePath(openPMD_Series *series, const char *basePath) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setBasePath(std::string(basePath)); +} + +char *openPMD_Series_meshesPath(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->meshesPath().c_str()); +} + +void openPMD_Series_setMeshesPath( + openPMD_Series *series, const char *meshesPath) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setMeshesPath(std::string(meshesPath)); +} + +char *openPMD_Series_particlesPath(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->particlesPath().c_str()); +} + +void openPMD_Series_setParticlesPath( + openPMD_Series *series, const char *particlesPath) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setParticlesPath(std::string(particlesPath)); +} + +char *openPMD_Series_author(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->author().c_str()); +} + +void openPMD_Series_setAuthor(openPMD_Series *series, const char *author) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setAuthor(std::string(author)); +} + +char *openPMD_Series_software(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->software().c_str()); +} + +void openPMD_Series_setSoftware( + openPMD_Series *series, const char *software, const char *version) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setSoftware(std::string(software), std::string(version)); +} + +char *openPMD_Series_date(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->date().c_str()); +} + +void openPMD_Series_setDate(openPMD_Series *series, const char *date) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setDate(std::string(date)); +} + +char *openPMD_Series_softwareDependencies(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->softwareDependencies().c_str()); +} + +void openPMD_Series_setSoftwareDependencies( + openPMD_Series *series, const char *softwareDependencies) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setSoftwareDependencies(std::string(softwareDependencies)); +} + +char *openPMD_Series_machine(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->machine().c_str()); +} + +void openPMD_Series_setMachine(openPMD_Series *series, const char *machine) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setMachine(std::string(machine)); +} + +openPMD_IterationEncoding +openPMD_Series_iterationEncoding(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return openPMD_IterationEncoding(cxx_series->iterationEncoding()); +} + +void openPMD_Series_setIterationEncoding( + openPMD_Series *series, openPMD_IterationEncoding iterationEncoding) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setIterationEncoding( + openPMD::IterationEncoding(iterationEncoding)); +} + +char *openPMD_Series_iterationFormat(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->iterationFormat().c_str()); +} + +void openPMD_Series_setIterationFormat( + openPMD_Series *series, const char *iterationFormat) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setIterationFormat(std::string(iterationFormat)); +} + +char *openPMD_Series_name(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->name().c_str()); +} + +void openPMD_Series_setName(openPMD_Series *series, const char *name) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->setName(std::string(name)); +} + +char *openPMD_Series_backend(const openPMD_Series *series) +{ + const auto cxx_series = (const openPMD::Series *)series; + return strdup(cxx_series->backend().c_str()); +} + +void openPMD_Series_flush(openPMD_Series *series, const char *backendConfig) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->flush(std::string(backendConfig ? backendConfig : "{}")); +} + +openPMD_ReadIterations *openPMD_Series_readIteration(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + const auto cxx_iterations = cxx_series->readIterations(); + const auto cxx_new_iterations = new openPMD::ReadIterations(cxx_iterations); + const auto iterations = (openPMD_ReadIterations *)cxx_new_iterations; + return iterations; +} + +void openPMD_Series_parseBase(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->parseBase(); +} + +openPMD_WriteIterations *openPMD_Series_writeIteration(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + const auto cxx_iterations = cxx_series->writeIterations(); + const auto cxx_new_iterations = + new openPMD::WriteIterations(cxx_iterations); + const auto iterations = (openPMD_WriteIterations *)cxx_new_iterations; + return iterations; +} + +void openPMD_Series_close(openPMD_Series *series) +{ + const auto cxx_series = (openPMD::Series *)series; + cxx_series->close(); +} diff --git a/src/binding/c/UnitDimension.cpp b/src/binding/c/UnitDimension.cpp new file mode 100644 index 0000000000..6f48e0d14e --- /dev/null +++ b/src/binding/c/UnitDimension.cpp @@ -0,0 +1,3 @@ +#include + +#include diff --git a/src/binding/c/WriteIterations.cpp b/src/binding/c/WriteIterations.cpp new file mode 100644 index 0000000000..4f149db5eb --- /dev/null +++ b/src/binding/c/WriteIterations.cpp @@ -0,0 +1,36 @@ +#include + +#include + +void openPMD_WriteIterations_delete(openPMD_WriteIterations *writeIterations) +{ + const auto cxx_writeIterations = + (openPMD::WriteIterations *)writeIterations; + delete cxx_writeIterations; +} + +openPMD_Iteration *openPMD_WriteIterations_get( + openPMD_WriteIterations *writeIterations, uint64_t key) +{ + const auto cxx_writeIterations = + (openPMD::WriteIterations *)writeIterations; + const auto cxx_iteration = (*cxx_writeIterations)[key]; + const auto cxx_new_iteration = new openPMD::Iteration(cxx_iteration); + const auto iteration = (openPMD_Iteration *)cxx_new_iteration; + return iteration; +} + +openPMD_IndexedIteration *openPMD_WriteIterations_currentIteration( + openPMD_WriteIterations *writeIterations) +{ + const auto cxx_writeIterations = + (openPMD::WriteIterations *)writeIterations; + const auto cxx_indexedIteration = cxx_writeIterations->currentIteration(); + if (!cxx_indexedIteration) + return nullptr; + const auto cxx_new_indexedIteration = + new openPMD::IndexedIteration(*cxx_indexedIteration); + const auto indexedIteration = + (openPMD_IndexedIteration *)cxx_new_indexedIteration; + return indexedIteration; +} diff --git a/src/binding/c/backend/Attributable.c b/src/binding/c/backend/Attributable.c new file mode 100644 index 0000000000..c114f82ec0 --- /dev/null +++ b/src/binding/c/backend/Attributable.c @@ -0,0 +1,126 @@ +#include + +bool openPMD_Attributable_setAttribute_cfloat( + openPMD_Attributable *attributable, const char *key, complex float value) +{ + return openPMD_Attributable_setAttribute_cfloat2( + attributable, key, crealf(value), cimagf(value)); +} + +bool openPMD_Attributable_setAttribute_cdouble( + openPMD_Attributable *attributable, const char *key, complex double value) +{ + return openPMD_Attributable_setAttribute_cdouble2( + attributable, key, creal(value), cimag(value)); +} + +bool openPMD_Attributable_setAttribute_clong_double( + openPMD_Attributable *attributable, + const char *key, + complex long double value) +{ + return openPMD_Attributable_setAttribute_clong_double2( + attributable, key, creall(value), cimagl(value)); +} + +bool openPMD_Attributable_setAttribute_vec_cfloat( + openPMD_Attributable *attributable, + const char *key, + const complex float *values, + size_t size) +{ + return openPMD_Attributable_setAttribute_vec_cfloat2( + attributable, key, (const float *)values, size); +} + +bool openPMD_Attributable_setAttribute_vec_cdouble( + openPMD_Attributable *attributable, + const char *key, + const complex double *values, + size_t size) +{ + return openPMD_Attributable_setAttribute_vec_cdouble2( + attributable, key, (const double *)values, size); +} + +bool openPMD_Attributable_setAttribute_vec_clong_double( + openPMD_Attributable *attributable, + const char *key, + const complex long double *values, + size_t size) +{ + return openPMD_Attributable_setAttribute_vec_clong_double2( + attributable, key, (const long double *)values, size); +} + +bool openPMD_Attributable_getAttribute_cfloat( + const openPMD_Attributable *attributable, + const char *key, + complex float *value) +{ + return openPMD_Attributable_getAttribute_cfloat2( + attributable, key, (float *)value); +} + +bool openPMD_Attributable_getAttribute_cdouble( + const openPMD_Attributable *attributable, + const char *key, + complex double *value) +{ + return openPMD_Attributable_getAttribute_cdouble2( + attributable, key, (double *)value); +} + +bool openPMD_Attributable_getAttribute_clong_double( + const openPMD_Attributable *attributable, + const char *key, + complex long double *value) +{ + return openPMD_Attributable_getAttribute_clong_double2( + attributable, key, (long double *)value); +} + +bool openPMD_Attributable_getAttribute_vec_cfloat( + const openPMD_Attributable *attributable, + const char *key, + complex float **values, + size_t *size) +{ + float *real_values; + const bool did_exist = openPMD_Attributable_getAttribute_vec_cfloat2( + attributable, key, (float **)&real_values, size); + if (!did_exist) + return false; + *values = (complex float *)real_values; + return true; +} + +bool openPMD_Attributable_getAttribute_vec_cdouble( + const openPMD_Attributable *attributable, + const char *key, + complex double **values, + size_t *size) +{ + double *real_values; + const bool did_exist = openPMD_Attributable_getAttribute_vec_cdouble2( + attributable, key, (double **)&real_values, size); + if (!did_exist) + return false; + *values = (complex double *)real_values; + return true; +} + +bool openPMD_Attributable_getAttribute_vec_clong_double( + const openPMD_Attributable *attributable, + const char *key, + complex long double **values, + size_t *size) +{ + long double *real_values; + const bool did_exist = openPMD_Attributable_getAttribute_vec_clong_double2( + attributable, key, (long double **)&real_values, size); + if (!did_exist) + return false; + *values = (complex long double *)real_values; + return true; +} diff --git a/src/binding/c/backend/Attributable.cpp b/src/binding/c/backend/Attributable.cpp new file mode 100644 index 0000000000..2f5287abf4 --- /dev/null +++ b/src/binding/c/backend/Attributable.cpp @@ -0,0 +1,383 @@ +#include + +#include + +#include +#include +#include +#include + +openPMD_Attributable *openPMD_Attributable_new() +{ + const auto cxx_attributable = new openPMD::Attributable(); + return (openPMD_Attributable *)cxx_attributable; +} + +void openPMD_Attributable_delete(openPMD_Attributable *attributable) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + delete cxx_attributable; +} + +#define DEFINE_SETATTTRIBUTE(NAME, TYPE) \ + bool openPMD_Attributable_setAttribute_##NAME( \ + openPMD_Attributable *attributable, const char *key, TYPE value) \ + { \ + const auto cxx_attributable = (openPMD::Attributable *)attributable; \ + return cxx_attributable->setAttribute(std::string(key), value); \ + } +#define DEFINE_SETATTTRIBUTE2(NAME, TYPE) \ + bool openPMD_Attributable_setAttribute_##NAME##2( \ + openPMD_Attributable * attributable, \ + const char *key, \ + TYPE value_re, \ + TYPE value_im) \ + { \ + const auto cxx_attributable = (openPMD::Attributable *)attributable; \ + return cxx_attributable->setAttribute( \ + std::string(key), std::complex(value_re, value_im)); \ + } +#define DEFINE_SETATTTRIBUTE_VEC(NAME, TYPE) \ + bool openPMD_Attributable_setAttribute_vec_##NAME( \ + openPMD_Attributable *attributable, \ + const char *key, \ + const TYPE *values, \ + size_t size) \ + { \ + const auto cxx_attributable = (openPMD::Attributable *)attributable; \ + std::vector cxx_values(values, values + size); \ + return cxx_attributable->setAttribute(std::string(key), cxx_values); \ + } +#define DEFINE_SETATTTRIBUTE_VEC2(NAME, TYPE) \ + bool openPMD_Attributable_setAttribute_vec_##NAME##2( \ + openPMD_Attributable * attributable, \ + const char *key, \ + const TYPE *values, \ + size_t size) \ + { \ + const auto cxx_attributable = (openPMD::Attributable *)attributable; \ + const std::vector> cxx_values( \ + (const std::complex *)values, \ + (const std::complex *)values + size); \ + return cxx_attributable->setAttribute(std::string(key), cxx_values); \ + } +DEFINE_SETATTTRIBUTE(char, char) +DEFINE_SETATTTRIBUTE(uchar, unsigned char) +DEFINE_SETATTTRIBUTE(schar, signed char) +DEFINE_SETATTTRIBUTE(short, short) +DEFINE_SETATTTRIBUTE(int, int) +DEFINE_SETATTTRIBUTE(long, long) +DEFINE_SETATTTRIBUTE(longlong, long long) +DEFINE_SETATTTRIBUTE(ushort, unsigned short) +DEFINE_SETATTTRIBUTE(uint, unsigned int) +DEFINE_SETATTTRIBUTE(ulong, unsigned long) +DEFINE_SETATTTRIBUTE(ulonglong, unsigned long long) +DEFINE_SETATTTRIBUTE(float, float) +DEFINE_SETATTTRIBUTE(double, double) +DEFINE_SETATTTRIBUTE(long_double, long double) +DEFINE_SETATTTRIBUTE2(cfloat, float) +DEFINE_SETATTTRIBUTE2(cdouble, double) +DEFINE_SETATTTRIBUTE2(clong_double, long double) +DEFINE_SETATTTRIBUTE_VEC(char, char) +DEFINE_SETATTTRIBUTE_VEC(uchar, unsigned char) +DEFINE_SETATTTRIBUTE_VEC(schar, signed char) +DEFINE_SETATTTRIBUTE_VEC(short, short) +DEFINE_SETATTTRIBUTE_VEC(int, int) +DEFINE_SETATTTRIBUTE_VEC(long, long) +DEFINE_SETATTTRIBUTE_VEC(longlong, long long) +DEFINE_SETATTTRIBUTE_VEC(ushort, unsigned short) +DEFINE_SETATTTRIBUTE_VEC(uint, unsigned int) +DEFINE_SETATTTRIBUTE_VEC(ulong, unsigned long) +DEFINE_SETATTTRIBUTE_VEC(ulonglong, unsigned long long) +DEFINE_SETATTTRIBUTE_VEC(float, float) +DEFINE_SETATTTRIBUTE_VEC(double, double) +DEFINE_SETATTTRIBUTE_VEC(long_double, long double) +DEFINE_SETATTTRIBUTE_VEC2(cfloat, float) +DEFINE_SETATTTRIBUTE_VEC2(cdouble, double) +DEFINE_SETATTTRIBUTE_VEC2(clong_double, long double) +DEFINE_SETATTTRIBUTE(bool, bool) +#undef DEFINE_SETATTTRIBUTE +#undef DEFINE_SETATTTRIBUTE2 +#undef DEFINE_SETATTTRIBUTE_VEC +#undef DEFINE_SETATTTRIBUTE_VEC2 + +bool openPMD_Attributable_setAttribute_string( + openPMD_Attributable *attributable, const char *key, const char *value) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + return cxx_attributable->setAttribute(std::string(key), std::string(value)); +} + +bool openPMD_Attributable_setAttribute_vec_string( + openPMD_Attributable *attributable, + const char *key, + const char *const *values, + size_t size) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + std::vector cxx_values(size); + for (size_t n = 0; n < size; ++n) + cxx_values[n] = std::string(values[n]); + return cxx_attributable->setAttribute(std::string(key), cxx_values); +} + +openPMD_Datatype openPMD_Attributable_attributeDatatype( + const openPMD_Attributable *attributable, const char *key) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + const std::string cxx_key = std::string(key); + if (!cxx_attributable->containsAttribute(cxx_key)) + return (openPMD_Datatype)openPMD::Datatype::UNDEFINED; + const openPMD::Attribute cxx_attribute = + cxx_attributable->getAttribute(cxx_key); + const openPMD::Datatype cxx_datatype = cxx_attribute.dtype; + return (openPMD_Datatype)cxx_datatype; +} + +#define DEFINE_GETATTRIBUTE(NAME, TYPE) \ + bool openPMD_Attributable_getAttribute_##NAME( \ + const openPMD_Attributable *attributable, \ + const char *key, \ + TYPE *value) \ + { \ + const auto cxx_attributable = \ + (const openPMD::Attributable *)attributable; \ + const auto cxx_attribute = \ + cxx_attributable->getAttribute(std::string(key)); \ + const auto cxx_value = cxx_attribute.getOptional(); \ + if (!cxx_value) \ + return false; \ + *value = *cxx_value; \ + return true; \ + } +#define DEFINE_GETATTRIBUTE2(NAME, TYPE) \ + bool openPMD_Attributable_getAttribute_##NAME##2( \ + const openPMD_Attributable *attributable, \ + const char *key, \ + TYPE *value) \ + { \ + const auto cxx_attributable = \ + (const openPMD::Attributable *)attributable; \ + const auto cxx_attribute = \ + cxx_attributable->getAttribute(std::string(key)); \ + const auto cxx_value = \ + cxx_attribute.getOptional>(); \ + if (!cxx_value) \ + return false; \ + value[0] = cxx_value->real(); \ + value[1] = cxx_value->imag(); \ + return true; \ + } +#define DEFINE_GETATTRIBUTE_VEC(NAME, TYPE) \ + bool openPMD_Attributable_getAttribute_vec_##NAME( \ + const openPMD_Attributable *attributable, \ + const char *key, \ + TYPE **__restrict__ values, \ + size_t *__restrict__ size) \ + { \ + const auto cxx_attributable = \ + (const openPMD::Attributable *)attributable; \ + const auto cxx_attribute = \ + cxx_attributable->getAttribute(std::string(key)); \ + const auto cxx_values = \ + cxx_attribute.getOptional>(); \ + if (!cxx_values) \ + return false; \ + *size = cxx_values->size(); \ + *values = (TYPE *)malloc(*size * sizeof **values); \ + for (size_t n = 0; n < *size; ++n) \ + (*values)[n] = (*cxx_values)[n]; \ + return true; \ + } +#define DEFINE_GETATTRIBUTE_VEC2(NAME, TYPE) \ + bool openPMD_Attributable_getAttribute_vec_##NAME##2( \ + const openPMD_Attributable *attributable, \ + const char *key, \ + TYPE **__restrict__ values, \ + size_t *__restrict__ size) \ + { \ + const auto cxx_attributable = \ + (const openPMD::Attributable *)attributable; \ + const auto cxx_attribute = \ + cxx_attributable->getAttribute(std::string(key)); \ + const auto cxx_values = \ + cxx_attribute.getOptional>>(); \ + if (!cxx_values) \ + return false; \ + *size = cxx_values->size(); \ + *values = (TYPE *)malloc(*size * sizeof(std::complex)); \ + for (size_t n = 0; n < *size; ++n) \ + ((std::complex *)*values)[n] = (*cxx_values)[n]; \ + return true; \ + } +DEFINE_GETATTRIBUTE(char, char) +DEFINE_GETATTRIBUTE(uchar, unsigned char) +DEFINE_GETATTRIBUTE(schar, signed char) +DEFINE_GETATTRIBUTE(short, short) +DEFINE_GETATTRIBUTE(int, int) +DEFINE_GETATTRIBUTE(long, long) +DEFINE_GETATTRIBUTE(longlong, long long) +DEFINE_GETATTRIBUTE(ushort, unsigned short) +DEFINE_GETATTRIBUTE(uint, unsigned int) +DEFINE_GETATTRIBUTE(ulong, unsigned long) +DEFINE_GETATTRIBUTE(ulonglong, unsigned long long) +DEFINE_GETATTRIBUTE(float, float) +DEFINE_GETATTRIBUTE(double, double) +DEFINE_GETATTRIBUTE(long_double, long double) +DEFINE_GETATTRIBUTE2(cfloat, float) +DEFINE_GETATTRIBUTE2(cdouble, double) +DEFINE_GETATTRIBUTE2(clong_double, long double) +DEFINE_GETATTRIBUTE_VEC(char, char) +DEFINE_GETATTRIBUTE_VEC(uchar, unsigned char) +DEFINE_GETATTRIBUTE_VEC(schar, signed char) +DEFINE_GETATTRIBUTE_VEC(short, short) +DEFINE_GETATTRIBUTE_VEC(int, int) +DEFINE_GETATTRIBUTE_VEC(long, long) +DEFINE_GETATTRIBUTE_VEC(longlong, long long) +DEFINE_GETATTRIBUTE_VEC(ushort, unsigned short) +DEFINE_GETATTRIBUTE_VEC(uint, unsigned int) +DEFINE_GETATTRIBUTE_VEC(ulong, unsigned long) +DEFINE_GETATTRIBUTE_VEC(ulonglong, unsigned long long) +DEFINE_GETATTRIBUTE_VEC(float, float) +DEFINE_GETATTRIBUTE_VEC(double, double) +DEFINE_GETATTRIBUTE_VEC(long_double, long double) +DEFINE_GETATTRIBUTE_VEC2(cfloat, float) +DEFINE_GETATTRIBUTE_VEC2(cdouble, double) +DEFINE_GETATTRIBUTE_VEC2(clong_double, long double) +DEFINE_GETATTRIBUTE(bool, bool) +#undef DEFINE_GETATTRIBUTE +#undef DEFINE_GETATTRIBUTE2 +#undef DEFINE_GETATTRIBUTE_VEC +#undef DEFINE_GETATTRIBUTE_VEC2 + +bool openPMD_Attributable_getAttribute_string( + const openPMD_Attributable *attributable, + const char *key, + char **__restrict__ value) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + const auto cxx_attribute = cxx_attributable->getAttribute(std::string(key)); + const auto cxx_value = cxx_attribute.getOptional(); + if (!cxx_value) + return false; + *value = strdup(cxx_value->c_str()); + return true; +} + +bool openPMD_Attributable_getAttribute_vec_string( + const openPMD_Attributable *attributable, + const char *key, + char ***__restrict__ values, + size_t *__restrict__ size) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + const auto cxx_attribute = cxx_attributable->getAttribute(std::string(key)); + const auto cxx_values = + cxx_attribute.getOptional>(); + if (!cxx_values) + return false; + *size = cxx_values->size(); + *values = (char **)malloc(*size * sizeof **values); + for (size_t n = 0; n < *size; ++n) + (*values)[n] = strdup((*cxx_values)[n].c_str()); + return true; +} + +bool openPMD_Attributable_deleteAttribute( + openPMD_Attributable *attributable, const char *key) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + return cxx_attributable->deleteAttribute(std::string(key)); +} + +char **openPMD_Attributable_attributes(const openPMD_Attributable *attributable) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + const auto cxx_attributes = cxx_attributable->attributes(); + const std::size_t num_attributes = cxx_attributes.size(); + char **const attributes = + (char **)malloc((num_attributes + 1) * sizeof *attributes); + for (std::size_t n = 0; n < num_attributes; ++n) + attributes[n] = strdup(cxx_attributes[n].c_str()); + attributes[num_attributes] = nullptr; + return attributes; +} + +size_t +openPMD_Attributable_numAttributes(const openPMD_Attributable *attributable) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + return cxx_attributable->numAttributes(); +} + +bool openPMD_Attributable_containsAttribute( + const openPMD_Attributable *attributable, const char *key) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + return cxx_attributable->containsAttribute(std::string(key)); +} + +// result must be freed +char *openPMD_Attributable_comment(const openPMD_Attributable *attributable) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + return strdup(cxx_attributable->comment().c_str()); +} + +void openPMD_Attributable_setComment( + openPMD_Attributable *attributable, const char *comment) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + cxx_attributable->setComment(std::string(comment)); +} + +// backendConfig may be NULL +void openPMD_Attributable_seriesFlush( + openPMD_Attributable *attributable, const char *backendConfig) +{ + const auto cxx_attributable = (openPMD::Attributable *)attributable; + cxx_attributable->seriesFlush( + std::string(backendConfig ? backendConfig : "{}")); +} + +void openPMD_Attributable_MyPath_free(openPMD_Attributable_MyPath *myPath) +{ + free(myPath->directory); + free(myPath->seriesName); + free(myPath->seriesExtension); + for (size_t n = 0; myPath->group[n]; ++n) + free(myPath->group[n]); + free(myPath->group); +} + +char * +openPMD_Attributable_MyPath_filePath(const openPMD_Attributable_MyPath *myPath) +{ + openPMD::Attributable::MyPath cxx_myPath; + cxx_myPath.directory = std::string(myPath->directory); + cxx_myPath.seriesName = std::string(myPath->seriesName); + cxx_myPath.seriesExtension = std::string(myPath->seriesExtension); + for (size_t n = 0; myPath->group[n]; ++n) + cxx_myPath.group.emplace_back(myPath->group[n]); + cxx_myPath.access = openPMD::Access(myPath->access); + return strdup(cxx_myPath.filePath().c_str()); +} + +openPMD_Attributable_MyPath * +openPMD_Attributable_myPath(const openPMD_Attributable *attributable) +{ + const auto cxx_attributable = (const openPMD::Attributable *)attributable; + const auto cxx_myPath = cxx_attributable->myPath(); + openPMD_Attributable_MyPath *myPath = + (openPMD_Attributable_MyPath *)malloc(sizeof *myPath); + myPath->directory = strdup(cxx_myPath.directory.c_str()); + myPath->seriesName = strdup(cxx_myPath.seriesName.c_str()); + myPath->seriesExtension = strdup(cxx_myPath.seriesExtension.c_str()); + const size_t size = cxx_myPath.group.size(); + myPath->group = (char **)malloc((size + 1) * sizeof *myPath->group); + for (size_t n = 0; n < size; ++n) + myPath->group[n] = strdup(cxx_myPath.group[n].c_str()); + myPath->group[size] = nullptr; + myPath->access = openPMD_Access(cxx_myPath.access); + return myPath; +} diff --git a/src/binding/c/backend/BaseRecordComponent.cpp b/src/binding/c/backend/BaseRecordComponent.cpp new file mode 100644 index 0000000000..4e120942a2 --- /dev/null +++ b/src/binding/c/backend/BaseRecordComponent.cpp @@ -0,0 +1,75 @@ +#include + +#include + +#include +#include + +const openPMD_Attributable *openPMD_BaseRecordComponent_getConstAttributable( + const openPMD_BaseRecordComponent *component) +{ + const auto cxx_component = (const openPMD::BaseRecordComponent *)component; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_component; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable *openPMD_BaseRecordComponent_getAttributable( + openPMD_BaseRecordComponent *component) +{ + const auto cxx_component = (openPMD::BaseRecordComponent *)component; + const auto cxx_attributable = (openPMD::Attributable *)cxx_component; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +void openPMD_BaseRecordComponent_resetDatatype( + openPMD_BaseRecordComponent *component, openPMD_Datatype datatype) +{ + const auto cxx_component = (openPMD::BaseRecordComponent *)component; + cxx_component->resetDatatype(openPMD::Datatype(datatype)); +} + +openPMD_Datatype openPMD_BaseRecordComponent_getDatatype( + const openPMD_BaseRecordComponent *component) +{ + const auto cxx_component = (const openPMD::BaseRecordComponent *)component; + return openPMD_Datatype(cxx_component->getDatatype()); +} + +bool openPMD_BaseRecordComponent_constant( + const openPMD_BaseRecordComponent *component) +{ + const auto cxx_component = (const openPMD::BaseRecordComponent *)component; + return cxx_component->constant(); +} + +openPMD_ChunkTable openPMD_BaseRecordComponent_availableChunks( + openPMD_BaseRecordComponent *component) +{ + const auto cxx_component = (openPMD::BaseRecordComponent *)component; + const auto cxx_chunkTable = cxx_component->availableChunks(); + openPMD_ChunkTable chunkTable; + chunkTable.size = cxx_chunkTable.size(); + chunkTable.writtenChunkInfo = (openPMD_WrittenChunkInfo *)malloc( + chunkTable.size * sizeof *chunkTable.writtenChunkInfo); + for (size_t n = 0; n < chunkTable.size; ++n) + { + const auto &cxx_writtenChunkInfo = cxx_chunkTable[n]; + openPMD_ChunkInfo chunkInfo; + chunkInfo.size = cxx_chunkTable[n].offset.size(); + assert(cxx_chunkTable[n].extent.size() == chunkInfo.size); + chunkInfo.offset = + (uint64_t *)malloc(chunkInfo.size * sizeof *chunkInfo.offset); + chunkInfo.extent = + (uint64_t *)malloc(chunkInfo.size * sizeof *chunkInfo.extent); + for (size_t d = 0; d < chunkInfo.size; ++d) + { + chunkInfo.offset[d] = cxx_writtenChunkInfo.offset[d]; + chunkInfo.extent[d] = cxx_writtenChunkInfo.extent[d]; + } + chunkTable.writtenChunkInfo[n].chunkInfo = chunkInfo; + chunkTable.writtenChunkInfo[n].sourceID = cxx_writtenChunkInfo.sourceID; + } + return chunkTable; +} diff --git a/src/binding/c/backend/Container_MeshRecordComponent.cpp b/src/binding/c/backend/Container_MeshRecordComponent.cpp new file mode 100644 index 0000000000..0f535cc148 --- /dev/null +++ b/src/binding/c/backend/Container_MeshRecordComponent.cpp @@ -0,0 +1,93 @@ +#include + +#include +#include + +#include +#include + +const openPMD_Attributable * +openPMD_Container_MeshRecordComponent_getConstAttributable( + const openPMD_Container_MeshRecordComponent *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + const auto cxx_attributable = (const openPMD::Attributable *)cxx_container; + const auto attributable = (const openPMD_Attributable *)cxx_attributable; + return attributable; +} + +openPMD_Attributable *openPMD_Container_MeshRecordComponent_getAttributable( + openPMD_Container_MeshRecordComponent *container) +{ + const auto cxx_container = + (openPMD::Container *)container; + const auto cxx_attributable = (openPMD::Attributable *)cxx_container; + const auto attributable = (openPMD_Attributable *)cxx_attributable; + return attributable; +} + +bool openPMD_Container_MeshRecordComponent_empty( + const openPMD_Container_MeshRecordComponent *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->empty(); +} + +size_t openPMD_Container_MeshRecordComponent_size( + const openPMD_Container_MeshRecordComponent *container) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->size(); +} + +void openPMD_Container_MeshRecordComponent_clear( + openPMD_Container_MeshRecordComponent *container) +{ + const auto cxx_container = + (openPMD::Container *)container; + cxx_container->clear(); +} + +openPMD_MeshRecordComponent *openPMD_Container_MeshRecordComponent_get( + openPMD_Container_MeshRecordComponent *container, const char *key) +{ + const auto cxx_container = + (openPMD::Container *)container; + const auto cxx_key = std::string(key); + if (!cxx_container->contains(cxx_key)) + return nullptr; + const auto cxx_component = + new openPMD::MeshRecordComponent(cxx_container->at(cxx_key)); + const auto component = (openPMD_MeshRecordComponent *)cxx_component; + return component; +} + +void openPMD_Container_MeshRecordComponent_set( + openPMD_Container_MeshRecordComponent *container, + const char *key, + const openPMD_MeshRecordComponent *component) +{ + const auto cxx_container = + (openPMD::Container *)container; + const auto cxx_component = (const openPMD::MeshRecordComponent *)component; + (*cxx_container)[std::string(key)] = *cxx_component; +} + +bool openPMD_Container_MeshRecordComponent_contains( + const openPMD_Container_MeshRecordComponent *container, const char *key) +{ + const auto cxx_container = + (const openPMD::Container *)container; + return cxx_container->contains(std::string(key)); +} + +void openPMD_Container_MeshRecordComponent_erase( + openPMD_Container_MeshRecordComponent *container, const char *key) +{ + const auto cxx_container = + (openPMD::Container *)container; + cxx_container->erase(std::string(key)); +} diff --git a/src/binding/c/backend/MeshRecordComponent.cpp b/src/binding/c/backend/MeshRecordComponent.cpp new file mode 100644 index 0000000000..1f73000365 --- /dev/null +++ b/src/binding/c/backend/MeshRecordComponent.cpp @@ -0,0 +1,126 @@ +#include + +#include + +#include +#include + +const openPMD_RecordComponent * +openPMD_MeshRecordComponent_getConstRecordComponent( + const openPMD_MeshRecordComponent *meshComponent) +{ + const auto cxx_meshComponent = + (const openPMD::MeshRecordComponent *)meshComponent; + const auto cxx_component = + (const openPMD::RecordComponent *)cxx_meshComponent; + const auto component = (const openPMD_RecordComponent *)cxx_component; + return component; +} + +openPMD_RecordComponent *openPMD_MeshRecordComponent_getRecordComponent( + openPMD_MeshRecordComponent *meshComponent) +{ + const auto cxx_meshComponent = + (openPMD::MeshRecordComponent *)meshComponent; + const auto cxx_component = (openPMD::RecordComponent *)cxx_meshComponent; + const auto component = (openPMD_RecordComponent *)cxx_component; + return component; +} + +void openPMD_MeshRecordComponent_delete(openPMD_MeshRecordComponent *component) +{ + const auto cxx_component = (openPMD::MeshRecordComponent *)component; + delete cxx_component; +} + +double *openPMD_MeshRecordComponent_position( + const openPMD_MeshRecordComponent *component) +{ + const auto cxx_component = (const openPMD::MeshRecordComponent *)component; + const auto cxx_position = cxx_component->position(); + double *position = (double *)malloc(cxx_position.size() * sizeof *position); + return position; +} + +size_t openPMD_MeshRecordComponent_positionSize( + const openPMD_MeshRecordComponent *component) +{ + const auto cxx_component = (const openPMD::MeshRecordComponent *)component; + const auto cxx_position = cxx_component->position(); + return cxx_position.size(); +} + +void openPMD_MeshRecordComponent_setPosition( + openPMD_MeshRecordComponent *component, const double *position, size_t size) +{ + const auto cxx_component = (openPMD::MeshRecordComponent *)component; + std::vector cxx_position(position, position + size); + cxx_component->setPosition(std::move(cxx_position)); +} + +void openPMD_MeshRecordComponent_makeConstant( + openPMD_MeshRecordComponent *component, + const void *data, + openPMD_Datatype datatype) +{ + const auto cxx_component = (openPMD::MeshRecordComponent *)component; + switch (datatype) + { + case openPMD_Datatype_CHAR: + cxx_component->makeConstant(*(const char *)data); + break; + case openPMD_Datatype_UCHAR: + cxx_component->makeConstant(*(const unsigned char *)data); + break; + case openPMD_Datatype_SCHAR: + cxx_component->makeConstant(*(const signed char *)data); + break; + case openPMD_Datatype_SHORT: + cxx_component->makeConstant(*(const short *)data); + break; + case openPMD_Datatype_INT: + cxx_component->makeConstant(*(const int *)data); + break; + case openPMD_Datatype_LONG: + cxx_component->makeConstant(*(const long *)data); + break; + case openPMD_Datatype_LONGLONG: + cxx_component->makeConstant(*(const long long *)data); + break; + case openPMD_Datatype_USHORT: + cxx_component->makeConstant(*(const unsigned short *)data); + break; + case openPMD_Datatype_UINT: + cxx_component->makeConstant(*(const unsigned int *)data); + break; + case openPMD_Datatype_ULONG: + cxx_component->makeConstant(*(const unsigned long *)data); + break; + case openPMD_Datatype_ULONGLONG: + cxx_component->makeConstant(*(const unsigned long long *)data); + break; + case openPMD_Datatype_FLOAT: + cxx_component->makeConstant(*(const float *)data); + break; + case openPMD_Datatype_DOUBLE: + cxx_component->makeConstant(*(const double *)data); + break; + case openPMD_Datatype_LONG_DOUBLE: + cxx_component->makeConstant(*(const long double *)data); + break; + case openPMD_Datatype_CFLOAT: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_CDOUBLE: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_CLONG_DOUBLE: + cxx_component->makeConstant(*(const std::complex *)data); + break; + case openPMD_Datatype_BOOL: + cxx_component->makeConstant(*(const bool *)data); + break; + default: + abort(); + } +} diff --git a/src/binding/c/version.cpp b/src/binding/c/version.cpp new file mode 100644 index 0000000000..a1b6270b7f --- /dev/null +++ b/src/binding/c/version.cpp @@ -0,0 +1,76 @@ +#include + +#include + +#include +#include + +const int openPMDapi_version_major = OPENPMDAPI_VERSION_MAJOR; +const int openPMDapi_version_minor = OPENPMDAPI_VERSION_MINOR; +const int openPMDapi_version_patch = OPENPMDAPI_VERSION_PATCH; +const char *const openPMDapi_version_label = OPENPMDAPI_VERSION_LABEL; + +const int openPMD_standard_major = OPENPMD_STANDARD_MAJOR; +const int openPMD_standard_minor = OPENPMD_STANDARD_MINOR; +const int openPMD_standard_patch = OPENPMD_STANDARD_PATCH; + +const int openPMD_standard_min_major = OPENPMD_STANDARD_MIN_MAJOR; +const int openPMD_standard_min_minor = OPENPMD_STANDARD_MIN_MINOR; +const int openPMD_standard_min_patch = OPENPMD_STANDARD_MIN_PATCH; + +const char *openPMD_getVersion() +{ + static const std::string version = openPMD::getVersion(); + return version.c_str(); +} + +const char *openPMD_getStandard() +{ + static const std::string standard = openPMD::getStandardMaximum(); + return standard.c_str(); +} + +const char *openPMD_getStandardDefault() +{ + static const std::string standard = openPMD::getStandardDefault(); + return standard.c_str(); +} + +const char *openPMD_getStandardMaximum() +{ + static const std::string standard = openPMD::getStandardMaximum(); + return standard.c_str(); +} + +const char *openPMD_getStandardMinimum() +{ + static std::string standard_minimum = openPMD::getStandardMinimum(); + return standard_minimum.c_str(); +} + +const openPMD_Variant *openPMD_getVariants() +{ + static const std::map variants = openPMD::getVariants(); + static const std::vector c_variants = [&]() { + std::vector c_vars; + for (const auto &[var, supp] : variants) + c_vars.push_back(openPMD_Variant{var.c_str(), supp}); + c_vars.push_back(openPMD_Variant{nullptr, false}); + return c_vars; + }(); + return c_variants.data(); +} + +const char *const *openPMD_getFileExtensions() +{ + static const std::vector file_extensions = + openPMD::getFileExtensions(); + static const std::vector c_file_extensions = [&]() { + std::vector c_exts; + for (const auto &ext : file_extensions) + c_exts.push_back(ext.c_str()); + c_exts.push_back(nullptr); + return c_exts; + }(); + return c_file_extensions.data(); +} diff --git a/test/c/CTest.c b/test/c/CTest.c new file mode 100644 index 0000000000..1a0db70628 --- /dev/null +++ b/test/c/CTest.c @@ -0,0 +1,37 @@ +#include + +#include +#include +#include + +void test_write(const char *const filePath) +{ + openPMD_Series *const series = + openPMD_Series_new_serial(filePath, openPMD_Access_CREATE, NULL); + assert(openPMD_Series_has_value(series)); + openPMD_Series_delete(series); +} + +void test_read(const char *const filePath) +{ + openPMD_Series *const series = + openPMD_Series_new_serial(filePath, openPMD_Access_READ_ONLY, NULL); + assert(openPMD_Series_has_value(series)); + openPMD_Series_delete(series); +} + +int main(int argc, char **argv) +{ + printf("openPMD C language binding test\n"); + + const char *const filePath = "/tmp/file.json"; + + printf("Write file \"%s\"...\n", filePath); + test_write(filePath); + + printf("Read file \"%s\"...\n", filePath); + test_read(filePath); + + printf("Done.\n"); + return 0; +}