Skip to content

Commit

Permalink
add OpenPMD.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-frey committed Aug 13, 2023
1 parent f3899ff commit cbb9de5
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ add_subdirectory (Expression)
add_subdirectory (Types)
add_subdirectory (Partition)
add_subdirectory (Stream)
add_subdirectory (Stream/HDF5)
add_subdirectory (Stream/Format)


if (ENABLE_SOLVERS)
Expand Down
3 changes: 1 addition & 2 deletions src/Stream/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ set (_SRCS
set (_HDRS
BasicStreams.h
BasicFileStream.h
StreamFormat.h
OpenPMD.h
)

include_DIRECTORIES (
Expand All @@ -18,6 +16,7 @@ add_ippl_headers (${_HDRS})

install (FILES ${_HDRS} DESTINATION include/Stream)


# vi: set et ts=4 sw=4 sts=4:

# Local Variables:
Expand Down
1 change: 1 addition & 0 deletions src/Stream/Format/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set (_SRCS
OpenPMD.cpp
)

set (_HDRS
Expand Down
4 changes: 2 additions & 2 deletions src/Stream/Format/Format.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef IPPL_IOS_STANDARD_H
#define IPPL_IOS_STANDARD_H
#ifndef IPPL_STREAM_FORMAT_H
#define IPPL_STREAM_FORMAT_H

#include "Utility/ParameterList.h"

Expand Down
31 changes: 31 additions & 0 deletions src/Stream/Format/OpenPMD.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Stream/Format/OpenPMD.h"

namespace ippl {

void OpenPMD::header(ParameterList* param) const {
// default parameter list
ParameterList pl;
pl.add<std::string>("version", version);
pl.add<std::string>("author", "none");
pl.add<std::string>("software", "none");
pl.add<std::string>("softwareVersion", "none");
pl.add<std::string>("softwareDependencies", "none");
pl.add<std::string>("date", this->date());
pl.add<std::string>("machine", "none");
pl.add<std::string>("comment", "none");

if (param != nullptr) {
pl.merge(*param);
}

*param = pl;
}

std::string OpenPMD::date() const {
std::time_t time = std::time({});
char timeString[std::size("YYYY-MM-DD HH:mm:ss zzzzz")];
std::strftime(std::data(timeString), std::size(timeString), "%F %T %z",
std::localtime(&time));
return timeString;
}
} // namespace ippl
20 changes: 9 additions & 11 deletions src/Stream/Format/OpenPMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#ifndef IPPL_STREAM_FORMAT_OPEN_PMD_H
#define IPPL_STREAM_FORMAT_OPEN_PMD_H

#include <ctime>
#include <string>

#include "Stream/Format/Format.h"

namespace ippl {
Expand All @@ -14,17 +17,12 @@ namespace ippl {
public:
OpenPMD() = default;

void header(ParameterList* param) const override {
std::cout << "This file is written in OpenPMD standard." << std::endl;

param->add<std::string>("version", "1.1.0");
param->add<std::string>("author", "none");
param->add<std::string>("software", "Ippl");
param->add<std::string>("softwareVersion", "2.1.0");
param->add<std::string>("data", "YYYY-MM-DD HH:mm:ss tz");
param->add<std::string>("machine", "machine");
param->add<std::string>("comment", "");
}
void header(ParameterList* param) const override;

private:
const std::string version = "1.1.0";

std::string date() const;
};
} // namespace ippl

Expand Down
26 changes: 26 additions & 0 deletions src/Stream/HDF5/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set (_SRCS
)

set (_HDRS
Stream.h
ParticleStream.h
ParticleStream.hpp
)

include_DIRECTORIES (
${CMAKE_CURRENT_SOURCE_DIR}
)

add_ippl_sources (${_SRCS})
add_ippl_headers (${_HDRS})

install (FILES ${_HDRS} DESTINATION include/Stream/HDF5)

# vi: set et ts=4 sw=4 sts=4:

# Local Variables:
# mode: cmake
# cmake-tab-width: 4
# indent-tabs-mode: nil
# require-final-newline: nil
# End:
2 changes: 1 addition & 1 deletion src/Stream/HDF5/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ namespace ippl {
const T& value = pair.second;

H5::DataSpace dspace(H5S_SCALAR); // FIXME We might also write arrays etc.
std::cout << "key " << key << std::endl;

H5::DataType type = core::get_hdf5_type(value);

H5::Attribute attr = this->h5file_m.createAttribute(key, type, dspace);
Expand Down

0 comments on commit cbb9de5

Please sign in to comment.