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

icsm-au / DynAdjust / 4558854622

pending completion
4558854622

push

github

GitHub
Merge pull request #213 from icsm-au/1.2.7

949 of 949 new or added lines in 30 files covered. (100.0%)

30192 of 38394 relevant lines covered (78.64%)

3682.47 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 string& stnfilename, const string& msrfilename, const string& networkname,
35
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
36
                        const string& stn_comment, const 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 string& stnfilename, const string& msrfilename, const string& networkname,
45
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
46
                        const string& stn_comment, const 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 string& filename)
5✔
53
{
54
        determineDNASTNFieldParameters<UINT16>("3.01", dsl_, dsw_);
5✔
55
        create_file_pointer(ptr, filename);
5✔
56
}
5✔
57
        
58
void dna_io_dna::create_file_msr(std::ofstream* ptr, const string& filename)
5✔
59
{
60
        determineDNAMSRFieldParameters<UINT16>("3.01", dml_, dmw_);
5✔
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 string& filename)
10✔
73
{
74
        try {
10✔
75
                // Create file pointer to DNA file. 
76
                file_opener(*ptr, filename);
10✔
77
        }
78
        catch (const runtime_error& e) {
×
79
                throw boost::enable_current_exception(runtime_error(e.what()));
×
80
        }
×
81
}
10✔
82
        
83
void dna_io_dna::open_file_pointer(std::ifstream* ptr, const string& filename)
1✔
84
{
85
        try {
1✔
86
                // Open DNA file.
87
                file_opener(*ptr, filename, ios::in, ascii, true);
1✔
88
        }
89
        catch (const runtime_error& e) {
×
90
                throw boost::enable_current_exception(runtime_error(e.what()));
×
91
        }
×
92
}
1✔
93

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

100
        // Write comments
101
        dna_comment(*ptr, "File type:    Station file");
5✔
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

108
void dna_io_dna::write_stn_header(std::ofstream* ptr, vdnaStnPtr* vStations, const string& networkname,
×
109
                        const CDnaDatum& datum, bool flagUnused, const 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 string& networkname,
5✔
132
                        const CDnaDatum& datum, bool flagUnused, const 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) {
37✔
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 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
        string version;
1✔
162
        INPUT_DATA_TYPE idt;
1✔
163
        CDnaDatum datum;
1✔
164
        string geoidVersion, fileEpsg, fileEpoch;
1✔
165
        UINT32 count(0);
1✔
166

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

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

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

175
void dna_io_dna::read_ren_data(std::ifstream* ptr, pv_string_vstring_pair stnRenaming)
1✔
176
{
177
        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✔
190
                        stringstream ss;
×
191
                        ss << "read_ren_data(): Could not read from the renaming file." << endl;
×
192
                        boost::enable_current_exception(runtime_error(ss.str()));
×
193
                }
1✔
194

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

199
                // Ignore lines with blank station name
200
                if (trimstr(sBuf.substr(dsl_.stn_name, dsw_.stn_name)).empty())                        
14✔
201
                        continue;
×
202
                
203
                // Ignore lines with comments
204
                if (sBuf.compare(0, 1, "*") == 0)
14✔
205
                        continue;
×
206
                
207
                string tmp;
14✔
208
                
209
                // Add the preferred name
210
                try {
14✔
211
                        tmp = trimstr(sBuf.substr(dsl_.stn_name, dsw_.stn_name));
14✔
212
                        stnNames.first = tmp;
14✔
213
                }
214
                catch (...) {
×
215
                        stringstream ss;
×
216
                        ss << "read_ren_data(): Could not extract station name from the record:  " << 
×
217
                                endl << "    " << sBuf << endl;
×
218
                        boost::enable_current_exception(runtime_error(ss.str()));
×
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));
14✔
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
                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, string& version, INPUT_DATA_TYPE& idt, 
76✔
252
        CDnaDatum& referenceframe, bool user_supplied_frame, bool override_input_frame,
253
        string& fileEpsg, string& fileEpoch, string& geoidversion, UINT32& count)
