• 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

58.48
/dynadjust/include/io/dnaiodna.cpp
1
//============================================================================
2
// Name         : dnaiodna.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  : DNA file io helper
21
//============================================================================
22

23
#include <include/io/dnaiodna.hpp>
24
#include <include/parameters/dnaepsg.hpp>
25
#include <include/measurement_types/dnameasurement_types.hpp>
26

27
using namespace dynadjust::measurements;
28
using namespace dynadjust::epsg;
29

30
namespace dynadjust { 
31
namespace iostreams {
32

33
void dna_io_dna::write_dna_files(vdnaStnPtr* vStations, vdnaMsrPtr* vMeasurements, 
×
34
                        const std::string& stnfilename, const std::string& msrfilename, const std::string& networkname,
35
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
36
                        const std::string& stn_comment, const std::string& msr_comment)
37
{
38

39
        write_stn_file(vStations, stnfilename, networkname, datum, projection, flagUnused, stn_comment);
×
40
        write_msr_file(vMeasurements, msrfilename, networkname, datum, msr_comment);
×
41
}
×
42

43
void dna_io_dna::write_dna_files(pvstn_t vbinary_stn, pvmsr_t vbinary_msr, 
5✔
44
                        const std::string& stnfilename, const std::string& msrfilename, const std::string& networkname,
45
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
46
                        const std::string& stn_comment, const std::string& msr_comment)
47
{
48
        write_stn_file(vbinary_stn, stnfilename, networkname, datum, projection, flagUnused, stn_comment);
5✔
49
        write_msr_file(*vbinary_stn, vbinary_msr, msrfilename, networkname, datum, msr_comment);
5✔
50
}
5✔
51
        
52
void dna_io_dna::create_file_stn(std::ofstream* ptr, const std::string& filename)
5✔
53
{
54
        determineDNASTNFieldParameters<UINT16>("3.01", dsl_, dsw_);
10✔
55
        create_file_pointer(ptr, filename);
5✔
56
}
5✔
57
        
58
void dna_io_dna::create_file_msr(std::ofstream* ptr, const std::string& filename)
5✔
59
{
60
        determineDNAMSRFieldParameters<UINT16>("3.01", dml_, dmw_);
10✔
61
        create_file_pointer(ptr, filename);
5✔
62
}
5✔
63

64
void dna_io_dna::prepare_sort_list(const UINT32 count)
5✔
65
{
66
        vStationList_.resize(count);
5✔
67

68
        // initialise vector with 0,1,2,...,n-2,n-1,n
69
        initialiseIncrementingIntegerVector<UINT32>(vStationList_, count);
5✔
70
}
5✔
71
        
72
void dna_io_dna::create_file_pointer(std::ofstream* ptr, const std::string& filename)
10✔
73
{
74
        try {
10✔
75
                // Create file pointer to DNA file. 
76
                file_opener(*ptr, filename);
10✔
77
        }
NEW
78
        catch (const std::runtime_error& e) {
×
NEW
79
                throw boost::enable_current_exception(std::runtime_error(e.what()));
×
UNCOV
80
        }
×
81
}
10✔
82
        
83
void dna_io_dna::open_file_pointer(std::ifstream* ptr, const std::string& filename)
1✔
84
{
85
        try {
1✔
86
                // Open DNA file.
87
                file_opener(*ptr, filename, std::ios::in, ascii, true);
1✔
88
        }
NEW
89
        catch (const std::runtime_error& e) {
×
NEW
90
                throw boost::enable_current_exception(std::runtime_error(e.what()));
×
UNCOV
91
        }
×
92
}
1✔
93

94
void dna_io_dna::write_stn_header_data(std::ofstream* ptr, const std::string& networkname, const std::string& datum,
5✔
95
        const std::string& epoch, const size_t& count, const std::string& comment)
96
{
97
        // Write version line
98
        dna_header(*ptr, "3.01", "STN", datum, epoch, count);
15✔
99

100
        // Write comments
101
        dna_comment(*ptr, "File type:    Station file");
10✔
102
        dna_comment(*ptr, "Project name: " + networkname);
5✔
103

104
        // Write header comment line, e.g. "Coordinates exported from reftran."
105
        dna_comment(*ptr, comment);
5✔
106
}
5✔
107

NEW
108
void dna_io_dna::write_stn_header(std::ofstream* ptr, vdnaStnPtr* vStations, const std::string& networkname,
×
109
                        const CDnaDatum& datum, bool flagUnused, const std::string& comment)
110
{
111
        // print stations
112
        // Has the user specified --flag-unused-stations, in which case, do not
113
        // print stations marked unused?
114
        size_t count(0);
×
115
        if (flagUnused) 
×
116
        {
117
                for_each(vStations->begin(), vStations->end(),
×
118
                        [&count](const dnaStnPtr& stn) {
×
119
                                if (stn.get()->IsNotUnused())
×
120
                                        count++;
×
121
                });
122
        }
123
        else
124
                count = vStations->size();
×
125

126
        // write header
127
        write_stn_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), count, comment);        
×
128
}
×
129
        
