      real function distan (iortho,x,cosi)                              DIST001
c ----------------------------------------------------------------------DIST002
c     calculate distance between point x,y,z and (0,0,0)                DIST003
c ----------------------------------------------------------------------DIST004
c     This program module is part of the PhysiSoft X-ray Library        DIST005
c     and may not be sold or reproduced for commercial purposes.        DIST006
c     Although it has been tested carefully, there is no warranty       DIST007
c     regarding accuracy or freedom from side-effects.                  DIST008
c                   (C) 1986-1990 Bernhard Rupp                         DIST009
c ----------------------------------------------------------------------DIST010
      dimension x(3),cosi(3)                                            DIST011
      distan=0.0                                                        DIST012
      do 0001 i=1,3                                                     DIST013
 0001    distan=distan+x(i)**2                                          DIST014
      if (iortho.ne.1) then                                             DIST015
         distan=distan+2*x(1)*x(2)*cosi(3)+2*x(1)*x(3)*cosi(2)          DIST016
     &         + 2*x(2)*x(3)*cosi(1)                                    DIST017
      end if                                                            DIST018
      distan=sqrt(distan)                                               DIST019
      return                                                            DIST020
      end                                                               DIST021
                                                                        DIST022
                                                                        DIST023
                                                                        DIST024
