• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

icsm-au / DynAdjust / 13494567994

24 Feb 2025 09:15AM UTC coverage: 81.168% (+2.0%) from 79.161%
13494567994

push

github

web-flow
Merge pull request #234 from icsm-au/1.2.8

Version 1.2.8 (fixes, ehnacements, improved datum management)

6131 of 8137 new or added lines in 90 files covered. (75.35%)

162 existing lines in 33 files now uncovered.

32214 of 39688 relevant lines covered (81.17%)

11775.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.55
/dynadjust/include/io/dnaiotpb.cpp
1
//============================================================================
2
// Name         : dnaiotpb.cpp
3
// Author       : Roger Fraser
4
// Contributors :
5
// Version      : 1.00
6
// Copyright    : Copyright 2017 Geoscience Australia
7
//
8
//                Licensed under the Apache License, Version 2.0 (the "License");
9
//                you may not use this file except in compliance with the License.
10
//                You may obtain a copy of the License at
11
//               
12
//                http ://www.apache.org/licenses/LICENSE-2.0
13
//               
14
//                Unless required by applicable law or agreed to in writing, software
15
//                distributed under the License is distributed on an "AS IS" BASIS,
16
//                WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
//                See the License for the specific language governing permissions and
18
//                limitations under the License.
19
//
20
// Description  : PB2002 Tectonic Plate Boundary file io operations
21
//============================================================================
22

23
#include <include/io/dnaiotpb.hpp>
24
#include <include/functions/dnastrmanipfuncs.hpp>
25
#include <include/functions/dnaiostreamfuncs.hpp>
26

