Skip to content

Commit d2dc3eb

Browse files
committed
Fix nulls in aread8 and work on gagewatershed duplicate point handling
1 parent 19dbb93 commit d2dc3eb

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

src/aread8.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int aread8( char* pfile, char* afile, char *datasrc, char *lyrname,int uselyrnam
133133

134134

135135
//Convert geo coords to grid coords
136-
int *outletsX; int *outletsY;
136+
int *outletsX=NULL; int *outletsY=NULL;
137137
if(usingShapeFile) {
138138
outletsX = new int[numOutlets];
139139
outletsY = new int[numOutlets];

src/gagewatershed.cpp

+24-12
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
7070
int numOutlets=0;
7171
int *ids=NULL;
7272
int *dsids=NULL;
73+
bool *idsout = NULL;
74+
int numOutletsout;
7375
int idnodata;
7476
FILE *fidout1;
7577
if (writeupid == 1) {
@@ -123,6 +125,7 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
123125
MPI_Bcast(ids, numOutlets, MPI_INT, 0, MCW);
124126
MPI_Bcast(&idnodata,1,MPI_INT,0,MCW);
125127
}
128+
idsout = new bool[numOutlets]; // Keep track of outlets that are output to avoid same grid cell outlets
126129
dsids=new int[numOutlets];
127130

128131
//printf("Rank: %d, Numoutlets: %d\n",rank,numOutlets); fflush(stdout);
@@ -169,19 +172,25 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
169172
node temp;
170173
queue<node> que;
171174

172-
for( int i=0; i<numOutlets; i++)
175+
for (int i = 0; i < numOutlets; i++)
173176
{
174177
p.geoToGlobalXY(x[i], y[i], outletsX[i], outletsY[i]);
175178
int xlocal, ylocal;
176-
wshed->globalToLocal(outletsX[i], outletsY[i],xlocal,ylocal);
177-
if(wshed->isInPartition(xlocal,ylocal)){ //xOutlets[i], yOutlets[i])){
178-
wshed->setData(xlocal,ylocal,(int32_t)ids[i]); //xOutlets[i], yOutlets[i], (long)ids[i]);
179-
//Push outlet cells on to que
180-
temp.x = xlocal;
181-
temp.y = ylocal;
182-
que.push(temp);
179+
wshed->globalToLocal(outletsX[i], outletsY[i], xlocal, ylocal);
180+
181+
dsids[i] = idnodata; // Set down id
182+
idsout[i] = false; // Set indicator of whether to output
183+
if (wshed->isInPartition(xlocal, ylocal)) { //xOutlets[i], yOutlets[i])){
184+
if (wshed->isNodata(xlocal, ylocal)) { // Only define outlet grid cell if not already defined to check for duplicate outlet points
185+
wshed->setData(xlocal, ylocal, (int32_t)ids[i]); //xOutlets[i], yOutlets[i], (long)ids[i]);
186+
//Push outlet cells on to que
187+
temp.x = xlocal;
188+
temp.y = ylocal;
189+
que.push(temp);
190+
idsout[i] = true;
191+
}
183192
}
184-
dsids[i]= idnodata;
193+
185194
}
186195

187196

@@ -272,7 +281,7 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
272281
int iidex;
273282
for(iidex=0; iidex<numOutlets; iidex++)
274283
{
275-
if(ids[iidex]==idup)break;
284+
if(idsout[iidex]==idup)break;
276285
}
277286
dsids[iidex]=idme;
278287
}
@@ -311,8 +320,11 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
311320

312321
// Reduce all values to the 0 process
313322
int *dsidsr;
323+
bool *dsiout;
314324
dsidsr=new int[numOutlets];
325+
dsiout = new bool[numOutlets];
315326
MPI_Reduce(dsids,dsidsr,numOutlets,MPI_INT, MPI_MAX,0, MCW);
327+
MPI_Reduce(idsout, dsiout, numOutlets, MPI_LOGICAL, MPI_LOR, 0, MCW);
316328

317329
//Stop timer
318330
double computet = MPI_Wtime();
@@ -327,8 +339,8 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
327339
fprintf(fidout,"id iddown\n");
328340
for(i=0; i<numOutlets; i++)
329341
{
330-
331-
fprintf(fidout,"%d %d\n",ids[i],dsidsr[i]);
342+
if(dsiout[i]) // Only print connectivity for outlets that have a gage watershed
343+
fprintf(fidout,"%d %d\n",ids[i],dsidsr[i]);
332344
}
333345
}
334346
}

0 commit comments

Comments
 (0)