• 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

54.47
/dynadjust/include/io/dnaiomap.cpp
1
//============================================================================
2
// Name         : dnaiomap.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  : DynAdjust station map file io operations
21
//============================================================================
22

23
#include <fstream>
24

25
#include <include/io/dnaiomap.hpp>
26
#include <include/functions/dnaiostreamfuncs.hpp>
27
#include <include/functions/dnastrmanipfuncs.hpp>
28

29
namespace dynadjust { 
30
namespace iostreams {
31

32
void dna_io_map::load_map_file(const std::string& map_filename, pv_string_uint32_pair stnsMap) 
52✔
33
{        
34
        std::ifstream map_file;
52✔
35
        std::stringstream ss;
52✔
36
        ss << "load_map_file(): An error was encountered when opening " << map_filename << "." << std::endl;
52✔
37

38
        try {
52✔
39
                // open stations map file.  Throws runtime_error on failure.
40
                file_opener(map_file, map_filename, std::ios::in | std::ios::binary, binary, true);
52✔
41
        }
NEW
42
        catch (const std::runtime_error& e) {
×
43
                ss << e.what();
×
NEW
44
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
45
        }
×
46
        catch (...) {
×
NEW
47
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
48
        }
×
49
        
50
        ss.str("");
156✔
51
        ss << "load_map_file(): An error was encountered when reading from " << map_filename << "." << std::endl;
52✔
52

53
        stnsMap->clear();
52✔
54
        UINT32 mapsize;
52✔
55
        string_uint32_pair stnID;
52✔
56
        char stationName[STN_NAME_WIDTH];        // 56 characters
52✔
57
        
58
        try {
52✔
59
                // read the file information
60
                readFileInfo(map_file);
52✔
61
                
62
                // read the number of records
63
                map_file.read(reinterpret_cast<char *>(&mapsize), sizeof(UINT32));
52✔
64
                stnsMap->reserve(mapsize);
52✔
65
                
66
                // read the records
67
                for (UINT32 i=0; i<mapsize; i++)
7,481✔
68
                {
69
                        map_file.read(const_cast<char *>(stationName), sizeof(stationName));
7,429✔
70
                        stnID.first = stationName;
7,429✔
71
                        map_file.read(reinterpret_cast<char *>(&stnID.second), sizeof(UINT32));
7,429✔
72
                        stnsMap->push_back(stnID);
7,429✔
73
                }
74
        }
NEW
75
        catch (const std::ios_base::failure& f) {
×
76
                ss << f.what();
×
NEW
77
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
78
        }
×
NEW
79
        catch (const std::runtime_error& e) {
×
80
                ss << e.what();
×
NEW
81
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
82
        }
×
83
        catch (...) {
×
NEW
84
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
85
        }
×
86

87
        map_file.close();
52✔
88

89
        if (stnsMap->size() < mapsize)
52✔
90
                throw boost::enable_current_exception(
×
NEW
91
                        std::runtime_error("load_map_file(): Could not allocate sufficient memory for the Station map."));
×
92
}
52✔
93

94
void dna_io_map::write_map_file(const std::string& map_filename, pv_string_uint32_pair stnsMap)
83✔
95
{
96
        std::ofstream map_file;
83✔
97
        std::stringstream ss;
83✔
98
        ss << "write_map_file(): An error was encountered when opening " << map_filename << "." << std::endl;
83✔
99

100
        try {
83✔
101
                // Open station map file.  Throws runtime_error on failure.
102
                file_opener(map_file, map_filename, 
83✔
103
                        std::ios::out | std::ios::binary, binary);
104
        }
NEW
105
        catch (const std::runtime_error& e) {
×
106
                ss << e.what();
×
NEW
107
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
108
        }
×
109
        catch (...) {
×
NEW
110
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
111
        }
×
112

113
        ss.str("");
249✔
114
        ss << "write_map_file(): An error was encountered when writing to " << map_filename << "." << std::endl;
83✔
115

116
        v_string_uint32_pair::const_iterator _it_stnmap(stnsMap->begin());
83✔
117
        UINT32 mapval(static_cast<UINT32>(stnsMap->size()));
83✔
118
        try {
83✔
119
                // write the file information
120
                writeFileInfo(map_file);
83✔
121
                
122
                // write the data
123
                map_file.write(reinterpret_cast<char *>(&mapval), sizeof(UINT32));
83✔
124
                char stationName[STN_NAME_WIDTH];
83✔
125
                memset(stationName, '\0', sizeof(stationName));
83✔
126
                for (; _it_stnmap!=stnsMap->end(); ++_it_stnmap)
7,124✔
127
                {
128
                        strcpy(stationName, _it_stnmap->first.c_str());
7,041✔
129
                        mapval = _it_stnmap->second;
7,041✔
130
                        map_file.write(stationName, sizeof(stationName));
7,041✔
131
                        map_file.write(reinterpret_cast<char *>(&mapval), sizeof(UINT32));
7,041✔
132
                }
133
        }
NEW
134
        catch (const std::ios_base::failure& f) {
×
135
                ss << f.what();
×
NEW
136
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
137
        }
×
NEW
138
        catch (const std::runtime_error& e) {
×
139
                ss << e.what();
×
NEW
140
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
141
        }
×
142
        catch (...) {
×
NEW
143
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
144
        }
×
145

146
        map_file.close();
83✔
147
}
83✔
148
        
149

150
void dna_io_map::write_map_file_txt(const std::string& map_filename, pv_string_uint32_pair stnsMap)
5✔
151
{
152
        std::ofstream map_file;
5✔
153
        std::stringstream ss;
5✔
154
        ss << "write_map_file_txt(): An error was encountered when opening " << map_filename << "." << std::endl;
5✔
155

156
        try {
5✔
157
                // Create station map text file.  Throws runtime_error on failure.
158
                file_opener(map_file, map_filename);
5✔
159
        }
NEW
160
        catch (const std::runtime_error& e) {
×
161
                ss << e.what();
×
NEW
162
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
163
        }
×
164
        catch (...) {
×
NEW
165
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
166
        }
×
167

168
        ss.str("");
15✔
169
        ss << "write_map_file_txt(): An error was encountered when writing to " << map_filename << "." << std::endl;
5✔
170

171
        try {
5✔
172
                std::stringstream ss_map;
5✔
173
                ss_map << stnsMap->size() << " stations";
5✔
174
                map_file << std::left << std::setw(STATION) << ss_map.str();
5✔
175
                map_file << std::setw(HEADER_20) << std::right << "Stn. index" << std::endl;
5✔
176
                v_string_uint32_pair::const_iterator _it_stnmap(stnsMap->begin());
5✔
177
                for (_it_stnmap=stnsMap->begin(); _it_stnmap!=stnsMap->end(); ++_it_stnmap)
392✔
178
                {
179
                        map_file << std::setw(STATION) << std::left << 
387✔
180
                                _it_stnmap->first.c_str() <<
387✔
181
                                std::setw(HEADER_20) << std::right << _it_stnmap->second << std::endl;
387✔
182
                }
183
        }
5✔
NEW
184
        catch (const std::ios_base::failure& f) {
×
185
                ss << f.what();
×
NEW
186
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
187
        }
×
NEW
188
        catch (const std::runtime_error& e) {
×
189
                ss << e.what();
×
NEW
190
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
191
        }
×
192
        catch (...) {
×
NEW
193
                throw boost::enable_current_exception(std::runtime_error(ss.str()));
×
194
        }
×
195

196
        map_file.close();
5✔
197
}
5✔
198

199
//void dna_io_map::load_renaming_file(const std::string& renaming_filename, pv_string_string_pair stnRenaming)
200
//{
201
//        std::ifstream renaming_file;
202
//
203
//        std::stringstream ss;
204
//        ss << "load_renaming_file(): An error was encountered when opening " << renaming_filename << "." << std::endl;
205
//
206
//        // The contents of the renaming file is as follows:
207
//        //
208
//        //  --------------------------------------------------------------------------------
209
//        //  DYNADJUST STATION RENAMING FILE
210
//        //  
211
//        //  Station count                      3 
212
//        //  Station name width                 20
213
//        //  --------------------------------------------------------------------------------
214
//        //  
215
//        //  STATION NAMES
216
//        //  
217
//        //  OLD NAME             NEW NAME
218
//        //  -------------------- --------------------
219
//        //  GABO                 262600060
220
//        //  BEEC                 209901750
221
//        //  PTLD                 341404410
222
//
223
//        //
224
//        try {
225
//                // Load renaming file.  Throws runtime_error on failure.
226
//                file_opener(renaming_file, renaming_filename, 
227
//                        std::ios::in, ascii, true);
228
//        }
229
//        catch (const std::runtime_error& e) {
230
//                ss << e.what();
231
//                throw boost::enable_current_exception(std::runtime_error(ss.str()));
232
//        }
233
//        catch (...) {
234
//                throw boost::enable_current_exception(std::runtime_error(ss.str()));
235
//        }
236
//        
237
//        ss.str("");
238
//        ss << "load_renaming_file(): An error was encountered when reading from " << renaming_filename << "." << std::endl;
239
//
240
//        stnRenaming->clear();
241
//
242
//        string_string_pair stnNames;
243
//        std::string sBuf("");
244
//        UINT32 stationWidth(STATION), stationCount(100);
245
//        UINT32 line(0);
246
//        
247
//        try {
248
//                
249
//                // continue until "STATION NAMES" is found
250
//                do 
251
//                {
252
//                        line++;
253
//                        getline(renaming_file, sBuf);
254
//
255
//                        if (boost::iequals(trimstr(sBuf), "STATION NAMES"))
256
//                                break;
257
//
258
//                        // blank or whitespace?
259
//                        if (trimstr(sBuf).empty())                
260
//                                continue;
261
//
262
//                        if (boost::iequals(trimstr(sBuf.substr(0, 13)), "Station count"))
263
//                        {
264
//                                stationCount = boost::lexical_cast<UINT16, std::string>(trimstr(sBuf.substr(PRINT_VAR_PAD)));
265
//                                continue;
266
//                        }
267
//
268
//                        if (boost::iequals(trimstr(sBuf.substr(0, 18)), "Station name width"))
269
//                        {
270
//                                stationWidth = boost::lexical_cast<UINT16, std::string>(trimstr(sBuf.substr(PRINT_VAR_PAD)));
271
//                                continue;
272
//                        }
273
//
274
//                }
275
//                while (!boost::iequals(trimstr(sBuf), "STATION NAMES"));
276
//                
277
//                stnRenaming->reserve(stationCount);
278
//                
279
//                // Okay, now get the data
280
//                while (!renaming_file.eof())
281
//                {
282
//                        getline(renaming_file, sBuf);
283
//
284
//                        // blank or whitespace?
285
//                        if (trimstr(sBuf).empty())                        
286
//                                continue;
287
//
288
//                        if (trimstr(sBuf).length() < stationWidth)
289
//                                continue;
290
//
291
//                        if (boost::iequals(trimstr(sBuf.substr(0, 8)), "OLD NAME"))
292
//                                continue;
293
//
294
//                        if (boost::iequals(trimstr(sBuf.substr(0, 3)), "---"))
295
//                                continue;
296
//
297
//                        // Ignore lines with blank station name
298
//                        if (trimstr(sBuf.substr(0, stationWidth)).empty())                        
299
//                                continue;
300
//
301
//                        // Ignore lines with blank substitute name
302
//                        if (trimstr(sBuf.substr(stationWidth+1)).empty())                        
303
//                                continue;
304
//
305
//                        // initialise
306
//                        stnNames.first = "";
307
//                        stnNames.second = "";
308
//
309
//                        // get the names
310
//                        stnNames.first = trimstr(sBuf.substr(0, stationWidth));        
311
//                        stnNames.second = trimstr(sBuf.substr(stationWidth+1));
312
//                        stnRenaming->push_back(stnNames);
313
//                }
314
//        }
315
//        catch (const std::ios_base::failure& f) {
316
//                if (renaming_file.eof())
317
//                {
318
//                        renaming_file.close();
319
//                        return;
320
//                }
321
//                ss << f.what();
322
//                throw boost::enable_current_exception(std::runtime_error(ss.str()));
323
//        }
324
//        catch (const std::runtime_error& e) {
325
//                if (renaming_file.eof())
326
//                {
327
//                        renaming_file.close();
328
//                        return;
329
//                }
330
//                ss << e.what();
331
//                throw boost::enable_current_exception(std::runtime_error(ss.str()));
332
//        }
333
//        catch (...) {
334
//                if (renaming_file.eof())
335
//                {
336
//                        renaming_file.close();
337
//                        return;
338
//                }
339
//                throw boost::enable_current_exception(std::runtime_error(ss.str()));
340
//        }
341
//
342
//        renaming_file.close();
343
//}
344

345

346
} // dnaiostreams
347
} // dynadjust
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