27
namespace dynadjust {
28
namespace iostreams {
29
        
30
void dna_io_tpb::load_tpb_file(const std::string& tpb_filename, v_string_v_doubledouble_pair& global_plates)
22✔
31
{
32
        // From the standard:
33
        // PB2002_plates.dig.For some applications it is necessary to
34
        // represent plates by closed outlines.They include computing the
35
        // areas of plates, determining which plate a given point lies
36
        // within, and mapping plates as regions of contrasting color.For
37
        // such applications, file PB2002_plates.dig is provided.It
38
        // contains 52 segments, each titled with the two - letter identifier
39
        // of a plate.Each segment is a closed curve outlining that plate
40
        // in the counterclockwise direction(as seen from outside the
41
        // Earth).The last point in the segment is identical to the first
42
        // point.Because each plate boundary necessarily appears twice in
43
        // this file, it is about twice as large as the first.
44
        //
45
        // Tectonic plate boundary file structure is as follows.
46
        // Note - coordinates are in degrees and are given in a counterclockwise  
47
        // direction.  Since reftran uses the boost geometry package to interpolate
48
        // which plate a point lies in, the polygon node coordinates will need
49
        // to be reversed and converted to decimal degrees.
50
        //
51
        //   <plate identifier>
52
        //   <long,lat>
53
        //   <long,lat>
54
        //      ...
55
        //   <long,lat>
56
        //   *** end of line segment ***
57
        //   <plate identifier>
58
        //   <long,lat>
59
        //   <long,lat>
60
        //      ...
61
        //   <long,lat>
62
        //   *** end of line segment ***
63

64
        std::ifstream tpb_file;
22✔
65
        std::stringstream ss;
22✔
66
        ss << "load_tpb_file(): An error was encountered when opening " << tpb_filename << "." << std::endl;
22✔
67
        
68
        try {
22✔
69
                // open ascii plate boundaries file.  Throws runtime_error on failure.
70
                file_opener(tpb_file, tpb_filename, std::ios::in, ascii, true);
22✔
71
        }
72
        catch (const std::runtime_error& e) {
1✔
73
                ss << e.what();
1✔
74
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
3✔
75
        }
1✔
76
        catch (...) {
×
NEW
77
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
78
        }
×
79

80
        ss.str("");
63✔
81
        ss << "load_tpb_file(): An error was encountered when reading from " << tpb_filename << "." << std::endl;
21✔
82

83
        v_doubledouble_pair plate_nodes;
21✔
84
        std::string plate_name, node_coordinates;
21✔
85
        vstring coordinates;
21✔
86

87
        try {
21✔
88

89
                global_plates.clear();
21✔
90

91
                while (!tpb_file.eof())                        // while EOF not found
1,160✔
92
                {
93
                        // get the plate identifier
94
                        getline(tpb_file, plate_name);
1,139✔
95

96
                        // blank or whitespace?
97
                        if (trimstr(plate_name).empty())
2,236✔
98
                                continue;
×
99
                        
100
                        // Ignore lines with comments
101
                        if ((plate_name.compare(0, 1, "*") == 0) &&
1,136✔
102
                                !boost::iequals(plate_name.substr(0, 7), "*** end"))
1,154✔
103
                                continue;
18✔
104

105
                        str_toupper<int>(plate_name);
1,100✔
106

107
                        // get the next set of plate coordinates
108
                        getline(tpb_file, node_coordinates);
1,100✔
109

110
                        while (!boost::iequals(node_coordinates.substr(0, 7), "*** end"))
513,108✔
111
                        {
112
                                // Extract coordinates from comma delimited string
113
                                SplitDelimitedString<std::string>(
255,454✔
114
                                        node_coordinates,                                // the comma delimited string
115
                                        std::string(","),                                // the delimiter
510,908✔
116
                                        &coordinates);                        // the respective values
117

118
                                plate_nodes.push_back(doubledouble_pair(
510,908✔
119
                                        DoubleFromString<double>(coordinates.at(0)),
255,454✔
120
                                        DoubleFromString<double>(coordinates.at(1))));
255,454✔
121

122
                                // get the plate identifier
123
                                getline(tpb_file, node_coordinates);
255,454✔
124
                        }
125

126
                        global_plates.push_back(string_v_doubledouble_pair(
2,200✔
127
                                plate_name, plate_nodes));
128

129
                        plate_nodes.clear();
1,100✔
130
                }
131

132
                tpb_file.close();
×
133
        }
134
        catch (const std::ios_base::failure& f) {
21✔
135
                if (tpb_file.eof())
21✔
136
                {
137
                        tpb_file.close();
21✔
138
                        return;
21✔
139
                }
140
                ss << f.what();
×
NEW
141
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
142
        }
21✔
NEW
143
        catch (const std::runtime_error& e) {
×
144
                ss << e.what();
×
NEW
145
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
146
        }
×
147
        catch (...) {
×
148
                if (tpb_file.eof())
×
149
                {
150
                        tpb_file.close();
×
151
                        return;
×
152
                }
NEW
153
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
154
        }        
×
155

156
        return;
157
}
65✔
158

159
void dna_io_tpb::load_tpp_file(const std::string& tpp_filename, v_plate_motion_eulers& plate_pole_parameters)
20✔
160
{
161
        // Tectonic pole parameters file structure is as follows.
162
        // Note - coordinates are in degrees.
163
        //
164
        //   <plate identifier> <latitude> <longitue> <pole rotation rate> <pole parameters author>
165
        //
166

167
        std::ifstream tpp_file;
20✔
168
        std::stringstream ss;
20✔
169
        ss << "load_tpp_file(): An error was encountered when opening " << tpp_filename << "." << std::endl;
20✔
170

171
        try {
20✔
172
                // open ascii pole parameters file.  Throws runtime_error on failure.
173
                file_opener(tpp_file, tpp_filename, std::ios::in, ascii, true);
20✔
174
        }
NEW
175
        catch (const std::runtime_error& e) {
×
176
                ss << e.what();
×
NEW
177
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
178
        }
×
179
        catch (...) {
×
NEW
180
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
181
        }
×
182

183
        ss.str("");
60✔
184
        ss << "load_tpp_file(): An error was encountered when reading from " << tpp_filename << "." << std::endl;
20✔
185

186
        plate_motion_euler pmm;
20✔
187
        std::string record;
20✔
188

189
        try {
20✔
190

191
                plate_pole_parameters.clear();
20✔
192
        
193
                while (!tpp_file.eof())                        // while EOF not found
1,170✔
194
                {
195
                        // get the plate parameters record
196
                        getline(tpp_file, record);
1,149✔
197

198
                        // blank or whitespace?
199
                        if (trimstr(record).empty())
2,260✔
200
                                continue;
×
201

202
                        // Ignore lines with comments
203
                        if (record.compare(0, 1, "*") == 0)
1,130✔
204
                                continue;
86✔
205

206
                        // Extract plate name
207
                        pmm.plate_name = record.substr(0, 2);
1,044✔
208

209
                        // Extract coordinates from comma delimited string
210
                        pmm.pole_latitude = DoubleFromString<double>(trimstr(record.substr(3, 10)));
2,088✔
211
                        pmm.pole_longitude = DoubleFromString<double>(trimstr(record.substr(12, 20)));
2,088✔
212
                        
213
                        // extract pole rotation rate
214
                        pmm.pole_rotation_rate = DoubleFromString<double>(trimstr(record.substr(22, 29)));
2,088✔
215
        
216
                        // extract plate motion model author
217
                        pmm.pole_param_author = record.substr(32);
1,044✔
218
                        
219
                        plate_pole_parameters.push_back(pmm);                        
1,044✔
220
                }
221

222
                tpp_file.close();
1✔
223
        }
224
        catch (const std::ios_base::failure& f) {
19✔
225
                if (tpp_file.eof())
19✔
226
                {
227
                        tpp_file.close();
19✔
228
                        return;
19✔
229
                }
230
                ss << f.what();
×
NEW
231
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
232
        }
19✔
NEW
233
        catch (const std::runtime_error& e) {
×
234
                ss << e.what();
×
NEW
235
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
236
        }
×
237
        catch (...) {
×
238
                if (tpp_file.eof())
×
239
                {
240
                        tpp_file.close();
×
241
                        return;
×
242
                }
NEW
243
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
244
        }
×
245

246
        return;
247
}
20✔
248

249
bool dna_io_tpb::validate_plate_files(v_string_v_doubledouble_pair& global_plates,
20✔
250
        v_plate_motion_eulers& plate_pole_parameters, std::string& message)
251
{
252
        if (plate_pole_parameters.size() != global_plates.size())
20✔
253
        {
254
                message = "There number of plates in the plate boundaries file and the pole parameters file are not equal.";
×
255
                return false;
×
256
        }
257

258
        //for (it_plate_motion_euler i= plate_pole_parameters.begin(), it_v_string_v_doubledouble_pair j = global_plates.begin();
259
        //        i!=plate_pole_parameters.end(), j!=global_plates.end(); 
260
        //        ++i, ++j)
261
        
262
        it_v_string_v_doubledouble_pair j = global_plates.begin();
20✔
263
        
264
        for (it_plate_motion_euler i = plate_pole_parameters.begin();
20✔
265
                i != plate_pole_parameters.end() && j != global_plates.end();
1,064✔
266
                ++i, ++j)
1,044✔
267
        {
268
                if (!boost::equals(i->plate_name, j->first))
1,044✔
269
                {
270
                        message = "There is a mismatch between the plates in the plate boundaries file and the pole parameters file.";
×
271
                        return false;
×
272
                }
273
        }
274

275
        return true;
20✔
276
}
277

278
} // dnaiostreams
279
} // dynadjust
280

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc