



      SUBROUTINE NQA001




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IUA, IRT, ILAB, IIAT, LOCIAT(NQAAPF), NAT, IFR,
     +              ISEQ, IAA, IST, IATT, IBOX, IX, IY, IZ, I, UNT,
     +              IERR, IAC, IDUMMY(1), NIATT, COL, ITODO
      REAL          VAL(10), SCALE, RX, RY, RZ, DX, DXY, DXYZ,
     +              RDUMMY(1)
      CHARACTER*4   ATARR(NQAAPF)
      CHARACTER*80  FILNAM, VATNAME
      LOGICAL       GVFISF, ESPBAD, T54EQUAL







      IF (WIFPAR(930).EQ.0) THEN
         CALL GVSTTE ('?M1313')
         GOTO 990
      END IF



      IF (WIFPAR(923).EQ.1) THEN
         IF (.NOT.ESPBAD(NQAESP0,NQAESPZ,47)) GOTO 990
      END IF
      WIFPAR(923)=1



      CALL ESPSET (NQAESP0,NQAESPZ,47)



      NQANF=0
      NQAATC=0
      IRT=0
      WIFPAR(909)=0
      CALL GVSIT0 (NQABDB,NQAMBX)
      CALL GVSRT0 (NQASC,NQAMBX)
      IF (WIFPAR(1309).LE.0) THEN
         ITODO=NBINDB
      ELSE
         ITODO=WIFPAR(1309)
      END IF



      CALL GVSCCC (FILNAM,FILDIR(30),'NQUAL.DAT')
      CALL GVSROF (UNT,IERR)
      IF (IERR.NE.0) GOTO 990
      CALL GETFILE (UNT,' ',FILNAM,IERR)
      IF (IERR.NE.0) GOTO 990



   10 CONTINUE
      CALL GVSFMT ('?FMT027A')
      READ (UNT,FMT,ERR=999,END=20) LINE



      IF (LINE(1:1).EQ.'#') THEN



         DO 30 IUA=1,NUMUA
            IF (LINE(2:5).EQ.AANAME(IUA)) THEN
               IRT=IUA
               IF (IRT.GT.NQANRT) THEN
                  CALL GVSTTE ('?NQAM043')
                  GOTO 990
               END IF
               GOTO 50
            END IF
   30    CONTINUE
         CALL GVSTTB ('?NQAM002')
   50    CONTINUE



      ELSE IF (LINE(1:1).EQ.'!') THEN
         GOTO 10



      ELSE



         IF (IRT.EQ.0) THEN
            CALL GVSTTB ('?NQAM003')
            GOTO 990
         END IF



         CALL GVSFMT ('?FMT699A')
         READ (LINE,FMT,ERR=990,END=990) ATARR
         NAT=0



         DO 40 ILAB=1,NQAAPF
            IF (ATARR(ILAB).EQ.'    ') THEN
               GOTO 40
            END IF




            DO 60 IIAT=1,HATPRA(IRT)
               IF (T54EQUAL(MUTROW4(IIAT,IRT),ATARR(ILAB))) THEN
                  NAT=NAT+1
                  LOCIAT(NAT)=IIAT
                  GOTO 40
               END IF
   60       CONTINUE
            CALL GVSTTB ('?NQAM004')
            CALL GVST6C ('?NQAM005',AANAME(IRT),.TRUE.)
            CALL GVST6C ('?NQAM006',ATARR(ILAB),.TRUE.)
   40    CONTINUE
         IF (NQANF.GE.NQAMFR) THEN
            CALL GVSTTE ('?NQAM007')
         END IF
         IF (NAT.GT.2) THEN
            NQANF=NQANF+1
            NQARTP(NQANF)=IRT
            NQANAT(NQANF)=NAT



            NQAIBB(NQANF)=.TRUE.
            DO 70 IIAT=1,NAT
               NQAIAT(IIAT,NQANF)=LOCIAT(IIAT)



               IF (LOCIAT(IIAT).GT.5) NQAIBB(NQANF)=.FALSE.
   70       CONTINUE
         ELSE
            CALL GVSTTB ('?NQAM008')
         END IF
      END IF
      GOTO 10
   20 CONTINUE
      CALL GVSCLF (UNT)



      DO 41 IRT=1,NQANRT
         NQASFR(IRT)=NQANF
         NQAEFR(IRT)=1
         DO 31 IFR=1,NQANF
            IF (NQARTP(IFR).EQ.IRT) THEN
               IF (IFR.LT.NQASFR(IRT)) NQASFR(IRT)=IFR
               IF (IFR.GT.NQAEFR(IRT)) NQAEFR(IRT)=IFR
            END IF
   31    CONTINUE
   41 CONTINUE




      CALL GVSIT0 (NQAIRT,NQAHAT+1)
      DO 90 IIAT=1,MAXTAT
         DO 80 IRT=1,NQANRT
            IF (IIAT.GT.HATPRA(IRT)) GOTO 80
            NQAATC=NQAATC+1



            NQAJBB(NQAATC)=((IIAT.LE.5).AND.(FAMTYP(IRT).EQ.1))
            NQAATT(IIAT,IRT)=NQAATC
            IF (NQAATC.LT.NQAANY) THEN
               NQAREV(NQAATC)(1:4)=AANAME(IRT)
               NQAREV(NQAATC)(5:8)=MUTROW4(IIAT,IRT)(1:4)
               NQAIRT(NQAATC)=IRT
            END IF
   80    CONTINUE
   90 CONTINUE



      NQAJBB(NQAH2O)=.FALSE.
      NQAREV(NQAH2O)='H2O H2O'
      NQAJBB(NQAANY)=.FALSE.
      NQAREV(NQAANY)='ANY ANY'
      NQAJBB(0)=.FALSE.
      NQAREV(0)='EMPTY!!!'



      CALL GVSIT0 (NQAFRQ,NQANRT)
      DO 176 ISEQ=1,NBINDB
         DO 173 IAA=1,NAAFIL(ISEQ)
            IF (ALLSEQ(IAA,ISEQ).GT.0.AND.ALLSEQ(IAA,ISEQ).LE.NQANRT)
     +       NQAFRQ(ALLSEQ(IAA,ISEQ))=NQAFRQ(ALLSEQ(IAA,ISEQ))+1
  173    CONTINUE
  176 CONTINUE



      NQANMSK=0
      DO 190 IX=1,NQASZ
         RX=NQASTR+(IX-1)*NQAGRD
         DX=RX**2
         DO 180 IY=1,NQASZ
            RY=NQASTR+(IY-1)*NQAGRD
            DXY=DX+RY**2
            DO 170 IZ=1,NQASZ
               RZ=NQASTR+(IZ-1)*NQAGRD
               DXYZ=DXY+RZ**2
               IF (DXYZ.LE.NQADS2) THEN
                  NQAMSK(IX,IY,IZ)=.TRUE.
                  NQANMSK=NQANMSK+1
               ELSE
                  NQAMSK(IX,IY,IZ)=.FALSE.
               END IF
  170       CONTINUE
  180    CONTINUE
  190 CONTINUE






         NQARECL=(NQANMSK+3)/4*4




      CALL GVSCCC (LINE,FILDIR(30),'NQABOX.DAT')
      IF (GVFISF(LINE)) THEN
         NQANBX=0
      ELSE
         NQANBX=1
         CALL GVSTT6 ('?NQAM011')
      END IF
      IF (BOXUNT.GT.0) CALL GVSCLF (BOXUNT)
      CALL GVSROF (BOXUNT,IERR)
      IF (IERR.NE.0) GOTO 990
      CALL GVSODF (BOXUNT,.FALSE.,LINE,'UNKNOWN',(NQANMSK+3)/4,' ',IERR)



      IF (NQANBX.EQ.0) THEN
         READ (BOXUNT,REC=1,ERR=995) NQANBX
         IF (ABS(NQANBX).GT.200000) THEN
            CALL BYTSWP (NQANBX)
         END IF
      END IF
      IF (NQANBX.GT.NQAMBX) THEN
         CALL GVSTTE ('?NQAM045')
         GOTO 990
      END IF



      CALL GVSCCC (LINE,FILDIR(30),'NQAPTR.TXT')
      IF (GVFISF(LINE)) THEN
         CALL GVSROF (UNT,IERR)
         IF (IERR.NE.0) GOTO 990
         CALL GVSOPF (LINE,UNT,'OLD')
  100    CONTINUE
         CALL GVSFMT ('?FMT1382')
         READ (UNT,FMT,END=200,ERR=998) IFR,IST,IATT,IBOX,SCALE
         NQABDB(IFR,IST,IATT)=IBOX
         NQASC(IFR,IST,IATT)=SCALE
         GOTO 100
  200    CONTINUE
         CALL GVSCLF (UNT)



         CALL NQA018
      ELSE
         CALL GVSTT6 ('?NQAM014')
      END IF



      IF (WIFPAR(598).LT.100) THEN
         CALL GVSCCC (LINE,FILDIR(30),'NQANOR.WAT')
      ELSE
         CALL GVSCCC (LINE,FILDIR(30),'NQANOR.DAT')
      ENDIF
      IF (GVFISF(LINE)) THEN
         CALL GVSROF (UNT,IERR)
         IF (IERR.NE.0) GOTO 990
         CALL GVSOPF (LINE,UNT,'OLD')
  300    CONTINUE
         CALL GVSFMT ('?FMT1383')
         READ (UNT,FMT,END=400,ERR=997) IRT,IST,IAC,VAL
         DO 350 I=1,10
            NQAAVE(I,IRT,IST,IAC)=VAL(I)
  350    CONTINUE
         GOTO 300
  400    CONTINUE
         CALL GVSCLF (UNT)
      ELSE



         CALL GVSTT6 ('?NQAM015')
         CALL NQA029
      END IF



      IF (WIFPAR(598).LT.100) THEN
         CALL GVSCCC (LINE,FILDIR(30),'NQASTR.WAT')
      ELSE
         CALL GVSCCC (LINE,FILDIR(30),'NQASTR.DAT')
      ENDIF
      IF (GVFISF(LINE)) THEN
         CALL GVSROF (UNT,IERR)
         IF (IERR.NE.0) GOTO 990
         CALL GVSOPF (LINE,UNT,'OLD')
         CALL GVSFMT ('?FMT1384')
         READ (UNT,FMT,ERR=996) NQASAV
         CALL GVSCLF (UNT)
      ELSE
         CALL GVSTT6 ('?NQAM016')
         CALL NQA029A
      END IF



      NQANVA=0
  500 CONTINUE
      NQANVA=NQANVA+1
      CALL NQA036 (IDUMMY,RDUMMY,NIATT,1,VATNAME,COL,NQANVA,IERR)
      IF (IERR.EQ.1) GOTO 510
      IF (NQANVA.GT.NQAMVA) THEN
         CALL GVSTTE ('?R00167')
         GOTO 510
      END IF
      NQAVCL(NQANVA)=COL
      CALL GVSSTX (NQAVNM(NQANVA), VATNAME)
      GOTO 500



  510 CONTINUE
      NQANVA=NQANVA-1
      GOTO 990



  995 CONTINUE
      CALL GVSTTE ('?NQAM059')
      GOTO 990
  996 CONTINUE
      CALL GVSTTE ('?NQAM017')
      CALL GVSCLF (UNT)
      GOTO 990
  997 CONTINUE
      CALL GVSTTE ('?NQAM018')
      CALL GVSCLF (UNT)
      GOTO 990
  998 CONTINUE
      CALL GVSTTE ('?NQAM019')
      CALL GVSCLF (UNT)
      GOTO 990
  999 CONTINUE
      CALL GVSTTE ('?NQAM020')
      CALL GVSCLF (UNT)



 990  CONTINUE

 
      RETURN
      END
      SUBROUTINE NQA002 (IAA,IFR,RMAT,TVEC,IERR)




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      REAL          RMAT(3,3), TVEC(3), LOCSUP(3,NQAAPF), RMS,
     +              BASSUP(3,NQAAPF), MAXERR
      INTEGER       IRT, IAA, IFR, IIAT, IAT, IERR



      INTEGER       NHASH, IHASH
      PARAMETER     (NHASH=1001)
      INTEGER       HASHIAA(NHASH),HASHIFR(NHASH),HASHIERR(NHASH)
      REAL          HASHRMAT(3,3,NHASH), HASHTVEC(3,3,NHASH)
      EQUIVALENCE   (ESPACE(NQAESPZ+5000+0*NHASH),HASHIAA)
      EQUIVALENCE   (ESPACE(NQAESPZ+5000+1*NHASH),HASHIFR)
      EQUIVALENCE   (ESPACE(NQAESPZ+5000+2*NHASH),HASHIERR)
      EQUIVALENCE   (ESPACE(NQAESPZ+5000+3*NHASH),HASHTVEC)
      EQUIVALENCE   (ESPACE(NQAESPZ+5000+6*NHASH),HASHRMAT)







      IERR=0
      CALL GVSRT0 (RMAT,9)
      CALL GVSRT0 (TVEC,3)
      RMAT(1,1)=1.0
      RMAT(2,2)=1.0
      RMAT(3,3)=1.0
      IRT=RESTYP(IAA)



      IF (WIFPAR(909).EQ.-1) THEN
         CALL ESPSET (NQAESPZ+5000,NQAESPZ+5000+15*NHASH,51)
         WIFPAR(909)=1
         WIFPAR(910)=0
         WIFPAR(911)=0
         CALL GVSIT0(HASHIAA,NHASH)



      ELSE IF (WIFPAR(909).EQ.-2) THEN
         CALL ESPKIL (NQAESPZ+5000,NQAESPZ+5000+15*NHASH,51,'NQA002')
         WIFPAR(909)=0
         GOTO 998
      END IF



      IF (IRT.NE.NQARTP(IFR)) THEN
         CALL GVSTTE ('?NQAM021')
         GOTO 998
      END IF



      IF (WIFPAR(909).GT.0) THEN
         IHASH=MOD(5*IAA+IFR-NQASFR(IRT),NHASH)+1
         IF (IAA.EQ.HASHIAA(IHASH).AND.IFR.EQ.HASHIFR(IHASH)) THEN
            CALL GVSCPR (RMAT,HASHRMAT(1,1,IHASH),9)
            CALL GVSCPR (TVEC,HASHTVEC(1,1,IHASH),3)
            WIFPAR(910)=WIFPAR(910)+1
            IERR=HASHIERR(IHASH)
            GOTO 998
         ELSE
            WIFPAR(911)=WIFPAR(911)+1
         END IF
      END IF



      DO 100 IIAT=1,NQANAT(IFR)
         IAT=PNTAAS(IAA)+NQAIAT(IIAT,IFR)-1
         IF (.NOT.ISATOK(IAT)) THEN
            IERR=1
            GOTO 998
         END IF



         LOCSUP(1,IIAT)=XCOORD(IAT)
         LOCSUP(2,IIAT)=YCOORD(IAT)
         LOCSUP(3,IIAT)=ZCOORD(IAT)
 100  CONTINUE



      CALL NQA028 (BASSUP,IFR)



      CALL GVSSPN (NQANAT(IFR),BASSUP,LOCSUP,RMAT,TVEC,RMS,MAXERR)
      IF (RMS.GT.0.2) THEN







         IF(RMS.GT.0.5) IERR=1
      END IF



      IF (WIFPAR(909).GT.0) THEN
         IHASH=MOD(5*IAA+IFR-NQASFR(IRT),NHASH)+1
         HASHIAA(IHASH)=IAA
         HASHIFR(IHASH)=IFR
         CALL GVSCPR (HASHRMAT(1,1,IHASH),RMAT,9)
         CALL GVSCPR (HASHTVEC(1,1,IHASH),TVEC,3)
         HASHIERR(IHASH)=IERR
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA003 (IAA,IFR,BOX,WGTBOX)




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SYMINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       MAXP
      PARAMETER     (MAXP=NQASZ**3/8)
      INTEGER       IAA, IFR, BOX(NQASZ,NQASZ,NQASZ), IRT, NUM, ICON,
     +              JAAARR(MAXP), JAASYM(MAXP), ISYM, JAT, JAA, JRT,
     +              JATT, ATS, GRX, GRY, GRZ, IX, IY, IZ, GRX1, GRX2,
     +              GRY1, GRY2, GRZ1, GRZ2, IERR, IAT, IIAT, IST, NQA008
      REAL          RMAT(3,3), TVEC(3), DST(NQASZ,NQASZ,NQASZ),
     +              RX, RY, RZ, DX, DXY, DXYZ, VDW2, D2, TMP(3), HV,
     +              LOWD, D, WGTBOX(NQASZ,NQASZ,NQASZ), SCAL
      LOGICAL       WIFIRW, WIFITW, IDONE







      IRT=RESTYP(IAA)
      IST=NQA008(IAA)



      DO 190 IX=1,NQASZ
         DO 180 IY=1,NQASZ
            DO 170 IZ=1,NQASZ
               IF (NQAMSK(IX,IY,IZ)) THEN
                  BOX(IX,IY,IZ)=0
                  DST(IX,IY,IZ)=99.9
                  WGTBOX(IX,IY,IZ)=32.0
               ELSE
                  BOX(IX,IY,IZ)=NQAIGN
                  DST(IX,IY,IZ)=0.0
                  WGTBOX(IX,IY,IZ)=0.0
               END IF
 170        CONTINUE
 180     CONTINUE
 190  CONTINUE



      IF (IRT.NE.NQARTP(IFR)) THEN
         CALL GVSTTE ('?NQAM024')
         GOTO 998
      END IF



      CALL NQA002 (IAA,IFR,RMAT,TVEC,IERR)
      IF (IERR.NE.0) GOTO 998



      CALL GVSRT0 (TMP,3)
      CALL GVSMVP (TMP,RMAT,TVEC)
      CALL WIFPUSHPPP (1183,1)
      CALL FCONAAI (IAA,NQATCH,.TRUE.,JAAARR,JAASYM,NUM,MAXP)
      CALL WIFPOPPPP (1183)



      IF (NUM.EQ.0) THEN
         CALL GVSTT6 ('?NQAM026')
         CALL RHSWMV (RMAT,TVEC)
         CALL GVSCOD ('?NQAM026')
      END IF
      DO 100 ICON=1,NUM
         JAA=JAAARR(ICON)
         ISYM=JAASYM(ICON)



         IF (WIFIRW(JAA)) THEN
            SCAL=32.0
            GOTO 94
         END IF



         LOWD=999.9
         DO 99 JAT=PNTAAS(JAA),PNTAAE(JAA)
            IF (PROTON(JAT)) GOTO 99
            TMP(1)=XCOORD(JAT)
            TMP(2)=YCOORD(JAT)
            TMP(3)=ZCOORD(JAT)



            IF (ISYM.GT.1) 
     +           CALL GVSMPV (TMP, SYMMAT(1,1,ISYM), SYMVEC(1,ISYM))
            DO 98 IIAT=1,NQANAT(IFR)
               IAT=PNTAAS(IAA)+NQAIAT(IIAT,IFR)-1
               D2=(XCOORD(IAT)-TMP(1))**2+
     +            (YCOORD(IAT)-TMP(2))**2+
     +            (ZCOORD(IAT)-TMP(3))**2
               IF (D2.LT.(VDWRAD(IAT)+VDWRAD(JAT)+NQATCH)**2) THEN



                  SCAL=32.0
                  GOTO 94
               END IF
               IF (D2.LT.(VDWRAD(IAT)+VDWRAD(JAT)+2.0*NQATCH)**2) THEN
                  D=SQRT(D2)-VDWRAD(IAT)-VDWRAD(JAT)
                  IF (D.LT.LOWD) THEN
                     LOWD=D
                  END IF
               END IF
   98       CONTINUE
   99    CONTINUE



         SCAL=64.0-32.0*LOWD/NQATCH



         IF (SCAL.LT.0.5) GOTO 100



   94    CONTINUE
         JRT=RESTYP(JAA)




         HV=0.0
         DO 95 JAT=PNTAAS(JAA),PNTAAE(JAA)
            IF (PROTON(JAT)) GOTO 95
            TMP(1)=XCOORD(JAT)
            TMP(2)=YCOORD(JAT)
            TMP(3)=ZCOORD(JAT)



            IF (ISYM.GT.1) 
     +           CALL GVSMPV (TMP, SYMMAT(1,1,ISYM), SYMVEC(1,ISYM))




            DO 981 IIAT=1,NQANAT(IFR)
               IAT=PNTAAS(IAA)+NQAIAT(IIAT,IFR)-1
               D2=(XCOORD(IAT)-TMP(1))**2+
     +              (YCOORD(IAT)-TMP(2))**2+
     +              (ZCOORD(IAT)-TMP(3))**2
               IF (D2.LT.(VDWRAD(IAT)+VDWRAD(JAT)+NQACLS)**2) GOTO 982
  981       CONTINUE



            GOTO 95
  982       CONTINUE




            CALL GVSMPV (TMP,RMAT,TVEC)



            IF (JRT.GT.0.AND.JRT.LE.NQANRT) THEN



               JATT=NQAATT(JAT-PNTAAS(JAA)+1,JRT)



               IF (JATT.GT.NQAANY) THEN
                  JATT=NQAANY

               ELSE IF (ISYM.EQ.1.AND.ABS(IAA-JAA).LT.3) THEN



                  IF (CHAINN(2,IAA).EQ.CHAINN(2,JAA)) THEN
                     JATT=NQAIGN
                  END IF
               ELSE



                  IF (HV.GT.0.3) THEN
                     JATT=NQAIGN
                  END IF
               END IF
            ELSE IF (WIFITW(JAT)) THEN



               IF (WEIGHT(JAT)*100.GT.WIFPAR(598)) THEN
                  JATT=NQAH2O
                  SCAL=32.0
               ELSE 
                  JATT=NQAIGN




                  GOTO 95
               END IF               
            ELSE



               JATT=NQAANY
            END IF



            ATS=INT(VDWRAD(JAT)/NQAGRD)+1
            GRX=NINT((TMP(1)-NQASTR)/NQAGRD)+1
            GRY=NINT((TMP(2)-NQASTR)/NQAGRD)+1
            GRZ=NINT((TMP(3)-NQASTR)/NQAGRD)+1
            GRX1=MAX(1,GRX-ATS)
            GRY1=MAX(1,GRY-ATS)
            GRZ1=MAX(1,GRZ-ATS)
            GRX2=MIN(NQASZ,GRX+ATS)
            GRY2=MIN(NQASZ,GRY+ATS)
            GRZ2=MIN(NQASZ,GRZ+ATS)



            IDONE=.FALSE.
            VDW2=VDWRAD(JAT)**2
            DO 90 IX=GRX1,GRX2
               RX=NQASTR+(IX-1)*NQAGRD
               DX=(TMP(1)-RX)**2
               DO 80 IY=GRY1,GRY2
                  RY=NQASTR+(IY-1)*NQAGRD
                  DXY=DX+(TMP(2)-RY)**2
                  DO 70 IZ=GRZ1,GRZ2
                     RZ=NQASTR+(IZ-1)*NQAGRD
                     DXYZ=DXY+(TMP(3)-RZ)**2
                     IF (DXYZ.GT.VDW2) GOTO 70



                     IF (DXYZ.LT.DST(IX,IY,IZ)) THEN



                        DST(IX,IY,IZ)=DXYZ
                        BOX(IX,IY,IZ)=JATT
                        WGTBOX(IX,IY,IZ)=SCAL
                        IDONE=.TRUE.
                     END IF
   70             CONTINUE
   80          CONTINUE
   90       CONTINUE



            IF (JATT.NE.NQAIGN.AND.IDONE) THEN
               NQAACN(JATT,IST)=NQAACN(JATT,IST)+1
            END IF
   95    CONTINUE



 100  CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA004 (IAA,IFR,FRQR,BOXARR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       BOXARR(NQASZ,NQASZ,NQASZ,0:NQAHAT,NQANST)
      INTEGER       IX, IY, IZ, BOX(NQASZ,NQASZ,NQASZ), IAA, IFR, IST,
     +              NQA008, IATT, IRT
      REAL          FRQR(0:NQAHAT), WGTBOX(NQASZ,NQASZ,NQASZ), WT







      IRT=RESTYP(IAA)
      IATT=NQAATT(1,IRT)
      WT=FRQR(IATT)



      CALL NQA003 (IAA,IFR,BOX,WGTBOX)
      IST=NQA008(IAA)



      DO 100 IX=1,NQASZ
         DO 90 IY=1,NQASZ
            DO 80 IZ=1,NQASZ
               IATT=BOX(IX,IY,IZ)
               IF (IATT.NE.NQAIGN) THEN
                  BOXARR(IX,IY,IZ,IATT,IST)=
     +             BOXARR(IX,IY,IZ,IATT,IST)+
     +             NINT(WGTBOX(IX,IY,IZ)*FRQR(IATT)*WT)
               END IF
 80         CONTINUE
 90      CONTINUE
 100  CONTINUE





      RETURN
      END
      SUBROUTINE NQA005 (IFR,BOXARR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       BOXARR(NQASZ,NQASZ,NQASZ,0:NQAHAT,NQANST)
      INTEGER       IAA, IFR, IRT, ISEQ, IERR, IATT, IAT, ITODO
      REAL          FRQR(0:NQAHAT), NQA035







      CALL NQA001
      CALL GVSIT0 (BOXARR,NQABAZ)
      CALL GVSIT0 (NQAACN,NQANST*(1+NQAHAT))
      IF (IFR.GT.NQANF) THEN
         CALL GVSTTB ('?NQAM027')
         GOTO 998
      END IF
      IRT=NQARTP(IFR)



      IF (WIFPAR(1309).LE.0) THEN
         ITODO=NBINDB
      ELSE
         ITODO=WIFPAR(1309)
      END IF
      DO 100 ISEQ=1,ITODO
         CALL GVSTTI ('?M1314',ISEQ)
         WIFPAR(4)=ISEQ



         CALL MOL100
         CALL NQA026 (ISEQ,IERR)
         IF (IERR.NE.0) GOTO 100
         WIFPAR(1052)=0
         CALL MOL200



         CALL GVSSTX (FILNMS(62),NAMFIL(ISEQ))



         DO 200 IATT=0,NQAHAT
            FRQR(IATT)=NQA035(IATT)
            IF (FRQR(IATT).GT.0.001) FRQR(IATT)=1.0/FRQR(IATT)
  200    CONTINUE



         CALL NQA020



         DO 90 IAA=1,NUMAAF
            IF (RESTYP(IAA).EQ.IRT.AND.CHANAM(IAA).EQ.FILCNM(ISEQ)) THEN
               DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
                  IF (.NOT.ISATOK(IAT).AND..NOT.PROTON(IAT)) GOTO 90
   80          CONTINUE
               CALL NQA004 (IAA,IFR,FRQR,BOXARR)
            END IF
   90    CONTINUE
  100 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA007 (IFR,PTRUNT,BOXARR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       BOXARR(NQASZ,NQASZ,NQASZ,0:NQAHAT,NQANST),
     +              IFR, IST, THISBX, PTRUNT, IATT
      REAL          SCALE







      DO 10 IST=1,NQANST



         DO 20 IATT=0,NQAHAT



            IF (NQAACN(IATT,IST).LT.NQAMPS.OR.IATT.EQ.0) THEN
               THISBX=0
            ELSE
               THISBX=NQANBX+1



               CALL NQA010 (THISBX,SCALE,BOXARR(1,1,1,IATT,IST),1.0)



               CALL GVSFMT ('?FMT1154')
               WRITE (PTRUNT,FMT,ERR=999) IFR,IST,IATT,THISBX,
     +          NQAREV(IATT),NQAACN(IATT,IST), SCALE
            END IF
   20    CONTINUE
   10 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('NQA007')



  998 CONTINUE


      RETURN
      END
      INTEGER FUNCTION NQA008(IAA)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'HSTINC.INC'
      INTEGER       IAA







      IF (.NOT.HSTDON.OR.WIFPAR(828).NE.2) THEN
         CALL DSP010
         IF (WIFPAR(828).NE.2) CALL GVSTTB ('?NQAM046')
         HSTDON=.TRUE.
      END IF



      IF (LOCHST(IAA).EQ.'H'.OR.LOCHST(IAA).EQ.'3') THEN
         NQA008=2
      ELSE IF (LOCHST(IAA).EQ.'S') THEN
         NQA008=1
      ELSE
         NQA008=3
      END IF





      RETURN
      END
      SUBROUTINE NQA009



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       XESP
      PARAMETER     (XESP=100001)
      INTEGER       IFR, PTRUNT, IERR
      INTEGER       BOXARR(NQASZ,NQASZ,NQASZ,0:NQAHAT,NQANST)
      LOGICAL       GVFYON
      EQUIVALENCE   (BOXARR,ESPACE(XESP))







      CALL GVSBOX ('?M2252')
      CALL GVSTT6 ('?M2253')
      IF (.NOT.GVFYON('?M2254',' ')) GOTO 998



      WIFPAR(930)=1
      CALL NQA001



      WIFPAR(912)=0
      WIFPAR(913)=0
      WIFPAR(917)=3
      WIFPAR(918)=1



      CALL ESPSET (XESP,XESP+NQABAZ-1,48)
      CALL GVSCCC (LINE,FILDIR(30),'NQAPTR.TXT')
      CALL GVSROF (PTRUNT,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSOPF (LINE,PTRUNT,'NEW')



      DO 100 IFR=1,NQANF
         CALL GVSTTI2 ('?M4767',IFR,NQANF)



         CALL GVSTTI ('?NQAM028',IFR)
         CALL NQA005 (IFR,BOXARR)



         CALL NQA007 (IFR,PTRUNT,BOXARR)
         CALL ESPKIL (XESP,XESP+NQABAZ-1,48,'NQA009')
 100  CONTINUE
      CALL GVSCLF (PTRUNT)



      WIFPAR(923)=0



      WIFPAR(930)=0



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA010 (IBOX,SCALE,BOX,RNUM)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IBOX, IX, BOX(NQASZ3), IBYT
      REAL          REABOX(NQASZ3)



      BYTE          BYTBOX(NQASZ3)

      REAL          SCALE, TARGET, RNUM, HIGH



      PARAMETER      (TARGET=127.4)







      IF (RNUM.LT.1.E-3) CALL GVSTTB ('?NQAM048')



      DO 50 IX=1,NQASZ3
         REABOX(IX)=FLOAT(BOX(IX))/RNUM
   50 CONTINUE



      HIGH=0.0
      DO 100 IX=1,NQASZ3
         HIGH=MAX(HIGH,REABOX(IX))
  100 CONTINUE



      IF (HIGH.LT.0.1) THEN
         SCALE=1.0
         CALL GVSTTE ('?NQAM049')
         CALL GVSTTR ('?NQAM050',HIGH)
      ELSE 
         SCALE=TARGET/HIGH
      END IF
      IBYT=0
      DO 110 IX=1,NQASZ3
         IF (NQAMSK1(IX)) THEN
            IBYT=IBYT+1
            BYTBOX(IBYT)=NINT(SCALE*REABOX(IX))
         END IF
  110 CONTINUE



      IF (IBYT.NE.NQANMSK) THEN
         CALL GVSTTB ('?NQAM051')
         CALL GVSTTI2 ('?NQAM052',IBYT,NQANMSK)
         CALL GVSKIL
         GOTO 998
      END IF
      SCALE=1.0/SCALE
      WRITE (BOXUNT,REC=IBOX,ERR=999) (BYTBOX(IX),IX=1,IBYT)



      IF (IBOX.GT.NQANBX) THEN
         NQANBX=IBOX
         WRITE (BOXUNT,REC=1,ERR=999) NQANBX
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('NQA010')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA011 (IBOX,CPTR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IBOX, CPTR, IBYT, IX
      CHARACTER*(NQASZ3) BUF



      BYTE          BYTBOX(NQASZ3)

      EQUIVALENCE   (BUF,BYTBOX)







      IF (IBOX.GT.NQANBX.OR.IBOX.LT.0) THEN
         CALL GVSTTE ('?NQAM032')
         CALL GVSTTI ('IBOX=',IBOX)
         CPTR=0
         GOTO 998
      END IF
      IF (IBOX.EQ.0) THEN
         CPTR=0
         GOTO 998
      END IF
      CPTR=NQAIP(IBOX)
      IF (CPTR.GT.0) GOTO 998



      IF (NQAIC.GE.NQACP) NQAIP(NQACN(NQACP))=0



      READ (BOXUNT,REC=IBOX,ERR=999) BUF(1:NQANMSK)



      IBYT=0
      DO 10 IX=1,NQASZ3
         IF (NQAMSK1(IX)) THEN
            IBYT=IBYT+1
            NQACB(IX,NQACP)=BYTBOX(IBYT)
         ELSE
            NQACB(IX,NQACP)=0
         END IF
   10 CONTINUE
      IF (IBYT.NE.NQANMSK) THEN
         CALL GVSTTB ('?NQAM053')
         CALL GVSKIL
         GOTO 998
      END IF
      NQACN(NQACP)=IBOX
      NQAIP(IBOX)=NQACP



      CPTR=NQACP



      IF (NQAIC.LT.NQACP) NQAIC=NQACP
      NQACP=NQACP+1
      IF (NQACP.GT.NQANC) NQACP=1
      GOTO 998



  999 CONTINUE
      CALL GVSEIR ('NQA011')
      CALL GVSKIL



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA012 (IFR,IFT1,IFT2)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IAA, IFT1, IFT2, IFR, IRT
      REAL          BB, SS







      CALL NQA001
      IRT=NQARTP(IFR)



      DO 100 IAA=IFT1,IFT2
         IF (IRT.EQ.RESTYP(IAA)) THEN
            CALL NQA013 (IFR,IAA,BB,SS)



            NQARSC(IAA)=NQARSC(IAA)+BB+SS



            IF (NQAIBB(IFR)) THEN
               NQAXBB(IAA)=NQAXBB(IAA)+BB
               NQAXBS(IAA)=NQAXBS(IAA)+SS
            ELSE
               NQAXSB(IAA)=NQAXSB(IAA)+BB
               NQAXSS(IAA)=NQAXSS(IAA)+SS
            END IF
         END IF
 100  CONTINUE





      RETURN
      END
      SUBROUTINE NQA013 (IFR,IAA,BB,SS)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IAA, IFR, IST, NQA008, BOX(NQASZ3), IX, CPTR,
     +              IBOX, TMP2, IATT
      REAL          BB, SS, SCORE, TMP1, WGTBOX(NQASZ3)
      REAL          CONTRIB(0:NQAHAT)







      CALL NQA001



      CALL NQA003 (IAA,IFR,BOX,WGTBOX)



      CALL GVSRT0 (CONTRIB,NQAHAT+1)



      IST=NQA008(IAA)



      DO 190 IX=1,NQASZ3



         IATT=BOX(IX)
         IF (IATT.EQ.NQAIGN) GOTO 190
         IF (IATT.EQ.0) GOTO 190
         IBOX=NQABDB(IFR,IST,IATT)



         IF (IBOX.GT.0) THEN



            CPTR=NQAIP(IBOX)




            IF (CPTR.EQ.0) CALL NQA011 (IBOX,CPTR)



            TMP1=NQASC(IFR,IST,IATT)
            TMP2=NQACB(IX,CPTR)
            IF (ABS(TMP1).LT.10000.0.AND.ABS(TMP2).LT.10000.0) THEN
               SCORE=NINT(FLOAT(TMP2)*TMP1*WGTBOX(IX))
               CONTRIB(IATT)=CONTRIB(IATT)+SCORE
            END IF
         END IF
 190  CONTINUE



      BB=0.0
      SS=0.0
      DO 200 IATT=0,NQAHAT
         SCORE=CONTRIB(IATT)
         IF (SCORE.GT.NQAMSC) SCORE=NQAMSC
         IF (NQAJBB(IATT)) THEN
            BB=BB+SCORE
         ELSE
            SS=SS+SCORE
         END IF
  200 CONTINUE





      RETURN
      END
      SUBROUTINE NQA014 (IFT1,IFT2)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IFT1, IFT2, IFR, IAA
      LOGICAL       INTERRUPTED







      CALL GVSRT0 (NQARSC,MAXAA)
      CALL GVSRT0 (NQAXBB,MAXAA)
      CALL GVSRT0 (NQAXBS,MAXAA)
      CALL GVSRT0 (NQAXSB,MAXAA)
      CALL GVSRT0 (NQAXSS,MAXAA)



      IF (WIFPAR(930).EQ.0) THEN
         CALL GVSTTE ('?M1313')
         GOTO 998
      END IF



      DO 100 IFR=1,NQANF


         CALL NQA012 (IFR,IFT1,IFT2)
         IF (INTERRUPTED()) GOTO 998
 100  CONTINUE



      DO 200 IAA=1,NUMAAF
         CALL NQA029B (IAA)
 200  CONTINUE



  998 CONTINUE


      RETURN
      END

      SUBROUTINE NQA015 



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'


      RETURN
      END
      SUBROUTINE NQA015A



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IRT, JRT, IST, JST, IERR,
     +              NUM, SCRUNT, NORUNT, MAXN, I, IAC, NSEL, ITYP
      PARAMETER     (MAXN=10000)
      REAL          AVE(5), STD(5), VAL(5), OLDSTD(5),
     +              SCRVAL(5,MAXN), SELVAL(MAXN), OLDAVE(5)
      INTEGER       IACVAL(MAXN)
      EQUIVALENCE   (SCRVAL,ESPACE(1001))
      EQUIVALENCE   (SELVAL,ESPACE(1001+5*MAXN))
      EQUIVALENCE   (IACVAL,ESPACE(1001+6*MAXN))







      CALL ESPSET (1001,1000+7*MAXN,52)



      IF (WIFPAR(598).LT.100) THEN
         CALL GVSCCC (LINE,FILDIR(30),'NQANOR.WAT')
      ELSE
         CALL GVSCCC (LINE,FILDIR(30),'NQANOR.DAT')
      ENDIF
      CALL GVSROF (NORUNT,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSOPF (LINE,NORUNT,'NEW')
      CALL GVSROF (SCRUNT,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSRT0 (OLDAVE,5)
      CALL GVSRT0 (OLDSTD,5)
      DO 200 IRT=1,NQANRT
         DO 190 IST=1,NQANST



            NUM=0
            CALL GVSOPF ('NQASCR.DAT',SCRUNT,'OLD')
  300       CONTINUE
            CALL GVSFMT ('?FMT1157')
            READ (SCRUNT,FMT,END=310) JRT,JST,IAC,VAL
            IF (IRT.EQ.JRT.AND.IST.EQ.JST) THEN
               NUM=NUM+1
               IACVAL(NUM)=IAC
               DO 305 I=1,5
                  SCRVAL(I,NUM)=VAL(I)
  305          CONTINUE
               IF (NUM.GT.MAXN) THEN
                  CALL GVSCOD ('?NQAM054')
                  GOTO 310
               END IF
            END IF
            GOTO 300
  310       CONTINUE



            DO 360 IAC=1,NQANAC



               DO 365 ITYP=1,5
                  NSEL=0
                  CALL GVSFMT ('?FMT1158')
                  WRITE (LINE,FMT,ERR=999) ITYP
                  CALL GVSTT6 (LINE)
                  DO 370 I=1,NUM
                     IF (IACVAL(I).EQ.IAC) THEN
                        NSEL=NSEL+1
                        SELVAL(NSEL)=SCRVAL(ITYP,I)
                     END IF
  370             CONTINUE



                  CALL NQA030 (SELVAL,NSEL,AVE(ITYP),STD(ITYP))
                  CALL GVSFMT ('?R00088')
                  WRITE (LINE,FMT,ERR=999) IRT,IST,NSEL,AVE(ITYP),
     +             STD(ITYP)
                  CALL GVSTT6 (LINE)



                  CALL NQA031 (SELVAL,NSEL,AVE(ITYP),4.0*STD(ITYP))



                  CALL NQA030 (SELVAL,NSEL,AVE(ITYP),STD(ITYP))
                  CALL GVSFMT ('?R00089')
                  WRITE (LINE,FMT,ERR=999) IAC,NSEL,AVE(ITYP),STD(ITYP)
                  CALL GVSTT6 (LINE)



                  IF (IAC.GT.1) THEN
                     IF (OLDAVE(ITYP).GT.2.5*AVE(ITYP)) THEN
                        AVE(ITYP)=OLDAVE(ITYP)
                        STD(ITYP)=OLDSTD(ITYP)
                     END IF
                  END IF



                  IF (NSEL.LT.10.OR.STD(ITYP).LT.2.0) THEN



                     IF (IAC.EQ.1) THEN



                        OLDAVE(ITYP)=0.0
                        OLDSTD(ITYP)=1.0E9
                     END IF
                     AVE(ITYP)=OLDAVE(ITYP)
                     STD(ITYP)=OLDSTD(ITYP)
                  END IF
                  OLDAVE(ITYP)=AVE(ITYP)
                  OLDSTD(ITYP)=STD(ITYP)
  365          CONTINUE



               CALL GVSFMT ('?FMT1156')
               WRITE (NORUNT,FMT,ERR=997) IRT,IST,IAC,
     +          (AVE(ITYP),STD(ITYP),ITYP=1,5)
  360       CONTINUE
 190     CONTINUE
 200  CONTINUE

      CALL GVSCLF (NORUNT)
      WRITE (BOXUNT,REC=1,ERR=999) NQANBX
      CALL GVSCLF (BOXUNT)
      WIFPAR(923)=0
      CALL NQA001



      CALL ESPKIL (1001,1000+7*MAXN,52,'NQA015A')
      GOTO 998



 997  CALL GVSTTE ('?NQAM034')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('NQA015A')



  998 CONTINUE


      RETURN
      END

      LOGICAL FUNCTION NQA016 (IATT,JATT)



















      IMPLICIT      NONE
      INTEGER       IBTAB(167), IATT, JATT
      DATA IBTAB /
     +    1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1,
     +    4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 4, 4,
     +    7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7,
     +   10,10,10,10,10,12,10,10,10,10,10,10,11,10,10,10,10,10,10,10,
     +   13,14,16,16,20,   23,27,30,33,34,16,41,16,30,47,47,27,20,20,
     +      15,17,19,21,   24,28,30,27,35,38,41,19,30,48,48,29,50,21,
     +         18,17,22,   25,29,30,29,36,39,42,38,43,   49,29,51,22,
     +         18,18,22,   26,29,31,29,37,40,   39,44,         52,22,
     +            18,22,   26,   32,            40,45,         53,55,
     +               22,   25,                     46,         54,55,
     +               22,                           46,         22,56,
     +                                                         22,57,
     +                                                         22,
     +                                                         22/





      IF (IATT.GT.167.OR.JATT.GT.167.OR.IATT.LT.1.OR.JATT.LT.1) THEN
         NQA016=.FALSE.
         GOTO 998
      END IF
      NQA016=(IBTAB(IATT).EQ.IBTAB(JATT))



  998 CONTINUE


      RETURN 
      END
      SUBROUTINE NQA017 (IN1,IN2)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, JAA, IRT, IST, NQA008, IERR, MAXIAA, IMOD,
     +              ISTART, ISTOP, IN1, IN2, IFT1, IFT2, GVFLEN,
     +              NUMMDL, ACTIVE
      CHARACTER*23  IAAS, JAAS, DIF001
      REAL          V1, V2, V3, V4, V5, AVNQA, MAXVAL, A1, A2, A3, 
     +              A4, A5
      LOGICAL       INTERRUPTED, HASPROTEIN, WIFIR3, GVFRIN







      IF (.NOT.HASPROTEIN()) THEN
         CALL GVSTT6 ('?NQAM037D')
         GOTO 998
      END IF
      IF (WIFPAR(84).EQ.1) THEN
         CALL SHOWTEXT ('?M2397')
      END IF



      IF (DEFALL) THEN
         IFT1=IN1
         IFT2=IN2
      ELSE
         CALL SETIFT (IFT1,IFT2,IN1,IN2)
         IF (IFT1.EQ.0) GOTO 998
      END IF



      IF (WIFPAR(930).EQ.0) THEN
         CALL GVSTTE ('?R00206')
         GOTO 998
      END IF



      CALL WIF041X
      CALL NQA001
      CALL NQA020
      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)
      CALL NQA014 (IFT1,IFT2)
      IF (INTERRUPTED()) GOTO 998



      CALL SHOWTEXT ('?NQAM056')
      DO 100 IAA=IFT1,IFT2
         IRT=RESTYP(IAA)
         IF (IRT.GT.0.AND.IRT.LE.NQANRT) THEN
            IST=NQA008(IAA)
            IAAS=DIF001(IAA)
            IF (ABS(NQARSC(IAA)).GT.99.9) THEN
               CALL GVSFMT ('?R00090')
            ELSE
               CALL GVSFMT ('?R00091')
            END IF
            CALL GVSCTB (LINE,80)
            IF (.NOT.GVFRIN(NQARSC(IAA),-10.0,10.0)) NQARSC(IAA)=0.0
            IF (.NOT.GVFRIN(NQAXBB(IAA),-10.0,10.0)) NQAXBB(IAA)=0.0
            IF (.NOT.GVFRIN(NQAXBS(IAA),-10.0,10.0)) NQAXBS(IAA)=0.0
            IF (.NOT.GVFRIN(NQAXSB(IAA),-10.0,10.0)) NQAXSB(IAA)=0.0
            IF (.NOT.GVFRIN(NQAXSS(IAA),-10.0,10.0)) NQAXSS(IAA)=0.0
            WRITE (LINE,FMT,ERR=999) IAAS,IST,NQARSC(IAA),
     +       NQAXBB(IAA),NQAXBS(IAA),NQAXSB(IAA),NQAXSS(IAA)
            IF (WIFPAR(279).EQ.0) CALL GVSTT6 (LINE)



            PRPVAL(IAA)=NQARSC(IAA)
         END IF
 100  CONTINUE
      CALL NQA033 (IFT1,IFT2,A1,A2,A3,A4,A5,V1,V2,V3,V4,V5,IERR)
      GENRVL(44)=V1



      IF (IERR.EQ.0.AND.WIFPAR(838).EQ.0) THEN
         CALL GVSLIN
         IF ((IFT1.EQ.1.AND.IFT2.EQ.NUMAAF).OR.(IFT2-IFT1.GE.29)) THEN
            GENIVL(8)=1
            CALL GVSFMT ('?NQAM035')
            WRITE (LINE,FMT,ERR=999) A1,V1
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM036')
            WRITE (LINE,FMT,ERR=999) A2,V2
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037')
            WRITE (LINE,FMT,ERR=999) A3,V3
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037A')
            WRITE (LINE,FMT,ERR=999) A4,V4
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037B')
            WRITE (LINE,FMT,ERR=999) A5,V5
            CALL GVSTT6 (LINE)
         ELSE
            GENIVL(8)=0
            CALL GVSFMT ('?NQAM035')
            WRITE (LINE,FMT,ERR=999) A1
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM036')
            WRITE (LINE,FMT,ERR=999) A2
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037')
            WRITE (LINE,FMT,ERR=999) A3
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037A')
            WRITE (LINE,FMT,ERR=999) A4
            CALL GVSTT6 (LINE)
            CALL GVSFMT ('?NQAM037B')
            WRITE (LINE,FMT,ERR=999) A5
            CALL GVSTT6 (LINE)
            CALL GVSTT6 ('?NQAM037C')
         END IF
         CALL GVSLIN
      END IF



      IF (WIFPAR(838).NE.0) GOTO 998



      IF (WIFPAR(279).EQ.0) GOTO 998
      CALL CDB013 ('BADNQA','NEUNQA','GOODNQA')



      CALL GVSBTT (WRK1TF,NUMAAT)
 60   CONTINUE
      MAXIAA=0
      MAXVAL=-2.50
      DO 50 IAA=1,NUMAAF
         IF (WRK1TF(IAA).AND.PRPVAL(IAA).LT.MAXVAL.AND.
     +       PRPVAL(IAA).GT.-999.0) THEN
            MAXVAL=PRPVAL(IAA)
            MAXIAA=IAA
         END IF
 50   CONTINUE
      IF (MAXIAA.GT.0) THEN
         IAA=MAXIAA
         WRK1TF(IAA)=.FALSE.
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)), 
     +    PRPVAL(IAA)
         CALL PDBC93 (LINE2)
         GOTO 60
      END IF



      CALL CDB012



      CALL CDB013 ('BADSNQA',' ','GOODSNQA')



      ISTART=1
 299  CONTINUE
      ISTOP=0
      IF (ISTART.LE.NUMAAF-3) THEN
         DO 300 IAA=ISTART,NUMAAF



            IF (IAA.GE.NUMAAF) ISTOP=IAA
            IF (WIFIR3(IAA)) ISTOP=IAA
            IF (RESTYP(IAA).GT.NQANRT) ISTOP=IAA
            IF (PRPVAL(IAA).GT.-1.75) ISTOP=IAA-1



            IF (ISTOP-ISTART.GT.2) THEN



               AVNQA=0.0
               DO 290 JAA=ISTART,ISTOP
                  AVNQA=AVNQA+PRPVAL(JAA)
 290           CONTINUE
               AVNQA=AVNQA/FLOAT(ISTOP-ISTART+1)



               CALL PDBC92A (ISTART,0)
               CALL GVSSTX (IAAS,LINE92(1:23))
               CALL PDBC92A (ISTOP,0)
               CALL GVSSTX (JAAS,LINE92(1:23))
               WRITE (LINE,PDBFMT,ERR=999) IAAS,JAAS,AVNQA
               CALL PDBC93 (LINE)
            END IF



            ISTART=ISTOP+1
 300     CONTINUE
         GOTO 299
      END IF



      CALL CDB012



      IF (GENIVL(8).EQ.1) THEN
         IF (V1.LT.-4.0) THEN
            CALL PDBMES ('BADMNQA')
         ELSE IF (V1.LT.-3.0) THEN
            CALL PDBMES ('MEDMNQA')
         ELSE
            CALL PDBMES ('GOODMNQA')
         END IF
      END IF



      ACTIVE=0
      VALACT=2
      DO 700 IMOD=1,NUMMDL()
         CALL WIFPUSHPPP (846,IMOD)
         CALL NQA033 (IFT1,IFT2,A1,A2,A3,A4,A5,V1,V2,V3,V4,V5,IERR)
         CALL WIFPOPPPP (846)
         IF (IERR.EQ.0) THEN
            NMRVAL(1,IMOD)=A1
            NMRVAL(2,IMOD)=V1
            ACTIVE=ACTIVE+1
         ELSE
            NMRVAL(1,IMOD)=-999.9
            NMRVAL(2,IMOD)=-999.9
         END IF
  700 CONTINUE
      IF (ACTIVE.GT.1) CALL PDBMES ('NQANMR')



      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('NQA017')



 998  CONTINUE

      
      RETURN
      END
      SUBROUTINE NQA018



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'







      NQAIC=0
      NQACP=1
      CALL GVSIT0 (NQAIP,NQAMBX)





      RETURN
      END
      SUBROUTINE NQA019



















      IMPLICIT      NONE


      RETURN
      END
      SUBROUTINE NQA020



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA





      DO 10 IAA=1,NUMAAT
         ACCDON(IAA)=.FALSE.
 10   CONTINUE
      CALL ENVTOT




      
      RETURN
      END
      SUBROUTINE NQA021 (IAA,SCORE)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IFR, IRT, IAA
      REAL          SCORE







      CALL NQA001
      NQARSC(IAA)=0.0
      IRT=RESTYP(IAA)
      IF (IRT.GT.0.AND.IRT.LE.NQANRT) THEN



         DO 10 IFR=NQASFR(IRT),NQAEFR(IRT)
            CALL NQA012 (IFR,IAA,IAA)
 10      CONTINUE



         CALL NQA029B (IAA)
         SCORE=NQAXSS(IAA)
      ELSE
         SCORE=0.0
      END IF





      RETURN
      END
      REAL FUNCTION NQA024 (IATT,RX,RY,RZ)



















      IMPLICIT      NONE
      REAL          RX, RY, RZ, RESULT(8), SCARR(1)
      INTEGER       IATT, IATTARR(1)




      SCARR(1)=10.0
      IATTARR(1)=IATT
      CALL NQA024A (IATTARR,SCARR,1,RX,RY,RZ,0.0,0.0,0.0,RESULT)
      NQA024=RESULT(1)





      RETURN
      END
      SUBROUTINE NQA024A (IATTARR,SCARR,NIATT,RX,RY,RZ,DX,DY,DZ,RESULT)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INCLUDE       'SYMINC.INC'
      INTEGER       IATT, IFR, IST, IBOX, JAAARR(100), JAASYM(100),
     +              ICONT, IX1, IY1, IZ1, NQA008, CPTR, IERR, IRT, IAA,
     +              NUM, ISYM, JSYM, IX2, IY2, IZ2, SYMNEG, IIATT,
     +              I2, J2, K2, I, J, K, L, NIATT, IATTARR(NIATT)
      REAL          RX, RY, RZ, RMAT(3,3), TVEC(3), TMP(3), TMP1,
     +              FIX, FIY, FIZ, FX1, FX2, FY1, FY2, FZ1, FZ2, RAD,
     +              CX, CY, CZ, RESULT(0:1,0:1,0:1,*), DX, DY, DZ, TMP2,
     +              SCARR(NIATT), SCALE, NQA040







      L(IX1,IY1,IZ1)=1+IX1+NQASZ*(IY1+NQASZ*IZ1)



      IF (WIFPAR(924).EQ.0) THEN
         CALL GVSRT0 (RESULT,8)
      ELSE
         CALL GVSRT0 (RESULT,8*NIATT)
      END IF



      CX=RX+0.5*DX
      CY=RY+0.5*DY
      CZ=RZ+0.5*DZ
      RAD=NQADST+0.5*SQRT(DX**2+DY**2+DZ**2)
      CALL FCONAA1I (CX,CY,CZ,RAD,JAAARR,JAASYM,NUM,100)
      IF (NUM.EQ.0) GOTO 998
      I2=1
      J2=1
      K2=1
      IF (DX.LE.0.0) I2=0
      IF (DY.LE.0.0) J2=0
      IF (DZ.LE.0.0) K2=0



      DO 100 ICONT=1,NUM
         IAA=JAAARR(ICONT)
         ISYM=JAASYM(ICONT)
         JSYM=SYMNEG(ISYM)




         IRT=RESTYP(IAA)
         IF (IRT.GT.NQANRT.OR.IRT.LT.1) GOTO 100



         IST=NQA008(IAA)



         DO 200 IFR=NQASFR(IRT),NQAEFR(IRT)



            CALL NQA002 (IAA,IFR,RMAT,TVEC,IERR)
            IF (IERR.NE.0) GOTO 200



            DO 500 I=0,I2
               DO 490 J=0,J2
                  DO 480 K=0,K2
                     TMP(1)=RX+I*DX
                     TMP(2)=RY+J*DY
                     TMP(3)=RZ+K*DZ



                     SCALE=NQA040(TMP(1),TMP(2),TMP(3))



                     IF (JSYM.GT.1) CALL GVSMPV (TMP,SYMMAT(1,1,JSYM),
     +                SYMVEC(1,JSYM))
                     CALL GVSMPV (TMP,RMAT,TVEC)




                     FIX=(TMP(1)-NQASTR)/NQAGRD
                     IX1=INT(FIX)
                     IX2=IX1+1
                     IF (FIX.LT.0.0.OR.IX2.GE.NQASZ) GOTO 480
                     FIY=(TMP(2)-NQASTR)/NQAGRD
                     IY1=INT(FIY)
                     IY2=IY1+1
                     IF (FIY.LT.0.0.OR.IY2.GE.NQASZ) GOTO 480
                     FIZ=(TMP(3)-NQASTR)/NQAGRD
                     IZ1=INT(FIZ)
                     IZ2=IZ1+1
                     IF (FIZ.LT.0.0.OR.IZ2.GE.NQASZ) GOTO 480



                     FX1=FIX-FLOAT(IX1)
                     FY1=FIY-FLOAT(IY1)
                     FZ1=FIZ-FLOAT(IZ1)
                     FX2=1.0-FX1
                     FY2=1.0-FY1
                     FZ2=1.0-FZ1



                     DO 700 IIATT=1,NIATT
                        IATT=IATTARR(IIATT)



                        IBOX=NQABDB(IFR,IST,IATT)
                        IF (IBOX.EQ.0) GOTO 700
                        CPTR=NQAIP(IBOX)



                        IF (CPTR.EQ.0) CALL NQA011 (IBOX,CPTR)



                        TMP2=FX2*FY2*FZ2*NQACB(L(IX1,IY1,IZ1),CPTR)+
     +                       FX1*FY2*FZ2*NQACB(L(IX2,IY1,IZ1),CPTR)+
     +                       FX2*FY1*FZ2*NQACB(L(IX1,IY2,IZ1),CPTR)+
     +                       FX1*FY1*FZ2*NQACB(L(IX2,IY2,IZ1),CPTR)+
     +                       FX2*FY2*FZ1*NQACB(L(IX1,IY1,IZ2),CPTR)+
     +                       FX1*FY2*FZ1*NQACB(L(IX2,IY1,IZ2),CPTR)+
     +                       FX2*FY1*FZ1*NQACB(L(IX1,IY2,IZ2),CPTR)+
     +                       FX1*FY1*FZ1*NQACB(L(IX2,IY2,IZ2),CPTR)



                        IF (IATT.GE.0) THEN
                           TMP1=NQASC(IFR,IST,IATT)/FLOAT(NQAFRQ(IRT))
                        ELSE 
                           TMP1=1.0
                        END IF
                        IF (WIFPAR(924).EQ.0) THEN
                           RESULT(I,J,K,1)=RESULT(I,J,K,1)+
     +                          SCARR(IIATT)*TMP2*TMP1*SCALE
                        ELSE
                           RESULT(I,J,K,IIATT)=SCARR(IIATT)
     +                          *TMP2*TMP1*SCALE
                        END IF



  700                CONTINUE



  480             CONTINUE
  490          CONTINUE
  500       CONTINUE



  200    CONTINUE



  100 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA025



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAPINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IERR, IAA, IAT, I, IX, IY, IZ, IATT, GVFLFI, NIATT,
     +              IATTARR(50), IFR, IST
      LOGICAL       GVFIBN, INTERRUPTED
      REAL          XMIN, YMIN, ZMIN, XMAX, YMAX, ZMAX, RESOLU,
     +              RX, RY, RZ, RESULT(8), SCARR(50), SCALE, TSCAL
      CHARACTER*80  WORD







      IF (WIFPAR(930).EQ.0) THEN
         CALL GVSTTE ('?R00206')
         GOTO 998
      END IF



      IF (MAPNOW.EQ.MAXMAP+1) THEN
         CALL GVSTTE ('?NEWE318')
         IERR=1
         GOTO 998
      END IF
      IF (.NOT.GVFIBN(MAPNOW,1,MAXMAP)) THEN
         CALL GVSTTB ('?NEWB119')
         IERR=1
         GOTO 998
      END IF



      IERR=0
      XMIN= 10000.0
      YMIN= 10000.0
      ZMIN= 10000.0
      XMAX=-10000.0
      YMAX=-10000.0
      ZMAX=-10000.0
      PROD(MAPNOW)=1.0
      IPLUS(MAPNOW)=0
      MAPMIN(MAPNOW)=0.0
      MAPMAX(MAPNOW)=1000.0
      CALL GVSBTF (WRK1TF,MAXAA)



      CALL NQA001



      CALL IPROMPT ('?NEWP70')
      CALL GVSCTB (MAPNAM(MAPNOW),80)
      CALL NEEDWORD (MAPNAM(MAPNOW),' ',IERR)
      IF (IERR.NE.0) GOTO 998



      CALL IPROMPT ('?NEWP71')
      CALL GVSCTB (MAPTXT(MAPNOW),80)
      CALL GETFULLLINE (MAPTXT(MAPNOW),IERR)
      IF (IERR.EQ.1) GOTO 998



      CALL WIFWTF ('?NQAM057',IERR)
      IF (IERR.NE.0) GOTO 998



 224  CONTINUE
      CALL IPROMPT ('?NQAM058')
      CALL NEEDWORD (WORD,' ',IERR)
      IF (IERR.EQ.1) GOTO 998
      CALL GVSCUC (WORD)
      I=GVFLFI(1,IATT,WORD)
      IF (I.EQ.1) THEN
         IATTARR(1)=IATT
         SCARR(1)=10.0
         NIATT=1
      ELSE 



         DO 225 IATT=1,NQANVA
            IF (NQAVNM(IATT).EQ.WORD) THEN
               IATTARR(1)=NQAVAT+IATT
               SCARR(1)=10.0
               NIATT=1
               GOTO 226
            END IF
  225    CONTINUE
         CALL GVSTTE ('?M1315')
         GOTO 224
  226    CONTINUE
      END IF



      TSCAL=0
      DO 250 I=1,NIATT
         IATT=IATTARR(I)
         SCALE=0.0
         DO 246 IFR=1,NQANF
            DO 243 IST=1,NQANST
               SCALE=SCALE+NQASC(IFR,IST,IATT)
  243       CONTINUE
  246    CONTINUE
         CALL GVSFMT ('?R00102')
         WRITE (LINE,FMT,ERR=999) NQAREV(IATTARR(I)),SCARR(I),
     +    SCARR(I)*SCALE/1000.0
         CALL GVSTT6 (LINE)
         TSCAL=TSCAL+SCARR(I)*SCALE
  250 CONTINUE








      CALL GVSTTR ('?R00095',TSCAL/1000.0)
      DO 260 I=1,NIATT
         SCARR(I)=SCARR(I)*1.0E6/TSCAL
  260 CONTINUE



      DO 30 IAA=1,NUMAAT
         IF (.NOT.WRK1TF(IAA)) GOTO 30
         DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (PROTON(IAT)) GOTO 20
            XMIN=MIN(XMIN,XCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            YMIN=MIN(YMIN,YCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            ZMIN=MIN(ZMIN,ZCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            XMAX=MAX(XMAX,XCOORD(IAT)+VDWRAD(IAT)+NQACLS)
            YMAX=MAX(YMAX,YCOORD(IAT)+VDWRAD(IAT)+NQACLS)
            ZMAX=MAX(ZMAX,ZCOORD(IAT)+VDWRAD(IAT)+NQACLS)
   20    CONTINUE
   30 CONTINUE



      ACELLM(MAPNOW)=XMAX-XMIN
      BCELLM(MAPNOW)=YMAX-YMIN
      CCELLM(MAPNOW)=ZMAX-ZMIN



      RESOLU=MAX(ACELLM(MAPNOW)/FLOAT(MAXGRD),
     +           BCELLM(MAPNOW)/FLOAT(MAXGRD),
     +           CCELLM(MAPNOW)/FLOAT(MAXGRD))+0.1
      IF (WIFPAR(808).GT.10) THEN
         RESOLU=MAX(RESOLU,FLOAT(WIFPAR(808))/100.0)
      END IF



      RESOLU=MAX(RESOLU,NQAGRD/2.0)



      ALPHAM(MAPNOW)=90.0
      BETAM(MAPNOW)=90.0
      GAMMAM(MAPNOW)=90.0



      NDIVA(MAPNOW)=2*NINT(ACELLM(MAPNOW)/2.0/RESOLU)
      NDIVB(MAPNOW)=2*NINT(BCELLM(MAPNOW)/2.0/RESOLU)
      NDIVC(MAPNOW)=2*NINT(CCELLM(MAPNOW)/2.0/RESOLU)



      NU(MAPNOW)=NDIVA(MAPNOW)
      NV(MAPNOW)=NDIVB(MAPNOW)
      NW(MAPNOW)=NDIVC(MAPNOW)



      STEPU(MAPNOW)=ACELLM(MAPNOW)/NDIVA(MAPNOW)
      STEPV(MAPNOW)=BCELLM(MAPNOW)/NDIVB(MAPNOW)
      STEPW(MAPNOW)=CCELLM(MAPNOW)/NDIVC(MAPNOW)



      DO 80 IZ=1,NW(MAPNOW)
         DO 70 IY=1,NV(MAPNOW)
            DO 60 IX=1,NU(MAPNOW)
               GRID(IX,IY,IZ)=0
   60       CONTINUE
   70    CONTINUE
   80 CONTINUE



      UVWORG(1,MAPNOW)=XMIN/ACELLM(MAPNOW)
      UVWORG(2,MAPNOW)=YMIN/BCELLM(MAPNOW)
      UVWORG(3,MAPNOW)=ZMIN/CCELLM(MAPNOW)
      CALL GVSRT0 (UVWMAT(1,1,MAPNOW),9)
      UVWMAT(1,1,MAPNOW)=STEPU(MAPNOW)/ACELLM(MAPNOW)
      UVWMAT(2,2,MAPNOW)=STEPV(MAPNOW)/BCELLM(MAPNOW)
      UVWMAT(3,3,MAPNOW)=STEPW(MAPNOW)/CCELLM(MAPNOW)



      CALL ENVTOT



      WIFPAR(909)=-1



      CALL GVSTTI ('?R00096',NW(MAPNOW))
      CALL GVSTTI2 ('?R00097',NU(MAPNOW),NV(MAPNOW))
      DO 180 IZ=1,NW(MAPNOW),2
         CALL GVSTTI ('?R00098',IZ)
         RZ=ZMIN+(IZ-1)*STEPW(MAPNOW)
         DO 170 IY=1,NV(MAPNOW),2
            IF (INTERRUPTED()) GOTO 181
            RY=YMIN+(IY-1)*STEPV(MAPNOW)
            DO 160 IX=1,NU(MAPNOW),2
               RX=XMIN+(IX-1)*STEPU(MAPNOW)
               CALL NQA024A (IATTARR,SCARR,NIATT,RX,RY,RZ,
     +          STEPU(MAPNOW),STEPV(MAPNOW),STEPW(MAPNOW),RESULT)
               GRID(IX,IY,IZ)=NINT(RESULT(1))
               GRID(IX+1,IY,IZ)=NINT(RESULT(2))
               GRID(IX,IY+1,IZ)=NINT(RESULT(3))
               GRID(IX+1,IY+1,IZ)=NINT(RESULT(4))
               GRID(IX,IY,IZ+1)=NINT(RESULT(5))
               GRID(IX+1,IY,IZ+1)=NINT(RESULT(6))
               GRID(IX,IY+1,IZ+1)=NINT(RESULT(7))
               GRID(IX+1,IY+1,IZ+1)=NINT(RESULT(8))
  160       CONTINUE
  170    CONTINUE
  180 CONTINUE
  181 CONTINUE



      CALL WIF180



      WIFPAR(909)=-2
      CALL NQA002(1,1,ESPACE(1),ESPACE(1),IERR)



      CALL GVSTTI ('?R00099',WIFPAR(910))
      CALL GVSTTI ('?R00100',WIFPAR(911))
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('NQA025')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA026 (ISEQ,IERR)



















      IMPLICIT      NONE 
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       ISEQ, IERR
      CHARACTER*14  FNAM
      LOGICAL       GVFISF, JACKIT

      RETURN
      END
      SUBROUTINE NQA027



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'




      IF (WIFPAR(923).NE.0) THEN
         WIFPAR(923)=0
         CALL GVSCLF (BOXUNT)
      END IF





      RETURN
      END
      SUBROUTINE NQA028 (BASIS,IFR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      REAL          BASIS(3,NQAAPF)      
      INTEGER       IFR, IRT, IIAT







      IRT=NQARTP(IFR)




      DO 10 IIAT=1,NQANAT(IFR)
         BASIS(1,IIAT)=STDCRD(1,NQAIAT(IIAT,IFR),IRT)-
     +                 STDCRD(1,NQAIAT(1,IFR),IRT)
         BASIS(2,IIAT)=STDCRD(2,NQAIAT(IIAT,IFR),IRT)-
     +                 STDCRD(2,NQAIAT(1,IFR),IRT)
         BASIS(3,IIAT)=STDCRD(3,NQAIAT(IIAT,IFR),IRT)-
     +                 STDCRD(3,NQAIAT(1,IFR),IRT)
 10   CONTINUE



      IF (NQANAT(IFR).GT.4) CALL GVSCM1 (BASIS,NQANAT(IFR))





      RETURN
      END
      SUBROUTINE NQA029



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IST,IRT,IAC





      DO 300 IST=1,NQANST
         DO 200 IRT=1,NQANRT
            DO 100 IAC=1,NQANAC
               NQAAVE(TOTAVE,IRT,IST,IAC)=0.0
               NQAAVE(TOTSTD,IRT,IST,IAC)=1.0
               NQAAVE(BBAVE,IRT,IST,IAC)=0.0
               NQAAVE(BBSTD,IRT,IST,IAC)=1.0
               NQAAVE(BSAVE,IRT,IST,IAC)=0.0
               NQAAVE(BSSTD,IRT,IST,IAC)=1.0
               NQAAVE(SBAVE,IRT,IST,IAC)=0.0
               NQAAVE(SBSTD,IRT,IST,IAC)=1.0
               NQAAVE(SSAVE,IRT,IST,IAC)=0.0
               NQAAVE(SSSTD,IRT,IST,IAC)=1.0
  100       CONTINUE
  200    CONTINUE
  300 CONTINUE
      CALL NQA029A





      RETURN
      END
      SUBROUTINE NQA029A



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'







      NQASAV(TOTAVE)=0.0
      NQASAV(TOTSTD)=1.0
      NQASAV(BBAVE)=0.0
      NQASAV(BBSTD)=1.0
      NQASAV(BSAVE)=0.0
      NQASAV(BSSTD)=1.0
      NQASAV(SBAVE)=0.0
      NQASAV(SBSTD)=1.0
      NQASAV(SSAVE)=0.0
      NQASAV(SSSTD)=1.0





      RETURN
      END
      SUBROUTINE NQA029B (IAA)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IAA, IRT, IST, IAC, NQA008, NQA032







      IRT=RESTYP(IAA)



      IF (IRT.GT.0.AND.IRT.LE.NQANRT) THEN



         IST=NQA008(IAA)



         IAC=NQA032(IAA)



         IF (NQAAVE(TOTSTD,IRT,IST,IAC).GT.1.E-3) THEN
            NQARSC(IAA)=(NQARSC(IAA)-NQAAVE(TOTAVE,IRT,IST,IAC))/
     +       NQAAVE(TOTSTD,IRT,IST,IAC)
         ELSE
            CALL GVSTTB ('?R00103')
         END IF

         IF (NQAAVE(BBSTD,IRT,IST,IAC).GT.1.E-3) THEN
            NQAXBB(IAA)=(NQAXBB(IAA)-NQAAVE(BBAVE,IRT,IST,IAC))/
     +       NQAAVE(BBSTD,IRT,IST,IAC)
         ELSE
            CALL GVSTTB ('?R00103')
         END IF

         IF (NQAAVE(BSSTD,IRT,IST,IAC).GT.1.E-3) THEN
            NQAXBS(IAA)=(NQAXBS(IAA)-NQAAVE(BSAVE,IRT,IST,IAC))/
     +       NQAAVE(BSSTD,IRT,IST,IAC)
         ELSE
            CALL GVSTTB ('?R00103')
         END IF

         IF (NQAAVE(SBSTD,IRT,IST,IAC).GT.1.E-3) THEN
            NQAXSB(IAA)=(NQAXSB(IAA)-NQAAVE(SBAVE,IRT,IST,IAC))/
     +       NQAAVE(SBSTD,IRT,IST,IAC)
         ELSE
            CALL GVSTTB ('?R00103')
         END IF

         IF (NQAAVE(SSSTD,IRT,IST,IAC).GT.1.E-3) THEN
            NQAXSS(IAA)=(NQAXSS(IAA)-NQAAVE(SSAVE,IRT,IST,IAC))/
     +       NQAAVE(SSSTD,IRT,IST,IAC)
         ELSE
            CALL GVSTTB ('?R00103')
         END IF
      END IF





      RETURN
      END
      SUBROUTINE NQA030 (ARR,NUM,AVE,STD)



















      IMPLICIT      NONE 
      INTEGER       NUM
      REAL          ARR(*), AVE, STD, ADEV, VAR





      IF (NUM.GT.1) THEN
         CALL NQA030A (ARR,NUM,AVE,ADEV,STD,VAR)
      ELSE
         IF (NUM.EQ.1) THEN
            AVE=ARR(1)
         ELSE 
            AVE=0.0
         END IF
         STD=1.0
      END IF
      IF (STD.EQ.0.0) THEN
         CALL GVSTT6 ('?R00103')
         STD=1.0
      END IF





      RETURN
      END
      SUBROUTINE NQA030A (ROW,N,AVE,ADEV,SDEV,VAR)



















      IMPLICIT      NONE
      INTEGER       N, J
      REAL          ROW(N), S, P, AVE,ADEV,SDEV,VAR







      IF (N.LE.1) THEN
         CALL GVSTTE ('?R00104')
         CALL GVSTTI ('?R00105',N)
         GOTO 998
      END IF



      S=0.0
      DO 10 J=1,N
         S=S+ROW(J)
   10 CONTINUE
      AVE=S/N



      ADEV=0.
      VAR=0.
      DO 20 J=1,N
         S=ROW(J)-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
   20 CONTINUE
      ADEV=ADEV/N
      VAR=VAR/(N-1)
      SDEV=SQRT(VAR)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA031 (ARR,NUM,AVE,DEV)



















      IMPLICIT      NONE
      REAL          ARR(*), AVE, DEV
      INTEGER       NUM, I





      I=1
   10 CONTINUE
         IF (I.GT.NUM) GOTO 998
         IF (ARR(I).GT.AVE+DEV.OR.ARR(I).LT.AVE-DEV) THEN
            ARR(I)=ARR(NUM)
            NUM=NUM-1
         ELSE
            I=I+1
         END IF
      GOTO 10



  998 CONTINUE


      RETURN
      END
      INTEGER FUNCTION NQA032(IAA)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IAA, IAT, IST, NQA008
      REAL          TACC, MAXACC(NQANRT,NQANST)
      SAVE          MAXACC

      DATA          MAXACC
     +    /28,23,32,46,61,15,43,39,52,43,45,36,33,47,53,34,30,36,43,47,
     +     36,29,50,45,79,31,54,49,57,48,50,39,37,50,63,36,36,37,71,58,
     +     50,43,55,64,78,41,72,63,79,71,80,58,53,67,83,49,55,60,71,70/

















      IF (RESTYP(IAA).GT.0.AND.RESTYP(IAA).LE.NQANRT) THEN
         IF (.NOT.ACCDON(IAA)) CALL WIF041 (IAA)
         IST=NQA008(IAA)
         TACC=0
         DO 120 IAT=PNTAAS(IAA),PNTAAE(IAA)
            TACC=TACC+ACCESS(IAT)
  120    CONTINUE
         TACC=TACC/MAXACC(RESTYP(IAA),IST)
         NQA032=MIN(INT(NQANAC*TACC)+1,NQANAC)
      ELSE
         NQA032=1
      END IF





      RETURN
      END
      SUBROUTINE NQA033 (IFT1,IFT2,A1,A2,A3,A4,A5,V1,V2,V3,V4,V5,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INCLUDE       'RESULT.INC'
      REAL          V1, V2, V3, V4, V5, A1, A2, A3, A4, A5
      INTEGER       N1, N2, N3, N4, N5
      REAL          S1, S2, S3, S4, S5
      INTEGER       IAA, IRT, NAT, NATBB, NATSS, IFT1, IFT2, IERR







      IF (IFT1.LT.1.OR.IFT2.LT.IFT1.OR.IFT2.GT.NUMAAT) THEN
         CALL GVSTTE ('?R00106')
         V1=0.0
         V2=0.0
         V3=0.0
         V4=0.0
         V5=0.0
         A1=0.0
         A2=0.0
         A3=0.0
         A4=0.0
         A5=0.0
         IERR=1
         GOTO 998
      END IF



      N1=0
      N2=0
      N3=0
      N4=0
      N5=0
      S1=0.0
      S2=0.0
      S3=0.0
      S4=0.0
      S5=0.0



      DO 100 IAA=IFT1,IFT2



         IF (WIFPAR(846).NE.0.AND.WIFPAR(846).NE.MODNMB(IAA)) GOTO 100
         IRT=RESTYP(IAA)
         IF (IRT.LE.NQANRT.AND.IRT.GT.0) THEN
            NAT=HATPRA(IRT)
            IF (FAMTYP(IRT).EQ.1) THEN
               NATBB=MIN(5,NAT)
               NATSS=NAT-NATBB
            ELSE
               NATBB=0
               NATSS=NAT
            END IF
            N1=N1+NAT
            S1=S1+NAT*NQARSC(IAA)
            N2=N2+NATBB
            S2=S2+NATBB*NQAXBB(IAA)
            N3=N3+NATBB
            S3=S3+NATBB*NQAXBS(IAA)
            N4=N4+NATSS
            S4=S4+NATSS*NQAXSB(IAA)
            N5=N5+NATSS
            S5=S5+NATSS*NQAXSS(IAA)
         END IF
  100 CONTINUE
      IF (N1.GT.0) THEN
         A1=S1/N1
         V1=(A1-NQASAV(TOTAVE))/NQASAV(TOTSTD)
      ELSE
         A1=0.0
         V1=0.0
      END IF
      IF (N2.GT.0) THEN
         A2=S2/N2
         V2=(A2-NQASAV(BBAVE))/NQASAV(BBSTD)
      ELSE
         A2=0.0
         V2=0.0
      END IF
      IF (N3.GT.0) THEN
         A3=S3/N3
         V3=(A3-NQASAV(BSAVE))/NQASAV(BSSTD)
      ELSE
         A3=0.0
         V3=0.0
      END IF
      IF (N4.GT.0) THEN
         A4=S4/N4
         V4=(A4-NQASAV(SBAVE))/NQASAV(SBSTD)
      ELSE 
         A4=0.0
         V4=0.0
      END IF
      IF (N5.GT.0) THEN
         A5=S5/N5
         V5=(A5-NQASAV(SSAVE))/NQASAV(SSSTD)
      ELSE
         A5=0.0
         V5=0.0
      END IF
      GENRVL(15)=V1
      GENRVL(16)=V2
      GENRVL(17)=V3
      GENRVL(18)=V4
      GENRVL(19)=V5
      GENRVL(38)=A1
      GENRVL(39)=A2
      GENRVL(40)=A3
      GENRVL(41)=A4
      GENRVL(42)=A5
      IF (N1.EQ.0) THEN
         IERR=1
      ELSE
         IERR=0
      END IF



  998 CONTINUE


      RETURN
      END
      REAL FUNCTION NQA035 (IATT)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IAA, IRT, IATT, ISOUP, JATARR(1), JATSYM(1),
     +              IAT, NUM
      REAL          FRAQ, MULT, JATDST(1)
      LOGICAL       WIFISW
      PARAMETER     (MULT=30.0)





      IF (IATT.EQ.NQAIGN) THEN
         CALL GVSTTE ('?R00107')
         NQA035=0.0
         GOTO 998
      END IF
      IF (IATT.EQ.NQAH2O) THEN



         FRAQ=0.0
         CALL ENVNOWAT
         DO 100 ISOUP=1,NUMSOU
            IF (.NOT.WIFISW(ISOUP)) GOTO 100
            DO 90 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
               DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
                  IF (PROTON(IAT)) GOTO 80
                  CALL FCONATI (IAT,NQATCH,JATARR,JATSYM,JATDST,NUM,1)
                  FRAQ=FRAQ+NUM
   80          CONTINUE
   90       CONTINUE
  100    CONTINUE





            FRAQ=MAX(FRAQ,NUMAAF/4.0)
      ELSE IF (IATT.EQ.0) THEN



         FRAQ=FLOAT(NUMATF)/10.0
      ELSE
         IRT=NQAIRT(IATT)
         IF (IRT.EQ.0.OR.IRT.GT.NQANRT) THEN



            FRAQ=0.0
            DO 200 IAA=1,NUMAAT
               IF (IRT.EQ.0.OR.IRT.GT.NQANRT) FRAQ=FRAQ+
     +          PNTAAE(IAA)-PNTAAS(IAA)+1
  200       CONTINUE
         ELSE



            FRAQ=0.0
            DO 300 IAA=1,NUMAAF
               IF (IRT.EQ.RESTYP(IAA)) FRAQ=FRAQ+1.0
  300       CONTINUE
         END IF
      END IF





      FRAQ=MULT*FRAQ/FLOAT(NUMATF)



      IF (FRAQ.LT.0.1) FRAQ=0.1
      IF (FRAQ.GT.3.0) FRAQ=3.0
      NQA035=FRAQ



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA036 (IATTARR,SCARR,NIATT,MAX,NAME,COL,IVAT,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       MAX, IERR, LUN, JVAT, COL, GVFLFI
      INTEGER       IATTARR(MAX), LINENO, IVAT, NIATT, I, GVFLFR
      REAL          SCARR(MAX), SCALE
      CHARACTER*(*) NAME
      CHARACTER*80  RESNAME, ATOMNAME
      LOGICAL       FOUND, GVFISF, GVFFOP







      LINENO=0
      JVAT=0



      IF (GVFISF('NQUAV.DAT')) THEN
         LINE='NQUAV.DAT'
      ELSE
         CALL GVSCCC (LINE,FILDIR(30),'NQUAV.DAT')
      END IF



      CALL GVSROF (LUN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSOPF (LINE,LUN,'OLD')
      IF (.NOT.GVFFOP(LUN)) THEN
         IERR=1
         GOTO 998
      END IF
      FOUND=.FALSE.
  230 CONTINUE
      CALL GVSFMT ('?FMT027A')
         READ (LUN,FMT,END=240,ERR=999) LINE
         LINENO=LINENO+1



         IF (LINE(1:1).EQ.'#') GOTO 230
         IF (LINE(1:1).EQ.' '.AND..NOT.FOUND) GOTO 230
         IF (LINE(1:1).NE.' '.AND.FOUND) GOTO 240
         JVAT=JVAT+1
         IF (IVAT.EQ.JVAT) THEN
            FOUND=.TRUE.
            CALL SPLITLINE (LINE,NAME,LINE)
            I=GVFLFI(1,COL,LINE)
            IF (I.NE.1) GOTO 998
            NIATT=0
         ELSE
            CALL GVSSHL (LINE)
            CALL SPLITLINE (LINE,RESNAME,LINE)
            CALL SPLITLINE (LINE,ATOMNAME,LINE)
            I=GVFLFR(1,SCALE,LINE)
            IF (I.NE.1) GOTO 998
            DO 235 I=0,NQAVAT
               IF ((ATOMNAME.EQ.'*'.OR.NQAREV(I)(5:8).EQ.ATOMNAME).AND.
     +             (RESNAME.EQ.'*'.OR.NQAREV(I)(1:4).EQ.RESNAME)) THEN
                  IF (NIATT.GE.MAX) THEN
                     IF (MAX.GT.1) CALL GVSTTE ('?R00168')
                     IERR=2
                     CALL GVSCLF (LUN)
                     GOTO 990
                  END IF
                  NIATT=NIATT+1
                  IATTARR(NIATT)=I
                  SCARR(NIATT)=SCALE
               END IF
  235       CONTINUE
         END IF
         GOTO 230
  240 CONTINUE
      CALL GVSCLF (LUN)
      IF (.NOT.FOUND.OR.NIATT.EQ.0) THEN
         IERR=1
      ELSE
         IERR=0
      END IF
      GOTO 990



  998 CONTINUE
      CALL GVSTTE ('?R00093')
      CALL GVSTTI ('?R00094',LINENO)
      CALL GVSCLF (LUN)
      IERR=1
      GOTO 990

  999 CONTINUE
      CALL GVSTTE ('?R00101')
      CALL GVSCLF (LUN)
      IERR=1



 990  CONTINUE


      RETURN
      END
      SUBROUTINE NQA037



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      INTEGER       IERR, IAA, IAT, I, IX, IY, IZ, IATTARR(NQAMVA)
      REAL          XMIN, YMIN, ZMIN, XMAX, YMAX, ZMAX, RESOLU,
     +              RX, RY, RZ, RESULT(8,NQAMVA), SCARR(NQAMVA) 







      IERR=0
      XMIN= 10000.0
      YMIN= 10000.0
      ZMIN= 10000.0
      XMAX=-10000.0
      YMAX=-10000.0
      ZMAX=-10000.0
      CALL GVSBTF (WRK1TF,MAXAA)



      IF (WIFPAR(930).EQ.0) THEN
         CALL GVSTTE ('?R00206')
         GOTO 998
      END IF



      CALL NQA001



      CALL WIFWTF ('?NQAM057',IERR)
      IF (IERR.NE.0) GOTO 998



      DO 30 IAA=1,NUMAAT
         IF (.NOT.WRK1TF(IAA)) GOTO 30
         DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (PROTON(IAT)) GOTO 20
            XMIN=MIN(XMIN,XCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            YMIN=MIN(YMIN,YCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            ZMIN=MIN(ZMIN,ZCOORD(IAT)-VDWRAD(IAT)-NQACLS)
            XMAX=MAX(XMAX,XCOORD(IAT)+VDWRAD(IAT)+NQACLS)
            YMAX=MAX(YMAX,YCOORD(IAT)+VDWRAD(IAT)+NQACLS)
            ZMAX=MAX(ZMAX,ZCOORD(IAT)+VDWRAD(IAT)+NQACLS)
   20    CONTINUE
   30 CONTINUE



      RESOLU=NQAGRD/1.4



      CALL ENVTOT



      WIFPAR(909)=-1



      WIFPAR(924)=1



      DO 130 I=1,NQANVA
         IATTARR(I)=NQAVAT+I
         SCARR(I)=1.0
  130 CONTINUE



      CALL GRTVIN
      DO 180 IZ=0,NINT((ZMAX-ZMIN)/RESOLU),2
         CALL GVSTTI ('?R00098',IZ)
         RZ=ZMIN+IZ*RESOLU
         DO 170 IY=0,NINT((YMAX-YMIN)/RESOLU),2
            RY=YMIN+IY*RESOLU
            DO 160 IX=0,NINT((XMAX-XMIN)/RESOLU),2
               RX=XMIN+IX*RESOLU



               CALL NQA024A (IATTARR,SCARR,NQANVA,RX,RY,RZ,
     +              RESOLU,RESOLU,RESOLU,RESULT)
               CALL NQA038 (RX,RY,RZ,RESULT,1)
               CALL NQA038 (RX+RESOLU,RY,RZ,RESULT,2)
               CALL NQA038 (RX,RY+RESOLU,RZ,RESULT,3)
               CALL NQA038 (RX+RESOLU,RY+RESOLU,RZ,RESULT,4)
               CALL NQA038 (RX,RY,RZ+RESOLU,RESULT,5)
               CALL NQA038 (RX+RESOLU,RY,RZ+RESOLU,RESULT,6)
               CALL NQA038 (RX,RY+RESOLU,RZ+RESOLU,RESULT,7)
               CALL NQA038 (RX+RESOLU,RY+RESOLU,RZ+RESOLU,RESULT,8)
 160        CONTINUE
 170     CONTINUE
         CALL DOTSAVE
 180  CONTINUE



      CALL GRADOT (' ')



      WIFPAR(909)=-2
      CALL NQA002(1,1,ESPACE(1),ESPACE(1),IERR)



      WIFPAR(924)=0



      CALL GVSTTI ('?R00099',WIFPAR(910))
      CALL GVSTTI ('?R00100',WIFPAR(911))



  998 CONTINUE


      RETURN
      END
      SUBROUTINE NQA038 (RX,RY,RZ,RESULT,IND)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      REAL          MAXVAL, RESULT(8,NQANVA), RX, RY, RZ
      INTEGER       COL, I, IND, IERR







      MAXVAL=0.0
      COL=-1
      DO 161 I=1,NQANVA
         IF (RESULT(IND,I).GT.MAXVAL) THEN
            MAXVAL=RESULT(IND,I)
            COL=NQAVCL(I)
         END IF
  161 CONTINUE
      IF (COL.GE.0) CALL GRTDOT (RX,RY,RZ,COL,IERR)





      RETURN
      END
      REAL FUNCTION NQA039 (X,Y,Z,RAD)





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SYMINC.INC'
      INTEGER       MX2
      PARAMETER     (MX2=100)
      INTEGER       CONIAT(MX2), CONSYM(MX2), NUM, ISYM, JAT, ICON,
     +              OCCUPIED, K, JATPRV, ONE, IAP
      REAL          CONDST(MX2), X, Y, Z, RAD, TMP(3), PP(4,MX2), DXL,
     +              DYL, DZL, MIND12, D12, RAD2, R2RAD, PX







      CALL FCONAT1I (X,Y,Z,RAD,CONIAT,CONSYM,CONDST,NUM,MX2)



      IF (NUM.EQ.0) THEN
         NQA039=0.0
         GOTO 998
      END IF
      MIND12=100.0
      ONE=0
      RAD2=RAD**2
      R2RAD=1.0/(2.0*RAD)



      DO 55 ICON=1,NUM



         JAT=CONIAT(ICON)



         IF (PROTON(JAT).OR.(.NOT.ISATOK(JAT))) GOTO 55



         ISYM=CONSYM(ICON)
         TMP(1)=XCOORD(JAT)
         TMP(2)=YCOORD(JAT)
         TMP(3)=ZCOORD(JAT)
         IF (ISYM.NE.1) CALL GVSMPV (TMP,SYMMAT(1,1,ISYM),
     +    SYMVEC(1,ISYM))
         DXL=TMP(1)-X
         DYL=TMP(2)-Y
         DZL=TMP(3)-Z
         D12=DXL**2+DYL**2+DZL**2



         PP(1,ICON)=DXL
         PP(2,ICON)=DYL
         PP(3,ICON)=DZL
         PP(4,ICON)=(RAD2-VDWRAD(JAT)**2+D12)*R2RAD



         IF (D12.LT.MIND12) THEN
            ONE=ICON
            MIND12=D12
         END IF
   55 CONTINUE



      IF (ONE.GT.1) THEN
         PX=PP(1,ONE)
         PP(1,ONE)=PP(1,1)
         PP(1,1)=PX
         PX=PP(2,ONE)
         PP(2,ONE)=PP(2,1)
         PP(2,1)=PX
         PX=PP(3,ONE)
         PP(3,ONE)=PP(3,1)
         PP(3,1)=PX
         PX=PP(4,ONE)
         PP(4,ONE)=PP(4,1)
         PP(4,1)=PX
      END IF



      JATPRV=1
      OCCUPIED=0
      CALL WIF083
      DO 10 K=1,WIFPAR(68)



         IF (PP(1,JATPRV)*XUACC(K)+PP(2,JATPRV)*YUACC(K)+
     +        PP(3,JATPRV)*ZUACC(K).GT.PP(4,JATPRV)) THEN
            OCCUPIED=OCCUPIED+1
            GOTO 10
         END IF



         DO 5 IAP=1,NUM
            IF (PP(1,IAP)*XUACC(K)+PP(2,IAP)*YUACC(K)+
     +           PP(3,IAP)*ZUACC(K).GT.PP(4,IAP)) THEN
               OCCUPIED=OCCUPIED+1
               JATPRV=IAP
               GOTO 10
            END IF
    5    CONTINUE
   10 CONTINUE
      NQA039=FLOAT(OCCUPIED)/FLOAT(WIFPAR(68))



  998 CONTINUE


      RETURN
      END
      REAL FUNCTION NQA040 (X,Y,Z)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      REAL          NQA039, X, Y, Z





      IF (WIFPAR(929).GT.100) THEN
         NQA040=MIN(1.0/MAX(0.01,NQA039(X,Y,Z,3.0)),
     +    FLOAT(WIFPAR(929))/100.0)
      ELSE
         NQA040=1.0
      END IF





      RETURN
      END
      SUBROUTINE NQA041



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFISF
      CHARACTER*80  FILNAM





      CALL GVSCCC (FILNAM,FILDIR(30),'NQABOX.DAT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      CALL GVSCCC (FILNAM,FILDIR(30),'NQANOR.WAT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      CALL GVSCCC (FILNAM,FILDIR(30),'NQAPTR.TXT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      CALL GVSCCC (FILNAM,FILDIR(30),'NQASTR.WAT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      CALL GVSCCC (FILNAM,FILDIR(30),'NQUAL.DAT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      CALL GVSCCC (FILNAM,FILDIR(30),'NQUAV.DAT')
      IF (.NOT.GVFISF(FILNAM)) GOTO 999
      WIFPAR(930)=1
      GOTO 998



  999 CONTINUE
      WIFPAR(930)=0
      CALL GVSTT6 ('?R00207')



  998 CONTINUE


      RETURN
      END
      BLOCK DATA NQA
      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'NQAINC.INC'
      DATA  BOXUNT  /0/
      END
