@@ -53,7 +53,7 @@ using namespace std;
5353
5454
5555
56- int gagewatershed ( char *pfile, char *swfile, char * wfile, char * datasrc,char * lyrname,int uselyrname,int lyrno, char *idfile,int writeid,int useswg, int writeupid, char *upidfile)
56+ int gagewatershed ( char *pfile,char *wfile, char * datasrc,char * lyrname,int uselyrname,int lyrno, char *idfile,int writeid, int writeupid,char *upidfile)
5757{// 1
5858
5959 MPI_Init (NULL ,NULL );{
@@ -68,7 +68,7 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
6868 int *ids=NULL ;
6969 int *dsids=NULL ;
7070 int idnodata;
71-
71+
7272 double begint = MPI_Wtime ();
7373 tiffIO p (pfile,SHORT_TYPE);
7474 long totalX = p.getTotalX ();
@@ -143,20 +143,6 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
143143 p.read (xstart, ystart, ny, nx, flowData->getGridPointer ());
144144 // printf("Pfile read"); fflush(stdout);
145145
146- // if using subwatershed grid for rapid watershed delineation, get information from file
147- tdpartition *swData;
148- if ( useswg == 1 ){
149- tiffIO sw (swfile,LONG_TYPE);
150- if (!p.compareTiff (sw)){
151- printf (" File sizes do not match\n %s\n " ,swfile);
152- MPI_Abort (MCW,5 );
153- return 1 ;
154- }
155- swData = CreateNewPartition (sw.getDatatype (), totalX, totalY, dxA, dyA, sw.getNodata ());
156- swData->localToGlobal (0 , 0 , xstart, ystart);
157- sw.read (xstart, ystart, swData->getny (), swData->getnx (), swData->getGridPointer ());
158- }
159-
160146 // Begin timer
161147 double readt = MPI_Wtime ();
162148 // printf("Read time %lf\n",readt);
@@ -174,26 +160,22 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
174160 node temp;
175161 queue<node> que;
176162
177-
178-
179163 for ( int i=0 ; i<numOutlets; i++)
180164 {
181165 p.geoToGlobalXY (x[i], y[i], outletsX[i], outletsY[i]);
182166 int xlocal, ylocal;
183167 wshed->globalToLocal (outletsX[i], outletsY[i],xlocal,ylocal);
184-
185168 if (wshed->isInPartition (xlocal,ylocal)){ // xOutlets[i], yOutlets[i])){
186169 wshed->setData (xlocal,ylocal,(int32_t )ids[i]); // xOutlets[i], yOutlets[i], (long)ids[i]);
187170 // Push outlet cells on to que
188171 temp.x = xlocal;
189172 temp.y = ylocal;
190173 que.push (temp);
191-
192-
193174 }
194175 dsids[i]= idnodata;
195176 }
196-
177+
178+
197179 // con is used to check for contamination at the edges
198180 long i,j;
199181 short k;
@@ -223,24 +205,20 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
223205 wshed->share ();
224206 // open upid file to write and update upstream watershed id file ( need to confirm)
225207 FILE *fp1;
226-
227- fp1 = fopen (upidfile," a" );
228- if (!rank) fprintf (fp1," Upstream Contributing Watershed ID:\n " );
208+ fp1 = fopen (upidfile," a" );
209+ if (!rank) fprintf (fp1," Upstream Contributing coordinates:\n " );
229210
230211 // flowData->getData(500,600,tempShort);
231212 finished = false ;
232213 // Ring terminating while loop
233214 while (!finished) {
234215 while (!que.empty ()){
235216 // Takes next node with no contributing neighbors
236- int idex=0 ;
237217 temp = que.front ();
238218 que.pop ();
239219 i = temp.x ;
240220 j = temp.y ;
241-
242221 // if not labeled, label with downstream result
243-
244222 if (wshed->isNodata (i,j))
245223 {
246224 flowData->getData (i,j,k);
@@ -264,34 +242,16 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
264242 p.globalXYToGeo (gx,gy,wi,wj);
265243 // printf("%f, %f", wi,wj);
266244 fprintf (fp1," %f, %f\n " ,wi,wj);
267- if (useswg==1 );// {long sss=swData->getData(in,jn,tempLong);
268- // fprintf (fp1,"%ld\n",sss);}
245+
269246 }
270247 if (sdir > 0 )
271248 {
272- int idex=0 ;
273249 if ((sdir-k==4 || sdir-k==-4 ))
274250 {
275251 // add to Q
276252 if (flowData->hasAccess (in,jn) && !flowData->isNodata (in,jn) && wshed->isNodata (in,jn)){
277253 // Decrement the number of contributing neighbors in neighbor
278254 neighbor->addToData (in,jn,(short )-1 );
279- // for rapid watershed delineation
280- if (useswg==1 ){
281- // short swidup=swData->getData(in,jn,tempSubwgrid); // get upstream watershed ID
282- // short swidme=swData->getData(i,j,tempSubwgrid); // get outlet point watershed ID
283- // if upstream ID is not equal to outlet point watershed ID then write into upidfile
284- // swidup may be nodata value therefore also check is it greater than or equal to zero
285- // if((swidup!=swidme) & (swidup>=0)){
286- // write into upidfile
287- // printf("Upstream edge is reached\n");
288- // fprintf (fp1,"%d\n",swidup);
289- // }
290-
291- }
292-
293-
294-
295255
296256 // Check if neighbor needs to be added to que
297257 if (flowData->isInPartition (in,jn) && neighbor->getData (in, jn, tempShort) == 0 ){
@@ -300,12 +260,10 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
300260 que.push (temp);
301261 }
302262 }
303-
304263 if (!wshed->isNodata (in,jn))
305264 {
306265 int32_t idup=wshed->getData (in,jn,tempLong);
307266 int32_t idme=wshed->getData (i,j,tempLong);
308- ;
309267 // Find the array index for idup
310268 int iidex;
311269 for (iidex=0 ; iidex<numOutlets; iidex++)
@@ -321,7 +279,7 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
321279 // Pass information
322280 neighbor->addBorders ();
323281 wshed->share ();
324-
282+
325283 // If this created a cell with no contributing neighbors, put it on the queue
326284 for (i=0 ; i<nx; i++){
327285 if (neighbor->getData (i, -1 , tempShort)!=0 && neighbor->getData (i, 0 , tempShort)==0 ){
@@ -342,18 +300,13 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
342300 finished = que.empty ();
343301 finished = wshed->ringTerm (finished);
344302 }
345-
346303 // Reduce all values to the 0 process
347304 int *dsidsr;
348305 dsidsr=new int [numOutlets];
349306 MPI_Reduce (dsids, dsidsr,numOutlets,MPI_INT, MPI_MAX,0 , MCW);
350- // MPI_Reduce(upids, dsidsr,numOutlets,MPI_INT, MPI_MAX,0, MCW);
351307
352308 // Stop timer
353309 double computet = MPI_Wtime ();
354-
355-
356-
357310
358311// Write id.txt with from and to links
359312 if (writeid == 1 )
@@ -370,7 +323,6 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
370323 }
371324 }
372325
373-
374326 // Create and write TIFF file
375327 long lNodata = MISSINGLONG;
376328 tiffIO wshedIO (wfile, LONG_TYPE, &lNodata, p);
@@ -390,4 +342,3 @@ int gagewatershed( char *pfile, char *swfile,char *wfile, char* datasrc,char* ly
390342
391343
392344
393-
0 commit comments