130

131
void dna_io_dna::write_stn_header(std::ofstream* ptr, pvstn_t vbinary_stn, const std::string& networkname,
5✔
132
                        const CDnaDatum& datum, bool flagUnused, const std::string& comment)
133
{
134
        // print stations
135
        // Has the user specified --flag-unused-stations, in which case, do not
136
        // print stations marked unused?
137
        size_t count(0);
5✔
138
        if (flagUnused) 
5✔
139
        {
140
                for_each(vbinary_stn->begin(), vbinary_stn->end(),
1✔
141
                        [&count](const station_t& stn) {
24✔
142
                                if (stn.unusedStation == 0)
24✔
143
                                        count++;
13✔
144
                });
145
        }
146
        else
147
                count = vbinary_stn->size();
4✔
148

149
        // write header
150
        write_stn_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), count, comment);
15✔
151
}
5✔
152
        
153

154
void dna_io_dna::read_ren_file(const std::string& filename, pv_string_vstring_pair stnRenaming)
1✔
155
{
156
        std::ifstream renaming_file;
1✔
157

158
        // create file pointer
159
        open_file_pointer(&renaming_file, filename);
1✔
160

161
        std::string version;
1✔
162
        INPUT_DATA_TYPE idt;
1✔
163
        CDnaDatum datum;
1✔
164
        std::string geoidVersion, fileEpsg, fileEpoch;
1✔
165
        UINT32 count(0);
1✔
166

167
        // read header information
168
        read_dna_header(&renaming_file, version, idt, datum, fileEpsg, fileEpoch, geoidVersion, count);
1✔
169

170
        read_ren_data(&renaming_file, stnRenaming);
1✔
171

172
        renaming_file.close();
1✔
173
}
4✔
174

