!+ Subroutine to find the gradient of the residual in the coalbedo.
!
! Method:
!	Straightforward.
!
! 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.
!
!- ---------------------------------------------------------------------
      SUBROUTINE SS_ALBEDO_GRADIENT(N_DATA, I_FIT_TYPE, N_PARAMETER
     &   , VOL_FRACTION, RADIUS_EFFECTIVE, SS_ALBEDO
     &   , PARM, GRADIENT)
!
!
      IMPLICIT NONE
!
!
!     INCLUDE HEADER FILES.
      INCLUDE 'incl/dimensions_spec.ucf'
      INCLUDE 'incl/cloud_parametrization.pcf'
!
!     DUMMY VARIABLES
      INTEGER 	!, INTENT(IN)
     &     N_DATA
!             NUMBER OF DATA POINTS
     &   , N_PARAMETER
!             NUMBER OF PARAMETERS
     &   , I_FIT_TYPE
!             TYPE OF FIT REQUIRED
      REAL*8	!, INTENT(IN)
     &     SS_ALBEDO(N_DATA)
!             ACTUAL S. S. ALBEDO
     &   , VOL_FRACTION(N_DATA)
!             VOLUME FRACTION OF ABSORBER
     &   , RADIUS_EFFECTIVE(N_DATA)
!             EFFECTIVE RADIUS
     &   , PARM(N_PARAMETER)
!             FITTING PARAMETERS
      REAL*8	!, INTENT(OUT)
     &     GRADIENT(NPD_CLOUD_PARAMETER)
!             GRADIENT OF SCATTERING
!
!     LOCAL VARIABLES.
      INTEGER
     &     I
!             LOOP PARAMETER
!
!
!     INITIALIZE THE GRADIENT TO ZERO.
      DO I=1, N_PARAMETER
         GRADIENT(I)=0.0D+00
      ENDDO
!
!     SET NON-ZERO TERMS FOR DIFFERENT SCHEMES.
      IF (I_FIT_TYPE.EQ.IP_SLINGO_SCHRECKER) THEN
         DO I=1, N_DATA
            GRADIENT(1)=GRADIENT(1)-2.0D+00*(SS_ALBEDO(I)
     &         -(PARM(1)+PARM(2)*RADIUS_EFFECTIVE(I)))
            GRADIENT(2)=GRADIENT(2)-2.0D+00*(SS_ALBEDO(I)
     &         -(PARM(1)+PARM(2)*RADIUS_EFFECTIVE(I)))
     &         *RADIUS_EFFECTIVE(I)
         ENDDO
      ELSE IF (I_FIT_TYPE.EQ.IP_ACKERMAN_STEPHENS) THEN
         DO I=1, N_DATA
            GRADIENT(1)=GRADIENT(1)-2.0D+00*(SS_ALBEDO(I)
     &         -(PARM(1)+PARM(2)*EXP(PARM(3)
     &         *LOG(RADIUS_EFFECTIVE(I)))))
            GRADIENT(2)=GRADIENT(2)-2.0D+00*(SS_ALBEDO(I)
     &         -(PARM(1)+PARM(2)*EXP(PARM(3)
     &         *LOG(RADIUS_EFFECTIVE(I)))))
     &         *EXP(PARM(3)*LOG(RADIUS_EFFECTIVE(I)))
            GRADIENT(3)=GRADIENT(3)-2.0D+00*(SS_ALBEDO(I)
     &         -(PARM(1)+PARM(2)*EXP(PARM(3)
     &         *LOG(RADIUS_EFFECTIVE(I)))))*PARM(2)
     &         *EXP(PARM(3)*LOG(RADIUS_EFFECTIVE(I)))
     &         *LOG(RADIUS_EFFECTIVE(I))
         ENDDO
      ENDIF
!
!     NORMALIZE THE GRADIENT.
      DO I=1, N_PARAMETER
         GRADIENT(I)=GRADIENT(I)/DBLE(N_DATA)
      ENDDO
!
!
      RETURN
      END
