where.f
c<html>
c<body>
c<pre>
program test
c
c Example of WHERE, ELSE WHERE, END WHERE
c
c John Mahaffy 2/16/96
c
parameter (nd=10,ndh=nd/2,nduh=nd-ndh-1)
c<a name="real"><font color="FF0000">
real, dimension(nd):: a=(/(2*j,j=1,nd)/), b, c
c</a></font>
integer iflag(nd)
data b/ndh*1,0.0,nduh*2./,c/nd*-77.77/
where (b.ne.0) c=a/b
write (*,2000) c(1:nd)
2000 format ('a/b = ',/,(10f7.2))
c
c The above protects against divide by zero, but doesn't actually assign
c values to elements in c when the corresponding element in b is zero
c The following covers that, and sets a flag when a divide by zero is
c present
c
c<a name="where"><font color="FF0000">
where (b(1:nd).ne.0.0)
c</font></a>
c=a/b
iflag=0
c<a name="ewhere"><font color="FF0000">
else where
c</font></a>
c=0.0
iflag=1
c<a name="ew"><font color="0000FF">
end where
c</font></a>
write (*,2000) c(1:nd)
write (*,1000) iflag(1:nd)
1000 format ('iflag= ',/,(10i7))
stop
end
c</pre>
c</body>
c</html>