254
{
255
        string sBuf;
76✔
256
        getline((*ptr), sBuf);
76✔
257
        sBuf = trimstr(sBuf);
76✔
258

259
        // Set the default version
260
        version = "1.00";
76✔
261

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

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

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

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

303
        // Station file
304
        if (iequals(type, "stn"))
76✔
305
                idt = stn_data;
34✔
306
        // MEasurement file
307
        else if (iequals(type, "msr"))
42✔
308
                idt = msr_data;
41✔
309
        // Geoid information file
310
        else if (iequals(type, "geo"))
1✔
311
                idt = geo_data;
×
312
        // Station renaming
313
        else if (iequals(type, "ren"))
1✔
314
                idt = ren_data;
1✔
315
        else
316
        {
317
                idt = unknown;
×
318
                stringstream ssError;
×
319
                ssError << "The supplied filetype '" << type << "' is not recognised" << endl;
×
320
                throw boost::enable_current_exception(runtime_error(ssError.str()));
×
321
        }
×
322

323
        if (sBuf.length() < 29)
76✔
324
        {
325
                count = 100;
2✔
326
                return;
2✔
327
        }
328

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

344
        string epoch_version;
74✔
345
        // Attempt to get the default epoch / geoid version
346
        try {
74✔
347
                if (sBuf.length() > 56)
74✔
348
                        epoch_version = trimstr(sBuf.substr(43, 14));
74✔
349
                else if (sBuf.length() > 43)
×
350
                        epoch_version = trimstr(sBuf.substr(43));
×
351
                else
352
                        epoch_version = "";
×
353
        }
354
        catch (...) {
×
355
                // epoch / version not provided?
356
                epoch_version = "";
×
357
        }
×
358

359
        // Try to get the reference frame
360
        try {
74✔
361
                
362

363
                switch (idt)
74✔
364
                {
365
                case stn_data:
74✔
366
                case msr_data:
74✔
367

368
                        // Capture file epsg
369
                        if (file_referenceframe.empty())
74✔
370
                                // Get the epsg code from the default datum 
371
                                fileEpsg = referenceframe.GetEpsgCode_s();
×
372
                        else
373
                                fileEpsg = epsgStringFromName<string>(file_referenceframe);
74✔
374

375
                        if (epoch_version.empty())
74✔
376
                                // No, so get the epoch from the default datum 
377
                                fileEpoch = referenceframe.GetEpoch_s();
×
378
                        else
379
                                fileEpoch = epoch_version;
74✔
380

381
                        // Presently, the logic for handling default reference frame is duplicated for 
382
                        // each file type, here and in dnaparser_pimpl.cxx:
383
                        //     void referenceframe_pimpl::post_type(...)
384

385
                        // 2. Does the user want to override the default datum?
386
                        if (override_input_frame)
74✔
387
                                // Do nothing, just return as referenceframe will become 
388
                                // the default for all stations and measurements loaded
389
                                // from the file.
390
                                break;
391
                        
392
                        // 3. Does the user want the referenceframe attribute in the file to become the default?
393
                        if (!user_supplied_frame)
68✔
394
                        {
395
                                if (!file_referenceframe.empty())
58✔
396
                                        // adopt the reference frame supplied in the file
397
                                        referenceframe.SetDatumFromName(file_referenceframe, epoch_version);
58✔
398
                        }
399

400
                        // Since import doesn't offer an option to capture epoch on the command line,
401
                        // take the epoch from the file (if not empty).
402
                        if (!epoch_version.empty())
68✔
403
                                referenceframe.SetEpoch(epoch_version);
68✔
404
                                                
405
                        break;
406

407
                case geo_data:
×
408
                        geoidversion = epoch_version;
×
409
                        break;
410
                default:
411
                        break;
412
                }
413
        }
414
        catch (const runtime_error& e) {
×
415
                stringstream ssError;
×
416
                ssError << "The supplied frame is not recognised" << endl <<
×
417
                        e.what() << endl;
×
418
                throw boost::enable_current_exception(runtime_error(ssError.str()));
×
419
        }        
×
420

421
        // Attempt to get the data count
422
        try {
74✔
423
                if (sBuf.length() > 66)
74✔
424
                        count = val_uint<UINT32, string>(trimstr(sBuf.substr(57, 10)));
74✔
425
                else if (sBuf.length() > 57)
×
426
                        count = val_uint<UINT32, string>(trimstr(sBuf.substr(57)));
×
427
                else 
428
                        count = 100;
×
429
        }
430
        catch (...) {
×
431
                count = 100;
×
432
        }
×
433
}
76✔
434

435

436
void dna_io_dna::write_stn_file(pvstn_t vbinary_stn, const string& stnfilename, const string& networkname,
5✔
437
                                const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
438
                                const string& comment)
