!+ Function to calculate the aspect ratio of a particle.
!
! Method:
!	The aspect ratio of spheres (always 1) or hexagonal cylinders
!	is calculated. In the latter case, an external distribution
!       may be used, or the fits given by Auer and Veal in conjunction
!	with the Heymsfield-Platt distribution.
!
! Current Owner of Code: J. M. Edwards
!
! History:
!	 Version 	   Date	  		Comment
!   
!	 1.0		   12-04-95		First Version under RCS
!						(J. M. Edwards)
!
! Description of Code:
!   FORTRAN 77 with extensions listed in documentation. 
!
!- ---------------------------------------------------------------------
      FUNCTION ASPECT_PARTICLE(IERR, I_DISTRIBUTION, I_SHAPE_PARTICLE
     &   , N_SIZE, RADIUS, ASPECT, D2_ASPECT
     &   , RADIUS_POINT
     &   )
!
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_pp.ucf'
      INCLUDE 'incl/distribution.pcf'
      INCLUDE 'incl/def_std_io.icf'
      INCLUDE 'incl/error.pcf'
      INCLUDE 'incl/shape_particle.pcf'
      INCLUDE 'incl/math_cnst.ccf'
      INCLUDE 'incl/max_size.acf'
!
!     DUMMY ARGUMENTS.
      INTEGER	!, INTENT(OUT)
     &     IERR
!             ERROR FLAG
      INTEGER	!, INTENT(IN)
     &     I_DISTRIBUTION
!             NUMBER OF DISTRIBUTION
     &   , I_SHAPE_PARTICLE
!             SHAPE OF PARTICLE
     &   , N_SIZE
!             NUMBER OF PARTICLE SIZES
      REAL*8	!, INTENT(OUT)
     &     ASPECT_PARTICLE
!             ASPECT RATIO OF PARTICLE
      REAL*8	!, INTENT(IN)
     &     RADIUS(0: NPD_SIZE)
!             RADII IN DISTRIBUTION
     &   , ASPECT(0: NPD_SIZE)
!             ARRAY OF ASPECTS
     &   , D2_ASPECT(0: NPD_SIZE)
!             2ND DERIVATIVE OF ASPECT
     &   , RADIUS_POINT
!             RADIUS FOR EVALUATION
!
!     LOCAL VARIABLES.
      INTEGER
     &     N_KNOT
!             NUMBER OF KNOT POINTS
      REAL*8
     &     DISCRIMINANT
!             DISCRIMINANT IN FORMULA FOR LENGTH
     &   , LENGTH
!             LENGTH OF CRYSTAL
!
!     SUBROUTINES CALLED:
      EXTERNAL
     &     SPLINE_EVALUATE
!
!
!
      IF (I_SHAPE_PARTICLE.EQ.IP_SHAPE_SPHERE) THEN
!        THE ASPECT RATIO OF A SPHERE IS OBVIOUSLY 1.
         ASPECT_PARTICLE=1.0D+00
         RETURN
      ELSE IF (I_SHAPE_PARTICLE.EQ.IP_SHAPE_HEXCYL) THEN
!        A CUTOFF IS PLACED AT A PRESCRIBED LIMIT.
         IF (RADIUS_POINT.GT.MAX_RADIUS_SCATTERER) THEN
            ASPECT_PARTICLE=1.0D+00
            RETURN
         ENDIF
!
!        EVALUATE THE DIFFERENTIAL POPULATION 
!        AS DIRECTED BY I_DISTRIBUTION.
         IF (I_DISTRIBUTION.EQ.IP_EXTERNAL) THEN
            IF (N_SIZE.GT.1) THEN
               N_KNOT=N_SIZE+1
               CALL SPLINE_EVALUATE(IERR, N_KNOT, RADIUS
     &            , ASPECT, D2_ASPECT
     &            , RADIUS_POINT, ASPECT_PARTICLE)
               IF (IERR.NE.I_NORMAL) THEN
                  IF (IERR.EQ.I_ERR_RANGE) THEN
                     ASPECT_PARTICLE=0.0D+00
                     IERR=I_NORMAL
                  ELSE
                     IERR=I_ERR_FATAL
                     RETURN
                  ENDIF
               ENDIF
!
!              THE ASPECT RATIO CANNOT BE NEGATIVE.
               IF (ASPECT_PARTICLE.LT.0.0D+00) ASPECT_PARTICLE=0.0D+00
!
            ELSE
               ASPECT_PARTICLE=ASPECT(N_SIZE)
            ENDIF
         ELSE IF (I_DISTRIBUTION.EQ.IP_LOG_NORMAL) THEN
            WRITE(IU_ERR, '(/A)') '*** ERROR: NO CALCULATION OF '
     &         //'ASPECT IS AVAILABLE WITH THIS DISTRIBUTION.'
            IERR=I_ERR_FATAL
            RETURN
         ELSE IF (I_DISTRIBUTION.EQ.IP_MODIFIED_GAMMA) THEN
            WRITE(IU_ERR, '(A)') '*** ERROR: NO CALCULATION OF '
     &         //'ASPECT IS AVAILABLE WITH THIS DISTRIBUTION.'
            IERR=I_ERR_FATAL
            RETURN
         ELSE IF (I_DISTRIBUTION.EQ.IP_HEYMSFIELD_PLATT) THEN
!           THE FORMULAE FOR THE ASPECT RATIO ARE TAKEN FROM 
!           AUER AND VEAL J. ATM. SCI. [27] p. 919 (1970).
            IF (RADIUS_POINT.GT.0.0D+00) THEN
               DISCRIMINANT=1.004004D+00-9.36D+03*(2.0D+00*RADIUS_POINT
     &            +8.479D-06)
               IF (DISCRIMINANT.GT.0.0D+00) THEN
                  LENGTH=2.1368D-04*(1.002D+00-SQRT(DISCRIMINANT))
                  IF (LENGTH.GT.2.0D-04)
     &               LENGTH=4.7185D+06*EXP(2.415D+00*LOG(RADIUS_POINT))
               ELSE
                  LENGTH=4.7185D+06*EXP(2.415D+00*LOG(RADIUS_POINT))
               ENDIF
               ASPECT_PARTICLE=LENGTH/(2.00D+00*RADIUS_POINT)
            ELSE
               ASPECT_PARTICLE=1.0D+00
            ENDIF
         ENDIF
      ENDIF
!
!
      RETURN
      END
