real function esum() include 'esum.inc' real diff,sum real sx0(4),sp0(4) common /sumc/diff,sum,sx0,sp0 data diff,sum/0,0/ diff=0 if (xin(4).eq.0) then print *, 'cant call esum twice, joker' endif do i=1,3 diff=diff+(xin(i)-sx0(i))**2 diff=diff+(pin(i)-sp0(i))**2 sx0(i)=xout(i) sp0(i)=pout(i) enddo if (diff.lt.10) then sum=sum+desum esum=-1 else esum=sum sum=desum endif xin(4)=0 end