[GRASS-SVN] r51865 - grass/trunk/raster/r.terraflow
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue May 29 04:02:04 PDT 2012
Author: mmetz
Date: 2012-05-29 04:02:04 -0700 (Tue, 29 May 2012)
New Revision: 51865
Modified:
grass/trunk/raster/r.terraflow/ccforest.cpp
grass/trunk/raster/r.terraflow/fill.cpp
grass/trunk/raster/r.terraflow/filldepr.cpp
grass/trunk/raster/r.terraflow/flow.cpp
grass/trunk/raster/r.terraflow/grass2str.h
grass/trunk/raster/r.terraflow/main.cpp
grass/trunk/raster/r.terraflow/nodata.cpp
grass/trunk/raster/r.terraflow/plateau.cpp
grass/trunk/raster/r.terraflow/sortutils.h
grass/trunk/raster/r.terraflow/streamutils.h
grass/trunk/raster/r.terraflow/sweep.cpp
grass/trunk/raster/r.terraflow/water.cpp
Log:
r.terraflow make stats file optional
Modified: grass/trunk/raster/r.terraflow/ccforest.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/ccforest.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/ccforest.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -125,7 +125,8 @@
assert(!superTree);
superTree = new ccforest<T>();
- DEBUG_CCFOREST *stats << "sort edgeStream (by cclabel)): ";
+ if (stats)
+ DEBUG_CCFOREST *stats << "sort edgeStream (by cclabel)): ";
keyCmpKeyvalueType<T> fo;
sort(&edgeStream, fo); /* XXX -changed this to use a cmp obj */
@@ -143,18 +144,22 @@
assert(ae == AMI_ERROR_NO_ERROR);
#if(0)
- DEBUG_CCFOREST *stats << "------------------------------" << endl;
- DEBUG_CCFOREST *stats << "processing edge " << *e << endl;
+ if (stats) {
+ DEBUG_CCFOREST *stats << "------------------------------" << endl;
+ DEBUG_CCFOREST *stats << "processing edge " << *e << endl;
+ }
DEBUG_CCFOREST pq->print();
#endif
if(*e == prevEdge) {
- DEBUG_CCFOREST *stats << "\tduplicate " << *e << " removed\n";
+ if (stats)
+ DEBUG_CCFOREST *stats << "\tduplicate " << *e << " removed\n";
continue; /* already have this done */
}
prevEdge = *e;
- DEBUG_CCFOREST *stats << "processing edge " << *e << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "processing edge " << *e << endl;
/* find root (assign parent) */
if(e->src() != prevSrc) {
@@ -200,12 +205,14 @@
}
/* drain the priority queue */
- DEBUG_CCFOREST *stats << "draining priority queue" << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "draining priority queue" << endl;
while (!pq->is_empty()) {
cckeyvalue kv;
pq->extract_min(kv);
assert(kv.src() >= kv.dst());
- DEBUG_CCFOREST *stats << "processing edge " << kv << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "processing edge " << kv << endl;
removeDuplicates(kv.src(), kv.dst(), *pq);
AMI_err ae = rootStream->write_item(kv);
@@ -216,9 +223,11 @@
/* note that rootStream is naturally ordered by src */
if(superTree->size()) {
- DEBUG_CCFOREST *stats << "resolving cycles..." << endl;
- /* printStream(rootStream); */
- DEBUG_CCFOREST *stats << "sort rootStream: ";
+ if (stats) {
+ DEBUG_CCFOREST *stats << "resolving cycles..." << endl;
+ /* printStream(rootStream); */
+ DEBUG_CCFOREST *stats << "sort rootStream: ";
+ }
AMI_STREAM<cckeyvalue> *sortedRootStream;
dstCmpKeyvalueType<T> dstfo;
@@ -245,7 +254,8 @@
}
delete sortedRootStream;
- DEBUG_CCFOREST *stats << "sort relabeledRootStream: ";
+ if (stats)
+ DEBUG_CCFOREST *stats << "sort relabeledRootStream: ";
rootStream = sort(relabeledRootStream, fo);
/* laura: changed this
rootStream = new AMI_STREAM<cckeyvalue>();
@@ -254,17 +264,21 @@
*/
delete relabeledRootStream;
- DEBUG_CCFOREST *stats << "resolving cycles... done." << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "resolving cycles... done." << endl;
}
rootStream->seek(0);
- DEBUG_CCFOREST *stats << "Rootstream length="
+ if (stats){
+ DEBUG_CCFOREST *stats << "Rootstream length="
<< rootStream->stream_len() << endl;
- DEBUG_CCFOREST printStream(*stats, rootStream);
- DEBUG_CCFOREST *stats << "Explicit root count=" << explicitRootCount << endl;
+ DEBUG_CCFOREST printStream(*stats, rootStream);
+ DEBUG_CCFOREST *stats << "Explicit root count=" << explicitRootCount << endl;
+ }
rt_stop(rt);
- stats->recordTime("ccforest::findAllRoots", (long int)rt_seconds(rt));
+ if (stats)
+ stats->recordTime("ccforest::findAllRoots", (long int)rt_seconds(rt));
}
@@ -292,7 +306,8 @@
findAllRoots(); /* find all the roots if not done */
- DEBUG_CCFOREST *stats << "looking for " << i << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "looking for " << i << endl;
if(!savedRootValid || savedRoot.src() < i) { /* need to read more */
ae = rootStream->read_item(&kroot);
while(ae == AMI_ERROR_NO_ERROR && kroot->src() < i) {
@@ -308,12 +323,15 @@
if(savedRootValid==1 && savedRoot.src() == i) { /* check savedRoot */
retRoot = savedRoot.dst();
- DEBUG_CCFOREST *stats << "using saved/found value" << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "using saved/found value" << endl;
} else {
- DEBUG_CCFOREST *stats << "not found" << endl;
+ if (stats)
+ DEBUG_CCFOREST *stats << "not found" << endl;
retRoot = i;
}
- DEBUG_CCFOREST *stats << "lookup for " << i << " gives " << retRoot
+ if (stats)
+ DEBUG_CCFOREST *stats << "lookup for " << i << " gives " << retRoot
<< "; saved = " << savedRoot << endl;
return retRoot;
}
Modified: grass/trunk/raster/r.terraflow/fill.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/fill.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/fill.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -170,12 +170,14 @@
rt_start(rtTotal);
assert(elstr && filledstr == NULL && dirstr == NULL && labeledWater == NULL);
- stats->comment("------------------------------");
- stats->comment("COMPUTING FLOW DIRECTIONS");
+ if (stats) {
+ stats->comment("------------------------------");
+ stats->comment("COMPUTING FLOW DIRECTIONS");
- /* adjust nodata -- boundary nodata distinguished from inner
- nodata */
- stats->comment("classifying nodata (inner & boundary)");
+ /* adjust nodata -- boundary nodata distinguished from inner
+ nodata */
+ stats->comment("classifying nodata (inner & boundary)");
+ }
elstr_reclass = classifyNodata(elstr);
delete elstr;
@@ -185,8 +187,10 @@
/* ---------------------------------------------------------------------- */
/* find the plateaus. */
/* ---------------------------------------------------------------------- */
- stats->comment("----------", opt->verbose);
- stats->comment("assigning preliminary directions");
+ if (stats) {
+ stats->comment("----------", opt->verbose);
+ stats->comment("assigning preliminary directions");
+ }
rt_start(rt);
dirstr = new AMI_STREAM<direction_type>;
@@ -199,9 +203,11 @@
delete winstr; /* not used; not made */
rt_stop(rt);
- stats->recordTime("findingPlateaus", rt);
- stats->recordLength("plateaus", platstr);
- stats->recordLength("plateau stats", statstr);
+ if (stats) {
+ stats->recordTime("findingPlateaus", rt);
+ stats->recordLength("plateaus", platstr);
+ stats->recordLength("plateau stats", statstr);
+ }
FILL_SAVEALL {
/* printStream(*stats, statstr); */
FILL_DEBUG cout << "sort plateauStr (by ij): ";
@@ -223,35 +229,40 @@
delete platstr;
delete statstr;
rt_stop(rt);
- stats->recordTime("assigning directions", rt);
- *stats << "maxWatershedCount=" << labelFactory::getLabelCount() << endl;
-
+ if (stats) {
+ stats->recordTime("assigning directions", rt);
+ *stats << "maxWatershedCount=" << labelFactory::getLabelCount() << endl;
+ }
rt_start(rt);
mergedWaterStr = merge2waterGrid(waterstr, dirstr, elstr);
delete dirstr;
delete waterstr;
rt_stop(rt);
- stats->recordTime("merging", rt);
- stats->recordLength("mergedWaterStr", mergedWaterStr);
+ if (stats) {
+ stats->recordTime("merging", rt);
+ stats->recordLength("mergedWaterStr", mergedWaterStr);
+ }
-
/* ---------------------------------------------------------------------- */
/* watershed analysis */
/* IN: mergedWaterStr, labelFactory::... */
/* ---------------------------------------------------------------------- */
- stats->comment("--------------", opt->verbose);
- stats->comment("generating watersheds and watershed graph");
+ if (stats) {
+ stats->comment("--------------", opt->verbose);
+ stats->comment("generating watersheds and watershed graph");
+ }
rt_start(rt);
waterWindows = new AMI_STREAM<waterWindowType>();
createWaterWindows(mergedWaterStr, nrows, ncols, waterWindows);
delete mergedWaterStr;
rt_stop(rt);
- stats->recordTime("creating windows", rt);
- stats->recordLength("waterWindows", waterWindows);
+ if (stats) {
+ stats->recordTime("creating windows", rt);
+ stats->recordLength("waterWindows", waterWindows);
+ }
-
/* ---------------------------------------------------------------------- */
rt_start(rt);
labeledWater = new AMI_STREAM<labelElevType>();
@@ -266,7 +277,8 @@
assert(labeledWater->stream_len() == nrows * ncols);
rt_stop(rt);
- stats->recordTime("generating watersheds", rt);
+ if (stats)
+ stats->recordTime("generating watersheds", rt);
/* ---------------------------------------------------------------------- */
/* find boundaries */
@@ -296,7 +308,8 @@
raise = fill_depression(boundaryStr, labelFactory::getLabelCount());
delete boundaryStr;
rt_stop(rt);
- stats->recordTime("filling depressions", rt);
+ if (stats)
+ stats->recordTime("filling depressions", rt);
/*fill the terrain*/
rt_start(rt);
@@ -305,16 +318,17 @@
assert(filledstr->stream_len() == nrows * ncols);
delete [] raise;
rt_stop(rt);
- stats->recordTime("updating filled grid", rt);
- stats->recordLength("filledstr", filledstr);
-
+ if (stats) {
+ stats->recordTime("updating filled grid", rt);
+ stats->recordLength("filledstr", filledstr);
- /* ---------------------------------------------------------------------- */
- /* find plateaus again and reassign directions */
- /* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
+ /* find plateaus again and reassign directions */
+ /* ---------------------------------------------------------------------- */
- stats->comment("------------------------------");
- stats->comment("REASSIGNING DIRECTIONS");
+ stats->comment("------------------------------");
+ stats->comment("REASSIGNING DIRECTIONS");
+ }
rt_start(rt);
winstr = NULL;
@@ -323,9 +337,11 @@
platstr = findPlateaus(filledstr, nrows, ncols, nodataType::ELEVATION_NODATA,
winstr, dirstr, statstr);
rt_stop(rt);
- stats->recordTime("findingPlateaus2", rt);
- stats->recordLength("final plateaus", platstr);
- stats->recordLength("final plateau stats", statstr);
+ if (stats) {
+ stats->recordTime("findingPlateaus2", rt);
+ stats->recordLength("final plateaus", platstr);
+ stats->recordLength("final plateau stats", statstr);
+ }
FILL_SAVEALL {
FILL_DEBUG cout << "sort plateauStr (by ij): ";
AMI_STREAM<plateauType> *tmp = sort(platstr, ijCmpPlateauType());
@@ -338,13 +354,14 @@
rt_start(rt);
waterstr = new AMI_STREAM<waterType>();
long dc = assignDirections(statstr, platstr, waterstr);
- if(dc) {
+ if(dc && stats) {
*stats << "WARNING: " << dc << " depressions (islands) detected\n";
}
delete platstr;
delete statstr;
rt_stop(rt);
- stats->recordTime("final directions", rt);
+ if (stats)
+ stats->recordTime("final directions", rt);
/* merge */
rt_start(rt);
@@ -356,12 +373,14 @@
sprintf(path, "%s/flowStream", base_dir);
flowStream = new AMI_STREAM<waterWindowBaseType>(path);
/*flowStream->persist(PERSIST_PERSISTENT); */
- stats->comment("creating flowStream: ", flowStream->sprint());
+ if (stats)
+ stats->comment("creating flowStream: ", flowStream->sprint());
merge2waterBase(waterstr, dirstr, filledstr, flowStream);
delete waterstr;
rt_stop(rt);
- stats->recordTime("merge water,dir,elev to flow", rt);
+ if (stats)
+ stats->recordTime("merge water,dir,elev to flow", rt);
rt_stop(rtTotal);
#ifdef SAVE_ASCII
@@ -372,8 +391,10 @@
"direction.asc", printDirection());
#endif
- stats->recordTime("Total compute flow direction running time", rtTotal);
- stats->comment("compute flow directions done.");
+ if (stats) {
+ stats->recordTime("Total compute flow direction running time", rtTotal);
+ stats->comment("compute flow directions done.");
+ }
return flowStream;
}
@@ -386,7 +407,8 @@
long labelCount = 0;
AMI_STREAM<labelElevType> *tmp;
- *stats << "--- watershed stats" << endl;
+ if (stats)
+ *stats << "--- watershed stats" << endl;
FILL_DEBUG cout << "sort labeledWater (by wat label): ";
tmp = sort(labeledWater, labelCmpLabelElevType());
@@ -401,9 +423,11 @@
}
assert(ae == AMI_ERROR_END_OF_STREAM);
- *stats << "watershed count = " << labelCount << endl;
- *stats << "---" << endl;
- stats->flush();
+ if (stats) {
+ *stats << "watershed count = " << labelCount << endl;
+ *stats << "---" << endl;
+ stats->flush();
+ }
delete tmp;
}
@@ -424,8 +448,10 @@
AMI_err ae;
plateauStats *ps;
- stats->comment("----------", opt->verbose);
- stats->comment("assigning directions on plateaus");
+ if (stats) {
+ stats->comment("----------", opt->verbose);
+ stats->comment("assigning directions on plateaus");
+ }
labelFactory::reset(); /* we are relabeling now */
@@ -461,8 +487,11 @@
}
}
}
- *stats << "depression count = " << depressionCount << endl;
- *stats << "spill count = " << spillCount << endl;
+ if (stats) {
+ *stats << "depression count = " << depressionCount << endl;
+ *stats << "spill count = " << spillCount << endl;
+ }
+
return depressionCount;
}
@@ -480,7 +509,8 @@
AMI_err ae;
plateauStats *ps;
- stats->comment("assigning final directions");
+ if (stats)
+ stats->comment("assigning final directions");
statstr->seek(0);
platstr->seek(0);
@@ -644,7 +674,8 @@
verbosedir("labels.asc"), printLabel());
findBoundaries(labeledWater, nrows, ncols, boundaryStr);
- stats->recordLength("all boundaries", boundaryStr);
+ if (stats)
+ stats->recordLength("all boundaries", boundaryStr);
FILL_SAVEALL {
FILL_DEBUG cout << "sort boundaryStr (by ij): ";
@@ -658,8 +689,10 @@
removeDuplicatesEx(&boundaryStr, boundaryCmpBoundaryType());
rt_stop(rt);
- stats->recordTime("generating boundaries", rt);
- stats->recordLength("boundary stream", boundaryStr);
+ if (stats) {
+ stats->recordTime("generating boundaries", rt);
+ stats->recordLength("boundary stream", boundaryStr);
+ }
/*if(GETOPT("veryfillverbose")) printStream(cout, boundaryStr);
SAVE_ON_OPTION(boundaryStr, "saveBoundaryStream");
Modified: grass/trunk/raster/r.terraflow/filldepr.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/filldepr.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/filldepr.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -52,8 +52,10 @@
fill_depression(AMI_STREAM<boundaryType> *boundaryStr,
cclabel_type maxWatersheds) {
- stats->comment("----------", opt->verbose);
- stats->comment("flooding depressions");
+ if (stats) {
+ stats->comment("----------", opt->verbose);
+ stats->comment("flooding depressions");
+ }
/* find available memory */
size_t mem_avail = getAvailableMemory();
Modified: grass/trunk/raster/r.terraflow/flow.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/flow.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/flow.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -54,8 +54,10 @@
rt_start(rtTotal);
assert(fillStream && outstr == NULL);
- stats->comment("------------------------------");
- stats->comment("COMPUTING FLOW ACCUMULATION");
+ if (stats) {
+ stats->comment("------------------------------");
+ stats->comment("COMPUTING FLOW ACCUMULATION");
+ }
{ /* timestamp stats file and print memory */
time_t t = time(NULL);
@@ -70,12 +72,15 @@
ctime_r(&t, buf);
buf[24] = '\0';
#endif
- stats->timestamp(buf);
- *stats << endl;
+ if (stats) {
+ stats->timestamp(buf);
+ *stats << endl;
+ }
size_t mm_size = (opt->mem << 20); /* (in bytes) */
formatNumber(buf, mm_size);
- *stats << "memory size: " << buf << " bytes\n";
+ if (stats)
+ *stats << "memory size: " << buf << " bytes\n";
}
/* create sweepstream using info from fillStream */
@@ -89,15 +94,20 @@
/* sort output stream into a grid */
rt_start(rt);
- stats->comment( "sorting sweep output stream");
- stats->recordLength("output stream", outstr);
+ if (stats) {
+ stats->comment( "sorting sweep output stream");
+ stats->recordLength("output stream", outstr);
+ }
sort(&outstr, ijCmpSweepOutput());
rt_stop(rt);
- stats->recordLength("output stream", outstr);
- stats->recordTime("sorting output stream", rt);
+ if (stats) {
+ stats->recordLength("output stream", outstr);
+ stats->recordTime("sorting output stream", rt);
+ }
rt_stop(rtTotal);
- stats->recordTime("compute flow accumulation", rtTotal);
+ if (stats)
+ stats->recordTime("compute flow accumulation", rtTotal);
#ifdef SAVE_ASCII
printStream2Grid(outstr, nrows, ncols, "flowaccumulation.asc",
@@ -197,7 +207,8 @@
rt_start(rt);
- stats->comment("creating sweep stream from fill output stream");
+ if (stats)
+ stats->comment("creating sweep stream from fill output stream");
assert(fillStream->stream_len() == nrows * ncols);
@@ -213,20 +224,24 @@
fprintf(stderr, " (%d items, item size=%d B\n ",
(int)sweepstr->stream_len(), sizeof(sweepItem));;
}
- stats->recordLength("sweep stream", sweepstr);
+ if (stats)
+ stats->recordLength("sweep stream", sweepstr);
/* sort sweep stream by (increasing) priority */
if (opt->verbose) {
fprintf(stderr, "sorting sweep stream (%.2fMB) in priority order\n",
(double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20));
}
- stats->comment("sorting sweep stream");
+ if (stats)
+ stats->comment("sorting sweep stream");
sort(&sweepstr, PrioCmpSweepItem());
rt_stop(rt);
- stats->recordTime("create sweep stream", rt);
- stats->recordLength("(sorted) sweep stream", sweepstr);
+ if (stats) {
+ stats->recordTime("create sweep stream", rt);
+ stats->recordLength("(sorted) sweep stream", sweepstr);
+ }
return sweepstr;
}
Modified: grass/trunk/raster/r.terraflow/grass2str.h
===================================================================
--- grass/trunk/raster/r.terraflow/grass2str.h 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/grass2str.h 2012-05-29 11:02:04 UTC (rev 51865)
@@ -49,7 +49,8 @@
{
char * foo;
str->name(&foo);
- *stats << "Reading raster map <" << cellname
+ if (stats)
+ *stats << "Reading raster map <" << cellname
<< "> to stream <" << foo << ">." << endl;
G_verbose_message(_("Reading data from <%s> to stream <%s>"), cellname, foo);
}
@@ -144,7 +145,8 @@
str->stream_len());
assert((off_t) nrows * ncols == str->stream_len());
rt_stop(rt);
- stats->recordTime("reading raster map", rt);
+ if (stats)
+ stats->recordTime("reading raster map", rt);
return str;
}
@@ -169,7 +171,8 @@
{
char * foo;
str->name(&foo);
- *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">.\n";
+ if (stats)
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">.\n";
G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
}
@@ -221,7 +224,8 @@
Rast_close (outfd);
rt_stop(rt);
- stats->recordTime("writing raster map", rt);
+ if (stats)
+ stats->recordTime("writing raster map", rt);
str->seek(0);
@@ -252,7 +256,8 @@
{
char * foo;
str->name(&foo);
- *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
+ if (stats)
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
}
@@ -299,7 +304,8 @@
Rast_close (outfd);
rt_stop(rt);
- stats->recordTime("writing raster map", rt);
+ if (stats)
+ stats->recordTime("writing raster map", rt);
str->seek(0);
return;
@@ -325,7 +331,8 @@
{
char * foo;
str->name(&foo);
- *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
+ if (stats)
+ *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
}
@@ -372,7 +379,8 @@
Rast_close (outfd);
rt_stop(rt);
- stats->recordTime("writing raster map", rt);
+ if (stats)
+ stats->recordTime("writing raster map", rt);
str->seek(0);
return;
@@ -414,7 +422,8 @@
{
char * foo;
str->name(&foo);
- *stats << "Writing stream <" << foo << "> to raster maps <"
+ if (stats)
+ *stats << "Writing stream <" << foo << "> to raster maps <"
<< cellname1 << "> and <" << cellname2 << ">." << endl;
G_verbose_message(_("Writing stream <%s> to raster maps <%s> and <%s>"),
foo, cellname1, cellname2);
@@ -485,7 +494,8 @@
rt_stop(rt);
- stats->recordTime("writing stream to raster maps", rt);
+ if (stats)
+ stats->recordTime("writing stream to raster maps", rt);
str->seek(0);
return;
Modified: grass/trunk/raster/r.terraflow/main.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/main.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/main.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -142,7 +142,6 @@
stats_opt->type = TYPE_STRING;
stats_opt->required = NO;
stats_opt->description= _("Name of file containing runtime statistics");
- stats_opt->answer = G_store("stats.out");
if (G_parser(argc, argv)) {
@@ -497,16 +496,18 @@
fprintf(stderr, "(THESE INTERMEDIATE STREAMS WILL NOT BE DELETED IN CASE OF ABNORMAL TERMINATION OF THE PROGRAM. TO SAVE SPACE PLEASE DELETE THESE FILES MANUALLY!)\n");
}
- /* open the stats file */
- stats = new statsRecorder(opt->stats);
- record_args(argc, argv);
- {
- char buf[BUFSIZ];
- long grid_size = nrows * ncols;
- *stats << "region size = " << formatNumber(buf, grid_size) << " elts "
- << "(" << nrows << " rows x " << ncols << " cols)\n";
+ if (opt->stats) {
+ /* open the stats file */
+ stats = new statsRecorder(opt->stats);
+ record_args(argc, argv);
+ {
+ char buf[BUFSIZ];
+ long grid_size = nrows * ncols;
+ *stats << "region size = " << formatNumber(buf, grid_size) << " elts "
+ << "(" << nrows << " rows x " << ncols << " cols)\n";
- stats->flush();
+ stats->flush();
+ }
}
/* set up STREAM memory manager */
@@ -522,7 +523,8 @@
/* initialize nodata */
nodataType::init();
- *stats << "internal nodata value: " << nodataType::ELEVATION_NODATA << endl;
+ if (stats)
+ *stats << "internal nodata value: " << nodataType::ELEVATION_NODATA << endl;
/* start timing -- after parse_args, which are interactive */
rt_start(rtTotal);
@@ -593,15 +595,18 @@
delete outstr;
rt_stop(rtTotal);
- stats->recordTime("Total running time: ", rtTotal);
- stats->timestamp("end");
+ if (stats) {
+ stats->recordTime("Total running time: ", rtTotal);
+ stats->timestamp("end");
+ }
G_done_msg(" ");
/* free the globals */
free(region);
free(opt);
- delete stats;
+ if (stats)
+ delete stats;
return 0;
}
Modified: grass/trunk/raster/r.terraflow/nodata.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/nodata.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/nodata.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -266,7 +266,8 @@
nodataType *pt;
/* sort by label */
- NODATA_DEBUG *stats << "sort nodataStream (by nodata label): ";
+ if (stats)
+ NODATA_DEBUG *stats << "sort nodataStream (by nodata label): ";
AMI_STREAM<nodataType> *sortedInStream;
sortedInStream = sort(nodataStream, labelCmpNodataType());
delete nodataStream;
@@ -289,7 +290,8 @@
AMI_STREAM<elevation_type> *
detectEdgeNodata::merge() {
- NODATA_DEBUG *stats << "sort nodataStream (by ij): ";
+ if (stats)
+ NODATA_DEBUG *stats << "sort nodataStream (by ij): ";
/*
AMI_STREAM<nodataType> *sortedNodataStream;
sortedNodataStream = sort(nodataStream, ijCmpNodataType());
@@ -317,30 +319,38 @@
Rtimer rt;
rt_start(rt);
- stats->comment("finding nodata", opt->verbose);
+ if (stats)
+ stats->comment("finding nodata", opt->verbose);
detectEdgeNodata md(nrows, ncols, nodataType::ELEVATION_NODATA);
md.generateNodata(*elstr);
- *stats << "nodata stream length = " << md.getNodata()->stream_len() << endl;
+ if (stats)
+ *stats << "nodata stream length = " << md.getNodata()->stream_len() << endl;
{
char * foo;
md.getNodata()->name(&foo);
- *stats << "nodata stream name: " << foo << endl;
+ if (stats)
+ *stats << "nodata stream name: " << foo << endl;
}
rt_stop(rt);
- stats->recordTime("classifyNodata::generate nodata", rt);
+ if (stats)
+ stats->recordTime("classifyNodata::generate nodata", rt);
rt_start(rt);
- stats->comment("relabeling nodata", opt->verbose);
+ if (stats)
+ stats->comment("relabeling nodata", opt->verbose);
md.relabelNodata(); /* re-assign labels (combine connected plateaus) */
rt_stop(rt);
- stats->recordTime("classifyNodata::relabeling", rt);
+ if (stats)
+ stats->recordTime("classifyNodata::relabeling", rt);
rt_start(rt);
- stats->comment("merging relabeled grid", opt->verbose);
+ if (stats)
+ stats->comment("merging relabeled grid", opt->verbose);
AMI_STREAM<elevation_type> *mergeStr;
mergeStr = md.merge();
rt_stop(rt);
- stats->recordTime("classifyNodata::merge", rt);
+ if (stats)
+ stats->recordTime("classifyNodata::merge", rt);
mergeStr->seek(0);
return mergeStr;
Modified: grass/trunk/raster/r.terraflow/plateau.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/plateau.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/plateau.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -422,20 +422,27 @@
/* find plateaus */
rt_start(rt);
- stats->comment("----------", opt->verbose);
- stats->comment("finding flat areas (plateaus and depressions)");
+ if (stats) {
+ stats->comment("----------", opt->verbose);
+ stats->comment("finding flat areas (plateaus and depressions)");
+ }
detectPlateaus md(nrows, ncols,nodata_value, dirStr, winstr);
md.generatePlateaus(*elstr);
rt_stop(rt);
- stats->recordTime("findPlateaus::generate plateaus", rt);
- stats->recordLength("plateaus", md.getPlateaus());
+ if (stats) {
+ stats->recordTime("findPlateaus::generate plateaus", rt);
+ stats->recordLength("plateaus", md.getPlateaus());
+ }
rt_start(rt);
- stats->comment("removing duplicate plateaus", opt->verbose);
+ if (stats)
+ stats->comment("removing duplicate plateaus", opt->verbose);
md.removeDuplicates(); /* get rid of duplicates of same plateau point */
rt_stop(rt);
- stats->recordTime("findPlateaus::removing duplicates", rt);
- stats->recordLength("plateaus", md.getPlateaus());
+ if (stats) {
+ stats->recordTime("findPlateaus::removing duplicates", rt);
+ stats->recordLength("plateaus", md.getPlateaus());
+ }
#if(0)
{ /* XXX */
@@ -447,19 +454,24 @@
#endif
rt_start(rt);
- stats->comment("relabeling plateaus", opt->verbose);
+ if (stats)
+ stats->comment("relabeling plateaus", opt->verbose);
md.relabelPlateaus(); /* re-assign labels (combine connected plateaus) */
rt_stop(rt);
- stats->recordTime("findPlateaus::relabeling", rt);
- stats->recordLength("plateaus", md.getPlateaus());
+ if (stats) {
+ stats->recordTime("findPlateaus::relabeling", rt);
+ stats->recordLength("plateaus", md.getPlateaus());
+ }
rt_start(rt);
- stats->comment("generating plateau statistics", opt->verbose);
+ if (stats)
+ stats->comment("generating plateau statistics", opt->verbose);
md.generateStats(statStr);
rt_stop(rt);
- stats->recordTime("findPlateaus::generating stats", rt);
- stats->recordLength("plateaus", md.getPlateaus());
-
+ if (stats) {
+ stats->recordTime("findPlateaus::generating stats", rt);
+ stats->recordLength("plateaus", md.getPlateaus());
+ }
dirStr->seek(0);
return md.getPlateaus();
}
Modified: grass/trunk/raster/r.terraflow/sortutils.h
===================================================================
--- grass/trunk/raster/r.terraflow/sortutils.h 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/sortutils.h 2012-05-29 11:02:04 UTC (rev 51865)
@@ -37,7 +37,8 @@
Rtimer rt;
AMI_STREAM<T> *sortedStr;
- stats->recordLength("pre-sort", *str);
+ if (stats)
+ stats->recordLength("pre-sort", *str);
rt_start(rt);
/* let AMI_sort create its output stream and delete the inout stream */
@@ -45,8 +46,10 @@
AMI_sort(*str,&sortedStr, &fo, eraseInputStream);
rt_stop(rt);
- stats->recordLength("sort", sortedStr);
- stats->recordTime("sort", rt);
+ if (stats) {
+ stats->recordLength("sort", sortedStr);
+ stats->recordTime("sort", rt);
+ }
sortedStr->seek(0);
*str = sortedStr;
@@ -66,15 +69,18 @@
Rtimer rt;
AMI_STREAM<T> *strOut;
- stats->recordLength("pre-sort", strIn);
+ if (stats)
+ stats->recordLength("pre-sort", strIn);
rt_start(rt);
AMI_sort(strIn, &strOut, &fo);
assert(strOut);
rt_stop(rt);
- stats->recordLength("sort", strOut);
- stats->recordTime("sort", rt);
+ if (stats) {
+ stats->recordLength("sort", strOut);
+ stats->recordTime("sort", rt);
+ }
strOut->seek(0);
return strOut;
Modified: grass/trunk/raster/r.terraflow/streamutils.h
===================================================================
--- grass/trunk/raster/r.terraflow/streamutils.h 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/streamutils.h 2012-05-29 11:02:04 UTC (rev 51865)
@@ -56,7 +56,8 @@
AMI_err ae;
ofstream fstrm(name);
- stats->comment("saving grid: ", name);
+ if (stats)
+ stats->comment("saving grid: ", name);
fstrm << "rows=" << nrows << endl;
fstrm << "cols=" << ncols << endl;
@@ -91,7 +92,8 @@
AMI_err ae;
ofstream fstrm(name);
- stats->recordLength("saving grid", str);
+ if (stats)
+ stats->recordLength("saving grid", str);
fstrm << "rows=" << nrows << endl;
fstrm << "cols=" << ncols << endl;
Modified: grass/trunk/raster/r.terraflow/sweep.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/sweep.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/sweep.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -136,23 +136,27 @@
FLOW_DATASTR*
initializePQ() {
- stats->comment("sweep:initialize flow data structure", opt->verbose);
+ if (stats)
+ stats->comment("sweep:initialize flow data structure", opt->verbose);
FLOW_DATASTR *flowpq;
#ifdef IM_PQUEUE
- stats->comment("FLOW_DATASTRUCTURE: in-memory pqueue");
+ if (stats)
+ stats->comment("FLOW_DATASTRUCTURE: in-memory pqueue");
flowpq = new FLOW_DATASTR(PQ_SIZE);
char buf[1024];
sprintf(buf, "initialized to %.2fMB\n", (float)PQ_SIZE / (1<<20));
- *stats << buf;
+ if (stats)
+ *stats << buf;
#endif
#ifdef EM_PQUEUE
- stats->comment("FLOW_DATASTRUCTURE: ext-memory pqueue");
+ if (stats)
+ stats->comment("FLOW_DATASTRUCTURE: ext-memory pqueue");
flowpq = new FLOW_DATASTR(nrows * ncols);
#endif
#ifdef EMPQ_ADAPTIVE
- if (opt->verbose) stats->comment("FLOW_DATASTRUCTURE: adaptive pqueue");
+ if (opt->verbose && stats) stats->comment("FLOW_DATASTRUCTURE: adaptive pqueue");
flowpq = new FLOW_DATASTR();
#endif
return flowpq;
@@ -209,7 +213,8 @@
assert(sweepstr);
- *stats << "sweeping\n";
+ if (stats)
+ *stats << "sweeping\n";
fprintf(stderr, "sweeping: ");
/* create and initialize flow data structure */
FLOW_DATASTR *flowpq;
@@ -308,17 +313,21 @@
G_percent(1, 1, 2); /* finish it */
- *stats << "sweeping done\n";
+ if (stats)
+ *stats << "sweeping done\n";
char buf[1024];
sprintf(buf, "pqsize = %ld \n", (long)flowpq->size());
- *stats << buf;
+ if (stats)
+ *stats << buf;
assert(outstr->stream_len() == nitems);
delete flowpq;
rt_stop(rt);
- stats->recordTime("sweeping", rt);
- stats->recordLength("sweep output stream", outstr);
+ if (stats) {
+ stats->recordTime("sweeping", rt);
+ stats->recordLength("sweep output stream", outstr);
+ }
return outstr;
}
Modified: grass/trunk/raster/r.terraflow/water.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/water.cpp 2012-05-29 10:07:23 UTC (rev 51864)
+++ grass/trunk/raster/r.terraflow/water.cpp 2012-05-29 11:02:04 UTC (rev 51865)
@@ -226,11 +226,13 @@
createWaterWindows(AMI_STREAM<waterGridType> *mergedWaterStr,
const dimension_type nrows, const dimension_type ncols,
AMI_STREAM<waterWindowType> *waterWindows) {
- stats->comment("creating windows", opt->verbose);
+ if (stats)
+ stats->comment("creating windows", opt->verbose);
waterWindower winfo(waterWindows);
waterWindowBaseType nodata;
assert(mergedWaterStr->stream_len() > 0);
- stats->comment("warning: using slower scan", opt->verbose);
+ if (stats)
+ stats->comment("warning: using slower scan", opt->verbose);
scan3(*mergedWaterStr, nrows, ncols, nodata, winfo);
}
@@ -252,7 +254,8 @@
assert(prevWin.getDepth() == DEPTH_INITIAL);
EMPQueueAdaptive<fillPLabel, fillPriority> *pq;
- stats->comment("generateWatersheds", opt->verbose);
+ if (stats)
+ stats->comment("generateWatersheds", opt->verbose);
assert((*waterWindows)->stream_len() == (nrows * ncols));
@@ -268,7 +271,8 @@
/* pq->makeExternalDebug(); */
/* } */
- stats->comment("starting generate watersheds main loop", opt->verbose);
+ if (stats)
+ stats->comment("starting generate watersheds main loop", opt->verbose);
assert((*waterWindows)->stream_len() == (nrows * ncols));
/* not really in a grid, so row, col are not valid (but count correct) */
@@ -376,7 +380,8 @@
assert(pq->is_empty());
delete pq;
- stats->comment("done with generate watersheds", opt->verbose);
+ if (stats)
+ stats->comment("done with generate watersheds", opt->verbose);
}
@@ -452,7 +457,8 @@
findBoundaries(AMI_STREAM<labelElevType> *labeledWater,
const dimension_type nrows, const dimension_type ncols,
AMI_STREAM<boundaryType> *boundaryStr) {
- stats->comment("creating windows", opt->verbose);
+ if (stats)
+ stats->comment("creating windows", opt->verbose);
boundaryDetector det(boundaryStr, nrows, ncols);
/* cerr << "WARNING: using scan3 instead of scan2" << endl; */
scan3(*labeledWater, nrows, ncols, labelElevType(), det);
More information about the grass-commit
mailing list