C  Cleaned-up for Fortran Checker, 30/08/2009
C  Max globals increased to 10, 03/09/2009

      SUBROUTINE REPORT(T0,L00)
      IMPLICIT LOGICAL(A-Z)
      INTEGER MF,PF,DF,RF,M0,MK,M0K,LT0,LTK,DKLEN,NPLOTS,K,NK,N,D,I,J,
     1   P,Q,plot
      INTEGER*4 IPLOT
      DOUBLE PRECISION T0(M0),L00(LT0),C00(10,10),TK(6),DK(66),
     1   LKK(21),T(8),FK,F,CKK(10,10),A(6,10),EK(6),RN,STK(6),
     2   SATK(6),SA(6,10),SAA(6,10),SCKK(6,6),SACKK(6,6),E0(10)
      COMMON /FILES/MF,PF,DF,RF /SIZES/M0,MK,M0K,LT0,LTK,DKLEN,NPLOTS
      N=0
      F=0.D0
      DO 20 I=1,MK
         STK(I)=0.D0
         SATK(I)=0.D0
         DO 10 J=1,MK
            SCKK(I,J)=0.D0
   10       SACKK(I,J)=0.D0
         DO 20 J=1,M0
            SA(I,J)=0.D0
   20       SAA(I,J)=0.D0
      WRITE(RF,1)
    1 FORMAT(9H0    PLOT,5X,1HN,4X,8HFUNCTION,6X,
     1   36HLOCAL PARAMETERS AND STANDARD ERRORS)
      CALL CHINV(M0,LT0,L00,C00)
      DO 100 K=1,NPLOTS
C        Keep Fortran Checker happy:
         plot = K      
         CALL GET(plot,TK,DK,LKK)
         CALL TRPARS(T0,TK,T)
         CALL FUNCT(plot,T,FK,IPLOT,NK)
         F=F+FK
         N=N+NK
         CALL CHOL2(MK,LTK,M0,MK*M0,LKK,DK(MK+1))
         D=0
         DO 30 J=1,M0
            D=D+MK
            DO 30 I=1,MK
               A(I,J)=DK(D+I)
   30    CONTINUE
         CALL CHINV(MK,LTK,LKK,CKK)
         DO 40 I=1,MK
            DO 40 J=1,I
               DO 40 P=1,M0
                  CKK(I,J)=CKK(I,J)+C00(P,P)*A(I,P)*A(J,P)
                  IF(P.EQ.1) GO TO 40
                   DO 35 Q=1,P-1
                      CKK(I,J)=CKK(I,J)+2.D0*C00(P,Q)*A(I,P)*A(J,Q)
   35              CONTINUE
   40    CONTINUE
         DO 50 I=1,MK
   50       EK(I)=DSQRT(2.D0*CKK(I,I))
         WRITE(RF,2) IPLOT,NK,FK,(TK(I),I=1,MK),(EK(J),J=1,MK)
    2    FORMAT(1H ,I12,I4,(9G13.6/))
         RN=DFLOAT(NK)
         DO 80 I=1,MK
            STK(I)=STK(I)+RN*TK(I)
            SATK(I)=SATK(I)+RN*DABS(TK(I))
            DO 60 J=1,M0
               SA(I,J)=SA(I,J)+RN*A(I,J)
   60          SAA(I,J)=SAA(I,J)+DSIGN(RN,TK(I))*A(I,J)
C     CHANGED FROM...
C  60          SAA(I,J)=SAA(I,J)+RN*DSIGN(A(I,J),TK(I))
C     DUE TO NON-STANDARD IMPLEMENTATION OF SIGN FUNCTION
C     ON SOME MACHINES
            DO 70 J=1,I
               SCKK(I,J)=SCKK(I,J)+RN*CKK(I,J)
   70           SACKK(I,J)=SACKK(I,J)+DSIGN(RN,TK(I)*TK(J))*CKK(I,J)
