      SUBROUTINE GETGEG(IREAD,LABELS,GEO,LOPT,NA,NB,NC,AMS,NATOMS,INT)
      implicit double precision (A-H,O-Z)
      include 'SIZES'
      include 'MOP6FILE'
      dimension GEO(3,*),NA(*),NB(*),NC(*),AMS(*), LOPT(3,*)
     1         ,LABELS(*)
      common /GEOSYM/ NDEP, LOCPAR(MAXPAR), IDEPFN(MAXPAR),
     1                LOCDEP(MAXPAR)
      common /SIMBOL/ SIMBOL(MAXPAR)
      common /ATMASS/ ATMASS(NUMATM)
      common /ATOMTX/ LTXT, TXTATM(NUMATM)
      common /GEOVAR/ NVAR, LOC(2,MAXPAR), IDUMY, XPARAM(MAXPAR)
      dimension ISTART(20), LGEO(3,100)
      character LINE*80, TGEO(3,100)*12, TXTATM*8, STRING*80, SIMBOL*10
      logical LEADSP, INT
      character ELEMNT(107)*2, LTXT*1
      data (ELEMNT(I),I=1,107)/' H','HE',
     1 'LI','BE',' B',' C',' N',' O',' F','NE',
     2 'NA','MG','AL','SI',' P',' S','CL','AR',
     3 'K ','CA','SC','TI',' V','CR','MN','FE','CO','NI','CU',
     4 'ZN','GA','GE','AS','SE','BR','KR',
     5 'RB','SR',' Y','ZR','NB','MO','TC','RU','RH','PD','AG',
     6 'CD','IN','SN','SB','TE',' I','XE',
     7 'CS','BA','LA','CE','PR','ND','PM','SM','EU','GD','TB','DY',
     8 'HO','ER','TM','YB','LU','HF','TA',' W','RE','OS','IR','PT',
     9 'AU','HG','TL','PB','BI','PO','AT','RN',
     1 'FR','RA','AC','TH','PA','U','NP','PU','AM','CM','BK','CF','XX',
     2 'FM','MD','CB','++',' +','--',' -','TV'/
      NERR=0
      INT=.TRUE.
      NUMAT=0
      NA(1)=0
      NB(1)=0
      NC(1)=0
      NB(2)=0
      NC(2)=0
      NC(3)=0
      MAXTXT=0
      do 60 NATOMS=1,100
         read(MIOA,'(A)',end=70,ERR=70)LINE
         if (LINE.EQ.' ') go to 70
C
C   SEE IF TEXT IS ASSOCIATED WITH THIS ELEMENT
C
         I=INDEX(LINE,'(')
         if (I.NE.0) then
C
C  YES, ELEMENT IS LABELLED.
C
            K=INDEX(LINE,')')
            TXTATM(NATOMS)=LINE(I:K)
            MAXTXT=MAX(MAXTXT,K-I+1)
            STRING=LINE(1:I-1)//LINE(K+1:)
            LINE=STRING
         else
            TXTATM(NATOMS)=' '
         end if
************************************************************************
         do 10 I=1,80
            ILINE=ICHAR(LINE(I:I))
            if (ILINE.GE.ICHAR('a').AND.ILINE.LE.ICHAR('z')) then
               LINE(I:I)=CHAR(ILINE+ICHAR('A')-ICHAR('a'))
            end if
   10    continue