175
void dna_io_dna::read_ren_data(std::ifstream* ptr, pv_string_vstring_pair stnRenaming)
1✔
176
{
177
        std::string sBuf;
1✔
178

179
        string_vstring_pair stnNames;
1✔
180
        vstring altStnNames;
1✔
181

182
        while (!ptr->eof())                        // while EOF not found
15✔
183
        {
184
                try {
15✔
185
                        getline((*ptr), sBuf);
15✔
186
                }
187
                catch (...) {
1✔
188
                        if (ptr->eof())
1✔
189
                                return;
1✔
NEW
190
                        std::stringstream ss;
×
NEW
191
                        ss << "read_ren_data(): Could not read from the renaming file." << std::endl;
×
NEW
192
                        boost::enable_current_exception(std::runtime_error(ss.str()));
×
193
                }
1✔
194

195
                // blank or whitespace?
196
                if (trimstr(sBuf).empty())                        
28✔
197
                        continue;
×
198

199
                // Ignore lines with blank station name
200
                if (trimstr(sBuf.substr(dsl_.stn_name, dsw_.stn_name)).empty())                        
42✔
201
                        continue;
×
202
                
203
                // Ignore lines with comments
204
                if (sBuf.compare(0, 1, "*") == 0)
14✔
205
                        continue;
×
206
                
207
                std::string tmp;
14✔
208
                
209
                // Add the preferred name
210
                try {
14✔
211
                        tmp = trimstr(sBuf.substr(dsl_.stn_name, dsw_.stn_name));
28✔
212
                        stnNames.first = tmp;
14✔
213
                }
214
                catch (...) {
×
NEW
215
                        std::stringstream ss;
×
216
                        ss << "read_ren_data(): Could not extract station name from the record:  " << 
×
NEW
217
                                 std::endl << "    " << sBuf << std::endl;
×
NEW
218
                        boost::enable_current_exception(std::runtime_error(ss.str()));
×
UNCOV
219
                }                
×
220

221
                // Alternative names
222
                altStnNames.clear();
14✔
223
                UINT32 positionEndName(dsw_.stn_name+dsw_.stn_name);
14✔
224
                UINT32 positionNextName(dsw_.stn_name);
14✔
225
                while (sBuf.length() > positionNextName)
28✔
226
                {
227
                        if (sBuf.length() > positionEndName)
14✔
228
                                tmp = trimstr(sBuf.substr(positionNextName, dsw_.stn_name));
×
229
                        else
230
                                tmp = trimstr(sBuf.substr(positionNextName));
42✔
231

232
                        if (!tmp.empty())
14✔
233
                                altStnNames.push_back(tmp);
14✔
234

235
                        positionNextName = positionEndName;
14✔
236
                        positionEndName += dsw_.stn_name;
14✔
237
                }
238
                
239
                // sort for faster searching
240
                std::sort(altStnNames.begin(), altStnNames.end());
14✔
241

242
                // Add the alternate names
243
                stnNames.second = altStnNames;
14✔
244

245
                // Okay, add the pair to the list
246
                stnRenaming->push_back(stnNames);
14✔
247
        }
14✔
248
}
2✔
249
        
250

251
void dna_io_dna::read_dna_header(std::ifstream* ptr, std::string& version, INPUT_DATA_TYPE& idt, 
133✔
252
        CDnaDatum& referenceframe,
253
        std::string& fileEpsg, std::string& fileEpoch, std::string& geoidversion, UINT32& count)
