       subroutine normal(h,k,l,ipar,isys,icor,n,m,ipmax,gl,theta,a,wgt) NORM001
c ---------------------------------------------------------------       NORM002
c       sets up normal equations for systems                            NORM003
c       and fills coefficent matrix  (XLAT)                             NORM004
c ---------------------------------------------------------------       NORM005
c       version 3.0 last revised 23.2.89 ETH-LNS                        NORM006
c ---------------------------------------------------------------       NORM007
       integer h(*), k(*), l(*)                                         NORM008
       dimension gl(5,*), a(ipmax+1,*), ipar(*), wgt(*), theta(*)       NORM009
                                                                        NORM010
       m=ipar(isys)+2                                                   NORM011
       rad=180.0/3.1415927                                              NORM012
                                                                        NORM013
c ---- initialize coefficient array of normal equations                 NORM014
       do 7005 i=1,m-1                                                  NORM015
          do 7005 j=1,m                                                 NORM016
 7005  a(i,j)=0.0                                                       NORM017
                                                                        NORM018
c ---- set up normal equations for different systems                    NORM019
       do 7001 i=1,n                                                    NORM020
          th=theta(i)/rad                                               NORM021
          if(isys.eq.1) then                                            NORM022
             gl(1,i)=H(i)**2+K(i)**2+L(i)**2                            NORM023
          else if (isys.eq.2) then                                      NORM024
             gl(1,i)=H(i)**2+K(i)**2                                    NORM025
             gl(2,i)=L(i)**2                                            NORM026
          else if (isys.eq.3) then                                      NORM027
             gl(1,i)=H(i)**2+K(i)**2+H(i)*K(i)                          NORM028
             gl(2,i)=L(i)**2                                            NORM029
          else                                                          NORM030
             gl(1,i)=H(i)**2                                            NORM031
             gl(2,i)=K(i)**2                                            NORM032
             gl(3,i)=L(i)**2                                            NORM033
          end if                                                        NORM034
                                                                        NORM035
c ------- consider different drift functions                            NORM036
          if(icor.eq.2) then                                            NORM037
             gl(m-1,i)=0                                                NORM038
          else if(icor.eq.1) then                                       NORM039
             gl(m-1,i)=10*(sin(2.0*th)**2)                              NORM040
          else                                                          NORM041
             gl(m-1,i)=sin(2.0*th)**2*(1.0/sin(th)+1.0/theta(I))*10.0   NORM042
          end if                                                        NORM043
          gl(m,i)=sin(th)**2                                            NORM044
                                                                        NORM045
c ------- fill coefficent martix A                                      NORM046
          do 7001 ik=1,m-1                                              NORM047
             do 7001 j=1,m                                              NORM048
 7001  A(ik,j)=A(ik,j)+GL(ik,i)*GL(j,i)*wgt(i)                          NORM049
                                                                        NORM050
       return                                                           NORM051
       end                                                              NORM052
                                                                        NORM053
