Subroutine MFCAPO(x,y,z,r,t,p) c ================================ c c c Routine to convert from CArtesian to POlar coordinartes. C Input: x,y,z => cartesian x,y,z C Output: r,t,p => radius,theta,phi C c Implicit None c real x,y,z,r,t,p real pi,twopi,pihalf logical first /.true./ save first,pi,twopi,pihalf c if(first) then first=.false. pi=acos(-1.) twopi=2.*pi pihalf=0.5*pi endif if(abs(x).lt.1.E-6) x=0. if(abs(y).lt.1.E-6) y=0. if(abs(z).lt.1.E-6) z=0. r=sqrt(x*x+y*y+z*z) if(z.ne.0.) then t=acos(z/r) if(t.lt.0) t=t+pi else t=pihalf endif if(x+y.eq.0.) then p=0. else p=atan2(y,x) if(p.lt.0) p=p+twopi endif end c