10
10
11
11
#include < cstdlib>
12
12
#include < csignal>
13
+ #include < iomanip>
13
14
#include < unistd.h>
14
15
#include < sys/wait.h>
15
16
@@ -26,13 +27,6 @@ namespace isce3::unwrap {
26
27
char dumpresults_global = FALSE ;
27
28
char requestedstop_global = FALSE ;
28
29
29
- /* ouput stream pointers */
30
- /* sp0=error messages, sp1=status output, sp2=verbose, sp3=verbose counter */
31
- FILE *sp0 = NULL ;
32
- FILE *sp1 = NULL ;
33
- FILE *sp2 = NULL ;
34
- FILE *sp3 = NULL ;
35
-
36
30
/* node pointer for marking arc not on tree in apex array */
37
31
/* this should be treated as a constant */
38
32
nodeT NONTREEARC[1 ]={};
@@ -66,15 +60,15 @@ void snaphuUnwrap(const std::string& configfile){
66
60
double cputimestart;
67
61
long linelen, nlines;
68
62
63
+ auto info=pyre::journal::info_t (" isce3.unwrap.snaphu" );
69
64
70
65
/* get current wall clock and CPU time */
71
66
StartTimers (&tstart,&cputimestart);
72
67
73
- /* set output stream pointers (may be reset after inputs parsed) */
74
- SetStreamPointers ();
75
-
76
68
/* print greeting */
77
- fprintf (sp1," \n %s v%s\n " ,PROGRAMNAME,VERSION);
69
+ info << pyre::journal::at (__HERE__)
70
+ << PROGRAMNAME << " v" << VERSION
71
+ << pyre::journal::endl;
78
72
79
73
/* set default parameters */
80
74
SetDefaults (infiles,outfiles,params);
@@ -83,9 +77,6 @@ void snaphuUnwrap(const std::string& configfile){
83
77
/* read input config file */
84
78
ReadConfigFile (configfile.data (),infiles,outfiles,&linelen,params);
85
79
86
- /* set verbose output if specified */
87
- SetVerboseOut (params);
88
-
89
80
/* set names of dump files if necessary */
90
81
SetDumpAll (outfiles,params);
91
82
@@ -102,7 +93,9 @@ void snaphuUnwrap(const std::string& configfile){
102
93
Unwrap (infiles,outfiles,params,linelen,nlines);
103
94
104
95
/* finish up */
105
- fprintf (sp1," Program %s done\n " ,PROGRAMNAME);
96
+ info << pyre::journal::at (__HERE__)
97
+ << " Program " << PROGRAMNAME << " done"
98
+ << pyre::journal::endl;
106
99
DisplayElapsedTime (tstart,cputimestart);
107
100
108
101
} /* end of snaphuUnwrap() */
@@ -178,6 +171,8 @@ int Unwrap(infileT *infiles, outfileT *outfiles, paramT *params,
178
171
double tilecputimestart;
179
172
time_t tiletstart;
180
173
174
+ auto info=pyre::journal::info_t (" isce3.unwrap.snaphu" );
175
+
181
176
/* see if we need to do single-tile reoptimization and set up if so */
182
177
if (params->onetilereopt ){
183
178
noptiter=2 ;
@@ -203,7 +198,9 @@ int Unwrap(infileT *infiles, outfileT *outfiles, paramT *params,
203
198
SetTileInitOutfile (iteroutfiles->outfile ,iterparams->parentpid );
204
199
StrNCopy (tileinitfile,iteroutfiles->outfile ,MAXSTRLEN);
205
200
iteroutfiles->outfileformat =TILEINITFILEFORMAT;
206
- fprintf (sp1," Starting first-round tile-mode unwrapping\n " );
201
+ info << pyre::journal::at (__HERE__)
202
+ << " Starting first-round tile-mode unwrapping"
203
+ << pyre::journal::endl;
207
204
208
205
}
209
206
@@ -218,7 +215,9 @@ int Unwrap(infileT *infiles, outfileT *outfiles, paramT *params,
218
215
iterparams->ntilecol =1 ;
219
216
iterparams->rowovrlp =0 ;
220
217
iterparams->colovrlp =0 ;
221
- fprintf (sp1," Starting second-round single-tile unwrapping\n " );
218
+ info << pyre::journal::at (__HERE__)
219
+ << " Starting second-round single-tile unwrapping"
220
+ << pyre::journal::endl;
222
221
223
222
}else {
224
223
throw isce3::except::RuntimeError (ISCE_SRCINFO (),
@@ -315,17 +314,15 @@ int Unwrap(infileT *infiles, outfileT *outfiles, paramT *params,
315
314
316
315
/* set up tile parameters */
317
316
pid=getpid ();
318
- fprintf (sp1,
319
- " Unwrapping tile at row %ld, column %ld (pid %ld)\n " ,
320
- nexttilerow,nexttilecol,(long )pid);
317
+ info << pyre::journal::at (__HERE__)
318
+ << " Unwrapping tile at row " << nexttilerow
319
+ << " , column " << nexttilecol << " (pid "
320
+ << ((long )pid) << " )"
321
+ << pyre::journal::endl;
321
322
SetupTile (nlines,linelen,iterparams,tileparams,
322
323
iteroutfiles,tileoutfiles,
323
324
nexttilerow,nexttilecol);
324
325
325
- /* reset stream pointers for logging */
326
- ChildResetStreamPointers (pid,nexttilerow,nexttilecol,
327
- iterparams);
328
-
329
326
/* unwrap the tile */
330
327
UnwrapTile (iterinfiles,tileoutfiles,iterparams,tileparams,
331
328
nlines,linelen,tag);
@@ -390,8 +387,10 @@ int Unwrap(infileT *infiles, outfileT *outfiles, paramT *params,
390
387
if (dotilemask (nexttilerow,nexttilecol)){
391
388
392
389
/* set up tile parameters */
393
- fprintf (sp1," Unwrapping tile at row %ld, column %ld\n " ,
394
- nexttilerow,nexttilecol);
390
+ info << pyre::journal::at (__HERE__)
391
+ << " Unwrapping tile at row " << nexttilerow
392
+ << " , column " << nexttilecol
393
+ << pyre::journal::endl;
395
394
SetupTile (nlines,linelen,iterparams,tileparams,
396
395
iteroutfiles,tileoutfiles,
397
396
nexttilerow,nexttilecol);
@@ -460,6 +459,11 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
460
459
using Cost=typename CostTag::Cost;
461
460
Array2D<Cost> costs;
462
461
462
+ auto info=pyre::journal::info_t (" isce3.unwrap.snaphu" );
463
+ constexpr int output_detail_level=2 ;
464
+ auto verbose=pyre::journal::info_t (" isce3.unwrap.snaphu" ,output_detail_level);
465
+ auto status=pyre::journal::info_t (" isce3.unwrap.snaphu.status" ,output_detail_level);
466
+
463
467
/* get size of tile */
464
468
nrow=tileparams->nrow ;
465
469
ncol=tileparams->ncol ;
@@ -494,10 +498,14 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
494
498
/* if in quantify-only mode, evaluate cost of unwrapped input then return */
495
499
if (params->eval ){
496
500
mostflow=Short2DRowColAbsMax (flows,nrow,ncol);
497
- fprintf (sp1," Maximum flow on network: %ld\n " ,mostflow);
501
+ info << pyre::journal::at (__HERE__)
502
+ << " Maximum flow on network: " << mostflow
503
+ << pyre::journal::endl;
498
504
Array1D<int > dummy;
499
505
totalcost=EvaluateTotalCost (costs,flows,nrow,ncol,dummy,params,tag);
500
- fprintf (sp1," Total solution cost: %.9g\n " ,(double )totalcost);
506
+ info << pyre::journal::at (__HERE__) << " Total solution cost: "
507
+ << std::fixed << std::setprecision (9 ) << ((double )totalcost)
508
+ << pyre::journal::endl;
501
509
return (1 );
502
510
}
503
511
@@ -528,7 +536,9 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
528
536
529
537
/* integrate the phase and write out if necessary */
530
538
if (params->initonly || strlen (outfiles->initfile )){
531
- fprintf (sp1," Integrating phase\n " );
539
+ info << pyre::journal::at (__HERE__)
540
+ << " Integrating phase"
541
+ << pyre::journal::endl;
532
542
auto unwrappedphase=Array2D<float >(nrow,ncol);
533
543
IntegratePhase (wrappedphase,unwrappedphase,flows,nrow,ncol);
534
544
if (unwrappedest.size ()){
@@ -538,12 +548,16 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
538
548
539
549
/* return if called in init only; otherwise, free memory and continue */
540
550
if (params->initonly ){
541
- fprintf (sp1," Writing output to file %s\n " ,outfiles->outfile );
551
+ info << pyre::journal::at (__HERE__)
552
+ << " Writing output to file " << outfiles->outfile
553
+ << pyre::journal::endl;
542
554
WriteOutputFile (mag,unwrappedphase,outfiles->outfile ,outfiles,
543
555
nrow,ncol);
544
556
return (1 );
545
557
}else {
546
- fprintf (sp2," Writing initialization to file %s\n " ,outfiles->initfile );
558
+ verbose << pyre::journal::at (__HERE__)
559
+ << " Writing initialization to file " << outfiles->initfile
560
+ << pyre::journal::endl;
547
561
WriteOutputFile (mag,unwrappedphase,outfiles->initfile ,outfiles,
548
562
nrow,ncol);
549
563
}
@@ -581,13 +595,20 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
581
595
582
596
/* main loop: loop over flow increments and sources */
583
597
if (!allmasked){
584
- fprintf (sp1," Running nonlinear network flow optimizer\n " );
585
- fprintf (sp1," Maximum flow on network: %ld\n " ,mostflow);
586
- fprintf (sp2," Number of nodes in network: %ld\n " ,(nrow-1 )*(ncol-1 )+1 );
598
+ info << pyre::journal::at (__HERE__)
599
+ << " Running nonlinear network flow optimizer"
600
+ << pyre::journal::endl
601
+ << " Maximum flow on network: " << mostflow
602
+ << pyre::journal::endl;
603
+ verbose << pyre::journal::at (__HERE__)
604
+ << " Number of nodes in network: " << ((nrow-1 )*(ncol-1 )+1 )
605
+ << pyre::journal::endl;
587
606
while (TRUE ){
588
607
589
- fprintf (sp1," Flow increment: %ld (Total improvements: %ld)\n " ,
590
- nflow,ncycle);
608
+ info << pyre::journal::at (__HERE__)
609
+ << " Flow increment: " << nflow
610
+ << " (Total improvements: " << ncycle << " )"
611
+ << pyre::journal::endl;
591
612
592
613
/* set up the incremental (residual) cost arrays */
593
614
SetupIncrFlowCosts (costs,incrcosts,flows,nflow,nrow,narcrow,narcsperrow,
@@ -616,10 +637,14 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
616
637
617
638
/* show status if verbose */
618
639
if (source->row ==GROUNDROW){
619
- fprintf (sp3," Source %ld: (edge ground)\n " ,isource);
640
+ status << pyre::journal::at (__HERE__)
641
+ << " Source " << isource << " : (edge ground)"
642
+ << pyre::journal::endl;
620
643
}else {
621
- fprintf (sp3," Source %ld: row, col = %d, %d\n " ,
622
- isource,source->row ,source->col );
644
+ status << pyre::journal::at (__HERE__)
645
+ << " Source " << isource << " : row, col = "
646
+ << source->row << " , " << source->col
647
+ << pyre::journal::endl;
623
648
}
624
649
625
650
/* run the solver, and increment nflowdone if no cycles are found */
@@ -635,9 +660,10 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
635
660
636
661
/* evaluate and save the total cost (skip if first loop through nflow) */
637
662
Array1D<int > dummy;
638
- fprintf (sp2," Current solution cost: %.16g\n " ,
639
- (double )EvaluateTotalCost (costs,flows,nrow,ncol,dummy,params,tag));
640
- fflush (NULL );
663
+ verbose << pyre::journal::at (__HERE__)
664
+ << " Current solution cost: " << std::fixed << std::setprecision (16 )
665
+ << ((double )EvaluateTotalCost (costs,flows,nrow,ncol,dummy,params,tag))
666
+ << pyre::journal::endl;
641
667
if (notfirstloop){
642
668
oldtotalcost=totalcost;
643
669
totalcost=EvaluateTotalCost (costs,flows,nrow,ncol,dummy,params,tag);
@@ -646,7 +672,9 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
646
672
}
647
673
if (totalcost>oldtotalcost || (n>0 && totalcost==oldtotalcost)){
648
674
fflush (NULL );
649
- fprintf (sp1," Caution: Unexpected increase in total cost\n " );
675
+ info << pyre::journal::at (__HERE__)
676
+ << " Caution: Unexpected increase in total cost"
677
+ << pyre::journal::endl;
650
678
}
651
679
if (totalcost > mintotalcost){
652
680
nincreasedcostiter++;
@@ -667,8 +695,11 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
667
695
mostflow=MaxNonMaskFlow (flows,mag,nrow,ncol);
668
696
if (nincreasedcostiter>=mostflow){
669
697
fflush (NULL );
670
- fprintf (sp0," WARNING: Unexpected sustained increase in total cost."
671
- " Breaking loop\n " );
698
+ auto warnings=pyre::journal::warning_t (" isce3.unwrap.snaphu" );
699
+ warnings << pyre::journal::at (__HERE__)
700
+ << " WARNING: Unexpected sustained increase in total cost."
701
+ << " Breaking loop"
702
+ << pyre::journal::endl;
672
703
break ;
673
704
}
674
705
@@ -683,7 +714,9 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
683
714
nflow=1 ;
684
715
notfirstloop=TRUE ;
685
716
}
686
- fprintf (sp2," Maximum valid flow on network: %ld\n " ,mostflow);
717
+ verbose << pyre::journal::at (__HERE__)
718
+ << " Maximum valid flow on network: " << mostflow
719
+ << pyre::journal::endl;
687
720
688
721
/* dump flow arrays if necessary */
689
722
if (strlen (outfiles->flowfile )){
@@ -715,11 +748,16 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
715
748
/* evaluate and display the maximum flow and total cost */
716
749
Array1D<int > dummy;
717
750
totalcost=EvaluateTotalCost (costs,flows,nrow,ncol,dummy,params,tag);
718
- fprintf (sp1," Maximum flow on network: %ld\n " ,mostflow);
719
- fprintf (sp1," Total solution cost: %.9g\n " ,(double )totalcost);
751
+ info << pyre::journal::at (__HERE__)
752
+ << " Maximum flow on network: " << mostflow
753
+ << pyre::journal::endl << " Total solution cost: "
754
+ << std::fixed << std::setprecision (9 ) << ((double )totalcost)
755
+ << pyre::journal::endl;
720
756
721
757
/* integrate the wrapped phase using the solution flow */
722
- fprintf (sp1," Integrating phase\n " );
758
+ info << pyre::journal::at (__HERE__)
759
+ << " Integrating phase"
760
+ << pyre::journal::endl;
723
761
auto unwrappedphase=Array2D<float >(nrow,ncol);
724
762
IntegratePhase (wrappedphase,unwrappedphase,flows,nrow,ncol);
725
763
@@ -732,7 +770,9 @@ int UnwrapTile(infileT *infiles, outfileT *outfiles, paramT *params,
732
770
FlipPhaseArraySign (unwrappedphase,params,nrow,ncol);
733
771
734
772
/* write the unwrapped output */
735
- fprintf (sp1," Writing output to file %s\n " ,outfiles->outfile );
773
+ info << pyre::journal::at (__HERE__)
774
+ << " Writing output to file " << outfiles->outfile
775
+ << pyre::journal::endl;
736
776
WriteOutputFile (mag,unwrappedphase,outfiles->outfile ,outfiles,
737
777
nrow,ncol);
738
778
0 commit comments