c c sortclosures.f - input closed.xyz and create closure heirarchy table c c Saltus - 4 Sep 2001 - NPRA project c program sortclosures c Parameter (MAXCLOSE=40000,MAXPTS=1000) Dimension xpts(MAXCLOSE,MAXPTS),ypts(MAXCLOSE,MAXPTS), & zval(MAXCLOSE),npts(MAXCLOSE),nval(MAXCLOSE),ndir(MAXCLOSE), & nparent(MAXCLOSE),xmax(MAXCLOSE),xmin(MAXCLOSE), & ymax(MAXCLOSE),ymin(MAXCLOSE) c c xpts, ypts = x,y coords of closed contours c zval = z value of contour line c npts = # pts in contour c nval = contour ID number c ndir = +1 for closed high, -1 for closed low, 0 for unknown c nparent = 0 for no parent or nval of parent c c print *,'Enter contour increment:' c read *,zinc c open(10,file="closed.xyz",form='formatted',status='old') c c set ndir and nparent arrays to zeros c do 5 i=1,MAXCLOSE ndir(i)=0 nparent(i)=0 5 continue c c read in closed contours from output of findclosures.f c read(10,*)x,y,z,n,junk ntest=n ncount=1 npt=1 nval(ncount)=ncount zval(ncount)=z xpts(ncount,npt)=x ypts(ncount,npt)=y xmax(ncount)=x xmin(ncount)=x ymax(ncount)=y ymin(ncount)=y 10 continue read(10,*,end=999)x,y,z,n,junk if (n.eq.ntest) then npt=npt+1 c print *,npt,' point input' xpts(ncount,npt)=x ypts(ncount,npt)=y xmax(ncount)=max(x,xmax(ncount)) xmin(ncount)=min(x,xmin(ncount)) ymax(ncount)=max(y,ymax(ncount)) ymin(ncount)=min(y,ymin(ncount)) else npts(ncount)=npt ncount=ncount+1 c print *,ncount,' contour input' c print *,n,' orig contour #' npt=1 ntest=n nval(ncount)=ncount zval(ncount)=z xpts(ncount,npt)=x ypts(ncount,npt)=y xmax(ncount)=x xmin(ncount)=x ymax(ncount)=y ymin(ncount)=y end if goto 10 c 999 continue npts(ncount)=npt print *,ncount,' contours input to memory...' open(14,file="debug.xyz",form='formatted', & status='unknown') c c first pass through contours looking for parents and c assigning whether the contour is a closed high or low c do 30 i=1,ncount c c find nested contours c do 20 j=1,ncount if (j.eq.i) goto 20 if ((xmax(i).le.xmax(j)).and.(xmin(i).ge.xmin(j)).and. & (ymax(i).le.ymax(j)).and.(ymin(i).ge.ymin(j))) then c c i probably nested inside j c test to confirm c c print *,i,' probably nested in',j do 15 k=1,npts(i) xtest=xpts(i,k) ytest=ypts(i,k) intest=inside(xtest,ytest,xpts,ypts,npts(j),j, & MAXCLOSE,MAXPTS) c print *,intest,zval(i),zval(j) if (intest.eq.0) then if (zval(i).lt.zval(j)) then c c i is lower than j c nparent(i)=j ndir(i)=-1 else if (zval(i).gt.zval(j)) then c c i is higher than j c nparent(i)=j ndir(i)=1 else c c i is same as j c nparent(i)=j ndir(i)=-1*ndir(j) end if goto 20 end if 15 continue end if 20 continue 30 continue c c do 30 i=1,ncount c c for each contour, examine contours with zval>zval c if the contour polygon is inside one of these, then c it is a closed low with that contour as a parent c if not, proceed to the next test c c print *,i,' contour test...' c xtest=xpts(i,npts(i)) c ytest=ypts(i,npts(i)) c itest2=ifix(npts(i)/2) c xtest2=xpts(i,itest2) c ytest2=ypts(i,itest2) c do 20 j=1,ncount c if (j.eq.i) goto 20 c if (zval(j).gt.zval(i)) then c print *,j,' inside test...' c intest=inside(xtest,ytest,xpts,ypts,npts(j),j, c & MAXCLOSE,MAXPTS) c if (intest.ne.0) then c intest1=intest c intest=inside(xtest2,ytest2,xpts,ypts,npts(j),j, c & MAXCLOSE,MAXPTS) c if (intest1.ne.intest) then c print *,'2nd test diff from first' c end if c end if c print *,'+test, i,j=',i,j,' intest= ',intest,'xtest,ytest=', c & xtest,ytest c if (intest.eq.0) then c ndir(i)=-1 c nparent(i)=j c goto 30 c end if c end if c 20 continue c print *,' at 20' c c comes here if not a closed low with parent c examine contours with zval