439
{
440
        // Print DNA stations from a vector of stn_t
441
        std::ofstream dna_stn_file;
5✔
442

443
        try {
5✔
444
                // Create file pointer
445
                create_file_stn(&dna_stn_file, stnfilename);
5✔
446

447
                // Write header and comment
448
                write_stn_header(&dna_stn_file, vbinary_stn, networkname, datum, flagUnused, comment);
5✔
449

450
                // Sort on original file order
451
                prepare_sort_list(static_cast<UINT32>(vbinary_stn->size()));
5✔
452
                CompareStnFileOrder<station_t, UINT32> stnorderCompareFunc(vbinary_stn);
5✔
453
                sort(vStationList_.begin(), vStationList_.end(), stnorderCompareFunc);
5✔
454

455
                dnaStnPtr stnPtr(new CDnaStation(datum.GetName(), datum.GetEpoch_s()));
10✔
456

457
                // print stations
458
                // Has the user specified --flag-unused-stations, in wich case, do not
459
                // print stations marked unused?
460
                if (flagUnused) 
5✔
461
                {
462
                        // Print stations in DNA format
463
                        for_each(vStationList_.begin(), vStationList_.end(),
1✔
464
                                [&dna_stn_file, &stnPtr, &projection, &datum, &vbinary_stn, this](const UINT32& stn) {
66✔
465
                                        if (stnPtr->IsNotUnused())
24✔
466
                                        {
467
                                                stnPtr->SetStationRec(vbinary_stn->at(stn));
14✔
468
                                                stnPtr->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
14✔
469
                                                        const_cast<CDnaProjection*>(&projection), dna, &dsw_);
14✔
470
                                        }
471
                        });
24✔
472
                }
473
                else
474
                {
475
                        // Print stations in DNA format
476
                        for_each(vStationList_.begin(), vStationList_.end(),
4✔
477
                                [&dna_stn_file, &stnPtr, &projection, &datum, &vbinary_stn, this](const UINT32& stn) {
428✔
478
                                        stnPtr->SetStationRec(vbinary_stn->at(stn));
107✔
479
                                        stnPtr->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
107✔
480
                                                const_cast<CDnaProjection*>(&projection), dna, &dsw_);
107✔
481
                        });
107✔
482
                }
483

484
                dna_stn_file.close();
5✔
485
                
486
        }
×
487
        catch (const std::ifstream::failure& f) {
×
488
                throw boost::enable_current_exception(runtime_error(f.what()));
×
489
        }
×
490
}
5✔
491
        
492

493
void dna_io_dna::write_stn_file(vdnaStnPtr* vStations, const string& stnfilename, const string& networkname,
×
494
                        const CDnaDatum& datum, const CDnaProjection& projection, bool flagUnused,
495
                        const string& comment)
496
{
497
        // Print DNA stations from a vector of dnaStnPtr
498
        std::ofstream dna_stn_file;
×
499

500
        try {
×
501
                // Create file pointer
502
                create_file_stn(&dna_stn_file, stnfilename);
×
503

504
                // Write header and comment
505
                write_stn_header(&dna_stn_file, vStations, networkname, datum, flagUnused, comment);
×
506

507
                // Sort on original file order
508
                sort(vStations->begin(), vStations->end(), CompareStnFileOrder_CDnaStn<CDnaStation>());
×
509

510
                // print stations
511
                // Has the user specified --flag-unused-stations, in wich case, do not
512
                // print stations marked unused?
513
                if (flagUnused) 
×
514
                {
515
                        // Print stations in DNA format
516
                        for_each(vStations->begin(), vStations->end(),
×
517
                                [&dna_stn_file, &projection, &datum, this](const dnaStnPtr& stn) {
×
518
                                        if (stn.get()->IsNotUnused())
×
519
                                                stn.get()->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
×
520
                                                        const_cast<CDnaProjection*>(&projection), dna, &dsw_);
×
521
                        });
×
522
                }
523
                else
524
                {
525
                        // Print stations in DNA format
526
                        for_each(vStations->begin(), vStations->end(),
×
527
                                [&dna_stn_file, &projection, &datum, this](const dnaStnPtr& stn) {
×
528
                                        stn.get()->WriteDNAXMLStnCurrentEstimates(&dna_stn_file, datum.GetEllipsoidRef(), 
×
529
                                                const_cast<CDnaProjection*>(&projection), dna, &dsw_);
×
530
                        });
×
531
                }
532

533
                dna_stn_file.close();
×
534
                
535
        }
536
        catch (const std::ifstream::failure& f) {
×
537
                throw boost::enable_current_exception(runtime_error(f.what()));
×
538
        }        
×
539
}
×
540

541
void dna_io_dna::write_msr_header_data(std::ofstream* ptr, const string& networkname, const string& datum,
5✔
542
        const string& epoch, const size_t& count, const string& comment)
543
{
544
        // Write version line
545
        dna_header(*ptr, "3.01", "MSR", datum, epoch, count);
10✔
546

547
        // Write comments
548
        dna_comment(*ptr, "File type:    Measurement file");
5✔
549
        dna_comment(*ptr, "Project name: " + networkname);
5✔
550

551
        // Write header comment line
552
        dna_comment(*ptr, comment);
5✔
553

554
}
5✔
555

556