C     CHANGED FROM...
C  70          SACKK(I,J)=SACKK(I,J)+RN*DSIGN(DSIGN(CKK(I,J),TK(I)),
C    1            TK(J))
   80    CONTINUE
  100 CONTINUE
      F=-0.5D0*F
      WRITE(RF,3) NPLOTS,N,F,T0
    3 FORMAT(1H0/17H NUMBER OF PLOTS:,I4/24H0NUMBER OF MEASUREMENTS:,
     1   I5/16H0LOG-LIKELIHOOD:,G14.7///19H0GLOBAL PARAMETERS:/10G15.7)
      DO 110 I=1,M0
  110    E0(I)=DSQRT(2.D0*C00(I,I))
      WRITE(RF,4) (E0(J),J=1,M0)
    4 FORMAT(17H0STANDARD ERRORS:/10G15.7)
      WRITE(RF,5)
    5 FORMAT(14H0CORRELATIONS:)
      DO 130 I=1,M0
         DO 120 J=1,I
  120       E0(J)=C00(I,J)/DSQRT(C00(I,I)*C00(J,J))
         WRITE(RF,6)(E0(J),J=1,I)
  130 CONTINUE
    6 FORMAT(10G15.7)
      RN=1.D0/DFLOAT(N)
      DO 140 I=1,MK
         TK(I)=RN*STK(I)
  140    EK(I)=DSQRT(2.D0*RN*SCKK(I,I))
      WRITE(RF,7) (TK(J),J=1,MK)
    7 FORMAT(1H0/39H0LOCAL PARAMETERS (WEIGHTED AVERAGES): /6G15.7)
      WRITE(RF,4) (EK(J),J=1,MK)
      WRITE(RF,5)
      DO 160 I=1,MK
         DO 150 J=1,I
  150       EK(J)=SCKK(I,J)/DSQRT(SCKK(I,I)*SCKK(J,J))
         WRITE(RF,6)(EK(J),J=1,I)
  160 CONTINUE
      WRITE(RF,8)
    8 FORMAT(36H0CORRELATION WITH GLOBAL PARAMETERS:)
      DO 200 I=1,MK
         DO 190 J=1,M0
            E0(J)=0.D0
            DO 170 P=1,J
  170          E0(J)=E0(J)-SA(I,P)*C00(J,P)
            IF(J.EQ.M0) GO TO 190
             DO 180 P=J+1,M0
  180           E0(J)=E0(J)-SA(I,P)*C00(P,J)
  190    E0(J)=E0(J)/DSQRT(SCKK(I,I)*C00(J,J)/RN)
         WRITE(RF,6)(E0(J),J=1,M0)
  200 CONTINUE
      DO 240 I=1,MK
         TK(I)=RN*SATK(I)
  240    EK(I)=DSQRT(2.D0*RN*SACKK(I,I))
      WRITE(RF,9) (TK(J),J=1,MK)
    9 FORMAT(1H0/53H0ABS. VALUE OF LOCAL PARAMETERS (WEIGHTED AVERAGES):
     1   /6G15.7)
      WRITE(RF,4) (EK(J),J=1,MK)
      WRITE(RF,5)
      DO 260 I=1,MK
         DO 250 J=1,I
  250       EK(J)=SACKK(I,J)/DSQRT(SACKK(I,I)*SACKK(J,J))
         WRITE(RF,6)(EK(J),J=1,I)
  260 CONTINUE
      WRITE(RF,8)
      DO 300 I=1,MK
         DO 290 J=1,M0
            E0(J)=0.D0
            DO 270 P=1,J
  270          E0(J)=E0(J)-SAA(I,P)*C00(J,P)
            IF(J.EQ.M0) GO TO 290
             DO 280 P=J+1,M0
  280           E0(J)=E0(J)-SAA(I,P)*C00(P,J)
  290    E0(J)=E0(J)/DSQRT(SACKK(I,I)*C00(J,J)/RN)
         WRITE(RF,6)(E0(J),J=1,M0)
  300 CONTINUE
      RETURN
      END

