      FUNCTION ccf(waveln, sza, tcl, rsurf, pt, success)

      REAL*8  waveln, sza, tcl, rsurf, pt, ccf
      LOGICAL success

      INTEGER*4 lam0, lamn, lamx, ilam, klam
      INTEGER*4 sza0, szan, szax, isza, ksza
      INTEGER*4 tcl0, tcln, tclx, itcl, ktcl
      INTEGER*4 rs0, rsn, rsx, irs, krs
      INTEGER*4 ipt, kpt
      REAL*8    lamden(0:3), szaden(0:3), tclden(0:3), rsden(0:3)
      REAL*8    pt_coef(0:1)

      REAL*8    sum, prod, plam, psza, ptcl, prs, ppt

      INCLUDE "ccf.cmn"

d     write(6,11) waveln, sza, tcl, rsurf, pt
d  11 format(5(1pe15.6))
      CALL int_rang(waveln, lam_t, nlam_t, lam0, lamn, lamden, lamx)
      CALL int_rang(sza, sza_t, nsza_t, sza0, szan, szaden, szax)
      CALL int_rang(tcl, tcl_t, ntcl_t, tcl0, tcln, tclden, tclx)
      CALL int_rang(rsurf, rs_t, nrs_t, rs0, rsn, rsden, rsx)
      pt_coef(0)= (pt - pt_t(0))/(pt_t(1)-pt_t(0))
      pt_coef(1)= (pt_t(1) - pt)/(pt_t(1)-pt_t(0))

d     write(6,12)lam0, sza0, tcl0, rs0
d  12 format(5i15)

d     write(6,12)lamn, szan, tcln, rsn
      sum=0.
      DO ilam= 0, lamn
        plam= 1./lamden(ilam) 
        DO klam= 0, lamn
          IF (klam .NE. ilam) plam=plam*(waveln-lam_t(lam0+klam))
        END DO

        DO isza= 0, szan
          psza= 1./szaden(isza)
          DO ksza= 0, szan
            IF (ksza .NE. isza) psza=psza*(sza-sza_t(sza0+ksza))
          END DO

          DO itcl= 0, tcln
            ptcl= 1./tclden(itcl)
            DO ktcl= 0, tcln
              IF (ktcl .NE. itcl) ptcl=ptcl*(tcl-tcl_t(tcl0+ktcl))
            END DO

            DO irs= 0, rsn
              prs= 1./rsden(irs)
              DO krs= 0, rsn
                IF (krs .NE. irs) prs=prs*(rsurf-rs_t(rs0+krs))
              END DO

              DO ipt= 0, 1
                ppt= pt_coef(ipt)

                prod= plam*psza*ptcl*prs*ppt
                sum= sum + prod* ccftab(lam0+ilam, 
     &                                  sza0+isza, 
     &                                  tcl0+itcl, 
     &                                  rs0+irs, 
     &                                  ipt)
              END DO
            END DO
          END DO
        END DO
      END DO

      ccf=sum
      success=.TRUE.

      RETURN
      END
