subroutine smei_orb_diff(nx, ny, i_min, i_orbit, i_diff, orb_pattern, dev_cut, icount) integer nx integer ny integer i_min integer i_orbit integer i_diff real orb_pattern(nx,ny,3) integer icount real z(-1:1,-1:1) locFRM(i,j) = i+(j-1)*nx ! Translates 2D array indices (i,j) into linear index bad = BadR4() ! Zero the difference pattern everywhere call ArrR4Zero(nx*ny, orb_pattern(1,1,i_diff)) icount = 0 ! Here use the plane program to find deviations of a pixel from its ! immediate neighbors, call that the "pattern" do j=2,ny-1 ! Stay away from edges do i=2,nx-1 ! Pick up difference between current orbital pattern and the first one. do jj=-1,1 do ii=-1,1 ip = locFRM(i+ii,j+jj) z0 = orb_pattern(i+ii,j+jj,i_orbit) ! Minimum for this orbit z1 = orb_pattern(i+ii,j+jj,i_min ) ! Minimum for mimimum orbit if (z0 .ne. bad .and. z1. ne. bad) then z(ii,jj) = z0-z1 else z(ii,jj) = bad end if end do end do call ArrR4GetMinMax(9,z,zmin,zmax) z0 = z(0,0) ! Continue only if none of the 9 pixels are bad, and the center pixels is the ! smallest or largest value (with no other pixel equal to the center value). if (iArrR4ValuePresent(9,z,bad) .eq. 0 .and. & iArrR4ValuePresent(9,z,z0 ) .eq. 1 .and. (z0 .eq. zmin .or. z0 .eq. zmax)) then call smei_FitPlane(z,z,z0,a,b,sumzq) ! Try to improve a pattern value when just one screwy neighbor is present z0 = z(0,0) z1 = max(dev_cut,0.1*abs(z0)) ibad = 0 zbad = 0 do ii=-1,1 do jj=-1,1 val = z(ii,jj) if (abs(val) .gt. z1) then ! Shouldn't we exclude the center pixel here??? ibad = ibad+1 zbad = val end if end do end do if (ibad .le. 1) then z0 = z0-zbad/8.0 orb_pattern(i,j,i_diff) = z0 if (abs(z0) .gt. 10.0) icount = icount+1 end if end if end do end do return end