-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.cpp
179 lines (141 loc) · 4.22 KB
/
Main.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <ostream>
#include <iomanip>
#include <vector>
#include <ctime>
#include <sstream>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <typeinfo>
#include "OpenFileDialog.h"
std::vector<double>data;
int nx, ny, nz;
int cellx, celly, cellz;
double startx, starty, startz;
std::string name;
int main(int argc, char *argv[])
{
std::cout << "SGEMS to SKUA-GOCAD Converter\n";
std::cout << "==================================\n\n";
std::cout << "(c) Christian Lehmann 2019\n\n\n";
// Grid laden
char filter_grid[] = "SGemS-Grid (*.grd)\0*.grd\0"; //Object Files(*.obj)\0*.obj\0Text Files(*.txt)\0*.txt\0All Files
char title_grid[] = "Grid-Datei laden";
std::string filename_grid = openDialog(title_grid, filter_grid);
std::ifstream ifs_grid(filename_grid.c_str(), std::ifstream::in);
if (!ifs_grid.good())
{
std::cout << "Error loading:" << filename_grid << " No file found!" << "\n";
system("PAUSE");
exit(0);
}
// Daten laden
char filter_data[] = "SGemS Daten (*.*)\0*.*\0"; //Object Files(*.obj)\0*.obj\0Text Files(*.txt)\0*.txt\0All Files
char title_data[] = "Daten laden";
std::string filename_data = openDialog(title_data, filter_data);
std::ifstream ifs_data(filename_data.c_str(), std::ifstream::in);
if (!ifs_data.good())
{
std::cout << "Error loading:" << filename_data << " No file found!" << "\n";
system("PAUSE");
exit(0);
}
// Grid einlesen
std::string line;
int linenumber = 0;
while (!ifs_grid.eof() && std::getline(ifs_grid, line))
{
std::stringstream stringstream(line);
if (linenumber == 0) {} // in erster Zeile ist nur Gridname
if (linenumber == 1) { nx = std::stoi(line); }
if (linenumber == 2) { ny = std::stoi(line); }
if (linenumber == 3) { nz = std::stoi(line); }
if (linenumber == 4) { cellx = std::stoi(line); }
if (linenumber == 5) { celly = std::stoi(line); }
if (linenumber == 6) { cellz = std::stoi(line); }
if (linenumber == 7) { startx = std::stod(line); }
if (linenumber == 8) { starty = std::stod(line); }
if (linenumber == 9) { startz = std::stod(line); }
linenumber++;
}
// Daten einlesen
line = "";
linenumber = 0;
while (!ifs_data.eof() && std::getline(ifs_data, line))
{
std::stringstream stringstream(line);
if (linenumber == 0) {}
if (linenumber == 1) {}
if (linenumber == 2) { name = line; }
if (linenumber > 2) data.push_back(std::stod(line));
linenumber++;
}
fprintf_s(stderr, "test2");
// GOCAD ASCII erstellen
std::cout << "Schreibe GOCAD - Datei...\n";
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%d.%m.%Y_%HUhr%M");
auto str = oss.str();
std::string xmlfilename = name + "_Export_";
std::ofstream xmlfile;
xmlfile.open(xmlfilename + str + ".vs");
char header1[] = R"=====(GOCAD VSet 1
HEADER {
*atoms*size: 4
name: )=====";
xmlfile << header1 << name << std::endl;
char header2[] = R"=====(}
GOCAD_ORIGINAL_COORDINATE_SYSTEM
NAME " Pdgm_Epic Local"
PROJECTION Unknown
DATUM Unknown
AXIS_NAME X Y Z
AXIS_UNIT m m m
ZPOSITIVE Elevation
END_ORIGINAL_COORDINATE_SYSTEM
PROPERTIES )=====";
xmlfile << header2 << name;
char header3[] = R"=====(
PROPERTY_CLASS_HEADER X {
kind: X
unit: m
pclip: 99
}
PROPERTY_CLASS_HEADER Y {
kind: Y
unit: m
pclip: 99
}
PROPERTY_CLASS_HEADER Z {
kind: Depth
unit: m
is_z: on
pclip: 99
}
PROPERTY_CLASS_HEADER )=====";
xmlfile << header3 << name;
char header4[] = R"=====(
kind: Real Number
unit: unitless
}
)=====";
xmlfile << header4;
for (int i=0; i<data.size();i++)
{
double xneu, yneu, zneu;
int blockx, blocky, blockz;
blockz = 1 + (int)((i - 1) / (nx*ny));
blocky = 1 + (int)((i - (blockz - 1)*nx*ny) / nx);
blockx = i - (blockz - 1)*nx*ny - ((blocky - 1)*nx);
xneu = startx + (blockx*cellx);
yneu = starty + (blocky*celly);
zneu = startz + (blockz*cellz);
xmlfile << "PVRTX " << i << " " << std::to_string(xneu) << " " << std::to_string(yneu) << " " << std::to_string(zneu) << " " << std::to_string(data.at(i)) << std::endl;
}
xmlfile << "END";
}