



C






















C
      SUBROUTINE ALT000 (DONE)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'OPTION.INC'
      LOGICAL       DONE







      IF (OPTIN.EQ.MEN6COD(66)) GOTO  999
      CALL MEN076 (OPTIN,DONE)



  999 CONTINUE


      RETURN
      END
      SUBROUTINE ALT001 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      LOGICAL       GVFFOP









      IF (ALTUNT.EQ.0) THEN
         CALL GVSROF (ALTUNT,IERR)
         IF (ALTUNT.EQ.0.OR.IERR.NE.0) GOTO 998

      END IF



      IERR=0
      WIFPAR(198)=0



      IF (GVFFOP(ALTUNT)) CALL GVSCLF (ALTUNT)

      CALL GVSDEL ('ALTERR.LOG')
      CALL GVSOPF ('ALTERR.LOG',ALTUNT,'NEW')




      IF (.NOT.GVFFOP(ALTUNT)) THEN
         CALL GVSTTE ('?MOLC37A')
         IERR=1
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT002 (TEXT1,TEXT2,TEXT3)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       GVFPOS
      CHARACTER*(*) TEXT1, TEXT2, TEXT3
      LOGICAL       GVFFOP







      IF (ALTUNT.LE.0.OR.WIFPAR(334).EQ.1) GOTO 998
      IF (.NOT.GVFFOP(ALTUNT)) GOTO 998



      WIFPAR(198)=WIFPAR(198)+1



      CALL GVSLUN (ALTUNT)
      CALL GVSTTU (ALTUNT,TEXT1)
      CALL GVSTTU (ALTUNT,TEXT2)
      CALL GVSTTU (ALTUNT,TEXT3)
      IF (WIFPAR(1012).GE.1.AND.
     +    GVFPOS(TEXT1,'ANISOU').GT.0.OR.
     +    GVFPOS(TEXT2,'ANISOU').GT.0.OR.
     +    GVFPOS(TEXT3,'ANISOU').GT.0) THEN
         CALL GVSLUN (6)
         CALL GVSTTU (6,TEXT1)
         CALL GVSTTU (6,TEXT2)
         CALL GVSTTU (6,TEXT3)
         CALL GVSKIL
         CALL GVSCODA (' ')
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT003

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IT, JT, I, PAIRS(2,MAXRIN), CNTPAIR, SCORE, IMIN, 
     +              J
      REAL          GVFDV3
      LOGICAL       KILL(MAXRIN), OUTDON, MOL009
      CHARACTER*6   OIT, OJT, BIT, BJT
      CHARACTER*1   RIT, RJT, AIT, AJT
      SAVE          PAIRS







      IF (ITT.LE.1) GOTO 998
      IF (MOL009(READIN(1)(18:21))) GOTO 998




      CNTPAIR=0



      DO 5 IT=1,ITT
         IF (READIN(IT)(17:17).NE.' ') GOTO 6
 5    CONTINUE
      GOTO 998
 6    CONTINUE

      CALL ALT008





      DO 20 IT=1,ITT-1
         DO 10 JT=IT+1,ITT
            IF (MOL009(READIN(JT)(18:21)).AND.
     +       READIN(IT)(13:16).NE.' O  '.AND.
     +       READIN(JT)(13:16).EQ.' O  ') GOTO 20



            IF (READIN(IT)(13:16).NE.READIN(JT)(13:16)) GOTO 10
            IF (READIN(IT)(18:26).NE.READIN(JT)(18:26)) GOTO 10



            IF (READIN(IT)(17:17).EQ.' '.AND.
     +          READIN(JT)(17:17).EQ.' '.AND.
     +          READIN(IT)(27:27).EQ.' '.AND.
     +          READIN(JT)(27:27).EQ.' ') THEN



               IF (WIFPAR(1264).EQ.0) THEN
                  CALL ALT002 ('?M2720',READIN(IT)(1:66),   
     +             READIN(JT)(1:66))
                  OUTDON=.TRUE.



               END IF
               GOTO 10
            END IF



            CNTPAIR=CNTPAIR+1
            IF (CNTPAIR.GE.MAXRIN-1) THEN
               CALL GVSTTB ('?M2721')
               GOTO 998
            END IF
            PAIRS(1,CNTPAIR)=IT
            PAIRS(2,CNTPAIR)=JT
 10      CONTINUE
 20   CONTINUE




      IF (CNTPAIR.LE.0) GOTO 998





      CALL GVSBTF (KILL,MAXRIN)
      DO 30 I=1,CNTPAIR
         IT=PAIRS(1,I)
         JT=PAIRS(2,I)
         OUTDON=.FALSE.



         CALL GVSFMT ('?FMT672')
         READ (READIN(IT),FMT,ERR=999) SCRRW1(1), SCRRW1(2), SCRRW1(1)
         READ (READIN(JT),FMT,ERR=999) SCRRW2(1), SCRRW2(2), SCRRW2(1)
         IF (GVFDV3(SCRRW1,SCRRW2).LT.0.01) THEN
            CALL ALT002 ('?M2225A',READIN(IT)(1:66),READIN(JT)(1:66))
            OUTDON=.TRUE.
         END IF



         SCORE=0
         AIT=READIN(IT)(17:17)
         AJT=READIN(JT)(17:17)
         RIT=READIN(IT)(27:27)
         RJT=READIN(JT)(27:27)
         OIT=READIN(IT)(55:60)
         OJT=READIN(JT)(55:60)
         BIT=READIN(IT)(61:66)
         BJT=READIN(JT)(61:66)





         IF (WIFPAR(288).EQ.0) THEN
            IF (AIT.GT.AJT) THEN
               SCORE=SCORE+4
            ELSE IF (AIT.LT.AJT) THEN
               SCORE=SCORE-4
            ELSE 



               IF (RIT.GT.RJT) THEN
                  SCORE=SCORE+3
               ELSE IF (RIT.LT.RJT) THEN
                  SCORE=SCORE-3
               ELSE



                  IF (OIT.LT.OJT) THEN
                     SCORE=SCORE+2
                  ELSE IF (OIT.GT.OJT) THEN
                     SCORE=SCORE-2
                  ELSE 



                     IF (BIT.GT.BJT) THEN
                        SCORE=SCORE+1
                     ELSE IF (BIT.LT.BJT) THEN
                        SCORE=SCORE-1
                     END IF
                  END IF
               END IF
            END IF



         ELSE IF (WIFPAR(288).EQ.1) THEN
            IF (OIT.LT.OJT) THEN
               SCORE=SCORE+4
            ELSE IF (OIT.GT.OJT) THEN
               SCORE=SCORE-4
            ELSE 



               IF (BIT.GT.BJT) THEN
                  SCORE=SCORE+3
               ELSE IF (BIT.LT.BJT) THEN
                  SCORE=SCORE-3
               ELSE



                  IF (AIT.GT.AJT) THEN
                     SCORE=SCORE+2
                  ELSE IF (AIT.LT.AJT) THEN
                     SCORE=SCORE-2
                  ELSE



                     IF (RIT.GT.RJT) THEN
                        SCORE=SCORE+1
                     ELSE IF (AIT.LT.AJT) THEN
                        SCORE=SCORE-1
                     END IF
                  END IF
               END IF
            END IF
         END IF



         IF (SCORE.GT.0) THEN
            CALL GVSTUR (DATLOG,'Altatm problem. Score=',SCORE)
            CALL GVSWCP (READIN(IT),READIN(JT))
            CALL GVSTTU (DATLOG,READIN(IT))
            CALL GVSTTU (DATLOG,READIN(JT))
         END IF
         KILL(JT)=.TRUE.
         AIT=READIN(IT)(17:17)
         AJT=READIN(JT)(17:17)
         RIT=READIN(IT)(27:27)
         RJT=READIN(JT)(27:27)
         OIT=READIN(IT)(55:60)
         OJT=READIN(JT)(55:60)
         BIT=READIN(IT)(61:66)
         BJT=READIN(JT)(61:66)



         IF (AIT.GT.AJT) THEN
            CALL ALT002 ('?M2202',READIN(IT)(1:66),READIN(JT)(1:66))
            OUTDON=.TRUE.
         END IF
         IF (RIT.GT.RJT) THEN
            CALL ALT002 ('?M2203',READIN(IT)(1:66),READIN(JT)(1:66))
            OUTDON=.TRUE.
         END IF
         IF (BIT.GT.BJT) THEN
            CALL ALT002 ('?M2204',READIN(IT)(1:66),READIN(JT)(1:66))
            OUTDON=.TRUE.
         END IF
         IF (OIT.LT.OJT) THEN
            CALL ALT002 ('?M2205',READIN(IT)(1:66),READIN(JT)(1:66))
            OUTDON=.TRUE.
         END IF
 30   CONTINUE




      IMIN=0



      DO 50 I=ITT,2,-1
         IF (KILL(I)) THEN
            CALL GVSSTX (READN2(I-1),READIN(I))
            IMIN=IMIN+1
            IF (I.EQ.ITT) GOTO 50
            DO 40 J=I,ITT-1
               CALL GVSSTX (READIN(J),READIN(J+1))
               CALL GVSSTX (READN2(J),READN2(J+1))
 40         CONTINUE
         END IF
 50   CONTINUE
      ITT=ITT-IMIN










      GOTO 998



 999  CONTINUE
      CALL GVSTTE ('?M2722')



  998 CONTINUE



  
      RETURN
      END   
      SUBROUTINE ALT004 (IAA)

















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







      IF (.NOT.USEALT) GOTO 998



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         CALL ALT007 (IAT,IERR)
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT005 (DOPRINT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, CNTA, CNTB, CNTN, IAT, IERR
      LOGICAL       DOPRINT
      CHARACTER*1   CHARA, CHARB







      DO 100 IAA=1,NUMAAF
         IF (HASALT(IAA)) THEN
            CALL ALT006 (IAA,CHARA,CHARB,CNTA,CNTB,CNTN,IERR)
         ELSE
            GOTO 998
         END IF
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (DOPRINT.AND.IAT.LE.0) PRINT*,'Oeps...'
 10      CONTINUE
 100  CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT006 (IAA,CHARA,CHARB,CNTA,CNTB,CNTN,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, CNTA, CNTB, CNTN, IERR
      CHARACTER*1   CHARA, CHARB







      IF (.NOT.HASALT(IAA)) GOTO 998



      IERR=0
      CNTA=0
      CNTB=0
      CNTN=0
      CHARA=' '
      CHARB=' '



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (ALTATM(IAT).EQ.' ') THEN
            CNTN=CNTN+1
         ELSE
            IF (CHARA.EQ.' ') THEN
               CHARA=ALTATM(IAT)
            ELSE IF (CHARB.EQ.' ') THEN
               CHARB=ALTATM(IAT)
            END IF
         END IF
         IF (ALTATM(IAT).EQ.CHARA) THEN
            CNTA=CNTA+1
         ELSE IF (ALTATM(IAT).EQ.CHARB) THEN
            CNTB=CNTB+1
         ELSE
            IERR=1
            GOTO 998
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT007 (IAT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, IERR
      LOGICAL       XYZNAL







      IF (ALALAT(IAT).EQ.' '.AND.ALTATM(IAT).EQ.' ') THEN
         IERR=1
         GOTO 998
      END IF
      IF (XYZNAL(IAT)) THEN
         IERR=1
         GOTO 998
      END IF



      IERR=0



      CALL GVSWAP (XCOORD(IAT),ALTX(IAT))
      CALL GVSWAP (YCOORD(IAT),ALTY(IAT))
      CALL GVSWAP (ZCOORD(IAT),ALTZ(IAT))
      CALL GVSWAP (XBFACT(IAT),ALTXBF(IAT))
      CALL GVSWAP (WEIGHT(IAT),ALTWGT(IAT))
      CALL GVSWLP (ISATOK(IAT),ALTWGT(IAT))
      CALL GVSWCP (ALTATM(IAT),ALALAT(IAT))



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT008

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       I, J, INDAA3, IAATYP, GVFLEN
      LOGICAL       GVFIBN, MOL009
      CHARACTER*4   CHAR4, CHAR4A








      CALL GVSSTX (CHAR4,READIN(1)(18:20))
      CALL GVSSTX (CHAR4A,READIN(1)(18:20))
      CALL GVSSHL (CHAR4A)
      IF (GVFLEN(CHAR4A).LT.3) GOTO 998
      IAATYP=INDAA3(CHAR4)
      IF (.NOT.GVFIBN(IAATYP,1,WIFPAR(276))) GOTO 998
      IF (MOL009(CHAR4)) GOTO 998



      DO 10 I=1,ITT+1
         IF (READIN(I)(13:27).GT.READIN(I+1)(13:27)) GOTO 11
 10   CONTINUE
      GOTO 998
 11   CONTINUE



      DO 30 I=1,ITT-1
         DO 20 J=I+1,ITT


            IF (READIN(J)(13:27).LT.READIN(I)(13:27)) THEN
               CALL GVSWCP (READIN(I),READIN(J))
            END IF
 20      CONTINUE
 30   CONTINUE



      DO 40 I=1,ITT-1
         IF (READIN(I)(1:6).EQ.'ANISOU') THEN
            IF (READIN(I)(13:27).EQ.READIN(I+1)(13:27)) THEN
               CALL GVSWCP (READIN(I),READIN(I+1))
            END IF
         END IF
 40   CONTINUE

















  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT009

















      IMPLICIT      NONE
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       AUSED, BUSED, NUSED, I, IERR
      LOGICAL       MOL009
      CHARACTER*1   CHARA, CHARB, CHARS, CHAR17







      IF (MOL009(READIN(1)(18:21))) GOTO 998



      CHARA=' '
      CHARB=' '
      CHARS=' '
      AUSED=0
      BUSED=0
      NUSED=0



      DO 10 I=1,ITT
         CHAR17=READIN(I)(17:17)
         IF (CHAR17.EQ.' ') THEN
            NUSED=NUSED+1
            GOTO 10
         ELSE
            IF (CHAR17.NE.CHARA.AND.CHAR17.NE.CHARB) THEN
               IF (CHARA.EQ.' ') THEN
                  CHARA=READIN(I)(17:17)
               ELSE IF (CHARB.EQ.' ') THEN
                  CHARB=READIN(I)(17:17)
               END IF
            END IF
         END IF
         IF (READIN(I)(17:17).EQ.CHARA) THEN
            AUSED=AUSED+1
         ELSE IF (READIN(I)(17:17).EQ.CHARB) THEN
            BUSED=BUSED+1
         ELSE
            IERR=1
            GOTO 998
         END IF
 10   CONTINUE
      IF (AUSED.EQ.0.OR.BUSED.EQ.0) GOTO 998



      IF (AUSED.GT.BUSED) THEN
         CHARS=CHARB
      ELSE IF (BUSED.GT.AUSED) THEN
         CHARS=CHARA
      ELSE
         IF (CHARB.GT.CHARA) THEN
            CHARS=CHARB
         ELSE
            CHARS=CHARA
         END IF
      END IF



      DO 20 I=1,ITT
         IF (READIN(I)(17:17).EQ.CHARS) THEN
            print*,'so, in alt009, swap:'
            call gvstt6 (READIN(I))
            call gvstt6 (READN2(I))
            CALL GVSWCP (READIN(I),READN2(I))
         END IF
 20   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT010

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IERR, GVFCBT
      LOGICAL       GVFYON







      IF (NUMAAT.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         GOTO 998
      END IF
      IF (.NOT.USEALT) THEN
         CALL GVSTTE ('?M2736')
         IF (.NOT.GVFYON('?M2737',' ')) GOTO 998
         USEALT=.TRUE.
      END IF
      IF (GVFCBT(HASALT,NUMAAT).LE.0) THEN
         CALL GVSTTE ('?M2738')
         GOTO 998
      END IF



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



      DO 10 IAA=1,NUMAAT
         IF (WRK1TF(IAA)) THEN
            IF (HASALT(IAA)) THEN
               CALL ALT004 (IAA)
            END IF
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT011

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IERR, GVFCBT
      LOGICAL       GVFYON







      IF (NUMAAT.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         GOTO 998
      END IF
      IF (.NOT.USEALT) THEN
         CALL GVSTTE ('?M2736')
         IF (.NOT.GVFYON('?M2737',' ')) GOTO 998
         USEALT=.TRUE.
      END IF
      IF (GVFCBT(HASALT,NUMAAT).LE.0) THEN
         CALL GVSTTE ('?M2738')
         GOTO 998
      END IF



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



      DO 10 IAA=1,NUMAAT
         IF (WRK1TF(IAA)) THEN
            IF (HASALT(IAA)) THEN
               CALL SHOIAA (IAA)
            END IF
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT020 (IDONE)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, IDONE







      IDONE=0



      DO 100 IAT=1,NUMATF
         IF (ALTATM(IAT).NE.' ') THEN
            ALTX(IAT)=0.0
            ALTY(IAT)=0.0
            ALTZ(IAT)=0.0
            ALTXBF(IAT)=0.0
            ALTWGT(IAT)=0.0
            ALALAT(IAT)=' '
            ALTATM(IAT)=' '
            IDONE=IDONE+1
         END IF
 100  CONTINUE





      RETURN
      END   
      SUBROUTINE ALT050

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, GVFCBT, COUNT(3,10), IADD, IERR, NUMALT, ALT100
      LOGICAL       WIFIRW, WIFIRA, WIFIRM, WIFIR6, WIFIRD, WIFIRN,
     +              WIFIRZ, GVFYON, MIXED, ISMIX







      IF (NUMAAT.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         GOTO 998
      END IF
      IF (.NOT.USEALT) THEN
         CALL GVSTTE ('?M2736')
         IF (.NOT.GVFYON('?M2737',' ')) GOTO 998
         USEALT=.TRUE.
      END IF
      IF (GVFCBT(HASALT,NUMAAT).LE.0) THEN
         CALL GVSTT6 ('?M2738')
         GOTO 998
      END IF



      CALL GVSIT0 (COUNT,3*10)
      ISMIX=.FALSE.



      NUMALT=ALT100(IERR)
      CALL GVSTTI ('?M3126',NUMALT)



      DO 10 IAA=1,NUMAAT
         CALL ALT051 (IAA,MIXED,IERR)
         IF (MIXED) ISMIX=.TRUE.
         IF (WIFIRA(IAA)) THEN
            IADD=1
         ELSE IF (WIFIRM(IAA)) THEN
            IADD=4
         ELSE IF (WIFIR6(IAA)) THEN
            IADD=6
         ELSE IF (WIFIRD(IAA)) THEN
            IADD=2
         ELSE IF (WIFIRN(IAA)) THEN
            IADD=3
         ELSE IF (WIFIRW(IAA)) THEN
            IADD=5
         ELSE IF (WIFIRZ(IAA)) THEN
            IADD=7
         ELSE
            IADD=8
         END IF
         COUNT(1,IADD)=COUNT(1,IADD)+1
         IF (HASALT(IAA)) COUNT(2,IADD)=COUNT(2,IADD)+1
         IF (MIXED) COUNT(3,IADD)=COUNT(3,IADD)+1
 10   CONTINUE
      CALL GVSNL6 (1)
      CALL SHOWTEXT ('?M2739')
      CALL GVSNL6 (1)
      CALL GVSTTI3 ('?MOLHL1',COUNT(1,1),COUNT(2,1),COUNT(3,1))
      CALL GVSTTI3 ('?MOLHL2',COUNT(1,2),COUNT(2,2),COUNT(3,2))
      CALL GVSTTI3 ('?MOLHL3',COUNT(1,3),COUNT(2,3),COUNT(3,3))
      CALL GVSTTI3 ('?MOLHL4',COUNT(1,4),COUNT(2,4),COUNT(3,4))
      CALL GVSTTI3 ('?MOLHL5',COUNT(1,5),COUNT(2,5),COUNT(3,5))
      CALL GVSTTI3 ('?MOLHL6',COUNT(1,6),COUNT(2,6),COUNT(3,6))
      CALL GVSTTI3 ('?MOLHL7',COUNT(1,7),COUNT(2,7),COUNT(3,7))
      CALL GVSTTI3 ('?MOLHL11',COUNT(1,8),COUNT(2,8),COUNT(3,8))
      CALL GVSNL6 (1)



      CALL SHOWTEXT ('?M2772')
      DO 20 IAA=1,NUMAAT
         IF (WIFIRW(IAA)) GOTO 20
         IF (HASALT(IAA)) CALL WIF305 (IAA,IAA)
 20   CONTINUE



      IF (ISMIX) THEN
         CALL SHOWTEXT ('?M2773')
         DO 30 IAA=1,30
            CALL ALT051 (IAA,MIXED,IERR)
            IF (MIXED) CALL SHOIAA (IAA)
 30      CONTINUE
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT051 (IAA,MIXED,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, IERR
      LOGICAL       MIXED, GVFYON
      CHARACTER*1   CHAR1







      MIXED=.FALSE.
      IERR=0
      IF (.NOT.USEALT) THEN
         CALL GVSTTE ('?M2736')
         IF (.NOT.GVFYON('?M2737',' ')) GOTO 998
         USEALT=.TRUE.
      END IF
      IF (.NOT.HASALT(IAA)) THEN
         IERR=1
         GOTO 998
      END IF



      IERR=0
      CHAR1=' '



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (ALTATM(IAT).EQ.' ') GOTO 10
         IF (CHAR1.EQ.' ') CHAR1=ALTATM(IAT)
         IF (ALTATM(IAT).NE.CHAR1) THEN
            MIXED=.TRUE.
            GOTO 998
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT052 (IAA,ALTOCC,IERR)

















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







      ALTOCC=.FALSE.
      IERR=0



      IF (.NOT.HASALT(IAA)) GOTO 998



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (ALALAT(IAT).NE.' ') THEN
            IF (ALTWGT(IAT).GT.WEIGHT(IAT)) THEN
               ALTOCC=.TRUE.
               GOTO 998
            END IF
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT059

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IERR
      REAL          DIFF
      LOGICAL       WIFIRW, GVFYON







      IF (.NOT.USEALT) THEN
         IF (.NOT.DEFALL) THEN
            CALL GVSTTE ('?M2736')
            IF (.NOT.GVFYON('?M2737',' ')) GOTO 998
         END IF
         USEALT=.TRUE.
      END IF



      IF (DEFALL) THEN
         IF (NUMAAT.LE.0) THEN
            CALL GVSTTB ('?M4840')
            CALL SHOSOU
            CALL GVSKIL
            GOTO 998
         END IF
         CALL GVSBTT (WRK1TF,NUMAAT)
      ELSE
         CALL WIFWTF (' ',IERR)
         IF (IERR.NE.0) GOTO 998
      END IF



      DO 10 IAA=1,NUMAAT
         IF (.NOT.WRK1TF(IAA).OR.WIFIRW(IAA)) GOTO 10
         IF (HASALT(IAA)) THEN
            CALL WIFPUSHRES (IAA,IERR)
            IF (IERR.NE.0) GOTO 998
            CALL ALT060 (IAA,DIFF)
            IF (DIFF.LT.1.5) THEN
               CALL WIFPOPRES (IERR)
               IF (IERR.NE.0) GOTO 998
            ELSE
               CALL WIFKILPOP
            END IF
         END IF
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT060 (IAA,DIFF)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'BACKUP.INC'
      INTEGER       IAA, IAT, JAT, IERR
      REAL          QBND1, QBND2, QBNDB, DIFF
      LOGICAL       WIFIRR, CANSWP







      DIFF=0.0
      IF (.NOT.HASALT(IAA)) GOTO 998
      IF (.NOT.WIFIRR(IAA)) GOTO 998



      QBND1=9999.9
      QBND2=9999.9
      QBNDB=9999.9
      CALL ALT061 (IAA,QBND1,.FALSE.,IERR)
      IF (IERR.NE.0) GOTO 999
      QBNDB=QBND1



      CALL WIFPUSHRES (IAA,IERR)
      CALL ALT004 (IAA)
      CALL ALT061 (IAA,QBND2,.FALSE.,IERR)
      IF (IERR.EQ.0.AND.QBND2.LT.QBNDB) THEN



         RESPNT=RESPNT-1
         QBNDB=QBND2
      ELSE



         CALL ALT004 (IAA)
         IF (IERR.EQ.0) CALL WIFPOPRES (IERR)
      END IF



      DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (.NOT.CANSWP(IAT)) GOTO 20
         DO 10 JAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (ALALAT(JAT).EQ.' ') GOTO 10
            IF (.NOT.CANSWP(JAT)) GOTO 10
            CALL ALT007 (JAT,IERR)
            IF (IERR.NE.0) GOTO 999
            CALL ALT061 (IAA,QBND2,.FALSE.,IERR)
            IF (IERR.NE.0) GOTO 999
            IF (QBND2.GE.QBNDB) THEN
               CALL ALT007 (JAT,IERR)
            ELSE

               QBNDB=QBND2
            END IF
 10      CONTINUE
 20   CONTINUE



      DO 40 IAT=PNTAAS(IAA),PNTAAE(IAA)-1
         IF (.NOT.CANSWP(IAT)) GOTO 40
         IF (ALALAT(IAT).EQ.' ') GOTO 40
         DO 30 JAT=IAT,PNTAAE(IAA)
            IF (ALALAT(JAT).EQ.' ') GOTO 30
            IF (.NOT.CANSWP(JAT)) GOTO 30
            CALL ALT007 (IAT,IERR)
            CALL ALT007 (JAT,IERR)
            IF (IERR.NE.0) GOTO 999
            CALL ALT061 (IAA,QBND2,.FALSE.,IERR)
            IF (IERR.NE.0) GOTO 999
            IF (QBND2.GE.QBNDB) THEN
               CALL ALT007 (IAT,IERR)
               CALL ALT007 (JAT,IERR)
            ELSE


               QBNDB=QBND2
            END IF
 30      CONTINUE
 40   CONTINUE



      DIFF=QBND1-QBNDB
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('ALT060')
      CALL SHOIAA (IAA)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE ALT061 (IAA,QBND,PRINTIT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, JAT, IERR, IRT, ICON
      REAL          QBND, V(3), GVFLNV, WD, IDEAL, BWIDTH, QOCC, NO
      LOGICAL       WIFIRA, AREBOUND, PRINTIT







      IF (.NOT.HASALT(IAA)) THEN
         QBND=0.0
         IERR=1
         GOTO 998
      END IF



      IERR=0
      QBND=0.0
      IRT=RESTYP(IAA)
      IF (IRT.LE.0) THEN
         IERR=1
         GOTO 998
      END IF



      DO 10 ICON=1,MAXTAT
         IF (MUTCON(1,ICON,IRT).EQ.0) GOTO 11
         IF (DSTSIG(ICON,IRT).LE.0.0001) GOTO 10
         IAT=PNTAAS(IAA)+MUTCON(1,ICON,IRT)-1
         JAT=PNTAAS(IAA)+MUTCON(2,ICON,IRT)-1
         IF (.NOT.ISATOK(IAT)) GOTO 10
         IF (.NOT.ISATOK(JAT)) GOTO 10
         V(1)=XCOORD(IAT)-XCOORD(JAT)
         V(2)=YCOORD(IAT)-YCOORD(JAT)
         V(3)=ZCOORD(IAT)-ZCOORD(JAT)
         WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
         IDEAL=DSTCON(ICON,IRT)
         BWIDTH=DSTSIG(ICON,IRT)



         IF (IRT.EQ.3.AND.BOUND_TO(1,PNTAAS(IAA)+7).GT.0) THEN
            IF (PINIAA(IAT).EQ.8.OR.PINIAA(JAT).EQ.8) THEN
               IDEAL=1.36
               BWIDTH=0.03
            END IF
         ELSE IF (IRT.EQ.4.AND.BOUND_TO(1,PNTAAS(IAA)+8).GT.0) THEN
            IF (PINIAA(IAT).EQ.9.OR.PINIAA(JAT).EQ.9) THEN
               IDEAL=1.36
               BWIDTH=0.03
            END IF
         END IF



         QBND=QBND+(ABS(WD-IDEAL)/BWIDTH)**2
 10   CONTINUE
 11   CONTINUE




      IF (WIFIRA(IAA).AND.IAA.GT.1) THEN



         V(1)=XCOORD(PNTAAC(IAA))-XCOORD(PNTAAC(IAA-1))
         V(2)=YCOORD(PNTAAC(IAA))-YCOORD(PNTAAC(IAA-1))
         V(3)=ZCOORD(PNTAAC(IAA))-ZCOORD(PNTAAC(IAA-1))
         IF (GVFLNV(V).LT.1.0) GOTO 12



         IF (AREBOUND(PNTAAS(IAA-1)+2,PNTAAS(IAA))) THEN
            IAT=PNTAAS(IAA-1)+2
            JAT=PNTAAS(IAA)
            IF (.NOT.ISATOK(IAT)) GOTO 12
            IF (.NOT.ISATOK(JAT)) GOTO 12
            V(1)=XCOORD(IAT)-XCOORD(JAT)
            V(2)=YCOORD(IAT)-YCOORD(JAT)
            V(3)=ZCOORD(IAT)-ZCOORD(JAT)
            WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
            QBND=QBND+(ABS(WD-1.329)/0.02)**2
         END IF
      END IF
 12   CONTINUE
      IF (WIFIRA(IAA).AND.IAA.LT.NUMAAF) THEN



         V(1)=XCOORD(PNTAAC(IAA))-XCOORD(PNTAAC(IAA+1))
         V(2)=YCOORD(PNTAAC(IAA))-YCOORD(PNTAAC(IAA+1))
         V(3)=ZCOORD(PNTAAC(IAA))-ZCOORD(PNTAAC(IAA+1))
         IF (GVFLNV(V).LT.1.0) GOTO 13



         IF (AREBOUND(PNTAAS(IAA)+2,PNTAAS(IAA+1))) THEN
            IAT=PNTAAS(IAA)+2
            JAT=PNTAAS(IAA+1)
            IF (.NOT.ISATOK(IAT)) GOTO 13
            IF (.NOT.ISATOK(JAT)) GOTO 13
            V(1)=XCOORD(IAT)-XCOORD(JAT)
            V(2)=YCOORD(IAT)-YCOORD(JAT)
            V(3)=ZCOORD(IAT)-ZCOORD(JAT)
            WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
            QBND=QBND+(ABS(WD-1.329)/0.02)**2
         END IF
      END IF
 13   CONTINUE



      QBND=SQRT(QBND)



      QOCC=0.0
      NO=0.0
      DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (ALALAT(IAT).NE.' ') THEN
            NO=NO+1.0
            QOCC=QOCC+(1.0-WEIGHT(IAT))**2
         END IF
 20   CONTINUE
      IF (NO.GT.0.1) QOCC=SQRT(QOCC/NO)



      IF (PRINTIT) THEN
         CALL GVSTTR ('?M3576',QBND)
         CALL GVSTTR ('?M3577',QOCC)
         CALL GVSTTR ('?M3578',(QBND+QOCC)/2.0)
      END IF



      QBND=(QBND+QOCC)/2.0



  998 CONTINUE


      RETURN
      END   
      INTEGER FUNCTION ALT100(IERR)

















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







      ALT100=0
      IERR=0



      IF (NUMATF.LE.0) THEN
         IERR=1
         GOTO 998
      END IF



      DO 20 IAA=1,NUMAAT
         FOUND=.FALSE.
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (ALALAT(IAT).NE.' '.AND.ALALAT(IAT).NE.ALTATM(IAT)) THEN
               ALT100=ALT100+1
               FOUND=.TRUE.
            END IF
 10      CONTINUE

 20   CONTINUE



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION CANSWP(IAT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT
      LOGICAL       XYZNUL, XYZNAL







      CANSWP=.FALSE.



      IF (.NOT.ISATOK(IAT)) GOTO 998
      IF (ALALAT(IAT).EQ.' '.AND.ALTATM(IAT).EQ.' ') GOTO 998
      IF (XYZNAL(IAT)) GOTO 998
      IF (XYZNUL(IAT)) GOTO 998



      CANSWP=.TRUE.



  998 CONTINUE


      RETURN
      END   