************************************************************************
         NVALUE=0
         LEADSP=.TRUE.
         do 20 I=1,80
            if (LEADSP.AND.LINE(I:I).NE.' ') then
               NVALUE=NVALUE+1
               ISTART(NVALUE)=I
            end if
            LEADSP=(LINE(I:I).EQ.' ')
   20    continue
         do 30 J=1,107
   30    if (INDEX(' '//
     1            LINE(ISTART(1):ISTART(1)+2),ELEMNT(J)
     2              //' ').NE.0) go to 40
         if (INDEX(' '//LINE(ISTART(1):ISTART(1)+2),' X').NE.0) then
            J=99
            go to 40
         end if
         write(MIOB,'(2A)') ' ELEMENT NOT RECOGNIZED: ',
     %                        LINE(ISTART(1):ISTART(1)+2)
         NERR=NERR+1
   40    LABELS(NATOMS)=J
         if (J.NE.99) then
            NUMAT=NUMAT+1
            ATMASS(NUMAT) = READA(LINE(1:MAX(ISTART(2)-1,1)),ISTART(1))
            if (ATMASS(NUMAT).GT.1.D-15) then
               write(MIOB,'('' FOR ATOM'',I4,''  ISOTOPIC MASS:''
     %                       ,F15.5)')    NATOMS, ATMASS(NUMAT)
            else
               ATMASS(NUMAT)=AMS(J)
            end if
C#         write(MIOB,*) NATOMS,NUMAT,ATMASS(NUMAT)
         end if
         TGEO(1,NATOMS)=' '
         TGEO(2,NATOMS)=' '
         TGEO(3,NATOMS)=' '
         if (NATOMS.EQ.1) go to 50
         NA(NATOMS) = READA(LINE,ISTART(2))
         call GETVAL(LINE(ISTART(3):),GEO(1,NATOMS),TGEO(1,NATOMS))
         if (NATOMS.EQ.2) go to 50
         NB(NATOMS) = READA(LINE,ISTART(4))
         call GETVAL(LINE(ISTART(5):),GEO(2,NATOMS),TGEO(2,NATOMS))
         if (NATOMS.EQ.3) go to 50
         NC(NATOMS) = READA(LINE,ISTART(6))
         call GETVAL(LINE(ISTART(7):),GEO(3,NATOMS),TGEO(3,NATOMS))
   50    continue
   60 continue
   70 NATOMS=NATOMS-1
      do 80 I=1,NATOMS
         do 80 J=1,3
   80 LGEO(J,I)=-1
      IVAR=-1
      NVAR=0
      NDEP=0
      KERR=0
   90 read(MIOA,'(A)',end=180,ERR=180)LINE
      if (LINE.EQ.' ') then
         if (IVAR.EQ.-1) then
            MERR=0
            do 110 I=1,NATOMS
               do 100 J=1,3
  100          if (GEO(J,I).LT.-998) MERR=MERR+1
  110       continue
C
C  IF ALL SYMBOLS ARE DEFINED, then DO NOT READ 'FIXED' SYMBOLS
C
            if (MERR.EQ.0) go to 180
            IVAR=NVAR
            go to 90
         else
            go to 180
         end if
      end if
************************************************************************
      do 120 I=1,80
         ILINE=ICHAR(LINE(I:I))
         if (ILINE.GE.ICHAR('a').AND.ILINE.LE.ICHAR('z')) then
            LINE(I:I)=CHAR(ILINE+ICHAR('A')-ICHAR('a'))
         end if
  120 continue
************************************************************************
      do 130 I=1,80
  130 if (LINE(I:I).NE.' ') go to 140
  140 do 150 L=I,I+12
  150 if (LINE(L:L).EQ.' ') go to 160
  160 SUM = READA(LINE,L)
      N=0
      LERR=0
      do 170 J=1,NATOMS
         do 170 K=1,3
            if (TGEO(K,J)    .EQ.LINE(I:L) .OR.
     1         TGEO(K,J) (2:).EQ.LINE(I:L) .AND.
     2         TGEO(K,J) (1:1).EQ.'-') then
c
               if (LGEO(K,J).NE.-1) LERR=1
               LGEO(K,J)=LGEO(K,J)+1
               N=N+1
               GEO(K,J)=SUM
               if (N.EQ.1) then
                  NVAR=NVAR+1
                  LOC(1,NVAR)=J
                  LOC(2,NVAR)=K
                  XPARAM(NVAR)=SUM
                  SIMBOL(NVAR)=TGEO(K,J)
                  if (SIMBOL(NVAR) (1:1).EQ.'-') then
      write(MIOB,'(A)') ' NEGATIVE SYMBOLICS MUST BE PRECEEDED BY '
     %                //' THE POSITIVE EQUIVALENT'
                  write(MIOB,'(A)') ' FAULTY SYMBOLIC:  '//SIMBOL(NVAR)
c
               call filclo  !  J/M
               stop ' in GETGEG - fults in symbols'
c
               end if
               end if
               if (N.GT.1) then
                  NDEP=NDEP+1
                  LOCPAR(NDEP)=LOC(1,NVAR)
                  IDEPFN(NDEP)=LOC(2,NVAR)
                  if (TGEO(K,J) (1:1).EQ.'-') then
                     IDEPFN(NDEP)=14
                     if (LOC(2,NVAR).NE.3) then
                        KERR=KERR+1
                        write(MIOB,'(2A)')
     %                   ' ONLY DIHEDRAL SYMBOLICS CAN BE'
     %                 //'PRECEEDED BY A "-" SIGN'
                     end if
                  end if
                  LOCDEP(NDEP)=J
               end if
            end if
  170 continue
      KERR=KERR+LERR
      if (LERR.EQ.1) then
         write(MIOB,'(2A)')
     %    ' THE FOLLOWING SYMBOL HAS BEEN DEFINED MORE'//
     %    ' THAN ONCE:',LINE(I:L)
         NERR=NERR+1
      end if
      if (N.EQ.0) then
         write(MIOB,'(2A)')
     %              ' THE FOLLOWING SYMBOLIC WAS NOT USED:',LINE(I:L)
         NERR=NERR+1
      end if
      go to 90
  180 continue
      MERR=0
      do 200 I=1,NATOMS
         do 190 J=1,3
  190    if (GEO(J,I).LT.-998) MERR=MERR+1
C#     write(MIOB,'(2X,A,3F12.6,3I4)') ELEMNT(LABELS(I)),
C#     1(GEO(J,I),J=1,3), NA(I), NB(I), NC(I)
  200 continue
      if (MERR.NE.0) write(MIOB,'(I4,A)')
     %    MERR, ' GEOMETRY VARIABLES WERE NOT DEFINED'
      if (MERR+KERR+NERR.NE.0) then
         write(MIOB,'(A,I3,A)')
     % ' THE GEOMETRY DATA-SET CONTAINED',MERR+KERR+NERR,' ERRORS'
c
         call filclo  !  J/M
         stop ' in GETGEG - errors in geometry data set'
c
      end if
C
C  SORT PARAMETERS TO BE OPTIMIZED INTO INCREASING ORDER OF ATOMS
C
      if (IVAR.NE.-1) NVAR=IVAR
      do 230 I=1,NVAR
         J=100000
         do 210 L=I,NVAR
            if (J.GT.LOC(1,L)*4+LOC(2,L)) then
               K=L
               J=LOC(1,L)*4+LOC(2,L)
            end if
  210    continue
         STRING(1:10)=SIMBOL(I)
         SIMBOL(I)=SIMBOL(K)
         SIMBOL(K)=STRING
         SUM=XPARAM(I)
         XPARAM(I)=XPARAM(K)
         XPARAM(K)=SUM
         do 220 J=1,2
            L=LOC(J,I)
            LOC(J,I)=LOC(J,K)
  220    LOC(J,K)=L
  230 continue
C#      if (NVAR.NE.0)
C#     1    write(MIOB,'(//,''    PARAMETERS TO BE OPTIMIZED'')')
      DEGREE=ASIN(1.D0)/90
      do 240 I=1,NVAR
C#      write(MIOB,'(2I6,F12.6)') LOC(1,I),LOC(2,I),XPARAM(I)
  240 if (LOC(2,I).NE.1) XPARAM(I)=XPARAM(I)*DEGREE
C#      if (NDEP.NE.0) write(MIOB,'(//,''   SYMMETRY FUNCTIONS  '')')
C#      do 28 I=1,NDEP
C#   28 write(MIOB,'(3I6)') LOCPAR(I),IDEPFN(I),LOCDEP(I)
      LTXT=CHAR(MAXTXT)
      return
      end
