Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasms committed Jun 25, 2019
0 parents commit 2f0a559
Show file tree
Hide file tree
Showing 8 changed files with 10,987 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store

*.csv

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "dependencies/json"]
path = dependencies/json
url = https://github.com/nlohmann/json
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FISpact transLATER = FISLATER

Very early days, so just do:

```bash
g++-8 -I./include/ -I./dependencies/json/include ./tools/translate/main.cpp -o jsontocsv
```

Will use CMake later...


### About
Translates JSON to other common file formats.

- csv
- xml
- hdf5?
- tabulated?
- ...


Work ongoing...
1 change: 1 addition & 0 deletions dependencies/json
Submodule json added at 9a775b
52 changes: 52 additions & 0 deletions include/fislater.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef FISLATER_HPP
#define FISLATER_HPP

#include <fstream>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>

#include <nlohmann/json.hpp>

using json = nlohmann::json;

namespace fispact {

json from_json(std::string name){
std::ifstream ifs(name);
return json::parse(ifs);
}

void to_csv(json& j, std::string name){
std::ofstream ofs;
ofs.open(name);

std::vector<std::string> keys = {
"irradiation_time", "cooling_time", "flux", "alpha_heat", "beta_heat", "gamma_heat"
};

std::copy(keys.begin(), keys.end()-1, std::ostream_iterator<std::string>(ofs, ","));
ofs << keys.back() <<"\n";

for (auto& element: j["inventory_data"]){
std::string delimiter = "";
for (auto& key: keys) {
ofs << delimiter << std::scientific << std::setprecision(15) << element[key].get<double>();
delimiter = ",";
}
ofs <<"\n";
}
ofs.close();
}

template <typename T>
std::vector<T> inventoryvalues(const json& j, std::string key){
std::vector<T> values;
for (auto& element: j["inventory_data"])
values.emplace_back(element[key].get<T>());
return values;
}
}

#endif //FISLATER_HPP
Loading

0 comments on commit 2f0a559

Please sign in to comment.