557
void dna_io_dna::write_msr_header(std::ofstream* ptr, vdnaMsrPtr* vMeasurements, const string& networkname,
×
558
        const CDnaDatum& datum, const string& comment)
559
{
560
        // write header
561
        write_msr_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), vMeasurements->size(), comment);
×
562
}
×
563
        
564

565
void dna_io_dna::write_msr_header(std::ofstream* ptr, pvmsr_t vbinary_msrn, const string& networkname,
5✔
566
        const CDnaDatum& datum, const string& comment)
567
{
568
        // write header
569
        write_msr_header_data(ptr, networkname, datum.GetName(), datum.GetEpoch_s(), vbinary_msrn->size(), comment);
15✔
570
}
5✔
571

572

573
void dna_io_dna::write_msr_file(const vstn_t& vbinary_stn, pvmsr_t vbinary_msr, const string& msrfilename, const string& networkname,
5✔
574
        const CDnaDatum& datum, const string& comment)
575
{
576
        // Print DNA measurements        
577

578
        std::ofstream dna_msr_file;
5✔
579

580
        it_vmsr_t _it_msr(vbinary_msr->begin());
5✔
581
        dnaMsrPtr msrPtr;
5✔
582
        size_t dbindex;
5✔
583
        it_vdbid_t _it_dbid;
5✔
584

585
        try {
5✔
586
                // Create file pointer
587
                create_file_msr(&dna_msr_file, msrfilename);
5✔
588

589
                // Write header and comment
590
                write_msr_header(&dna_msr_file, vbinary_msr, networkname, datum, comment);
5✔
591

592
                // print measurements
593
                for (_it_msr=vbinary_msr->begin(); _it_msr!=vbinary_msr->end(); ++_it_msr)
183✔
594
                {
595
                        ResetMeasurementPtr<char>(&msrPtr, _it_msr->measType);
178✔
596

597
                        // Database IDs
598
                        if (m_databaseIDsSet_)
178✔
599
                        {
600
                                dbindex = std::distance(vbinary_msr->begin(), _it_msr);
178✔
601
                                _it_dbid = pv_msr_db_map_->begin() + dbindex;
178✔
602
                        }
603

604
                        msrPtr->SetMeasurementRec(vbinary_stn, _it_msr, _it_dbid);
178✔
605
                        msrPtr->WriteDNAMsr(&dna_msr_file, dmw_, dml_);
178✔
606
                }
607

608
                dna_msr_file.close();
5✔
609

610
        }
611
        catch (const std::ifstream::failure& f) {
×
612
                throw boost::enable_current_exception(runtime_error(f.what()));
×
613
        }
×
614
}
5✔
615
        
616
void dna_io_dna::write_msr_file(vdnaMsrPtr* vMeasurements, const string& msrfilename, const string& networkname,
×
617
        const CDnaDatum& datum,        const string& comment)
618
{
619
        // Print DNA measurements        
620
        
621
        std::ofstream dna_msr_file;
×
622
        
623
        _it_vdnamsrptr _it_msr(vMeasurements->begin());
×
624
        size_t dbindex;
×
625
        it_vdbid_t _it_dbid;
×
626
        
627
        try {
×
628
                // Create file pointer
629
                create_file_msr(&dna_msr_file, msrfilename);
×
630

631
                // Write header and comment
632
                write_msr_header(&dna_msr_file, vMeasurements, networkname, datum, comment);
×
633

634
                // print measurements
635
                for (_it_msr = vMeasurements->begin(); _it_msr != vMeasurements->end(); _it_msr++)
×
636
                {
637
                        // Get database IDs
638
                        dbindex = std::distance(vMeasurements->begin(), _it_msr);
×
639
                        _it_dbid = pv_msr_db_map_->begin() + dbindex;
×
640
                        _it_msr->get()->SetDatabaseMaps(_it_dbid);
×
641

642
                        // Write
643
                        _it_msr->get()->WriteDNAMsr(&dna_msr_file, dmw_, dml_);
×
644
                }
645
                
646
                dna_msr_file.close();
×
647
                
648
        }
649
        catch (const std::ifstream::failure& f) {
×
650
                throw boost::enable_current_exception(runtime_error(f.what()));
×
651
        }
×
652
        
653

654
}
×
655

656
void dna_io_dna::set_dbid_ptr(pv_msr_database_id_map pv_msr_db_map)
5✔
657
{
658
        pv_msr_db_map_ = pv_msr_db_map;
5✔
659
        if (pv_msr_db_map->size() > 0)
5✔
660
                m_databaseIDsSet_ = true;
5✔
661
        else
662
                m_databaseIDsSet_ = false;
×
663
}
5✔
664

665

666
} // dnaiostreams
667
} // dynadjust
668

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