Skip to content

Commit fb9bd1d

Browse files
committed
added compile option for netcdf
1 parent 7691c3d commit fb9bd1d

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

.zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"license": {
44
"id": "AGPL-3.0"
55
},
6-
"title": "libmrio",
6+
"title": "libmrio v2.1.0",
77
"upload_type": "software",
88
"creators": [
99
{

include/MRIOTable.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@ class Table {
6666
const T basesum(const SuperSector<I>* i, const SuperRegion<I>* r, const SuperSector<I>* j, const SuperRegion<I>* s) const noexcept;
6767
void write_to_csv(std::ostream& os) const;
6868
void write_to_mrio(std::ostream& os) const;
69+
#ifdef LIBMRIO_NETCDF
6970
void write_to_netcdf(const std::string& filename) const;
71+
#endif
7072
void read_from_csv(std::istream& indicesstream, std::istream& datastream, const T& threshold);
7173
void read_from_mrio(std::istream& instream, const T& threshold);
74+
#ifdef LIBMRIO_NETCDF
7275
void read_from_netcdf(const std::string& filename, const T& threshold);
76+
#endif
7377

7478
inline T& at(const Sector<I>* i, const Region<I>* r, const Sector<I>* j, const Region<I>* s) {
7579
assert(index_set_.at(i, r) >= 0);

makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CPP_FILES := $(wildcard src/*.cpp)
99
OBJ_FILES := $(patsubst src/%.cpp,bin/%.o,$(CPP_FILES))
1010
.SECONDARY: OBJ_FILES
1111
LD_FLAGS := -lstdc++ -lnetcdf_c++4 -lnetcdf
12-
CC_FLAGS := -std=c++11 -I include -I lib/settingsnode/include -I lib/settingsnode/lib/yaml-cpp/include -I lib/cpp-library
12+
CC_FLAGS := -std=c++11 -I include -I lib/settingsnode/include -I lib/settingsnode/lib/yaml-cpp/include -I lib/cpp-library -DWITH_NETCDF
1313
LIBMRIO_VERSION := $(shell git describe --tags --dirty --always | sed -e 's/v\([0-9]\+\.[0-9]\+\)\.\(0-\([0-9]\+\)\)\?\(.*\)/\1.\3\4/')
1414
LIBMRIO_FLAGS := $(GCC_WARNINGS) -DLIBMRIO_VERSION='"$(LIBMRIO_VERSION)"'
1515

src/MRIOTable.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
*/
1919

2020
#include "MRIOTable.h"
21-
#include <ncDim.h>
22-
#include <ncFile.h>
23-
#include <ncVar.h>
2421
#include <algorithm>
2522
#include <cmath>
2623
#include <cstdlib>
2724
#include <iomanip>
2825
#include <iostream>
29-
#include <netcdf>
3026
#include <sstream>
3127
#include <stdexcept>
28+
#ifdef LIBMRIO_NETCDF
29+
#include <ncDim.h>
30+
#include <ncFile.h>
31+
#include <ncVar.h>
32+
#include <netcdf>
33+
#endif
3234
#include "MRIOIndexSet.h"
3335
#include "csv-parser.h"
3436

@@ -254,6 +256,7 @@ void Table<T, I>::write_to_mrio(std::ostream& outstream) const {
254256
}
255257
}
256258

259+
#ifdef LIBMRIO_NETCDF
257260
template<typename T, typename I>
258261
void Table<T, I>::read_from_netcdf(const std::string& filename, const T& threshold) {
259262
netCDF::NcFile file(filename, netCDF::NcFile::read);
@@ -335,7 +338,9 @@ void Table<T, I>::read_from_netcdf(const std::string& filename, const T& thresho
335338
}
336339
index_set_.rebuild_indices();
337340
}
341+
#endif
338342

343+
#ifdef LIBMRIO_NETCDF
339344
template<typename T, typename I>
340345
void Table<T, I>::write_to_netcdf(const std::string& filename) const {
341346
debug_out();
@@ -389,6 +394,7 @@ void Table<T, I>::write_to_netcdf(const std::string& filename) const {
389394
flows_var.setFill<T>(true, std::numeric_limits<T>::quiet_NaN());
390395
flows_var.putVar(&data[0]);
391396
}
397+
#endif
392398

393399
template<typename T, typename I>
394400
void Table<T, I>::insert_sector_offset_x_y(const SuperSector<I>* i, const I& i_regions_count, const I& subsectors_count) {
@@ -546,9 +552,9 @@ void Table<T, I>::debug_out() const {
546552
std::cout << std::setprecision(3) << std::fixed;
547553
for (const auto& y : index_set_.total_indices) {
548554
std::cout << index_set_.at(y.sector, y.region) << " " << y.sector->name << " " << (!y.sector->parent() ? " " : y.sector->parent()->name) << " "
549-
<< (y.sector->parent() ? *y.sector->parent() : *y.sector) << " " << (*y.sector) << " " << y.sector->level_index() << " " << y.region->name << " "
550-
<< (!y.region->parent() ? " " : y.region->parent()->name) << " " << (y.region->parent() ? *y.region->parent() : *y.region) << " "
551-
<< (*y.region) << " " << y.region->level_index() << " | ";
555+
<< (y.sector->parent() ? *y.sector->parent() : *y.sector) << " " << (*y.sector) << " " << y.sector->level_index() << " " << y.region->name
556+
<< " " << (!y.region->parent() ? " " : y.region->parent()->name) << " " << (y.region->parent() ? *y.region->parent() : *y.region) << " "
557+
<< (*y.region) << " " << y.region->level_index() << " | ";
552558
for (const auto& x : index_set_.total_indices) {
553559
if (data[x.index * index_set_.size() + y.index] <= 0) {
554560
std::cout << " . ";

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ int main(int argc, char* argv[]) {
100100
throw std::runtime_error("Could not open data file");
101101
}
102102
basetable.read_from_mrio(data, threshold);
103+
#ifdef LIBMRIO_NETCDF
103104
} else if (type == "netcdf") {
104105
basetable.read_from_netcdf(filename, threshold);
106+
#endif
107+
} else {
108+
throw std::runtime_error("Unknown type '" + type + "'");
105109
}
106110
}
107111
std::cout << "done" << std::endl;
@@ -132,8 +136,12 @@ int main(int argc, char* argv[]) {
132136
throw std::runtime_error("Could not create output file");
133137
}
134138
disaggregation.refined_table().write_to_mrio(outfile);
139+
#ifdef LIBMRIO_NETCDF
135140
} else if (type == "netcdf") {
136141
disaggregation.refined_table().write_to_netcdf(filename);
142+
#endif
143+
} else {
144+
throw std::runtime_error("Unknown type '" + type + "'");
137145
}
138146
}
139147
std::cout << "done" << std::endl;

0 commit comments

Comments
 (0)