254
{
255
        std::string sBuf;
133✔
256
        getline((*ptr), sBuf);
133✔
257
        sBuf = trimstr(sBuf);
133✔
258
        m_filespecifiedReferenceFrame_ = false;
133✔
259
        m_filespecifiedEpoch_ = false;
133✔
260

261
        // Set the default version
262
        version = "1.00";
133✔
263

264
        // Attempt to get the file's version
265
        try {
133✔
266
                if (boost::iequals("!#=DNA", sBuf.substr(0, 6)))
266✔
267
                        version = trimstr(sBuf.substr(6, 6));
399✔
268
        }
NEW
269
        catch (const std::runtime_error& e) {
×
NEW
270
                throw boost::enable_current_exception(std::runtime_error(e.what()));
×
UNCOV
271
        }
×
272

273
        // Attempt to get the file's type
274
        try {
133✔
275
                determineDNASTNFieldParameters<UINT16>(version, dsl_, dsw_);
133✔
276
                determineDNAMSRFieldParameters<UINT16>(version, dml_, dmw_);
133✔
277
        }
NEW
278
        catch (const std::runtime_error& e) {
×
NEW
279
                std::stringstream ssError;
×
NEW
280
                ssError << "- Error: Unable to determine DNA file version." << std::endl <<
×
NEW
281
                        sBuf << std::endl << " " << e.what() << std::endl;
×
NEW
282
                throw boost::enable_current_exception(std::runtime_error(ssError.str()));
×
UNCOV
283
        }
×
284

285
        // Version 1
286
        if (boost::iequals(version, "1.00"))
133✔
287
        {
288
                idt = unknown;                                                        // could be stn or msr
×
289
                count = 100;                                                        // set default 100 stations
×
290
                return;
×
291
        }
292

293
        std::string type;
133✔
294
        // Attempt to get the file's type
295
        try {
133✔
296
                type = trimstr(sBuf.substr(12, 3));
266✔
297
        }
NEW
298
        catch (const std::runtime_error& e) {
×
NEW
299
                std::stringstream ssError;
×
NEW
300
                ssError << "- Error: File type has not been provided in the header" << std::endl <<
×
NEW
301
                        sBuf << std::endl << e.what() << std::endl;
×
NEW
302
                throw boost::enable_current_exception(std::runtime_error(ssError.str()));
×
UNCOV
303
        }
×
304

305
        // Station file
306
        if (boost::iequals(type, "stn"))
133✔
307
                idt = stn_data;
63✔
308
        // Measurement file
309
        else if (boost::iequals(type, "msr"))
70✔
310
                idt = msr_data;
69✔
311
        // Geoid information file
312
        else if (boost::iequals(type, "geo"))
1✔
313
                idt = geo_data;
×
314
        // Station renaming
315
        else if (boost::iequals(type, "ren"))
1✔
316
                idt = ren_data;
1✔
317
        else
318
        {
319
                idt = unknown;
×
NEW
320
                std::stringstream ssError;
×
NEW
321
                ssError << "The supplied filetype '" << type << "' is not recognised" << std::endl;
×
NEW
322
                throw boost::enable_current_exception(std::runtime_error(ssError.str()));
×
UNCOV
323
        }
×
324

325
        if (sBuf.length() < 29)
133✔
326
        {
327
                count = 100;
2✔
328
                return;
2✔
329
        }
330

331
        std::string file_referenceframe;
131✔
332
        // Attempt to get the default reference frame
333
        try {
131✔
334
                if (sBuf.length() > 42)
131✔
335
                        file_referenceframe = trimstr(sBuf.substr(29, 14));
393✔
336
                else if (sBuf.length() > 29)
×
337
                        file_referenceframe = trimstr(sBuf.substr(29));
×
338
                else
339
                        file_referenceframe = "";
×
340
        }
341
        catch (...) {
×
342
                // datum not provided?
343
                file_referenceframe = "";
×
344
        }
×
345

346
        if (!file_referenceframe.empty())
131✔
347
                m_filespecifiedReferenceFrame_ = true;
131✔
348

349
        std::string epoch_version;
131✔
350
        // Attempt to get the default epoch / geoid version
351
        try {
131✔
352
                if (sBuf.length() > 56)
131✔
353
                        epoch_version = trimstr(sBuf.substr(43, 14));
393✔
354
                else if (sBuf.length() > 43)
×
355
                        epoch_version = trimstr(sBuf.substr(43));
×
356
                else
357
                        epoch_version = "";
×
358
        }
359
        catch (...) {
×
360
                // epoch / version not provided?
361
                epoch_version = "";
×
362
        }
×
363

364
        if (!epoch_version.empty())
131✔
365
                m_filespecifiedEpoch_ = true;
131✔
366

367
        // Try to get the reference frame
368
        // For the first file, and unless the user has specified a reference frame,
369
        // the reference frame will be used to set the frame for all other files.
370
        try {
131✔
371

372
                switch (idt)
131✔
373
                {
374
                case stn_data:
131✔
375
                case msr_data:
131✔
376
                        
377
                        // Capture file epsg
378
                        if (file_referenceframe.empty())
131✔
379
                                // Empty? Get the epsg code from the project datum
380
                                fileEpsg = referenceframe.GetEpsgCode_s();
×
381
                        else
382
                                fileEpsg = epsgStringFromName<std::string>(file_referenceframe);
262✔
383

384
                        // capture file epoch
385
                        if (epoch_version.empty())
131✔
386
                        {
387
                                // Empty?  Get the epoch of the nominated epsg (set above)
NEW
388
                                fileEpoch = referenceepochFromEpsgString<std::string>(fileEpsg);
×
389
                        }
390
                        else
391
                                fileEpoch = epoch_version;
131✔
392

393
                        break;
UNCOV
394
                case geo_data:
×
395
                        geoidversion = epoch_version;
×
396
                        break;
397
                default:
398
                        break;
399
                }
400
        }
NEW
401
        catch (const std::runtime_error& e) {
×
NEW
402
                std::stringstream ssError;
×
NEW
403
                ssError << "The supplied frame (" << file_referenceframe << ") is not recognised" << std::endl <<
×
NEW
404
                        e.what() << std::endl;
×
NEW
405
                throw boost::enable_current_exception(std::runtime_error(ssError.str()));
×
UNCOV
406
        }        
×
407

408
        // Attempt to get the data count
409
        try {
131✔
410
                if (sBuf.length() > 66)
131✔
411
                        count = val_uint<UINT32, std::string>(trimstr(sBuf.substr(57, 10)));
393✔
412
                else if (sBuf.length() > 57)
×
NEW
413
                        count = val_uint<UINT32, std::string>(trimstr(sBuf.substr(57)));
×
414
                else 
415
                        count = 100;
×
416
        }
417
        catch (...) {
×
418
                count = 100;
×
419
        }
×
420
}
528✔
421

