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

icsm-au / DynAdjust / 4857311097

pending completion
4857311097

Pull #219

github

GitHub
Merge 3814a6b3c into dd0bd4fb6
Pull Request #219: Initial fixes and code enhancements for 1.2.8

419 of 419 new or added lines in 16 files covered. (100.0%)

30621 of 38760 relevant lines covered (79.0%)

3958.36 hits per line

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

70.56
/dynadjust/dynadjust/dnaadjustwrapper/dnaadjustprogress.cpp
1
//============================================================================
2
// Name         : dnaadjustprogress.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 Adjustment executable interface and progress
21
//============================================================================
22

23
#include <dynadjust/dnaadjustwrapper/dnaadjustprogress.hpp>
24

25
bool running;
26
boost::mutex cout_mutex;
27

28
dna_adjust_thread::dna_adjust_thread(dna_adjust* dnaAdj, project_settings* p,
24✔
29
                _ADJUST_STATUS_* adjustStatus)
24✔
30
                : _dnaAdj(dnaAdj), _p(p), _adjustStatus(adjustStatus) 
24✔
31
{
32
}
24✔
33

34
void dna_adjust_thread::operator()()
24✔
35
{
36
        running = true;
24✔
37
                
38
        if (!prepareAdjustment())
24✔
39
        {
40
                running = false;
4✔
41
                return;
4✔
42
        }
43
        if (!processAdjustment())
20✔
44
        {
45
                running = false;
×
46
                return;
×
47
        }
48

49
        // Do addition things here...
50

51
        running = false;
20✔
52
}
53

54
bool dna_adjust_thread::prepareAdjustment()
24✔
55
{
56
        try {
24✔
57
                *_adjustStatus = ADJUST_EXCEPTION_RAISED;
24✔
58
                _dnaAdj->PrepareAdjustment(*_p);
24✔
59
                *_adjustStatus = ADJUST_SUCCESS;
20✔
60
                return true;
20✔
61
        }
62
        catch (const NetAdjustException& e) {
4✔
63
                handlePrepareAdjustError(e.what());
×
64
        }
×
65
        catch (const NetMemoryException& e) {
×
66
                handlePrepareAdjustError(e.what());
×
67
        }
×
68
        catch (const runtime_error& e) {
4✔
69
                handlePrepareAdjustError(e.what());
4✔
70
        }
4✔
71
        catch (...) {
×
72
                string err("Undefined error.\n  This could be the result of insufficient memory or poorly configured data.");
×
73
                handlePrepareAdjustError(err);
×
74
        }
×
75
        *_adjustStatus = ADJUST_EXCEPTION_RAISED;
4✔
76
        return false;
4✔
77
}
78

79
bool dna_adjust_thread::processAdjustment()
20✔
80
{                
81
        try {
20✔
82
                *_adjustStatus = _dnaAdj->AdjustNetwork();
20✔
83
                *_adjustStatus = ADJUST_SUCCESS;
20✔
84
                return true;
20✔
85
        } 
86
        catch (const NetAdjustException& e) {
×
87
                handleProcessAdjustError(e.what());
×
88
        }
×
89
        catch (const NetMemoryException& e) {
×
90
                handleProcessAdjustError(e.what());
×
91
        }
×
92
        catch (const runtime_error& e) {
×
93
                handleProcessAdjustError(e.what());
×
94
        }
×
95
        catch (...) {
×
96
                string err("- Error: Undefined error.\n  This could be the result of insufficient memory or poorly configured data.");
×
97
                handleProcessAdjustError(err);
×
98
        }
×
99
        *_adjustStatus = ADJUST_EXCEPTION_RAISED;
×
100
        return false;
×
101
}
102

103
void dna_adjust_thread::handlePrepareAdjustError(const string& error_msg)
4✔
104
{
105
        running = false;
4✔
106
        stringstream ss;
4✔
107
        ss << /*PROGRESS_BACKSPACE_12 << */setw(PROGRESS_ADJ_BLOCK_12) << " " << endl
4✔
108
                << "- Error: " << endl << "  " << error_msg << endl;
4✔
109
        coutMessage(ss.str());
4✔
110
}
4✔
111

112
void dna_adjust_thread::handleProcessAdjustError(const string& error_msg)
×
113
{
114
        running = false;
×
115
        boost::this_thread::sleep(milliseconds(50));
×
116
        printErrorMsg(error_msg);
×
117
}
×
118

