C+ C NAME: C iGridScan C PURPOSE: C Counts the number of neighbours with valid function values C CALLING SEQUENCE: function iGridScan(nX,nY,Z,rBad,NSIDE) C INPUTS: C nX,nY integer dimensions of input grid C Z(nX,nY) real array of function values C bad bins identified by BadR4() C rBad real value indicating 'bad' bin C OUTPUTS: C iGridScan integer max # valid neighbours for empty bins C If nMax= 0 then the whole array is empty C If nMax=-1 then the whole array is valid C NSIDE(nX,nY,-1:1,-1:1) C integer*1 C NSIDE(I,J,0,0) = -1 if function value available C >= 0 # valid neighbours (if no function value available) C NSIDE(I,J,IX,JX) (IX,IY=-1 or 1) C = 0,1 if neigbour does not/does contain a valid fnc value C (only filled for empty bins) C MODIFICATION HISTORY: C APR-1999, Paul Hick (UCSD/CASS; pphick@ucsd.edu), extracted from GridFill C JUL-2005, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Changed type NSIDE from (unsigned) byte to (signed) integer*1. C- integer nX integer nY real Z(nX,nY) real rBad integer*1 NSIDE(nX,nY,-1:1,-1:1) InZ(I) = (1+sign(1,I))/2 ! Used to keep array indices for Z and NSIDE valid iGridScan = -1 nX1 = nX-1 nY1 = nY-1 do J=1,nY JY1 = -InZ(J -2) JY2 = InZ(nY1-J) do I=1,nX IX1 = -InZ(I -2) IX2 = InZ(nX1-I) if (Z(I,J) .eq. rBad) then ! If bin is empty ... NSIDE(I,J,0,0) = 0 do JY=JY1,JY2 do IX=IX1,IX2 !.. loop over all neighbours if (IX .ne. 0 .or. JY .ne. 0) then INX = I+IX ! Indices of neighbour JNY = J+JY if (Z(INX,JNY) .eq. rBad) then ! Empty neighbour NSIDE(I,J,IX,JY) = 0 else ! Valid neighbour NSIDE(I,J,0,0) = NSIDE(I,J,0,0)+1 ! Count... NSIDE(I,J,IX,JY) = 1 ! .. and identify neighbour end if end if end do end do !MSIDE = NSIDE(I,J,0,0) !NSIDE is integer*1 array !iGridScan = max(iGridScan,MSIDE) !Max. number of ... iGridScan = max(iGridScan,NSIDE(I,J,0,0))! Max. # valid neighbours among empty bins else NSIDE(I,J,0,0) = -1 end if end do end do return end