



C







      SUBROUTINE PDBL00 (DONE)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'OPTION.INC'
      INTEGER       IUNIT
      LOGICAL       DONE, GRTFILE







      IF (OPTIN.EQ.MEN6COD(126)) GOTO 998
      CALL MEN088 (OPTIN,DONE)







 998  CONTINUE


      RETURN
      END
      SUBROUTINE PDBL01 (IUNIT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'PDBLIS.INC'
      INTEGER       IUNIT, IERR
      LOGICAL       GVFFOP, GVFISF







      IERR=0



      IF (.NOT.GVFISF ('PDB.LIS')) THEN
         CALL GVSTTE ('?M4946')
         GOTO 999
      END IF
      IF (PDBLUN.NE.0) THEN
         IF (GVFFOP(PDBLUN)) THEN
            CALL GVSTTI ('?M4948',PDBLUN)
            CALL GVSCLF (PDBLUN)
         END IF
      END IF            
      IF (IUNIT.NE.PDBLUN.AND.IUNIT.NE.0) THEN
         IF (GVFFOP(IUNIT)) THEN
            CALL GVSTTI ('?M4949',IUNIT)
            CALL GVSCLF (IUNIT)
         END IF
      END IF            



      CALL GVSROF (IUNIT,IERR)
      IF (IUNIT.LE.0.OR.IERR.NE.0) GOTO 998



      CALL GETFILE (IUNIT,' ','PDB.LIS',IERR)
      IF (IERR.NE.0) GOTO 999
      PDBLUN=IUNIT
      
      GOTO 998



  999 CONTINUE
      IERR=1
      IUNIT=0
      PDBLUN=0
      CALL GVSTT6 ('?M4947')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PDBL02 (IUNIT)

















      IMPLICIT      NONE
      INCLUDE       'PDBLIS.INC'
      INTEGER       IUNIT
      LOGICAL       GVFFOP, GVFIBN







      IF (.NOT.GVFIBN(IUNIT,1,120)) THEN
         CALL GVSTTE ('?M4952')
      ELSE
         IF (.NOT.GVFFOP(IUNIT)) THEN
            CALL GVSTTE ('?M4950')
         END IF
      END IF
      IF (PDBLUN.NE.IUNIT) THEN
         CALL GVSTTI2 ('?M4951',IUNIT,PDBLUN)
         IF (.NOT.GVFIBN(PDBLUN,1,120)) THEN
            CALL GVSTTE ('?M4953')
         ELSE
            IF (.NOT.GVFFOP(PDBLUN)) THEN
               CALL GVSTTE ('?M4954')
            END IF
         END IF
      END IF



      IF (GVFIBN(IUNIT,1,120)) THEN
         IF (GVFFOP(IUNIT)) CALL GVSCLF (IUNIT)
      END IF
      IF (GVFIBN(PDBLUN,1,120)) THEN
         IF (GVFFOP(PDBLUN)) CALL GVSCLF (PDBLUN)
      END IF



      PDBLUN=0
      IUNIT=0





      RETURN
      END   
      SUBROUTINE PDBL03 (TEXT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, I, GVFLFR
      REAL          VALUES(7)
      LOGICAL       GVFISF
      CHARACTER*(*) TEXT
      CHARACTER*80  BIGTEXT
      EQUIVALENCE   (VALUES(1),WIFPAR(510))







      IF (LEN(TEXT).LT.1) THEN
         CALL GVSTTB ('?NEWB105')
         IERR=1
         GOTO 998
      END IF
      IF (GVFLEN(TEXT).LT.1) THEN
         CALL GVSTTB ('?NEWB106')
         IERR=1
         GOTO 998
      END IF
      IF (GVFISF(TEXT)) THEN
         CALL GVSSTX (FILNMS(62),TEXT)
         CALL GVSSTX (FILNMS(91),TEXT)
         IERR=0
         GOTO 998
      END IF



      IERR=0



      CALL GVSCTB (LINE2,80)
      CALL SPLITLINE (TEXT,LINE2,TEXT)
      I=GVFLFR(7,VALUES,TEXT)
      CALL GVSSTX (TEXT,LINE2)



      CALL GVSCTB (BIGTEXT,80)
      CALL MOL702 (TEXT,BIGTEXT,IERR)
      IF (GVFISF(BIGTEXT)) THEN
         CALL GVSSTX (TEXT,BIGTEXT(1:MIN(LEN(TEXT),GVFLEN(BIGTEXT))))



         CALL GVSSTX (FILNMS(62),TEXT)
         CALL GVSSTX (FILNMS(91),TEXT)
         GOTO 998
      END IF



      CALL GVST6C ('?NEWT340',TEXT,.TRUE.)
      IERR=1



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PDBL04 (LLINE,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      CHARACTER*(*) LLINE







      CALL PDBL03 (LLINE,IERR)



      IERR=0
      WIFPAR(491)=WIFPAR(491)+1
      CALL GVSSTX (SOUNAM(WIFPAR(491)),LLINE)



      CALL GVSCLF (11)
      CALL GETFILE (11,' ',LLINE,IERR)
      IF (IERR.NE.0) THEN
         CALL GVSTTE ('?M2411')
         CALL GVSTT6 (LLINE)
         GOTO 998
      ELSE
         CALL GVST6C ('?M1316',LLINE,.TRUE.)
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PDBL05 (TEXT,CLEAN)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ANISOU.INC'
      INTEGER       IERR, NUMDN1
      LOGICAL       GVFISF, CLEAN
      CHARACTER*80  LLINE
      CHARACTER*(*) TEXT







      IF (CLEAN) THEN
         IF (NUMATF.GE.1.OR.NUMAAF.GE.1.OR.NUMAAT.GE.1) CALL MOL100
         CALL MOLINI
         WIFPAR(491)=0
      END IF
      CALL KLONKCLEAN
      CALL GVSDEL ('DAVADRUG.*')
      CALL GVSDEL ('DRGDRG.*')
      CALL GVSDEL ('DRGWIF.*')
      CALL GVSDEL ('DRGGMX.*')
      CALL GVSDEL ('PRODRUG.*')



      CALL GVSSTX (LLINE,TEXT)
      IF (.NOT.GVFISF(LLINE)) THEN
         CALL MOL715 (LLINE(1:4),IERR)
         IF (IERR.NE.0) THEN
            CALL GVSTTB ('?MOLC38')
            GOTO 999
         END IF
      END IF



      CALL PDBL04 (LLINE,IERR)
      IF (IERR.NE.0) THEN
         CALL GVSTTB ('?MOLC38')
         GOTO 999
      END IF



      CALL MOL007




      CALL GVSSTX (SOUNAM(1),'DBASE')
      WIFPAR(491)=1
      CALL MOL703 (IERR)
      IF (IERR.NE.0) GOTO 998




      NUMDN1=0
      CALL WIFPUSHPPP (269,1)
      CALL WIFPUSHPPP (1052,0)
      CALL MOL003 (NUMDN1,IERR)
      IF (NUMDN1.EQ.0) CALL GVSTT6 ('?MOLB39')



      CALL KLONKDOWN
      CALL KLONKEND
      CALL WIFPOPPPP (1052)
      CALL GVSCLF (11)
      CALL GVSCLF (13)
      CALL MOL200



      CALL MOL042
      CALL WIFPOPPPP (269)



      CALL WIFPUSHPPP (1081,1)
      CALL USEDD1
      CALL WIFPOPPPP (1081)
      CALL MOL200









      GOTO 998



 999  CONTINUE
      CALL GVSEIR ('PDBL05')



 998  CONTINUE
      CALL GVSCLF (11)
      CALL GVSCLF (12)
      CALL GVSCLF (13)


      RETURN
      END

      SUBROUTINE PDBL65 (ISFOUT,JUNIT,KUNIT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       JUNIT, KUNIT, IAA, ICNT
      LOGICAL       WIFIRA
      CHARACTER*(*) ISFOUT







      ICNT=0
      DO 10 IAA=1,NUMAAF
         IF (WIFIRA(IAA)) ICNT=ICNT+1
 10   CONTINUE



      CALL MOLKIL3 (EXPDTA)
      IF (WIFPAR(466).EQ.0) THEN
         IF (WIFPAR(479).GE.1) THEN
            CALL GVSCBC (ISFOUT,'?M4989')
         ELSE
            IF (WIFPAR(497).GE.1) THEN
               CALL GVSCBC (ISFOUT,'?M4989A')
            ELSE
               IF (ICNT.LE.99) THEN
                  CALL GVSCBC (ISFOUT,'?M4989B')
               ELSE
                  CALL GVSTTU (JUNIT,FILNMS(90))
               END IF
            END IF
         END IF
      ELSE
         CALL GVSCBC (ISFOUT,EXPDTA)
      END IF
      CALL GVSTTU (KUNIT,ISFOUT)





      RETURN
      END   
      SUBROUTINE PDBL99 (MODE)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAPINC.INC'
      INCLUDE       'HSTINC.INC'
      INTEGER       IAA, IAATYP, I, J, IUNIT, IPNT, IHS, IERR
      REAL          SCORES(10000), TAU, WIFANG, AVE, SDEV, CNT(2,3,20),
     +              Z
      LOGICAL       GRTFILE, GVFIBN
      CHARACTER*4   MODE
      EQUIVALENCE   (SCORES, GRID(1,1,1))
      DATA IPNT     /0/




      IF (MODE.EQ.'CALC') THEN
         PRINT*,'START'



         IUNIT=0
         CALL GVSCCC (LINE,WHERIS,'TAU.VAL')
         IF (.NOT.GRTFILE(IUNIT,LINE)) GOTO 999



         DO 10 IAATYP=1,20
            READ (IUNIT,'(6F8.3)',ERR=999) ((CNT(I,J,IAATYP),
     +       I=1,2),J=1,3)
 10      CONTINUE
         CALL GVSCLF (IUNIT)



         CALL DSP001 (.FALSE.)
         CALL GHS021 (0,0,IERR)
         IF (IERR.NE.0) GOTO 999
         PRINT*,'START LOOP'



         DO 20 IAA=2,NUMAAF-1
            IF (.NOT.GVFIBN(RESTYP(IAA),1,20)) GOTO 20
            IF (.NOT.ISATOK(PNTAAS(IAA))) GOTO 20
            IF (.NOT.ISATOK(PNTAAC(IAA))) GOTO 20
            IF (.NOT.ISATOK(PNTAAC(IAA)+1)) GOTO 20
            TAU=WIFANG(PNTAAS(IAA),PNTAAC(IAA),PNTAAC(IAA)+1)
            IF (LOCHST(IAA).EQ.'H') THEN
               IHS=1
            ELSE IF (LOCHST(IAA).EQ.'S') THEN
               IHS=2
            ELSE
               IHS=3
            END IF
            Z=(TAU-CNT(1,IHS,RESTYP(IAA)))/CNT(2,IHS,RESTYP(IAA))
            CALL GHS022 (0,Z,IERR)
            PRINT*,'IAA,Z=',IAA,Z
            IF (IERR.NE.0) GOTO 999
 20      CONTINUE



         CALL GHS023 (0,0,AVE,SDEV,IERR)
         PRINT*,'AVE,SDEV=',AVE,SDEV
         IF (IERR.NE.0) GOTO 999
         IPNT=IPNT+1
         SCORES(IPNT)=SDEV
         CALL GHS028 ('Z-score distribution',0,0,IERR)
         CALL GHS024 (IERR)
         IF (IERR.NE.0) GOTO 999
      ELSE IF (MODE.EQ.'SHOW') THEN



         CALL GHS021 (0,0,IERR)
         IF (IERR.NE.0) GOTO 999
         DO 30 I=1,IPNT
            CALL GHS022 (0,SCORES(I),IERR)
            IF (IERR.NE.0) GOTO 999
 30      CONTINUE
         CALL GHS028 ('RMS-Z-score distribution',0,0,IERR)
         IF (IERR.NE.0) GOTO 999
         CALL GHS024 (IERR)
         IF (IERR.NE.0) GOTO 999
      END IF      
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('PDBL99')



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION MOLKIL1(MODE,CHAR4IN)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       KILUNT, IERR
      LOGICAL       GRTFILE, GVFFOP
      CHARACTER*4   CHAR4IN, CHAR4, CHAR4F, MODE
      DATA KILUNT   /0/
      SAVE          KILUNT







      MOLKIL1=.FALSE.
      CALL GVSSTX (CHAR4,CHAR4IN)
      CALL GVSCUC (CHAR4)



      IF (MODE.EQ.'OPEN') THEN
         IF (KILUNT.NE.0) THEN
            IF (GVFFOP(KILUNT)) THEN
               CALL GVSTT6 ('?M4961')
               GOTO 998
            END IF
         END IF
         CALL GVSCCC (LINE3,WHERIS,'exclude.list')
         IF (.NOT.GRTFILE(KILUNT,LINE3)) CALL GVSTT6 ('?M4962')
         GOTO 998
      ELSE IF (MODE.EQ.'CLOS') THEN
         CALL GVSCLF (KILUNT)
         GOTO 998
      END IF



 10   CONTINUE
         CALL GETLINE (KILUNT,CHAR4F,IERR)
         IF (IERR.NE.0) GOTO 998
         IF (CHAR4F.EQ.'*END') THEN
            CALL GVSREW (KILUNT)
            GOTO 998
         END IF
         IF (CHAR4.EQ.CHAR4F) THEN
            MOLKIL1=.TRUE.
            CALL GVSREW (KILUNT)
            GOTO 998
         END IF
      GOTO 10



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION MOLKIL2()

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA
      LOGICAL       WIFROK







      MOLKIL2=.FALSE.



      IF (NUMAAF.LE.0) THEN
         CALL GVSTT6 ('?M4958')
         MOLKIL2=.TRUE.
         GOTO 998
      END IF
      IF (WIFPAR(489).GE.1) THEN
         MOLKIL2=.TRUE.
         GOTO 998
      END IF



      IF (WIFPAR(466).NE.0) THEN
         CALL GVSTT6 ('?M4959')
         CALL GVSTT6 (EXPDTA)
         MOLKIL2=.TRUE.
         GOTO 998
      END IF



      DO 10 IAA=1,NUMAAF
         IF (WIFROK(IAA)) GOTO 998
 10   CONTINUE
      CALL GVSTT6 ('?M4960')
      MOLKIL2=.TRUE.



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOLKIL3 (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       GVFPOS
      CHARACTER*80  TEXT







      IF (TEXT(1:6).NE.'EXPDTA') GOTO 998



      WIFPAR(466)=0



      IF (TEXT(1:31).EQ.'EXPDTA    CRYO-ELECTRON MICROSC') THEN
         WIFPAR(466)=1
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    ELECTRON CRYSTAL') THEN
         WIFPAR(466)=1
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    ELECTRON MICROSC') THEN
         WIFPAR(466)=1
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    ELECTRON TOMOGRA') THEN
         WIFPAR(466)=1
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    FIBER DIFFRACTIO') THEN
         WIFPAR(466)=2
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    FLUORESCENCE TRA') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    FLUORESCENCE TRA') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    INFRARED SPECTRO') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    NEUTRON DIFFRACT') THEN
         IF (GVFPOS(TEXT,'X-RAY').EQ.0) WIFPAR(466)=3
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    NMR, MINIMIZED A') THEN
         WIFPAR(466)=5
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    NMR, REGULARIZED') THEN
         WIFPAR(466)=5
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    NMR, RESTRAINED ') THEN
         WIFPAR(466)=5
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    SOLUTION NMR; SO') THEN
         WIFPAR(466)=4
      ELSE IF (TEXT(1:22).EQ.'EXPDTA    SOLUTION NMR') THEN
         WIFPAR(466)=4
      ELSE IF (TEXT(1:13).EQ.'EXPDTA    NMR') THEN
         WIFPAR(466)=4
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    POWDER DIFFRACTI') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:25).EQ.'EXPDTA    SOLID-STATE NMR') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    SOLUTION SCATTER') THEN
         WIFPAR(466)=9
      ELSE IF (TEXT(1:26).EQ.'EXPDTA    X-RAY POWDER DIF') THEN
         WIFPAR(466)=9
      END IF



 998  CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION MOLKIL4()

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, NUNK, IISCA, INOTCA, ISOUP, NROK
      LOGICAL       WIFISA, WIFIRC, WIFROK, CH4EQCH4







      NUNK=0
      IISCA=0
      INOTCA=0
      NROK=0
      MOLKIL4=.FALSE.



      DO 10 IAA=1,NUMAAF
         IF (CH4EQCH4(ONESA3(IAA),'UNK ')) NUNK=NUNK+1
 10   CONTINUE
      IF (NUNK.GT.NINT(FLOAT(NUMAAF)/20.0).OR.NUNK.GT.10) THEN
         MOLKIL4=.TRUE.
         GOTO 998
      END IF



      DO 30 ISOUP=1,NUMSOU
         IF (.NOT.WIFISA(ISOUP)) GOTO 30
         DO 20 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
            IF (WIFIRC(IAA)) THEN
               IISCA=IISCA+1
            ELSE
               INOTCA=INOTCA+1
            END IF
 20      CONTINUE
 30   CONTINUE
      IF (IISCA.GT.NINT(FLOAT(IISCA+INOTCA)/20.0).OR.IISCA.GT.10) THEN
         MOLKIL4=.TRUE.
         GOTO 998
      END IF



      DO 40 IAA=1,NUMAAF
         IF (.NOT.WIFROK(IAA)) NROK=NROK+1
 40   CONTINUE
      IF (NROK.GT.NINT(FLOAT(NUMAAF)/10.0).OR.NROK.GT.20) THEN
         MOLKIL4=.TRUE.
         GOTO 998
      END IF



  998 CONTINUE


      RETURN
      END   
