OGS
Applications/FileIO/GocadIO/CoordinateSystem.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "CoordinateSystem.h"
5
6#include <boost/algorithm/string/trim.hpp>
7#include <boost/tokenizer.hpp>
8#include <iostream>
9
10#include "BaseLib/Logging.h"
11
12namespace FileIO
13{
14namespace Gocad
15{
16std::string parseName(std::string const& str)
17{
18 std::string name;
19 std::size_t const start = str.find_first_of('\"');
20 if (start != std::string::npos)
21 {
22 std::size_t const end = str.find_last_of('\"');
23 name = str.substr(start + 1, end - start - 1);
24 }
25 else
26 {
27 name = str.substr(str.find_first_of(' '), str.length());
28 }
29 boost::algorithm::trim(name);
30 return name;
31}
32
33bool CoordinateSystem::parse(std::istream& in)
34{
35 std::string line; // string used for reading a line
36 boost::char_separator<char> sep("-;| \"\r");
37
38 std::getline(in, line); // NAME name
39 boost::tokenizer<boost::char_separator<char>> tok(line, sep);
40 auto it(tok.begin());
41 if (*it != "NAME")
42 {
43 return false;
44 }
45 name = parseName(line);
46 projection = "";
47 datum = "";
48
49 while (std::getline(in, line))
50 {
51 tok.assign(line);
52 it = tok.begin();
53 if (*it == "AXIS_NAME")
54 {
55 ++it;
56 axis_name_u = *it;
57 ++it;
58 axis_name_v = *it;
59 ++it;
60 axis_name_w = *it;
61 }
62 else if (*it == "AXIS_UNIT")
63 {
64 ++it;
65 axis_unit_u = *it;
66 ++it;
67 axis_unit_v = *it;
68 ++it;
69 axis_unit_w = *it;
70 }
71 else if (*it == "ZPOSITIVE")
72 {
73 ++it;
74 if (*it == "Depth")
75 {
77 }
78 else
79 {
81 }
82 }
83 else if (*it == "PROJECTION")
84 {
85 projection = parseName(line);
86 }
87 else if (*it == "DATUM")
88 {
89 datum = parseName(line);
90 }
91 else if (*it == "END_ORIGINAL_COORDINATE_SYSTEM")
92 {
93 return true;
94 }
95 else
96 {
97 WARN("CoordinateSystem::parse() - Unknown keyword found: {:s}",
98 line);
99 }
100 }
101 ERR("Error: Unexpected end of file.");
102 return false;
103}
104
105std::ostream& operator<<(std::ostream& os, CoordinateSystem const& c)
106{
107 os << "Gocad CoordinateSystem " << c.name
108 << "\nAxis names: " << c.axis_name_u << ", " << c.axis_name_v << ", "
109 << c.axis_name_w << "\nAxis units: " << c.axis_unit_u << ", "
110 << c.axis_unit_v << ", " << c.axis_unit_w << "\nZ-orientation: ";
112 {
113 os << "downwards";
114 }
115 else
116 {
117 os << "upwards";
118 }
119 os << "\n";
120 return os;
121}
122
123} // end namespace Gocad
124} // end namespace FileIO
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
std::ostream & operator<<(std::ostream &os, CoordinateSystem const &c)
std::string parseName(std::string const &str)