422

423
void dna_io_dna::write_stn_file(pvstn_t vbinary_stn, const std::string& stnfilename, const std::string& networkname,
5✔
424
                                const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
425
                                const std::string& comment)
426
{
427
        // Print DNA stations from a vector of stn_t
428
        std::ofstream dna_stn_file;
5✔
429

430
        try {
5✔
431
                // Create file pointer
432
                create_file_stn(&dna_stn_file, stnfilename);
5✔
433

434
                // Write header and comment
435
                write_stn_header(&dna_stn_file, vbinary_stn, networkname, datum, flagUnused, comment);
5✔
436

437
                // Sort on original file order
438
                prepare_sort_list(static_cast<UINT32>(vbinary_stn->size()));
5✔
439
                CompareStnFileOrder<station_t, UINT32> stnorderCompareFunc(vbinary_stn);
5✔
440
                std::sort(vStationList_.begin(), vStationList_.end(), stnorderCompareFunc);
5✔
441

442
                dnaStnPtr stnPtr(new CDnaStation(datum.GetName(), datum.GetEpoch_s()));
15✔
443

444
                // print stations
445
                // Has the user specified --flag-unused-stations, in wich case, do not
446
                // print stations marked unused?
447
                if (flagUnused) 
5✔
448
                {
449
                        // Print stations in DNA format
450
                        for_each(vStationList_.begin(), vStationList_.end(),
1✔
451
                                [&dna_stn_file, &stnPtr, &projection, &datum, &vbinary_stn, this](const UINT32& stn) {
24✔
452
                                        if (stnPtr->IsNotUnused())
24✔
453
                                        {
454
                                                stnPtr->SetStationRec(vbinary_stn->at(stn));
14✔
455
                                                stnPtr->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
14✔
456
                                                        const_cast<CDnaProjection*>(&projection), dna, &dsw_);
14✔
457
                                        }
458
                        });
24✔
459
                }
460
                else
461
                {
462
                        // Print stations in DNA format
463
                        for_each(vStationList_.begin(), vStationList_.end(),
4✔
464
                                [&dna_stn_file, &stnPtr, &projection, &datum, &vbinary_stn, this](const UINT32& stn) {
107✔
465
                                        stnPtr->SetStationRec(vbinary_stn->at(stn));
107✔
466
                                        stnPtr->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
107✔
467
                                                const_cast<CDnaProjection*>(&projection), dna, &dsw_);
107✔
468
                        });
107✔
469
                }
