-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutputHDF.cpp
136 lines (130 loc) · 4.77 KB
/
outputHDF.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "spatialsim/outputHDF.h"
#include "spatialsim/mystruct.h"
#include "spatialsim/searchFunction.h"
#include "H5Cpp.h"
#include "sbml/SBMLTypes.h"
#include "sbml/extension/SBMLExtensionRegistry.h"
#include "sbml/packages/spatial/common/SpatialExtensionTypes.h"
#include "sbml/packages/spatial/extension/SpatialModelPlugin.h"
#include "sbml/packages/spatial/extension/SpatialExtension.h"
#include <vector>
#include <string>
#include <sstream>
using namespace H5;
LIBSBML_CPP_NAMESPACE_USE
using namespace std;
const string FILENAME = "TimeCourseData.h5";
const string IMGFILENAME = "ImageData.h5";
void makeHDF(std::string fname, ListOfSpecies* los, std::string outpath) {//シミュレーション開始前にファイルを作成
H5File file(outpath + "/result/" + fname + "/HDF5/" + FILENAME, H5F_ACC_TRUNC);
for (unsigned int i = 0; i < los->size(); ++i) {
file.createGroup(los->get(i)->getId());
}
}
void make3DHDF(std::string fname, ListOfSpecies* los, std::string outpath) {//シミュレーション開始前にファイルを作成
H5File file(outpath + "/result/" + fname + "/HDF5/" + IMGFILENAME, H5F_ACC_TRUNC);
for (unsigned int i = 0; i < los->size(); ++i) {
file.createGroup(los->get(i)->getId());
}
}
void outputValueData(std::vector<variableInfo*>&varInfoList, ListOfSpecies* los, int Xdiv, int Ydiv, int Zdiv, int dimension, int file_num, std::string fname, std::string outpath) {
int Xindex = Xdiv * 2 - 1, Yindex = Ydiv * 2 - 1, Zindex = Zdiv * 2 - 1;
int i, X, Y, Z;
string s_id;
stringstream ss;
ss << file_num;
hsize_t dim[dimension];
H5File file(outpath + "/result/" + fname + "/HDF5/" + FILENAME, H5F_ACC_RDWR);
DataSpace *dataspace;
DataSet* dataset;
Group spGroup;
variableInfo *sInfo;
for (i = 0; i < (int)los->size(); ++i) {
s_id = los->get(i)->getId();
sInfo = searchInfoById(varInfoList, s_id.c_str());
spGroup = file.openGroup(s_id);
if(sInfo->inVol) {//volume
double *value = new double[Zdiv * Ydiv * Xdiv];
dim[0] = Xdiv;
if (2 <= dimension) dim[1] = Ydiv;
if (3 == dimension) dim[2] = Zdiv;
dataspace = new DataSpace(dimension, dim);
for (Z = 0; Z < Zindex; Z += 2)
for (Y = 0; Y < Yindex; Y += 2)
for (X = 0; X < Xindex; X += 2)
value[Z / 2 * Ydiv * Xdiv + Y / 2 * Xdiv + X / 2] = sInfo->value[Z * Yindex * Xindex + Y * Xindex + X];
dataset = new DataSet(spGroup.createDataSet(ss.str(), PredType::NATIVE_DOUBLE, *dataspace));
dataset->write(value, PredType::NATIVE_DOUBLE);
delete[] value;
delete dataset;
delete dataspace;
}
else {//membrane
dim[0] = Xindex;
if (2 <= dimension) dim[1] = Yindex;
if (3 == dimension) dim[2] = Zindex;
dataspace = new DataSpace(dimension, dim);
dataset = new DataSet(spGroup.createDataSet(ss.str(), PredType::NATIVE_DOUBLE, *dataspace));
dataset->write(sInfo->value, PredType::NATIVE_DOUBLE);
delete dataset;
delete dataspace;
}
}
file.flush(H5F_SCOPE_LOCAL);
file.close();
}
void output3D_uint8 (std::vector<variableInfo*>&varInfoList, ListOfSpecies* los, int Xindex, int Yindex, int Zindex, int file_num, std::string fname, double range_max, std::string outpath) {
int i, X, Y, Z, index;
uint8_t ***value;
value = new uint8_t**[Xindex];
for (X = 0; X < Xindex; X++) {
value[X] = new uint8_t*[Yindex];
for (Y = 0; Y < Yindex; Y++) {
value[X][Y] = new uint8_t[Zindex];
for (Z = 0; Z < Zindex; Z++) {
value[X][Y][Z] = 0;
}
}
}
string s_id;
stringstream ss;
ss << file_num;
hsize_t dim[3];
dim[0] = Xindex;
dim[1] = Yindex;
dim[2] = Zindex;
H5File file(outpath + "/result/" + fname + "/HDF5/" + IMGFILENAME, H5F_ACC_RDWR);
DataSpace dataspace = DataSpace(3, dim);
DataSet* dataset;
Group spGroup;
variableInfo *sInfo;
GeometryInfo* geoInfo;
for (i = 0; i < (int)los->size(); ++i) {
s_id = los->get(i)->getId();
sInfo = searchInfoById(varInfoList, s_id.c_str());
geoInfo = sInfo->geoi;
spGroup = file.openGroup(s_id);
for (int j = 0; j < (int)geoInfo->domainIndex.size(); j++) {
index = geoInfo->domainIndex[j];
Z = index / (Xindex * Yindex);
Y = (index - Z * Xindex * Yindex) / Xindex;
X = index - Z * Xindex * Yindex - Y * Xindex;
if (range_max < sInfo->value[index]) value[X][Y][Z] = 255;
else value[X][Y][Z] = 255 * (sInfo->value[index] / range_max);
if (value[X][Y][Z] == 0) {
value[X][Y][Z] = 20;
}
}
dataset = new DataSet(spGroup.createDataSet(ss.str(), PredType::INTEL_U8, dataspace));
dataset->write(value, PredType::INTEL_U8);
delete dataset;
}
//free value array
for (X = 0; X < Xindex; X++) {
for (Y = 0; Y < Yindex; Y++) {
delete value[X][Y];
}
delete value[X];
}
delete value;
}