119
void dna_adjust_thread::printErrorMsg(const string& error_msg)
×
120
{
121
        stringstream ss, sst;
×
122
        
123
        switch (_p->a.adjust_mode)
×
124
        {
125
        case SimultaneousMode:
×
126
                // "  Iteration " = 12
127
                // setw(2)        =  2
128
                // -------------------
129
                //                  14
130
                sst << "  Iteration " << right << setw(2) << fixed << setprecision(0) << _dnaAdj->CurrentIteration();
×
131
                ss << PROGRESS_BACKSPACE_14 << setw(PROGRESS_ADJ_BLOCK_14) << right << sst.str();
×
132
                break;
×
133
        case Phased_Block_1Mode:
×
134
        case PhasedMode:
×
135
                // "  Iteration " = 12
136
                // setw(2)        =  2
137
                // ", block"      =  7
138
                // setw(6)        =  6
139
                // "(forward) "   = 10
140
                // -------------------
141
                //                  37
142
                sst << "  Iteration " << 
×
143
                        right << setw(2) << fixed << setprecision(0) << _dnaAdj->CurrentIteration() << ", block" << right << setw(6) << fixed << setprecision(0) << 
×
144
                        _dnaAdj->CurrentBlock() + 1 << (_dnaAdj->processingForward() ? " (forward)" : " (reverse)");
×
145
                ss << PROGRESS_BACKSPACE_37 << setw(37) << right << sst.str();
×
146
        }
147

148
        ss << endl << "- Error: Cannot compute the least squares estimates.  Reason:\n  " << error_msg << endl;
×
149
        coutMessage(ss);
×
150
}
×
151

152
void dna_adjust_thread::coutMessage(stringstream& message)
×
153
{
154
        coutMessage(message.str());
×
155
}
×
156

157
void dna_adjust_thread::coutMessage(const string& message)
4✔
158
{
159
        cout_mutex.lock();
4✔
160
        cout.flush();
4✔
161
        cout << message;
4✔
162
        cout.flush();
4✔
163
        cout_mutex.unlock();
4✔
164
}
4✔
165

166

167

168

169

170

171

172

173
dna_adjust_progress_thread::dna_adjust_progress_thread(dna_adjust* dnaAdj, project_settings* p)
24✔
174
                : _dnaAdj(dnaAdj), _p(p) {}
24✔
175

176
void dna_adjust_progress_thread::prepareAdjustment()
24✔
177
{
178
        if (_p->g.quiet)
24✔
179
                // Nothing to be displayed
180
                return;
4✔
181
        
182
        if (_p->a.report_mode)
24✔
183
                // Nothing to be displayed
184
                return;
185

186
        stringstream ss;
23✔
187
        ss << "+ Preparing for ";
23✔
188

189
        switch (_p->a.adjust_mode)
23✔
190
        {
191
        case Phased_Block_1Mode:
10✔
192
        case PhasedMode:
10✔
193
                ss << "a " << _dnaAdj->blockCount() << " block ";
10✔
194
                break;
195
        }
196
                        
197
        ss << "adjustment... ";                
23✔
198
        coutMessage(ss.str());
23✔
199
        ss.str("");
46✔
200
        
201
        UINT32 block, currentBlock(0);
23✔
202
        stringstream sst;
43✔
203
        bool first_time(true);
23✔
204
        
205
        switch (_p->a.adjust_mode)
23✔
206
        {
207
        case SimultaneousMode:
208
                while (running && _dnaAdj->IsPreparing())
23✔
209
                {
210
                        boost::this_thread::sleep(milliseconds(40));
10✔
211
                }
212
                
213
                if (_dnaAdj->ExceptionRaised())
13✔
214
                        return;
3✔
215

216
                ss << " done." << endl;
11✔
217
                coutMessage(ss.str());
11✔
218
                
219
                break;
11✔
220
        case Phased_Block_1Mode:
221
        case PhasedMode:
222
                while (running && _dnaAdj->IsPreparing())
26✔
223
                {
224
                        block = _dnaAdj->CurrentBlock();
16✔
225

226
                        if (block != currentBlock)
16✔
227
                        {
228
                                ss.str("");
2✔
229
                                ss << " block " << left << setw(5) << fixed << setprecision(0) << _dnaAdj->CurrentBlock() + 1;
1✔
230

231
                                sst.str("");
2✔
232
                                if (first_time)
1✔
233
                                {
234
                                        sst << setw(PROGRESS_ADJ_BLOCK_12) << left << " ";
1✔
235
                                        first_time = false;
236
                                }
237
                                sst << PROGRESS_BACKSPACE_12 << setw(PROGRESS_ADJ_BLOCK_12) << left << ss.str();
1✔
238
                                coutMessage(sst.str());
1✔
239
                                currentBlock = block;
1✔
240
                        }
241
                        boost::this_thread::sleep(milliseconds(40));
16✔
242
                }
243

244
                if (_dnaAdj->ExceptionRaised())
10✔
245
                        return;
246
                
247
                ss.str("");
18✔
248
                ss << " done.";
9✔
249
                sst.str("");
18✔
250
                if (!first_time)
9✔
251
                        sst << PROGRESS_BACKSPACE_12;
1✔
252
                sst << setw(PROGRESS_ADJ_BLOCK_12) << left << ss.str() << endl;
9✔
253
                coutMessage(sst.str());
18✔
254
                
255
        }
256
}
23✔
257

