forked from ClimateGlobalChange/tempestremap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeshToTxt.cpp
95 lines (76 loc) · 2.39 KB
/
MeshToTxt.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
///////////////////////////////////////////////////////////////////////////////
///
/// \file gecore2.cpp
/// \author Paul Ullrich
/// \version March 7, 2014
///
/// <remarks>
/// Copyright 2000-2014 Paul Ullrich
///
/// This file is distributed as part of the Tempest source code package.
/// Permission is granted to use, copy, modify and distribute this
/// source code and its documentation under the terms of the GNU General
/// Public License. This software is provided "as is" without express
/// or implied warranty.
/// </remarks>
#include "Announce.h"
#include "CommandLine.h"
#include "Exception.h"
#include "GridElements.h"
#include "netcdfcpp.h"
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv) {
NcError error(NcError::silent_nonfatal);
try {
// Input mesh file
std::string strInputMesh;
// Output node file
std::string strOutputNodes;
// Output face file
std::string strOutputFaces;
// Parse the command line
BeginCommandLine()
CommandLineString(strInputMesh, "in", "");
CommandLineString(strOutputNodes, "out_nodes", "nodes.dat");
CommandLineString(strOutputFaces, "out_faces", "faces.dat");
ParseCommandLine(argc, argv);
EndCommandLine(argv)
if (strInputMesh == "") {
return (-1);
}
AnnounceBanner();
// Load input mesh
AnnounceStartBlock("Loading input mesh");
Mesh meshInput(strInputMesh);
AnnounceEndBlock(NULL);
// Output nodes
AnnounceStartBlock("Writing nodes");
FILE * fpNodes = fopen(strOutputNodes.c_str(), "w");
for (int i = 0; i < meshInput.nodes.size(); i++) {
fprintf(fpNodes, "%1.10e %1.10e %1.10e\n",
static_cast<double>(meshInput.nodes[i].x),
static_cast<double>(meshInput.nodes[i].y),
static_cast<double>(meshInput.nodes[i].z));
}
fclose(fpNodes);
AnnounceEndBlock("Done!");
// Output faces
AnnounceStartBlock("Writing faces");
FILE * fpFaces = fopen(strOutputFaces.c_str(), "w");
for (int i = 0; i < meshInput.faces.size(); i++) {
for (int j = 0; j < meshInput.faces[i].edges.size(); j++) {
fprintf(fpFaces, "%i", meshInput.faces[i][j] + 1);
if (j != meshInput.faces[i].edges.size()-1) {
fprintf(fpFaces, " ");
}
}
fprintf(fpFaces, "\n");
}
fclose(fpFaces);
AnnounceEndBlock("Done!");
AnnounceBanner();
} catch(Exception & e) {
Announce(e.ToString().c_str());
}
}
///////////////////////////////////////////////////////////////////////////////