470

471
                dna_stn_file.close();
5✔
472
                
473
        }
×
474
        catch (const std::ifstream::failure& f) {
×
NEW
475
                throw boost::enable_current_exception(std::runtime_error(f.what()));
×
476
        }
×
477
}
5✔
478
        
479

NEW
480
void dna_io_dna::write_stn_file(vdnaStnPtr* vStations, const std::string& stnfilename, const std::string& networkname,
×
481
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
482
                        const std::string& comment)
483
{
484
        // Print DNA stations from a vector of dnaStnPtr
485
        std::ofstream dna_stn_file;
×
486

487
        try {
×
488
                // Create file pointer
489
                create_file_stn(&dna_stn_file, stnfilename);
×
490

491
                // Write header and comment
492
                write_stn_header(&dna_stn_file, vStations, networkname, datum, flagUnused, comment);
×
493

494
                // Sort on original file order
NEW
495
                std::sort(vStations->begin(), vStations->end(), CompareStnFileOrder_CDnaStn<CDnaStation>());
×
496

497
                // print stations
498
                // Has the user specified --flag-unused-stations, in wich case, do not
499
                // print stations marked unused?
500
                if (flagUnused) 
×
501
                {
502
                        // Print stations in DNA format
503
                        for_each(vStations->begin(), vStations->end(),
×
504
                                [&dna_stn_file, &projection, &datum, this](const dnaStnPtr& stn) {
×
505
                                        if (stn.get()->IsNotUnused())
×
506
                                                stn.get()->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
×
507
                                                        const_cast<CDnaProjection*>(&projection), dna, &dsw_);
×
508
                        });
×
509
                }
510
                else
511
                {
512
                        // Print stations in DNA format
513
                        for_each(vStations->begin(), vStations->end(),
×
514
                                [&dna_stn_file, &projection, &datum, this](const dnaStnPtr& stn) {
×
515
                                        stn.get()->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
×
516
                                                const_cast<CDnaProjection*>(&projection), dna, &dsw_);
×
517
                        });
×
518
                }
519

520
                dna_stn_file.close();
×
521
                
522
        }
523
        catch (const std::ifstream::failure& f) {
×
NEW
524
                throw boost::enable_current_exception(std::runtime_error(f.what()));
×
525
        }        
×
526
}
×
527

528
void dna_io_dna::write_msr_header_data(std::ofstream* ptr, const std::string& networkname, const std::string& datum,
5✔
529
        const std::string& epoch, const size_t& count, const std::string& comment)
530
{
531
        // Write version line
532
        dna_header(*ptr, "3.01", "MSR", datum, epoch, count);
15✔
533

534
        // Write comments
535
        dna_comment(*ptr, "File type:    Measurement file");
10✔
536
        dna_comment(*ptr, "Project name: " + networkname);
5✔
537

538
        // Write header comment line
539
        dna_comment(*ptr, comment);
5✔
540

541
}
5✔
542

543

NEW
544
void dna_io_dna::write_msr_header(std::ofstream* ptr, vdnaMsrPtr* vMeasurements, const std::string& networkname,
×
545
        const CDnaDatum& datum, const std::string& comment)
546
{
547
        // write header
548
        write_msr_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), vMeasurements->size(), comment);
×
549
}
×
550
        
551

552
void dna_io_dna::write_msr_header(std::ofstream* ptr, pvmsr_t vbinary_msrn, const std::string& networkname,
5✔
553
        const CDnaDatum& datum, const std::string& comment)
554
{
555
        // write header
556
        write_msr_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), vbinary_msrn->size(), comment);
15✔
557
}
5✔
558

559

560
void dna_io_dna::write_msr_file(const vstn_t& vbinary_stn, pvmsr_t vbinary_msr, const std::string& msrfilename, const std::string& networkname,
5✔
561
        const CDnaDatum& datum, const std::string& comment)
