@@ -70,6 +70,8 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
70
70
int numOutlets=0 ;
71
71
int *ids=NULL ;
72
72
int *dsids=NULL ;
73
+ bool *idsout = NULL ;
74
+ int numOutletsout;
73
75
int idnodata;
74
76
FILE *fidout1;
75
77
if (writeupid == 1 ) {
@@ -123,6 +125,7 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
123
125
MPI_Bcast (ids, numOutlets, MPI_INT, 0 , MCW);
124
126
MPI_Bcast (&idnodata,1 ,MPI_INT,0 ,MCW);
125
127
}
128
+ idsout = new bool [numOutlets]; // Keep track of outlets that are output to avoid same grid cell outlets
126
129
dsids=new int [numOutlets];
127
130
128
131
// 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
169
172
node temp;
170
173
queue<node> que;
171
174
172
- for ( int i= 0 ; i< numOutlets; i++)
175
+ for ( int i = 0 ; i < numOutlets; i++)
173
176
{
174
177
p.geoToGlobalXY (x[i], y[i], outletsX[i], outletsY[i]);
175
178
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
+ }
183
192
}
184
- dsids[i]= idnodata;
193
+
185
194
}
186
195
187
196
@@ -272,7 +281,7 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
272
281
int iidex;
273
282
for (iidex=0 ; iidex<numOutlets; iidex++)
274
283
{
275
- if (ids [iidex]==idup)break ;
284
+ if (idsout [iidex]==idup)break ;
276
285
}
277
286
dsids[iidex]=idme;
278
287
}
@@ -311,8 +320,11 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
311
320
312
321
// Reduce all values to the 0 process
313
322
int *dsidsr;
323
+ bool *dsiout;
314
324
dsidsr=new int [numOutlets];
325
+ dsiout = new bool [numOutlets];
315
326
MPI_Reduce (dsids,dsidsr,numOutlets,MPI_INT, MPI_MAX,0 , MCW);
327
+ MPI_Reduce (idsout, dsiout, numOutlets, MPI_LOGICAL, MPI_LOR, 0 , MCW);
316
328
317
329
// Stop timer
318
330
double computet = MPI_Wtime ();
@@ -327,8 +339,8 @@ int gagewatershed( char *pfile,char *wfile, char* datasrc,char* lyrname,int usel
327
339
fprintf (fidout," id iddown\n " );
328
340
for (i=0 ; i<numOutlets; i++)
329
341
{
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]);
332
344
}
333
345
}
334
346
}
0 commit comments