258
void dna_adjust_progress_thread::processAdjustment()
21✔
259
{
260
        if (_p->g.quiet)
21✔
261
                // Nothing to be displayed
262
                return;
×
263
        
264
        if (_p->a.max_iterations > 0)
21✔
265
                coutMessage(string("+ Adjusting network...\n"));
40✔
266

267
        UINT32 block, currentBlock(0);
21✔
268
        UINT32 currentIteration(0);
21✔
269
        stringstream ss, sst;
21✔
270
        bool first_time(true);
21✔
271

272
        switch (_p->a.adjust_mode)
21✔
273
        {
274
        case SimultaneousMode:
275
                        
276
                while (_dnaAdj->IsAdjusting())
13✔
277
                {
278
                        // use message bank
279
                        while (_dnaAdj->NewMessagesAvailable())
1✔
280
                        {
281
                                if (!_dnaAdj->GetMessageIteration(currentIteration))
×
282
                                        break;
283
                                ss.str("");
×
284
                                ss << "  Iteration " << right << setw(2) << fixed << setprecision(0) << currentIteration;
×
285
                                ss << ", max station corr: " << right << setw(PROGRESS_ADJ_BLOCK_12) <<
×
286
                                        _dnaAdj->GetMaxCorrection(currentIteration) << endl;
×
287
                                        
288
                                coutMessage(ss.str());
×
289
                        }
290
                        boost::this_thread::sleep(milliseconds(80));
1✔
291
                }
292
                
293
                break;
294
        case Phased_Block_1Mode:
295
        case PhasedMode:
296
                
297
                while (_dnaAdj->IsAdjusting())
64✔
298
                {
299
                        block = _dnaAdj->CurrentBlock();
55✔
300
                        
301
                        // use message bank
302
                        while (_dnaAdj->NewMessagesAvailable())
65✔
303
                        {
304
                                if (!_dnaAdj->GetMessageIteration(currentIteration))
10✔
305
                                        break;
306
                                                
307
                                ss.str("");
20✔
308
                                ss << "  Iteration " << right << setw(2) << fixed << setprecision(0) << currentIteration;
10✔
309
                                ss << ", max station corr: " << right << setw(PROGRESS_ADJ_BLOCK_12) << _dnaAdj->GetMaxCorrection(currentIteration) << endl;
20✔
310
                                
311
                                sst.str("");
20✔
312
                                if (first_time)
10✔
313
                                        sst << setw(PROGRESS_ADJ_BLOCK_28) << left << " ";
2✔
314
                                sst << PROGRESS_BACKSPACE_28 << setw(PROGRESS_ADJ_BLOCK_28) << left << ss.str();
10✔
315
                                coutMessage(sst.str());
10✔
316
                                first_time = true;
10✔
317
                        }
318

319
                        boost::this_thread::sleep(milliseconds(40));
55✔
320
                                        
321
                        // print new block to screen when adjusting only
322
                        if (block != currentBlock && _dnaAdj->IsAdjusting())
55✔
323
                        {                                                
324
                                ss.str("");
32✔
325
                                ss << "  Iteration " << right << setw(2) << fixed << setprecision(0) << _dnaAdj->CurrentIteration();
16✔
326

327
        #ifdef MULTI_THREAD_ADJUST
328
                                if (_p->a.multi_thread && !_dnaAdj->processingCombine())
16✔
329
                                        ss << left << setw(13) << ", adjusting...";
×
330
                                else
331
        #endif
332
                                ss << ", block " << left << setw(6) << fixed << setprecision(0) << _dnaAdj->CurrentBlock() + 1;
16✔
333
                                                
334
                                sst.str("");
32✔
335
                                if (first_time)
16✔
336
                                {
337
                                        sst << setw(PROGRESS_ADJ_BLOCK_28) << left << " ";
9✔
338
                                        first_time = false;
339
                                }
340
                                
341
                                sst << PROGRESS_BACKSPACE_28 << setw(PROGRESS_ADJ_BLOCK_28) << left << ss.str();
16✔
342
                                coutMessage(sst.str());
16✔
343

344
                                currentBlock = block;
16✔
345
                        }
346
                }
347
        }
348
}
21✔
349

350
void dna_adjust_progress_thread::operator()()
24✔
351
{
352
        if (_p->g.quiet)
24✔
353
                // Nothing to be displayed
354
                return;
355

356
        // cout messages related to preparing adjustment
357
        // prepareAdjustment() will continue while the following is true:
358
        //        running
359
        //        _dnaAdj->IsPreparing()
360
        //        !_dnaAdj->ExceptionRaised()
361
        prepareAdjustment();
24✔
362
        
363
        if (_dnaAdj->ExceptionRaised())
24✔
364
                return;        
365
        
366
        processAdjustment();        
21✔
367
}
368

369
void dna_adjust_progress_thread::coutMessage(const string& message)
90✔
370
{
371
        cout_mutex.lock();
90✔
372
        cout.flush();
90✔
373
        cout << message;
90✔
374
        cout.flush();
90✔
375
        cout_mutex.unlock();
90✔
376
}
90✔
377

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