562
{
563
        // Print DNA measurements        
564

565
        std::ofstream dna_msr_file;
5✔
566

567
        it_vmsr_t _it_msr(vbinary_msr->begin());
5✔
568
        dnaMsrPtr msrPtr;
5✔
569
        size_t dbindex;
5✔
570
        it_vdbid_t _it_dbid;
5✔
571

572
        try {
5✔
573
                // Create file pointer
574
                create_file_msr(&dna_msr_file, msrfilename);
5✔
575

576
                // Write header and comment
577
                write_msr_header(&dna_msr_file, vbinary_msr, networkname, datum, comment);
5✔
578

579
                // print measurements
580
                for (_it_msr=vbinary_msr->begin(); _it_msr!=vbinary_msr->end(); ++_it_msr)
183✔
581
                {
582
                        ResetMeasurementPtr<char>(&msrPtr, _it_msr->measType);
178✔
583

584
                        // Database IDs
585
                        if (m_databaseIDsSet_)
178✔
586
                        {
587
                                dbindex = std::distance(vbinary_msr->begin(), _it_msr);
178✔
588
                                _it_dbid = pv_msr_db_map_->begin() + dbindex;
178✔
589
                        }
590

591
                        msrPtr->SetMeasurementRec(vbinary_stn, _it_msr, _it_dbid);
178✔
592
                        msrPtr->WriteDNAMsr(&dna_msr_file, dmw_, dml_);
178✔
593
                }
594

595
                dna_msr_file.close();
5✔
596

597
        }
598
        catch (const std::ifstream::failure& f) {
×
NEW
599
                throw boost::enable_current_exception(std::runtime_error(f.what()));
×
600
        }
×
601
}
5✔
602
        
NEW
603
void dna_io_dna::write_msr_file(vdnaMsrPtr* vMeasurements, const std::string& msrfilename, const std::string& networkname,
×
604
        const CDnaDatum& datum,        const std::string& comment)
605
{
606
        // Print DNA measurements        
607
        
608
        std::ofstream dna_msr_file;
×
609
        
610
        _it_vdnamsrptr _it_msr(vMeasurements->begin());
×
611
        size_t dbindex;
×
612
        it_vdbid_t _it_dbid;
×
613
        
614
        try {
×
615
                // Create file pointer
616
                create_file_msr(&dna_msr_file, msrfilename);
×
617

618
                // Write header and comment
619
                write_msr_header(&dna_msr_file, vMeasurements, networkname, datum, comment);
×
620

621
                // print measurements
622
                for (_it_msr = vMeasurements->begin(); _it_msr != vMeasurements->end(); _it_msr++)
×
623
                {
624
                        // Get database IDs
625
                        dbindex = std::distance(vMeasurements->begin(), _it_msr);
×
626
                        _it_dbid = pv_msr_db_map_->begin() + dbindex;
×
627
                        _it_msr->get()->SetDatabaseMaps(_it_dbid);
×
628

629
                        // Write
630
                        _it_msr->get()->WriteDNAMsr(&dna_msr_file, dmw_, dml_);
×
631
                }
632
                
633
                dna_msr_file.close();
×
634
                
635
        }
636
        catch (const std::ifstream::failure& f) {
×
NEW
637
                throw boost::enable_current_exception(std::runtime_error(f.what()));
×
638
        }
×
639
        
640

641
}
×
642

643
void dna_io_dna::set_dbid_ptr(pv_msr_database_id_map pv_msr_db_map)
5✔
644
{
645
        pv_msr_db_map_ = pv_msr_db_map;
5✔
646
        if (pv_msr_db_map->size() > 0)
5✔
647
                m_databaseIDsSet_ = true;
5✔
648
        else
649
                m_databaseIDsSet_ = false;
×
650
}
5✔
651

652

653
} // dnaiostreams
654
} // dynadjust
655

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