I am trying to vectorize some old Fortran code and have run into a problem. In the finite difference grid, the code checks that it hasn't run into boundaries and so, depending on the component being computed, it tests whether (bth(i,j)>0 & bth(i+1,j)>0) or (bth(i,j)>0 & bth(i,j+1)>0).
I have settled on making a mask of valid bth locations with bthz(2:in,2:jn)=~(bth(2:in,2:jn)<0 & bth(3:ie,2:jn)<0) for example. That makes a zero mask that I then multiply by the terms of the equation. Not very elegant, but it works in a crude way. It calculates the edge terms (near the boundaries) which I don't want to do.
Any ideas on vectorizing the conditional bth test(s) so that the subsequent vectorized loop runs efficiently?