        SUBROUTINE ZSPFIT(X,Y,NPTS,XA,YA,NA,NITER,YFIT,STATUS)
	IMPLICIT NONE
        DOUBLE PRECISION X(*),Y(*),XA(*),YA(*),YFIT(*)
        INTEGER NPTS,NA,STATUS,NITER
C
C LOCAL VARIABLES
C
        DOUBLE PRECISION SIG(2200),COVAR(30,30),ALPHA(30,30),CHISQ
        INTEGER LISTA(30),I
        DOUBLE PRECISION SUM,AVE,ALAMDA
C
C  DATA DECLARATIONS
C
        DATA LISTA/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
     *          20,21,22,23,24,25,26,27,28,29,30/
        DATA SIG/2200*1.0/
C
C COMPUTE INITIAL NODE GUESS
C
        SUM=0.0
        DO 10 I=1,NPTS
10              SUM=SUM+Y(I)
        AVE=SUM/NPTS
        DO 15 I=1,NA
15              YA(I)=NA
C
C INITIALIZE LEAST SQUARES ROUTINE
C
        ALAMDA=-1.0
        CALL ZMRQSP(X,Y,SIG,NPTS,XA,YA,NA,LISTA,NA,COVAR,ALPHA,30,
     *                  CHISQ,ALAMDA,STATUS)
        IF(STATUS.NE.0) GO TO 1000
C
C ITERATE NITER TIMES
C
        DO 20 I=1,NITER
           CALL ZMRQSP(X,Y,SIG,NPTS,XA,YA,NA,LISTA,NA,COVAR,ALPHA,30,
     *                  CHISQ,ALAMDA,STATUS)
           IF(STATUS.NE.0) GO TO 1000
20      CONTINUE
C
C CLEAN UP
C
        ALAMDA=0.0
        CALL ZMRQSP(X,Y,SIG,NPTS,XA,YA,NA,LISTA,NA,COVAR,ALPHA,30,
     *                  CHISQ,ALAMDA,STATUS)
        IF(STATUS.NE.0) GO TO 1000
C
C COMPUTE FITTED VALUES
C
        CALL ZSPLIN(X,NPTS,XA,YA,NA,YFIT,STATUS)
1000    RETURN
        END
