



      SUBROUTINE GETUSESOU (TEXTIN,DEFTXT,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ENVIRO.INC'
      INTEGER       GVFLFI, ISR(2), ISOUP, IERR, GVFLEN, I
      LOGICAL       GVFIBN, DEFUSED, AHEAD, FOUND, ISSETNAME
      CHARACTER*(*) TEXTIN, DEFTXT
      CHARACTER*80  LOCLIN, TEXT







      IF (NUMSOU.LT.1) THEN
         CALL GVSTTE ('?NEWE435')
         GOTO 998
      END IF



      CALL ENVINI



      IF (GVFLEN(TEXTIN).GT.0) THEN
         CALL GVSSTX (TEXT,TEXTIN)
      ELSE
         CALL GVSSTX (TEXT,'?NEWP26')
      END IF




    5 CONTINUE
      IF (.NOT.AHEAD().AND.WIFPAR(710).NE.1) THEN
         CALL SHOSOU
         CALL GVSNL6 (1)
         CALL SHOWTEXTIF ('?M1880')
      END IF
   10 CONTINUE
         DEFUSED=.FALSE.



         IF (GVFLEN(DEFTXT).LE.0) THEN
            CALL IPROMPT (TEXT)
         ELSE
            CALL GVSCC4 (LOCLIN,TEXT,' (',DEFTXT,')')
            CALL IPROMPT (LOCLIN)
         END IF



         CALL GVSCTB (LOCLIN,80)
         CALL GETWORD (LOCLIN,IERR)
         IF (IERR.EQ.1) THEN
            IF (LOCLIN(1:2).EQ.'0 ') GOTO 100
            GOTO 999
         END IF
         IF (GVFLEN(LOCLIN).LE.0) THEN
            CALL GVSSTX (LOCLIN,DEFTXT)
            DEFUSED=.TRUE.
         END IF
         CALL GVSCUC (LOCLIN)
         CALL GVSSHL (LOCLIN)
         FOUND=.FALSE.



         IF (LOCLIN(1:4).EQ.'ALL ') THEN
            CALL ENVALL
            FOUND=.TRUE.



         ELSE IF (LOCLIN(1:5).EQ.'-ALL ') THEN
            CALL ENVALLNOT
            FOUND=.TRUE.



         ELSE IF (LOCLIN(1:6).EQ.'PROT ') THEN
            CALL ENVPROT
            FOUND=.TRUE.



         ELSE IF (LOCLIN(1:6).EQ.'NOWAT ') THEN
            CALL ENVNOWAT
            FOUND=.TRUE.



         ELSE IF (LOCLIN(1:4).EQ.'TOT ') THEN
            CALL ENVTOT
            FOUND=.TRUE.



         ELSE IF (ISSETNAME(LOCLIN)) THEN
            CALL ENVSETC (LOCLIN,FOUND)
         END IF



         IF (.NOT.FOUND) THEN



            CALL GVSIT0 (ISR,2)



            I=GVFLFI(1,ISR(1),LOCLIN)
            IF (I.EQ.0) GOTO 5
            IF (I.EQ.1.AND.ISR(1).EQ.0) GOTO 100
            IF (.NOT.GVFIBN(ISR(1),1,NUMSOU)) THEN
               CALL GVSTTE ('?R00078')
               GOTO 5
            END IF



            IF (AHEAD()) THEN
               CALL GVSCTB (LOCLIN,80)
               CALL GETWORD (LOCLIN,IERR)
               I=GVFLFI(1,ISR(2),LOCLIN)
               IF (I.EQ.1.AND.ISR(1).EQ.0) GOTO 100
               IF (I.EQ.0.OR.ISR(2).LE.0) ISR(2)=ISR(1)
            ELSE
               ISR(2)=ISR(1)
            END IF
            IF (.NOT.GVFIBN(ISR(2),1,NUMSOU)) THEN
               CALL GVSTTE ('?R00078')
               GOTO 5
            ELSE
               DO 20 ISOUP=ISR(1),ISR(2)
                  USESOU(ISOUP)=ISOUP
   20          CONTINUE
            END IF
         END IF
      IF (.NOT.DEFUSED) GOTO 10



  100 CONTINUE



      CALL GET001 (.FALSE.,IERR)
      IF (IERR.NE.0) GOTO 999
      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?M0902') 
      CALL GVSIT0 (USESOU,MAXMOL)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GET001 (PRINT,IERR)




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ENVIRO.INC'
      INTEGER       IERR, ISOUP, IAT, IAA, JAT, JSOUP, ILOOP
      LOGICAL       PRINT







      IERR=0



      IF (NUMSOU.LE.0) THEN
         CALL GVSTTB ('?M0903')
         IERR=1
         GOTO 998
      END IF



      DO 100 ISOUP=1,NUMSOU
         IF (USESOU(ISOUP).EQ.0) GOTO 100
         DO 90 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
            DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
               DO 70 ILOOP=1,8
                  JAT=BOUND_TO(ILOOP,IAT)
                  IF (JAT.GT.IAT.AND.JAT.GT.PNTAAE(NUMAAF)) THEN
                     JSOUP=CHAINN(2,ATIAA(JAT))
                     USESOU(JSOUP)=JSOUP
                     IF (PRINT) CALL GVSTTI ('?M2656',JSOUP)
                  END IF
   70          CONTINUE
   80       CONTINUE
   90    CONTINUE
  100 CONTINUE



  998 CONTINUE

                  
      RETURN
      END   
      SUBROUTINE WIFG1N (TEXT,INUM1,DEFAULT)

















      IMPLICIT      NONE
      INTEGER       GVFLFI, INUM1, I, IERR, DEFAULT
      CHARACTER*(*) TEXT
      CHARACTER*80  LOCLIN







      INUM1=0



      CALL I1PROMPT (TEXT,DEFAULT)



      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.EQ.1) GOTO 998
      IF (IERR.EQ.2) THEN
         INUM1=DEFAULT
         GOTO 998
      END IF



      I=GVFLFI(1,INUM1,LOCLIN)
      IF (I.EQ.0) THEN
         CALL FLUSHAHEAD
         GOTO 998
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFG1R (TEXT,RNUM1,DEFAULT)

















      IMPLICIT      NONE
      INTEGER       GVFLFR, I, IERR
      REAL          RNUM1, DEFAULT
      CHARACTER*(*) TEXT
      CHARACTER*80  LOCLIN







      RNUM1=0



      CALL R1PROMPT (TEXT,DEFAULT)



      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.EQ.1) GOTO 998
      IF (IERR.EQ.2) THEN
         RNUM1=DEFAULT
         GOTO 998
      END IF



      I=GVFLFR(1,RNUM1,LOCLIN)
      IF (I.EQ.0) THEN
         CALL FLUSHAHEAD
         GOTO 998
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFG2N (TEXT,INUM1,INUM2,DEFAULT)

















      IMPLICIT      NONE
      INTEGER       GVFLFI, INUM1, INUM2, I, IERR, DEFAULT
      CHARACTER*(*) TEXT
      CHARACTER*80  LOCLIN







      INUM1=0
      INUM2=0



      CALL I1XPROMPT (TEXT,DEFAULT)



      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.EQ.1) GOTO 998
      IF (IERR.EQ.2) THEN
         INUM1=1
         INUM2=DEFAULT
         GOTO 998
      END IF



      CALL GVSSHL (LOCLIN)
      CALL GVSCUC (LOCLIN)
      IF (LOCLIN(1:3).EQ.'ALL'.OR.LOCLIN(1:3).EQ.'TOT') THEN
         INUM1=1
         INUM2=DEFAULT
         GOTO 998
      END IF



      I=GVFLFI(1,INUM1,LOCLIN)
      IF (I.EQ.0) THEN
         CALL FLUSHAHEAD
         GOTO 998
      END IF



      CALL PEEKWORD (LOCLIN,IERR)
      IF (IERR.NE.0) THEN
         INUM2=INUM1
         GOTO 998
      END IF



      I=GVFLFI(1,INUM2,LOCLIN)
      IF (I.EQ.0) THEN
         INUM2=INUM1
      ELSE
         CALL GETWORD (LOCLIN,IERR)
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL310 (ISOUP,ITYPE,TEXT)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOU, ISOUP, ITYPE, GVFLEN
      LOGICAL       GVFIBN, AHEAD
      CHARACTER*(*) TEXT







      IF (NUMSOU.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         ISOUP=0
         GOTO 998
      END IF
      IF (.NOT.(GVFIBN(ITYPE,-1,8))) CALL GVSKIL




      IF (WIFPAR(1105).NE.0) THEN





         ISOUP=0
         IF (ITYPE.EQ.-1) THEN
            ISOUP=1
            GOTO 998
         END IF




         DO 4 ISOU=1,NUMSOU
            IF (SOUADM(5,ISOU).EQ.ITYPE) THEN
               ISOUP=ISOU
               GOTO 998
            END IF
    4    CONTINUE
         GOTO 998
      END IF



    5 CONTINUE
      IF (.NOT.AHEAD().AND.WIFPAR(1105).EQ.0) THEN
         CALL GVSNL6 (1)
         IF (GVFLEN(TEXT).GT.0) THEN
            IF (TEXT(1:1).NE.'?') THEN
               CALL GVSTT6 (TEXT)
            ELSE
               CALL SHOWTEXT (TEXT)
            END IF
         END IF
      END IF



      IF (WIFPAR(1105).EQ.0.OR.ITYPE.EQ.0) THEN
         CALL IPROMPT ('?MOLC65')
         CALL WIFBO1 (7,' ')
         CALL GVSFFI (1,ISOUP)
         IF (ISOUP.EQ.0) GOTO 998
      ELSE
         ISOUP=0
         DO 10 ISOU=1,NUMSOU
            IF (SOUADM(5,ISOU).EQ.ITYPE) THEN
               ISOUP=ISOU
               GOTO 998
            END IF
   10    CONTINUE
         GOTO 998
      END IF   



      IF (.NOT.GVFIBN(ISOUP,1,NUMSOU)) THEN
         CALL GVSTTE ('?MOLC08')
         GOTO 5
      END IF



      IF (ITYPE.EQ.0) THEN
         ISOUP=0
         GOTO 998
      END IF
      IF (ITYPE.NE.-1) THEN
         IF (SOUADM(5,ISOUP).NE.ITYPE) THEN
            IF (SOUADM(5,ISOUP).EQ.2.AND.ITYPE.EQ.6.OR.
     +          SOUADM(5,ISOUP).EQ.6.AND.ITYPE.EQ.2) THEN
               GOTO 998
            END IF
            CALL GVSTTE ('?MOLC66')
            IF (SOUADM(5,ISOUP).EQ.-1) THEN
               CALL GVSTTE ('?MOLC67')
            ELSE IF (.NOT.GVFIBN(SOUADM(5,ISOUP),1,7)) THEN
               CALL GVSTTB ('?MOLC68')
            ELSE
               CALL GVST6C ('?MOLC71',MTYPE(ITYPE),.TRUE.)
               CALL GVST6C ('?MOLC72',MTYPE(SOUADM(5,ISOUP)),.TRUE.)
            END IF
            GOTO 5
         END IF
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL310M (IMOD,TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IMOD, GVFLEN
      LOGICAL       GVFIBN, AHEAD
      CHARACTER*(*) TEXT







      IF (NUMSOU.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         IMOD=0
         GOTO 998
      END IF
      IF (WIFPAR(846).EQ.0) THEN
         CALL GVSTTE ('?NMREMP')
         IMOD=0
         GOTO 998
      END IF



   10 CONTINUE
      IF (.NOT.AHEAD().AND.WIFPAR(1105).EQ.0) THEN
         CALL GVSNL6 (1)
         IF (GVFLEN(TEXT).GT.0) THEN
            IF (TEXT(1:1).NE.'?') THEN
               CALL GVSTT6 (TEXT)
            ELSE
               CALL SHOWTEXT (TEXT)
            END IF
         END IF
      END IF



      CALL IPROMPT ('?MOLC65A')
      CALL WIFBO1 (7,' ')
      CALL GVSFFI (1,IMOD)
      IF (IMOD.EQ.0) GOTO 998



      IF (.NOT.GVFIBN(IMOD,1,WIFPAR(846))) THEN
         CALL GVSTTE ('?MOLC08A')
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SCN110 (BOOLS,TEXT,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'IRIGRA.INC'
      INTEGER       IERR, GVFCBT, GVFLEN, IAA
      LOGICAL       BOOLS(NUMUA), INTERRUPTED
      CHARACTER*(*) TEXT
      CHARACTER*80  LOCLIN

      RETURN
      END
      SUBROUTINE SCN111 (INAA,BOOLS,TEXTIN,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'IRIGRA.INC'
      INTEGER       IERR, ITST, INCTAA, IAATYP, I, GVFLEN, GVFCBT,
     +              IENDAA
      LOGICAL       GVFYON, GVFIBN, BOOLS(MAXTAT), INAA(NUMUA),
     +              INTERRUPTED, CH4EQCH4, T54EQUAL
      CHARACTER*80  TEXT, LOCLN2
      CHARACTER*(*) TEXTIN
      CHARACTER*4   CHAR4







      INCTAA=GVFCBT(INAA,WIFPAR(276))
      IF (.NOT.GVFIBN(INCTAA,1,WIFPAR(276))) THEN
         CALL GVSTTB ('?SCNM04')
         IERR=1
         GOTO 998
      END IF



      IF (GVFLEN(TEXTIN).LT.1) THEN
         CALL GVSSTX (TEXT,'?M0255')
      ELSE
         CALL GVSSTX (TEXT,TEXTIN)
      END IF



      IERR=0
      CALL GVSBTF (BOOLS,MAXTAT)




      IAATYP=0
      IENDAA=0
      DO 20 I=1,WIFPAR(276)
         IF (INAA(I)) IAATYP=I
         IF (INAA(I)) IENDAA=MAX(IENDAA,HATPRA(I))
   20 CONTINUE
      IF (.NOT.GVFIBN(IAATYP,1,WIFPAR(276))) THEN
         CALL GVSTTB ('?SCNM06')
         IERR=1
         GOTO 998
      END IF



   10 CONTINUE
      CALL GVST6C (TEXT,'?SCNM07',.TRUE.)
      IF (INTERRUPTED()) THEN
         IERR=1
         GOTO 998
      END IF



      IF (WIFPAR(287).EQ.0) THEN
         IF (INCTAA.EQ.1) THEN
            CALL GVSFMT ('?SCNM11')
            CALL GVSCTB (BIGLIN,132)
            WRITE (BIGLIN,FMT,ERR=999) 
     +       (MUTROW4(I,IAATYP),I=1,MIN(30,HATPRA(IAATYP)))
            IF (HATPRA(IAATYP).GT.30) BIGLIN(128:132)='.....'
            CALL GVSTT6 (BIGLIN)
         ELSE
            CALL SHOWTEXTIF ('?SCNM12')
         END IF
      END IF



      IF (WIFPAR(287).EQ.0) THEN
         CALL IPROMPT ('?SCNM08')
      ELSE
         CALL IPROMPT ('?SCNM08A')
      END IF
      CALL GETFULLLINE (LINE,IERR)
      IF (IERR.EQ.1) GOTO 998
      IF (IERR.EQ.2) THEN
         IF (INCTAA.GT.1) THEN
            CALL SHOWTEXT ('?SCNM13')
         ELSE
            CALL GVSFMT ('?SCNM11')
            CALL GVSCTB (BIGLIN,132)
            WRITE (BIGLIN,FMT,ERR=999) 
     +       (MUTROW4(I,IAATYP),I=1,MIN(30,HATPRA(IAATYP)))
            IF (HATPRA(IAATYP).GT.30) BIGLIN(128:132)='.....'
            CALL GVSTT6 (BIGLIN)
         END IF
         GOTO 10
      END IF
      CALL GVSCUC (LINE)
      IF (GVFLEN(LINE).LE.0) THEN
         CALL GVSTTE ('?SCNM10')
         GOTO 998
      END IF



   30 CONTINUE
         IF (GVFLEN(LINE).LE.0) GOTO 100
         CALL SPLITLINE (LINE,CHAR4,LOCLN2)
         IF (GVFLEN(CHAR4).LE.0) GOTO 100
         CALL GVSSTX (LINE,LOCLN2)



         IF (CHAR4.EQ.'BACK'.OR.CH4EQCH4(CHAR4,'BB  ').OR.
     +       CHAR4.EQ.'MAIN') THEN
            CALL GVSBTF (BOOLS,MAXTAT)
            CALL GVSBTT (BOOLS,4)
           GOTO 998
         END IF
         IF (CHAR4.EQ.'SIDE'.OR.CH4EQCH4(CHAR4,'SS  ').OR.
     +       CH4EQCH4(CHAR4,'SC  ')) THEN
            CALL GVSBTF (BOOLS,MAXTAT)
            CALL GVSBTT (BOOLS,IENDAA)
            CALL GVSBTF (BOOLS,4)
            GOTO 998
         END IF
         IF (CH4EQCH4(CHAR4,'ALL ')) THEN
            CALL GVSBTF (BOOLS,MAXTAT)
            CALL GVSBTT (BOOLS,IENDAA)
            GOTO 998
         END IF
         IF (CH4EQCH4(CHAR4,'DEF ')) THEN
            CALL SHOWTEXT ('?SCNM14')
            CALL GVSBTF (BOOLS,MAXTAT)
            CALL GVSBTT (BOOLS,IENDAA)
            CALL GVSBTF (BOOLS,4)
            IF (GVFCBT(BOOLS,MAXTAT).LT.3) BOOLS(2)=.TRUE.
            IF (GVFCBT(BOOLS,MAXTAT).LT.2) BOOLS(3)=.TRUE.
            IF (GVFCBT(BOOLS,MAXTAT).LT.3) BOOLS(1)=.TRUE.
            CALL GVSSTX (BIGLIN,'?M1223')
            DO 15 I=1,MAXTAT
               IF (BOOLS(I)) THEN
                  CALL GVSCPC (BIGLIN,MUTROW4(I,IAATYP))
                  CALL GVSCPC (BIGLIN,'-')
               END IF
   15       CONTINUE
            CALL GVSTT6 (BIGLIN)
            IF (.NOT.GVFYON('?SCNM09',' ')) GOTO 10
            GOTO 998
         END IF



         DO 40 ITST=HATPRA(IAATYP),1,-1
            IF (T54EQUAL(MUTROW4(ITST,IAATYP),CHAR4)) THEN
               BOOLS(ITST)=.TRUE.
            END IF
   40    CONTINUE
      GOTO 30



  100 CONTINUE
      IF (GVFCBT(BOOLS,MAXTAT).LE.0) THEN
         CALL GVSTTE ('?M0661')
         GOTO 10
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SCN111')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGAT (TEXT,IAA,IAT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, LOCIAT, IAT
      LOGICAL       WIFIRR, WIFIRW
      CHARACTER*(*) TEXT







      IERR=0
      IAA=0
      IAT=0
      CALL GVSBTF (LOCPAT,MAXTAT)
      CALL GVSBTF (LOCPAA,NUMUA)



      CALL WIFGRS (IAA,TEXT)
      IF (IAA.EQ.0) THEN
         IERR=1
         GOTO 998
      END IF



      IF (.NOT.WIFIRR(IAA)) THEN
         IF (WIFIRW(IAA)) THEN
            CALL WIFGATW (IAA,IAT,IERR)
         ELSE
            CALL WIFGATD (IAA,IAT,IERR)
         END IF
         IF (IAT.EQ.0.OR.IERR.NE.0) IAA=0
         IF (IAA.NE.0.AND.IAT.NE.0) CALL DIF015 (6,'?M1663',IAT)
         GOTO 998
      END IF



      CALL GVSBTF (LOCPAA,NUMUA)
      LOCPAA(RESTYP(IAA))=.TRUE.
   20 CONTINUE
      CALL WIFPUSHPPP (287,1)
      CALL SCN111 (LOCPAA,LOCPAT,'?WIFGAT',IERR)
      CALL WIFPOPPPP (287)
      IF (IERR.NE.0) GOTO 998



      DO 30 LOCIAT=1,MAXTAT
         IF (LOCPAT(LOCIAT)) THEN
            IAT=PNTAAS(IAA)+LOCIAT-1
            GOTO 998
         END IF
   30 CONTINUE



      CALL GVSTTE ('?BADGAT')
      GOTO 20



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGATD (IAA,IAT,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, IAA, IAT, IAT1, LENCHR, J
      CHARACTER*5   CHAR5
      CHARACTER*80  LOCLIN







      IERR=1



      CALL GVSNL6 (1)
      CALL GVSTT6 ('?M0255')
      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA),15
         CALL GVSCTB (LINE,80)
         DO 5 J=0,MIN(14,PNTAAE(IAA)-IAT)
            CALL GVSSTX (LINE(5*J+1:5*J+5),ONESAT(IAT+J))
 5       CONTINUE
         CALL GVSTT6 (LINE)
   10 CONTINUE



      CALL IPROMPT ('?WIFGAT')
      CALL GVSCTB (LOCLIN,80)
      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCUC (LOCLIN)
      CALL GVSSHL (LOCLIN)



      IAT=0
      IERR=1
      DO 30 IAT1=PNTAAS(IAA),PNTAAE(IAA)
         CALL GVSCTB (CHAR5,5)
         CALL GVSSTX (CHAR5,ONESAT(IAT1))
         CALL GVSSHL (CHAR5)
         LENCHR=GVFLEN(CHAR5)+1
         IF (LOCLIN(1:LENCHR).EQ.CHAR5(1:LENCHR)) THEN
            IAT=IAT1
            IERR=0
            GOTO 998
         END IF
   30 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGATW (IAA,IAT,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, IAT, IAT1
      LOGICAL       CH4EQCH4







      IERR=1



   10 CONTINUE
      CALL IPROMPT ('?WATER0')
      CALL GETWORD (LINE,IERR)
      IF (IERR.NE.0) GOTO 998



      CALL GVSCUC (LINE)
      DO 20 IAT1=PNTAAE(NUMAAF)+1,NUMATF
         IF (CH4EQCH4(ORGNAM(IAT1),LINE(1:4))) THEN
            IAT=IAT1
            IAA=ATIAA(IAT)
            GOTO 998
         END IF
   20 CONTINUE
      CALL GVSTTE ('?WATB10')
      GOTO 10



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGPR (ISEQ1,ISEQ2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       GVFLFI, ISEQ1, ISEQ2, I, IERR
      CHARACTER*80  LOCLIN







      ISEQ1=0
      ISEQ2=0



      CALL I1XPROMPT ('?RNG2PP',NBINDB)



      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.EQ.1) THEN
         GOTO 998
      ELSE IF (IERR.EQ.2) THEN
         ISEQ1=1
         ISEQ2=NBINDB





         WIFPAR(96)=-1
         GOTO 998
      END IF



      CALL GVSSHL (LOCLIN)
      IF (LOCLIN(1:3).EQ.'ALL'.OR.LOCLIN(1:3).EQ.'TOT') THEN
         ISEQ1=1
         ISEQ2=NBINDB
         GOTO 998
      END IF



      I=GVFLFI(1,ISEQ1,LOCLIN)



      IF (I.EQ.0) THEN
         CALL FLUSHAHEAD
         GOTO 998
      END IF



      CALL PEEKWORD (LOCLIN,IERR)
      IF (IERR.NE.0) THEN
         ISEQ2=ISEQ1
         GOTO 998
      END IF



      I=GVFLFI(1,ISEQ2,LOCLIN)
      IF (I.EQ.0) THEN
         ISEQ2=ISEQ1
      ELSE
         CALL GETWORD (LOCLIN,IERR)
      END IF





      WIFPAR(96)=-1



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGPS (IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       GVFLFI, ISEQ1, ISEQ2, I, IERR, GVFCBT, WIFFPS,
     +              GVFLEN
      LOGICAL       GVFIBN
      CHARACTER*80  LOCLIN







      IF (WIFPAR(827).EQ.1) THEN
         IERR=0
         GOTO 998
      END IF



      ISEQ1=0
      ISEQ2=0
      CALL GVSBTF (USE3SP,MAXSEQ)



 10   CONTINUE
         CALL IPROMPT ('?RNG2PS')
         CALL GVSCTB (LOCLIN,80)



 20      CONTINUE
            CALL GETWORD (LOCLIN,IERR)
            CALL GVSSHL (LOCLIN)



            IF (LOCLIN(1:2).EQ.'0 ') THEN
               IERR=0
               GOTO 998
            END IF
            IF (GVFLEN(LOCLIN).LE.0) THEN
               CALL SHOWTEXT ('?WIFBO0')
               GOTO 10
            ELSE
               IF (IERR.EQ.1) GOTO 998
            END IF



            ISEQ1=WIFFPS(LOCLIN)
            IF (GVFIBN(ISEQ1,1,NBINDB)) THEN
               USE3SP(ISEQ1)=.TRUE.
               GOTO 20
            END IF



         CALL GVSCUC (LOCLIN)
         CALL GVSSHL (LOCLIN)
         IF (LOCLIN(1:3).EQ.'ALL'.OR.LOCLIN(1:3).EQ.'TOT') THEN
            CALL GVSBTT (USE3SP,NBINDB)
            GOTO 10
         END IF



         I=GVFLFI(1,ISEQ1,LOCLIN)
         IF (I.EQ.0) THEN
            CALL FLUSHAHEAD
            GOTO 10
         END IF



         CALL PEEKWORD (LOCLIN,IERR)
         IF (IERR.NE.0) THEN
            ISEQ2=ISEQ1
            USE3SP(ISEQ1)=.TRUE.
            GOTO 10
         END IF



         I=GVFLFI(1,ISEQ2,LOCLIN)
         IF (I.EQ.0) THEN
            ISEQ2=ISEQ1
         ELSE
            CALL GETWORD (LOCLIN,IERR)
         END IF
         IF (ISEQ1.EQ.0) GOTO 998
         IF (ISEQ2.EQ.0) THEN
            USE3SP(ISEQ1)=.TRUE.
            GOTO 998
         END IF
         CALL GVSBTT (USE3SP(ISEQ1),ISEQ2-ISEQ1+1)
      GOTO 10



  998 CONTINUE
      IF (GVFCBT(USE3SP,MAXSEQ).GT.0) THEN
         IERR=0





         WIFPAR(96)=-1
      ELSE
         IERR=1   
      END IF


      RETURN
      END
      INTEGER FUNCTION WIFFPS(TEXT)

















      IMPLICIT      NONE
      INCLUDE       'DATBAS.INC'
      INTEGER       ISEQ, GVFLEN
      CHARACTER*(*) TEXT







      WIFFPS=0



      IF (LEN(TEXT).LT.4) GOTO 998
      IF (GVFLEN(TEXT).LT.4) GOTO 998



      DO 10 ISEQ=1,NBINDB
         IF (TEXT(1:4).EQ.NAMFIL(ISEQ)) THEN
            IF (GVFLEN(TEXT).EQ.5.AND.TEXT(5:5).NE.FILCNM(ISEQ)) GOTO 10
            WIFFPS=ISEQ
            GOTO 998
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIFGAA (AACID,INTEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       I, INDAA3, INDAA1, IERR, GVFLEN, IAATYP
      CHARACTER*(*) INTEXT
      CHARACTER*4   AACID
      CHARACTER*80  TEXT







      AACID='0   '
      IERR=0



      IF (GVFLEN(INTEXT).LE.0) THEN
         CALL GVSSTX (TEXT,'?M0266')
      ELSE
         CALL GVSSTX (TEXT,INTEXT)
      END IF



   10 CONTINUE
      CALL IPROMPT (TEXT)



      CALL GETWORD (AACID,IERR)
      CALL GVSCUC (AACID)
      IF (IERR.NE.0) THEN
         AACID='0   '
         GOTO 998
      END IF
      I=GVFLEN(AACID)



      IF (I.GE.3) THEN
         IAATYP=INDAA3(AACID)
         IF (IAATYP.EQ.0) THEN
            CALL GVSTT6 ('?RNGNPN')
            GOTO 10
         END IF
         IF (WIFPAR(141).NE.0) THEN
            IF (FAMTYP(IAATYP).NE.WIFPAR(141)) THEN
               CALL GVSTTE ('?M1606')
               GOTO 10
            END IF
         END IF



      ELSE IF (I.EQ.1) THEN
         IAATYP=INDAA1(AACID(1:1))
         IF (IAATYP.EQ.0) THEN
            CALL GVSTT6 ('?RNGNPN')
            GOTO 10
         END IF
         IF (WIFPAR(141).NE.0) THEN
            IF (FAMTYP(IAATYP).NE.WIFPAR(141)) THEN
               CALL GVSTTE ('?M1606')
               GOTO 10
            END IF
         END IF
         AACID=AANAME(IAATYP)



      ELSE
         CALL GVSTT6 ('?NOT1O3')
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFGRN (IFT1,IFT2,TEXT)





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'IRIGRA.INC'
      INCLUDE       'CLUFAM.INC'
      INCLUDE       'HSTINC.INC'
      INTEGER       IFT1, IFT2, I, ISOUP, IAT1, IAT2, IERR, WIF058,
     +              GVFLEN, GVFPOS, GVFLFI, ICLU, IFAM, IAA, LENLIN,
     +              GVFSCP, IPNTSO, HELPNT(2,4), INDAA3, IFRG
      LOGICAL       GVFIBN, AHEAD, WIFIRA, WIFIRW, WIFIRN, WIFIRD,
     +              WIFIRR, GOTWORD, WIFIRI, WIFIRZ, WASIR6, WIFIRM,
     +              WIFIRO
      CHARACTER*(*) TEXT
      CHARACTER*80  LOCLIN1, LOCLIN2
      CHARACTER*1   IOTYPE








      IFT1=0
      IFT2=0
      IOTYPE=' '
      WIFPAR(118)=0
      GOTWORD=.FALSE.




      IF (WIFPAR(862).EQ.1) GOTO 333
      IF (NUMAAT.LT.1.OR.NUMATF.LT.1) THEN
         CALL GVSTTE ('?SOUSML')
         GOTO 200
      END IF




  333 CONTINUE
   10 CONTINUE
      IFT1=0
      IFT2=0
      IF (TEXT(1:1).EQ.'?') THEN
         CALL SHOWTEXTIF (TEXT)
      ELSE
         IF (.NOT.AHEAD()) CALL GVSTT6 (TEXT)
      END IF
      IF (WIFPAR(860).NE.0.AND.WIFPAR(862).EQ.0) THEN
         CALL GVSSTX (LOCLIN1,'?GIVRNG')
         CALL GVSCPC (LOCLIN1,'(')
         CALL GVSWIL (LOCLIN1(71:80),WIFPAR(860),IERR)
         IF (IERR.NE.0) THEN
            CALL FLUSHAHEAD
            GOTO 200
         END IF
         CALL GVSCPC (LOCLIN1,',')
         CALL GVSRDB (LOCLIN1)
         CALL GVSWIL (LOCLIN1(71:80),WIFPAR(861),IERR)
         IF (IERR.NE.0) THEN
            CALL FLUSHAHEAD
            GOTO 200
         END IF
         CALL GVSRDB (LOCLIN1)
         CALL GVSCPC (LOCLIN1,')')
         CALL IPROMPT (LOCLIN1)
      ELSE
         IF (WIFPAR(862).EQ.0) THEN
            CALL IPROMPT ('?GIVRNG')
         ELSE
            CALL IPROMPT ('?GIVRES')
         END IF
      END IF



      CALL WIFBO1 (2,' ')



      CALL NEEDWORD (LOCLIN2,' ',IERR)
      CALL GVSSHL (LOCLIN2)
      IF (IERR.EQ.1) THEN
         IFT1=0
         IFT2=0
         GOTO 200
      END IF
      IF (GVFPOS(LOCLIN2,'GVSKIL').NE.0) CALL GVSKIL
      LENLIN=GVFLEN(LOCLIN2)
      GOTWORD=LENLIN.GT.0



      IF (LENLIN.LE.0) THEN
         IF (WIFPAR(860).NE.0) THEN
            DO 18 IAA=WIFPAR(860),WIFPAR(861)
               WRK1TF(IAA)=.TRUE.
   18       CONTINUE            
            IFT1=0
            GOTO 200
         ELSE
            CALL SHOSOU
            GOTO 10
         END IF
      END IF



      IF (NUMFAM.GT.0) THEN
         DO 20 IFAM=1,NUMFAM
            IF (LOCLIN2(1:LENLIN).EQ.FAMNAM(IFAM)(1:LENLIN)) THEN
               IFT1=FAMILY(1,IFAM)
               IFT2=FAMILY(2,IFAM)
               GOTO 200
            END IF
   20    CONTINUE
      END IF



      IF (NUMCLU.GT.0) THEN
          DO 40 ICLU=1,NUMCLU
            IF (LOCLIN2(1:LENLIN).EQ.CLUNAM(ICLU)(1:LENLIN)) THEN
               DO 30 IAA=1,LENCLU(ICLU)
                  WRK1TF(CLUSTR(IAA,ICLU))=.TRUE.
   30          CONTINUE
               WIFPAR(118)=1
               IFT1=0
               GOTO 200
            END IF
   40    CONTINUE
      END IF



      DO 47 ISOUP=1,NUMSOU
         IPNTSO=SOUPNT(SOUADM(1,ISOUP))
         IF (IPNTSO.LE.0) THEN
            CALL GVSTTI ('?M2658',IPNTSO)
            CALL GVSKIL
         END IF
         IF (GVFLEN(SOUNAM(IPNTSO)).LE.0) THEN
            CALL GVSTT6 ('?M2657')
            CALL GVSKIL
         END IF
         IF (GVFSCP(LOCLIN2,SOUNAM(IPNTSO),IERR).EQ.0) THEN
            IF (IERR.NE.0) GOTO 47
            DO 45 IAA=1,NUMAAT
               WRK1TF(IAA)=(SOUPNT(IAA).EQ.IPNTSO)
 45         CONTINUE
            WIFPAR(118)=1
            IFT1=0
            GOTO 200
         END IF
 47   CONTINUE



      IF (GVFLEN(LOCLIN2).EQ.1) THEN
         DO 49 ISOUP=1,NUMSOU
            IF (CHANAM(SOUADM(1,ISOUP)).EQ.LOCLIN2(1:1)) THEN
               IFT1=SOUADM(1,ISOUP)
               IFT2=SOUADM(2,ISOUP)
               GOTO 200
            END IF
 49      CONTINUE
      END IF



      CALL GVSCUC (LOCLIN2)





      IF (LOCLIN2(1:4).EQ.'PROT') THEN
         DO 1101 IAA=1,NUMAAT
            IF (WIFIRA(IAA)) WRK1TF(IAA)=.TRUE.
 1101    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:5).EQ.'WATER') THEN
         DO 1102 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRW(IAA)) WRK1TF(IAA)=.TRUE.
 1102    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:4).EQ.'DRUG') THEN
         DO 1103 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRD(IAA)) WRK1TF(IAA)=.TRUE.
 1103    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:3).EQ.'NUC') THEN
         DO 1104 IAA=1,NUMAAT
            IF (WIFIRN(IAA)) WRK1TF(IAA)=.TRUE.
 1104    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:3).EQ.'SUG') THEN
         DO 1105 IAA=1,NUMAAT
            IF (WIFIRZ(IAA)) WRK1TF(IAA)=.TRUE.
 1105    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:6).EQ.'4BUNDL') THEN
         CALL GET4HEL (1,NUMAAF,HELPNT,IERR)
         IF (IERR.NE.0) GOTO 200
         DO 1106 IAA=1,NUMAAF
            IF (GVFIBN(IAA,HELPNT(1,1),HELPNT(2,1))) WRK1TF(IAA)=.TRUE.
            IF (GVFIBN(IAA,HELPNT(1,2),HELPNT(2,2))) WRK1TF(IAA)=.TRUE.
            IF (GVFIBN(IAA,HELPNT(1,3),HELPNT(2,3))) WRK1TF(IAA)=.TRUE.
            IF (GVFIBN(IAA,HELPNT(1,4),HELPNT(2,4))) WRK1TF(IAA)=.TRUE.
 1106    CONTINUE
         CALL DIF010A (HELPNT(1,1),HELPNT(2,1),'?M2167')
         CALL DIF010A (HELPNT(1,2),HELPNT(2,2),'?M2168')
         CALL DIF010A (HELPNT(1,3),HELPNT(2,3),'?M2169')
         CALL DIF010A (HELPNT(1,4),HELPNT(2,4),'?M2170')
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:5).EQ.'HELIX') THEN
         CALL GVSCPB (WRK4TF,WRK1TF,NUMAAT)
         CALL DSP001 (.FALSE.)
         CALL GVSCPB (WRK1TF,WRK4TF,NUMAAT)
         DO 1107 IAA=1,NUMAAF
            IF (LOCHST(IAA).EQ.'H'.OR.LOCHST(IAA).EQ.'3') 
     +       WRK1TF(IAA)=.TRUE.
 1107    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:6).EQ.'STRAND'.OR.LOCLIN2(1:5).EQ.'SHEET') THEN
         CALL GVSCPB (WRK4TF,WRK1TF,NUMAAT)
         CALL DSP001 (.FALSE.)
         CALL GVSCPB (WRK1TF,WRK4TF,NUMAAT)
         DO 1108 IAA=1,NUMAAF
            IF (LOCHST(IAA).EQ.'S') WRK1TF(IAA)=.TRUE.
 1108    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:3).EQ.'ION') THEN
         DO 1109 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRM(IAA)) WRK1TF(IAA)=.TRUE.
 1109    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:3).EQ.'OXT') THEN
         DO 1110 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRO(IAA)) WRK1TF(IAA)=.TRUE.
 1110    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:6).EQ.'BURIED') THEN
         DO 1111 IAA=1,NUMAAF
            IF (.NOT.ACCDON(IAA)) CALL ACC017 (IERR)
            IF (SUMACC(IAA).LT.FLOAT(WIFPAR(29))/100.0)
     +       WRK1TF(IAA)=.TRUE.
 1111    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:6).EQ.'ACCESS') THEN
         DO 1112 IAA=1,NUMAAF
            IF (.NOT.ACCDON(IAA)) CALL ACC017 (IERR)
            IF (SUMACC(IAA).GE.FLOAT(WIFPAR(29))/100.0)
     +       WRK1TF(IAA)=.TRUE.
 1112    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:5).EQ.'NOWAT') THEN
         DO 1113 IAA=1,NUMAAT
            IF (.NOT.WIFIRW(IAA)) WRK1TF(IAA)=.TRUE.
 1113    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF



      IF (INDAA3(LOCLIN2(1:4)).NE.0) THEN
         DO 1114 IAA=1,NUMAAT
            IF (INDAA3(LOCLIN2(1:4)).EQ.RESTYP(IAA)) THEN
               WRK1TF(IAA)=.TRUE.
            END IF
 1114    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF

      IF (LOCLIN2(1:9).EQ.'LONGHELIX'.OR.LOCLIN2(1:9).EQ.'LONG HELI'.OR.
     +    LOCLIN2(1:9).EQ.'LONG-HELI'.OR.LOCLIN2(1:9).EQ.'LONG_HELI') 
     +    THEN
         CALL GVSCPB (WRK4TF,WRK1TF,NUMAAT)
         CALL DSP001 (.FALSE.)
         CALL GVSCPB (WRK1TF,WRK4TF,NUMAAT)
         IF (NUMFRG.LE.0) GOTO 200
         DO 1116 IFRG=1,NUMFRG
            IF (HSTTAB(3,IFRG).EQ.4.AND.HSTTAB(4,IFRG).GE.7) THEN
               DO 1115 IAA=HSTTAB(1,IFRG),HSTTAB(2,IFRG)
                  WRK1TF(IAA)=.TRUE.
 1115          CONTINUE
            END IF
 1116    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF






      IF (LOCLIN2(1:5).EQ.'-PROT') THEN
         DO 1201 IAA=1,NUMAAT
            IF (WIFIRA(IAA)) WRK1TF(IAA)=.FALSE.
 1201    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:6).EQ.'-WATER') THEN
         DO 1202 IAA=1,NUMAAT
            IF (WIFIRW(IAA)) WRK1TF(IAA)=.FALSE.
 1202    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:5).EQ.'-DRUG') THEN
         DO 1203 IAA=1,NUMAAT
            IF (WIFIRD(IAA)) WRK1TF(IAA)=.FALSE.
 1203    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:4).EQ.'-NUC') THEN
         DO 1204 IAA=1,NUMAAT
            IF (WIFIRN(IAA)) WRK1TF(IAA)=.FALSE.
 1204    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:4).EQ.'-SUG') THEN
         DO 1205 IAA=1,NUMAAT
            IF (WIFIRZ(IAA)) WRK1TF(IAA)=.FALSE.
 1205    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:5).EQ.'-ALL') THEN
         DO 1206 IAA=1,NUMAAF
            IF (WIFIRR(IAA)) WRK1TF(IAA)=.FALSE.
 1206    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:6).EQ.'-HELIX') THEN
         CALL GVSCPB (WRK4TF,WRK1TF,NUMAAT)
         CALL DSP001 (.FALSE.)
         CALL GVSCPB (WRK1TF,WRK4TF,NUMAAT)
         DO 1207 IAA=1,NUMAAF
            IF (LOCHST(IAA).EQ.'H'.OR.LOCHST(IAA).EQ.'3') 
     +       WRK1TF(IAA)=.FALSE.
 1207    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:7).EQ.'-STRAND'.OR.LOCLIN2(1:6).EQ.'-SHEET') THEN
         CALL GVSCPB (WRK4TF,WRK1TF,NUMAAT)
         CALL DSP001 (.FALSE.)
         CALL GVSCPB (WRK1TF,WRK4TF,NUMAAT)
         DO 1208 IAA=1,NUMAAF
            IF (LOCHST(IAA).EQ.'S') WRK1TF(IAA)=.FALSE.
 1208    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:4).EQ.'-ION') THEN
         DO 1209 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRM(IAA)) WRK1TF(IAA)=.FALSE.
 1209    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:4).EQ.'-OXT') THEN
         DO 1210 IAA=MAX(1,NUMAAF),NUMAAT
            IF (WIFIRO(IAA)) WRK1TF(IAA)=.FALSE.
 1210    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF
      IF (LOCLIN2(1:1).EQ.'-'.AND.INDAA3(LOCLIN2(2:5)).NE.0) THEN
         DO 1211 IAA=1,NUMAAT
            IF (INDAA3(LOCLIN2(2:5)).EQ.RESTYP(IAA)) 
     +       WRK1TF(IAA)=.FALSE.
 1211    CONTINUE
         IFT1=0
         WIFPAR(118)=1
         GOTO 200
      END IF





      IF (LOCLIN2(1:3).EQ.'ALL') THEN
         IFT1=1
         IFT2=NUMAAF
         GOTO 200
      END IF
      IF (LOCLIN2(1:3).EQ.'TOT') THEN
         IFT1=1
         IFT2=NUMAAT
         GOTO 200
      END IF
      IF (LOCLIN2(1:4).EQ.'LAST') THEN
         IFT1=NUMAAF
         IFT2=NUMAAF
         GOTO 200
      END IF
      IF (LOCLIN2(1:3).EQ.'END') THEN
         IFT1=NUMAAT
         IFT2=NUMAAT
         GOTO 200
      END IF





      IF (LOCLIN2(1:1).EQ.'P') THEN
         IF (LOCLIN2(2:2).EQ.'L'.AND.WIFIRI(IRSTAT(15))) THEN
            IFT1=IRSTAT(15)
            IFT2=IRSTAT(15)
            GOTO 200
         END IF
         IF (IRSTAT(6).EQ.0) THEN
            WASIR6=.TRUE.
            CALL GRTKOF
         ELSE
            WASIR6=.FALSE.
         END IF
         IF (WIFPAR(862).NE.0) THEN
            CALL GRA008 (IFT1,IAT1)
            IFT2=IFT1
         ELSE
            CALL GRA009 (IFT1,IAT1,IFT2,IAT2)
         END IF
         IF (WASIR6) CALL GRTKON
         GOTO 200
      END IF






      IF (GVFPOS('OUMS',LOCLIN2(1:1)).NE.0) THEN
         IOTYPE=LOCLIN2(1:1)
         LOCLIN2(1:1)=' '
         CALL GVSSHL (LOCLIN2)
      END IF





      IF (IOTYPE(1:1).EQ.'O') THEN



         IFT1=WIF058(LOCLIN2,0)
         IF (IFT1.EQ.0) THEN
            IFT2=0
            CALL GVST6C ('?RSNOTF',LOCLIN2,.TRUE.)
            CALL POKEAHEAD (LOCLIN2)
            CALL FLUSHAHEAD
            GOTO 200
         END IF



         IF (WIFPAR(862).EQ.1) THEN
            IFT2=IFT1
            GOTO 200
         END IF



         CALL CLEANLINE (LOCLIN2,2,IERR)
         IF (IERR.NE.0) THEN
            IFT2=IFT1
            GOTO 200
         END IF



         IFT2=WIF058(LOCLIN2,0)
         IF (IFT2.EQ.0.AND.(LOCLIN2(1:1).EQ.'O'.OR.
     +       LOCLIN2(1:1).EQ.'o')) THEN
            LOCLIN2(1:1)=' '
            CALL GVSSHL (LOCLIN2)
            IFT2=WIF058(LOCLIN2,0)
         END IF
         IF (IFT2.EQ.0) THEN
            IFT2=IFT1
            CALL GVST6C ('?RSNOTF',LOCLIN2,.TRUE.)
            CALL POKEAHEAD (LOCLIN2)
            CALL FLUSHAHEAD
         END IF
         GOTO 200
      END IF





      IF (IOTYPE.EQ.'U') THEN



         I=GVFLFI(1,ISOUP,LOCLIN2)
         IF (I.EQ.0) THEN
            CALL GVSTTE ('?MOLRSE')
            CALL POKEAHEAD (LOCLIN2)
            CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF
         IF (.NOT.GVFIBN(ISOUP,1,NUMSOU)) THEN
            CALL GVSTTE ('?BADMOL')
            CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF



         CALL CLEANLINE (LOCLIN2,1,IERR)
         IF (IERR.NE.0) THEN
            CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF



         IFT1=WIF058(LOCLIN2,ISOUP)
         IF (IFT1.EQ.0) THEN
            IFT2=0
            CALL GVST6C ('?RSNOTF',LOCLIN2,.TRUE.)
            CALL POKEAHEAD (LOCLIN2)
            CALL FLUSHAHEAD
            GOTO 200
         END IF



         IF (WIFPAR(862).EQ.1) THEN
            IFT2=IFT1
            GOTO 200
         END IF



         CALL CLEANLINE (LOCLIN2,2,IERR)
         IF (IERR.NE.0) THEN
            IFT2=IFT1
            GOTO 200
         END IF



         IFT2=WIF058(LOCLIN2,ISOUP)
         IF (IFT2.EQ.0) THEN
            IFT2=IFT1
            CALL POKEAHEAD (LOCLIN2)
            CALL FLUSHAHEAD
         END IF
         GOTO 200
      END IF







      IF (IOTYPE.EQ.'S') THEN



         I=GVFLFI(1,ISOUP,LOCLIN2)
         IF (I.EQ.0) THEN
            CALL GVSTTE ('?MOLRSE')
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF
         IF (.NOT.GVFIBN(ISOUP,1,NUMSOU)) THEN
            CALL GVSTTE ('?BADMOL')
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF



         CALL CLEANLINE (LOCLIN2,1,IERR)
         IF (IERR.NE.0) THEN
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF



         I=GVFLFI(1,IFT1,LOCLIN2)
         IF (I.EQ.0) THEN
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF
         IFT1=IFT1+SOUADM(1,ISOUP)-1



         IF (WIFPAR(862).EQ.1) THEN
            IFT2=IFT1
            GOTO 200
         END IF



         CALL CLEANLINE (LOCLIN2,2,IERR)
         IF (IERR.NE.0) THEN
            IF (IERR.NE.1) CALL POKEAHEAD (LOCLIN2)
            IFT2=IFT1
            GOTO 200
         END IF



         I=GVFLFI(1,IFT2,LOCLIN2)




         IF (I.EQ.0) THEN
            IFT2=IFT1
            CALL GVST6C ('?RSNOTF',LOCLIN2,.TRUE.)
            IF (IFT2.NE.0) CALL POKEAHEAD (LOCLIN2)
            GOTO 200
         END IF



         IFT2=IFT2+SOUADM(1,ISOUP)-1
         IF (.NOT.GVFIBN(IFT2,SOUADM(1,ISOUP),SOUADM(2,ISOUP))) THEN
            CALL GVSTTI ('?M0723',IFT2)
            IFT2=SOUADM(2,ISOUP)
         END IF
         GOTO 200
      END IF





      IF (IOTYPE.EQ.'M') THEN



         I=GVFLFI(1,ISOUP,LOCLIN2)
         IF (I.EQ.0) THEN
            CALL GVSTTE ('?MOLRSE')
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF
         IF (.NOT.GVFIBN(ISOUP,1,NUMSOU)) THEN
            CALL GVSTTE ('?BADMOL')
            CALL POKEAHEAD (LOCLIN2)
            IF (IERR.NE.1) CALL FLUSHAHEAD
            IFT1=0
            IFT2=0
            GOTO 200
         END IF



         IFT1=SOUADM(1,ISOUP)
         IFT2=SOUADM(2,ISOUP)
         GOTO 200
      END IF








      I=GVFLFI(1,IFT1,LOCLIN2)
      IF (I.EQ.0) THEN
         CALL POKEAHEAD (LOCLIN2)
         CALL FLUSHAHEAD
         GOTO 200
      END IF
      IF (IFT1.EQ.0) THEN
         CALL POKEAHEAD (LOCLIN2)
         IF (IERR.NE.1) CALL FLUSHAHEAD
         IFT2=0
         GOTO 200
      END IF



      IF (WIFPAR(862).EQ.1) THEN
         IFT2=IFT1
         GOTO 200
      END IF



      CALL CLEANLINE (LOCLIN2,2,IERR)
      IF (IERR.NE.0) THEN
         CALL POKEAHEAD (LOCLIN2)
         IF (IERR.NE.1) CALL FLUSHAHEAD
         IFT2=IFT1
         GOTO 200
      END IF



      I=GVFLFI(1,IFT2,LOCLIN2)




      IF (I.EQ.0.OR.IFT2.EQ.0) THEN
         IFT2=IFT1
         CALL GVST6C ('?RSNOTF',LOCLIN2,.TRUE.)
         CALL POKEAHEAD (LOCLIN2)
         CALL GVST6C ('?M3131',LOCLIN2,.FALSE.)
         GOTO 200
      END IF



  200 CONTINUE
      IF (IFT1.GT.IFT2) CALL GVSWIP (IFT1,IFT2)
      IF ((.NOT.GVFIBN(IFT1,0,NUMAAT)).OR.
     +    (.NOT.GVFIBN(IFT2,0,NUMAAT))) THEN
         CALL GVSTTE ('?BADRES')
         CALL GVSTTI2 ('?M1379',IFT1,IFT2)
         IFT1=0
         IFT2=0
         WIFPAR(118)=1
         CALL FLUSHAHEAD
      END IF
      IF (WIFPAR(860).EQ.0.AND.WIFPAR(118).EQ.0) THEN
         IF (GOTWORD.AND.IFT1.EQ.0) THEN
            CALL GVSTTE ('?M1027')
         END IF
      END IF



      WIFPAR(860)=0
      WIFPAR(861)=0
      WIFPAR(863)=0
      WIFPAR(864)=0






      RETURN
      END
      SUBROUTINE WIFGRS (IFT1,TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IDUMMY, IFT1
      LOGICAL       GVFIBN
      CHARACTER*(*) TEXT







      IFT1=0
      IF (NUMAAT.LT.1.OR.NUMATF.LT.1) THEN
         CALL GVSTTE ('?SOULOW')
         GOTO 998
      END IF



 10   CONTINUE
      WIFPAR(860)=0
      WIFPAR(861)=0
      WIFPAR(862)=1
      CALL WIFGRN (IFT1,IDUMMY,TEXT)
      IF (IDUMMY.GT.IFT1) THEN
         CALL GVSTTI ('?M0731',IDUMMY)
         GOTO 10
      END IF
      WIFPAR(862)=0
      IF (.NOT.GVFIBN(IFT1,0,NUMAAT)) THEN
         CALL GVSKIL
         IFT1=0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIFWTF (TEXT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       GVFLEN, GVFCBT, IFT1, IFT2, IAA, IERR, CNT
      CHARACTER*(*) TEXT
      LOGICAL       AHEAD







      IF (NUMAAT.LT.1) THEN
         CALL GVSTTE ('?SOUEMP')
         IERR=1
         GOTO 998
      END IF



      IERR=0
      CALL GVSBTF (WRK1TF,MAXAA)



      IF (WIFPAR(845).NE.0) THEN
         CALL GVSCPB (WRK1TF,CHOSTF,MAXAA)
         GOTO 998
      END IF



      IF (WIFPAR(493).NE.0) THEN
         CALL GVSBTT (WRK1TF,NUMAAF)
         GOTO 998
      END IF



   10 CONTINUE
      IF (WIFPAR(1105).EQ.0) THEN
         IF (GVFLEN(TEXT).GT.0) THEN
            IF (TEXT(1:1).EQ.'?') THEN
               CALL SHOWTEXTIF (TEXT)
            ELSE
               IF (AHEAD()) CALL GVSTT6 (TEXT)
            END IF
         ELSE
            CALL SHOWTEXTIF ('?M0709')
         END IF
      END IF



      CALL WIFGRN (IFT1,IFT2,' ')




      IF (WIFPAR(118).NE.0) THEN
         GOTO 10
      END IF




      IF (IFT1.EQ.0) THEN
         CNT=GVFCBT(WRK1TF,NUMAAT)
         IF (CNT.LE.0) THEN
            IERR=1
         ELSE
            IERR=0
         END IF
         GOTO 998
      END IF



      DO 20 IAA=IFT1,IFT2
         WRK1TF(IAA)=.TRUE.
   20 CONTINUE



      GOTO 10



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WRK1TFCOMPLETE

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, IBND, JAT
      LOGICAL       MISSING, WIFITI, GVFYON, EXTEND







      IF (WIFPAR(1091).GT.0) GOTO 998



      MISSING=.FALSE.



      DO 30 IAA=1,NUMAAT
         IF (WRK1TF(IAA)) THEN
            DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
               DO 10 IBND=1,8
                  JAT=BOUND_TO(IBND,IAT)
                  IF (JAT.GT.0) THEN
                     IF (WIFITI(JAT).AND.ISATOK(JAT)) THEN
                        IF (.NOT.WRK1TF(ATIAA(JAT))) THEN
                           MISSING=.TRUE.
                           IF (.NOT.DEFALL.AND.WIFPAR(1105).EQ.0.AND.
     +                          WIFPAR(1091).GE.0) THEN
                              CALL DIF008 ('?M1123',IAA)
                              CALL DIF008 ('?M1124',ATIAA(JAT))
                              CALL SHOIAA (ATIAA(JAT))
                           END IF
                        END IF
                     END IF
                  END IF
   10          CONTINUE
   20       CONTINUE
         END IF
   30 CONTINUE



      IF (.NOT.MISSING) GOTO 998



      EXTEND=.FALSE.
      IF (DEFALL.OR.WIFPAR(1105).NE.0.OR.WIFPAR(1091).LT.0.OR.
     +    WIFPAR(375).NE.0) THEN
         EXTEND=.TRUE.
      ELSE
         EXTEND=GVFYON('?M1125',' ')
      END IF
      IF (EXTEND) THEN
   35    CONTINUE
         MISSING=.FALSE.
         DO 60 IAA=1,NUMAAT
            IF (WRK1TF(IAA)) THEN
               DO 50 IAT=PNTAAS(IAA),PNTAAE(IAA)
                  DO 40 IBND=1,8
                     IF (WIFITI(BOUND_TO(IBND,IAT))) THEN
                        JAA=ATIAA(BOUND_TO(IBND,IAT))
                        IF (.NOT.WRK1TF(JAA)) THEN
                           MISSING=.TRUE.
                           WRK1TF(JAA)=.TRUE.
                        END IF
                     END IF
   40             CONTINUE
   50          CONTINUE
            END IF
   60    CONTINUE
         IF (MISSING) GOTO 35
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIFGRT (IFT1,TEXT,TYPE)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IDUMMY, IFT1, TYPE
      LOGICAL       GVFIBN
      CHARACTER*(*) TEXT







      IFT1=0
      IF (NUMAAT.LT.1.OR.NUMATF.LT.1) THEN
         CALL GVSTTE ('?SOULOW')
         GOTO 998
      END IF



   10 CONTINUE
      WIFPAR(860)=0
      WIFPAR(861)=0
      WIFPAR(862)=1
      CALL WIFGRN (IFT1,IDUMMY,TEXT)
      IF (IFT1.EQ.0) GOTO 998
      IF (IDUMMY.GT.IFT1) CALL GVSTTI ('?M0731',IDUMMY)
      WIFPAR(862)=0
      IF (.NOT.GVFIBN(IFT1,0,NUMAAT)) THEN
         CALL GVSKIL
         IFT1=0
      END IF



      IF (TYPE.EQ.-1) GOTO 998
      IF (FAMTYP(RESTYP(IFT1)).NE.TYPE) THEN
         CALL GVST6C ('?M1709',MTYPE(FAMTYP(RESTYP(IFT1))),.TRUE.)
         CALL GVST6C ('?M1710',MTYPE(TYPE),.TRUE.)
         CALL SHOSOU
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GETIVD (IVALUE,TEXT,LOWER,UPPER,DEFAULT,IERR)

















      IMPLICIT      NONE
      INTEGER       IVALUE, IERR, I, GVFFFI, LOWER, UPPER, DEFAULT
      LOGICAL       GVFIBN
      CHARACTER*(*) TEXT







      IERR=0
      IVALUE=DEFAULT



   10 CONTINUE
      CALL I1PROMPT (TEXT,DEFAULT)
      I=GVFFFI(1,IVALUE)



      IF (I.EQ.1.AND.IVALUE.EQ.0) THEN
         IERR=1
         GOTO 998
      END IF



      IF (I.EQ.0) THEN
         IVALUE=DEFAULT
         IVALUE=MIN(UPPER,MAX(IVALUE,LOWER))
      END IF



      IF (.NOT.GVFIBN(IVALUE,LOWER,UPPER)) THEN
         CALL GVSTTI2 ('?M0533',LOWER,UPPER)
         GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE GET4HEL (IFT1,IFT2,HELPNT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'HSTINC.INC'
      INTEGER       NUMUSE, IERR, 
     +              IHEL, JHEL, KHEL, LHEL, MINHIT1, NUL, IFT1, IFT2,
     +              HITS12, HITS13, HITS14, HITS23, HITS24, HITS34, 
     +              HELPNT(2,4), MINHIT2, MINCNT1, MINCNT2, MINCNT3
      REAL          CUTOFF
      LOGICAL       GVFIBN, FIRST








      IF (.NOT.HSTDON) THEN
         CALL WIFPUSHPPP (815,1)
         CALL DSP001 (.TRUE.)
         CALL WIFPOPPPP (815)
      END IF



      FIRST=.TRUE.
      CUTOFF=6.0
      IF (FIRST) THEN
         FIRST=.FALSE.
         CUTOFF=6.0
         MINHIT1=6
         MINHIT2=4
      ELSE
         CUTOFF=CUTOFF-0.5
         MINHIT1=4
         MINHIT2=2
      END IF
      NUMUSE=0
      MINCNT1=0
      MINCNT2=0
      MINCNT3=0
      NUL=0
      CALL GVSIT0 (HELPNT,2*4)
      IERR=0



      DO 40 IHEL=1,NUMFRG
         IF (HSTTAB(3,IHEL).NE.4) GOTO 40
         IF (HSTTAB(4,IHEL).LT.10) GOTO 40
         IF (.NOT.GVFIBN(HSTTAB(1,IHEL),IFT1,IFT2)) GOTO 40
         IF (.NOT.GVFIBN(HSTTAB(2,IHEL),IFT1,IFT2)) GOTO 40
         NUMUSE=NUMUSE+1
         CALL GVSFMT ('?FMT408')
         CALL GVSCTB (LINE,80)
         WRITE (LINE,FMT,ERR=40) IHEL,HSTTAB(1,IHEL),HSTTAB(2,IHEL)
         CALL GVSTT6 (LINE)
   40 CONTINUE
      IF (NUMUSE.LE.3) THEN
         CALL GVSTTE ('?M1623')
         IERR=1
         GOTO 998
      END IF



      DO 100 IHEL=1,NUMFRG-3
         IF (HSTTAB(3,IHEL).NE.4) GOTO 100
         IF (HSTTAB(4,IHEL).LT.10) GOTO 100



         DO 90 JHEL=IHEL+1,NUMFRG-2
            IF (HSTTAB(3,JHEL).NE.4) GOTO 90
            IF (HSTTAB(4,JHEL).LT.10) GOTO 90
            MINCNT1=0



            CALL CON018B (CUTOFF,HSTTAB(1,IHEL),HSTTAB(2,IHEL),
     +       HSTTAB(1,JHEL),HSTTAB(2,JHEL),6,HITS12)
            IF (HITS12.LT.MINHIT1) THEN
               IF (HITS12.LT.MINHIT2) THEN
                  GOTO 90
               ELSE
                  MINCNT1=MINCNT1+1
                  IF (MINCNT1.GT.2) GOTO 90
               END IF
            END IF



            DO 80 KHEL=JHEL+1,NUMFRG-1
               IF (HSTTAB(3,KHEL).NE.4) GOTO 80
               IF (HSTTAB(4,KHEL).LT.10) GOTO 80
               MINCNT2=MINCNT1



               CALL CON018B (CUTOFF,HSTTAB(1,IHEL),HSTTAB(2,IHEL),
     +          HSTTAB(1,KHEL),HSTTAB(2,KHEL),6,HITS13)
               IF (HITS13.LT.MINHIT1) THEN
                  IF (HITS13.LT.MINHIT2) THEN
                     GOTO 80
                  ELSE
                     MINCNT2=MINCNT2+1
                     IF (MINCNT2.GT.2) GOTO 80
                  END IF
               END IF



               CALL CON018B (CUTOFF,HSTTAB(1,JHEL),HSTTAB(2,JHEL),
     +          HSTTAB(1,KHEL),HSTTAB(2,KHEL),6,HITS23)
               IF (HITS23.LT.MINHIT1) THEN
                  IF (HITS23.LT.MINHIT2) THEN
                     GOTO 80
                  ELSE
                     MINCNT2=MINCNT2+1
                     IF (MINCNT2.GT.2) GOTO 80
                  END IF
               END IF



               DO 70 LHEL=KHEL+1,NUMFRG
                  IF (HSTTAB(3,LHEL).NE.4) GOTO 70
                  IF (HSTTAB(4,LHEL).LT.10) GOTO 70
                  MINCNT3=MINCNT2



                  CALL CON018B (CUTOFF,HSTTAB(1,IHEL),HSTTAB(2,IHEL),
     +             HSTTAB(1,LHEL),HSTTAB(2,LHEL),6,HITS14)
                  IF (HITS14.LT.MINHIT1) THEN
                     IF (HITS14.LT.MINHIT2) THEN
                        GOTO 70
                     ELSE
                        MINCNT3=MINCNT3+1
                        IF (MINCNT3.GT.2) GOTO 70
                     END IF
                  END IF



                  CALL CON018B (CUTOFF,HSTTAB(1,JHEL),HSTTAB(2,JHEL),
     +             HSTTAB(1,LHEL),HSTTAB(2,LHEL),6,HITS24)
                  IF (HITS24.LT.MINHIT1) THEN
                     IF (HITS24.LT.MINHIT2) THEN
                        GOTO 70
                     ELSE
                        MINCNT3=MINCNT3+1
                        IF (MINCNT3.GT.2) GOTO 70
                     END IF
                  END IF



                  CALL CON018B (CUTOFF,HSTTAB(1,KHEL),HSTTAB(2,KHEL),
     +             HSTTAB(1,LHEL),HSTTAB(2,LHEL),6,HITS34)
                  IF (HITS34.LT.MINHIT1) THEN
                     IF (HITS34.LT.MINHIT2) THEN
                        GOTO 70
                     ELSE
                        MINCNT3=MINCNT3+1
                        IF (MINCNT3.GT.2) GOTO 70
                     END IF
                  END IF



                  HELPNT(1,1)=HSTTAB(1,IHEL)
                  HELPNT(2,1)=HSTTAB(2,IHEL)
                  HELPNT(1,2)=HSTTAB(1,JHEL)
                  HELPNT(2,2)=HSTTAB(2,JHEL)
                  HELPNT(1,3)=HSTTAB(1,KHEL)
                  HELPNT(2,3)=HSTTAB(2,KHEL)
                  HELPNT(1,4)=HSTTAB(1,LHEL)
                  HELPNT(2,4)=HSTTAB(2,LHEL)
                  GOTO 998
   70          CONTINUE
   80       CONTINUE
   90    CONTINUE
  100 CONTINUE
      IERR=1



  998 CONTINUE



      RETURN
      END   
