



      SUBROUTINE MOL007




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INCLUDE       'SYMINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       I, IST, IEN, GVFLFR
      REAL          GVFDET, VOLERR, RESOL
      LOGICAL       CDUP, SDUP, SYMIAR, GVFFOP




         CALL TEXSECT ('?CHKM01')

      SCLFND=.FALSE.
      CELFND=.FALSE.
      SCLREAD=.FALSE.
      CELREAD=.FALSE.
      SYMALT=.FALSE.
      CDUP=.FALSE.
      SDUP=.FALSE.
      SYMHAS=.TRUE.
      WIFPAR(1503)=0
      CALL GVSMTU (CELTR, 3)
      NEWCLS=.FALSE.
      BIOMT=.FALSE.



      IF (WIFPAR(592).GT.0) THEN
         WIFPAR(592)=0
         CALL GVSTT6 ('?M0323')
      END IF



      NEADST=-1000.0
      NUMSYM=1
      CALL GVSMTU (SYMMAT(1,1,1),3)
      CALL GVSRT0 (SYMVEC(1,1),3)
      SYMNAM(1)=1555



      WIFPAR(941)=0



      IF (.NOT.GVFFOP(11)) THEN
         CALL GVSTTB ('?SYM001')
         RETURN
      END IF
      IF (WIFPAR(1102).NE.0) RETURN
      CALL GVSREW (11)



   10 CONTINUE
      CALL GVSFMT ('?FMT111')
      READ (11,FMT,END=900,ERR=905) LINE



      IF (LINE(1:6).EQ.'HEADER') THEN
         CALL GVSSHL (LINE(61:70))
         CALL GVSSTX (PDB4LC,LINE(61:64))



      ELSE IF (LINE(1:6).EQ.'CRYST1') THEN
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0) CALL GVSTTU 
     +    (WIFPAR(1203),LINE)
         CALL GVSSTX (CRYCRD(WIFPAR(491)),LINE)
         IF (CELREAD) THEN
            IF (.NOT.CDUP) THEN
               CALL PDBMES ('CELLDUP')
               CDUP=.TRUE.
            END IF
            GOTO 10
         ENDIF
         CELREAD=.TRUE.
         CALL GVSCTB (SPCNAM,12)
         CALL GVSFMT ('?FMT1047')
         READ (LINE,FMT,ERR=910,END=900) CELDIM,SPCNAM(1:11),SYMZ
         HAS_Z=LINE(70:70).NE.' '



         CALL RCRYST1



      ELSE IF (LINE(1:5).EQ.'MTRIX') THEN
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         NUMSYM=NUMSYM+1
         SYMNAM(NUMSYM)=0
         SYMSTS(NUMSYM)=SYMSTAT_MTRIX
         IF (LINE(1:6).NE.'MTRIX1') GOTO 920
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=920,END=920) (SYMMAT(1,I,NUMSYM),I=1,3), 
     +    SYMVEC(1,NUMSYM)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(1:6).NE.'MTRIX2') GOTO 920
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0) CALL GVSTTU 
     +    (WIFPAR(1203),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=920,END=920) (SYMMAT(2,I,NUMSYM),I=1,3), 
     +    SYMVEC(2,NUMSYM)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(1:6).NE.'MTRIX3') GOTO 920
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0) CALL GVSTTU 
     +    (WIFPAR(1203),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=920,END=920) (SYMMAT(3,I,NUMSYM),I=1,3), 
     +    SYMVEC(3,NUMSYM)
         VOLERR=ABS(GVFDET(SYMMAT(1,1,NUMSYM))-1)
         IF (VOLERR.GT.0.5) THEN
            CALL PDBMES ('MDETNOT1')
            NUMSYM=NUMSYM-1
         ELSE IF (VOLERR.GT.0.002) THEN
            CALL PDBMES ('MDETDIFF1')
         ELSE IF (.NOT.SYMIAR(SYMMAT(1,1,NUMSYM),0.002)) THEN
            CALL PDBMES ('MNOTROT')
         ENDIF





      ELSE IF (LINE(1:5).EQ.'SYMTR') THEN
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         NUMSYM=NUMSYM+1
         SYMNAM(NUMSYM)=0
         SYMSTS(NUMSYM)=SYMSTATSYMTR
         IF (LINE(1:6).NE.'SYMTR1') GOTO 940
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=940,END=940)
     +    (SYMMAT(1,I,NUMSYM),I=1,3), SYMVEC(1,NUMSYM)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(1:6).NE.'SYMTR2') GOTO 940
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=940,END=940)
     +    (SYMMAT(2,I,NUMSYM),I=1,3), SYMVEC(2,NUMSYM)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(1:6).NE.'SYMTR3') GOTO 940
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=940,END=940)
     +    (SYMMAT(3,I,NUMSYM),I=1,3), SYMVEC(3,NUMSYM)
         VOLERR=ABS(GVFDET(SYMMAT(1,1,NUMSYM))-1)
         IF (VOLERR.GT.0.5) THEN
            CALL PDBMES ('SDETNOT1')
            NUMSYM=NUMSYM-1
         ELSE IF (VOLERR.GT.0.002) THEN
            CALL PDBMES ('SDETDIFF1')
         ENDIF



         CALL SYMF2O (SYMMAT(1,1,NUMSYM),SYMVEC(1,NUMSYM))



      ELSE IF (LINE(1:5).EQ.'SCALE') THEN
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         IF (SCLREAD) THEN
            IF (.NOT.SDUP) THEN
               CALL PDBMES ('SCALDUP')
               SDUP=.TRUE.
            END IF
            GOTO 10
         ENDIF
         SCLREAD=.TRUE.
         IF (LINE(6:6).NE.'1') GOTO 930
         CALL GVSSTX (SCLCR1(WIFPAR(491)),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=930,END=930) (SYMSCL(1,I),I=1,3),SYMTRN(1)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(6:6).NE.'2') GOTO 930
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0) CALL GVSTTU 
     +    (WIFPAR(1203),LINE)
         CALL GVSSTX (SCLCR2(WIFPAR(491)),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=930,END=930) (SYMSCL(2,I),I=1,3),SYMTRN(2)
         CALL GVSFMT ('?FMT111')
         READ (11,FMT,END=900,ERR=905) LINE
         IF (LINE(6:6).NE.'3') GOTO 930
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         CALL GVSSTX (SCLCR3(WIFPAR(491)),LINE)
         CALL GVSFMT ('?FMT1048')
         READ (LINE,FMT,ERR=930,END=930) (SYMSCL(3,I),I=1,3),SYMTRN(3)
         CALL RSCALE



      ELSE IF (LINE(1:21).EQ.'REMARK   2 RESOLUTION') THEN
         IF (WIFPAR(1202).NE.0.AND.WIFPAR(1203).NE.0)
     +    CALL GVSTTU (WIFPAR(1203),LINE)
         IST=22
  101    IF (LINE(IST:IST).NE.' ') THEN
            IST=IST+1
            GOTO 101
         END IF
  102    IF (LINE(IST:IST).EQ.' ') THEN
            IST=IST+1
            GOTO 102
         END IF
         IEN=IST
  103    IF (LINE(IEN+1:IEN+1).NE.' ') THEN
            IEN=IEN+1
            GOTO 103
         END IF
         READ (LINE(IST:IEN),*,ERR=105) RESOL
         WIFPAR(941)=NINT(100.0*RESOL)
  105    CONTINUE



      ELSE IF (LINE(1:34).EQ.'REMARK   3   RESOLUTION RANGE HIGH') THEN
         I=GVFLFR(1,RESOL,LINE(14:71))
         WIFPAR(1291)=0
         IF (I.EQ.1) WIFPAR(1291)=NINT(100.0*RESOL)
      ELSE IF (LINE(1:33).EQ.'REMARK   3   RESOLUTION RANGE LOW') THEN
         I=GVFLFR(1,RESOL,LINE(14:71))
         WIFPAR(1292)=0
         IF (I.EQ.1) WIFPAR(1292)=NINT(100.0*RESOL)



      ELSE IF (LINE(1:13).EQ.'EXPDTA    NMR') THEN
         WIFPAR(1503)=1
         SYMHAS=.FALSE.



      ELSE IF (LINE(1:18).EQ.'REMARK 350   BIOMT') THEN
         BIOMT=.TRUE.
      ELSE IF (LINE(1:4).EQ.'ATOM'.OR.LINE(1:4).EQ.'HETA') THEN
         GOTO 20
      ELSE IF (LINE(1:4).EQ.'END ') THEN
         CALL GVSTT6 ('?SYM002')
         GOTO 20
      END IF
      GOTO 10



 20   CONTINUE
      CALL GVSREW (11)



      IF (WIFPAR(279).LE.0) CALL SYMAGR
      RETURN



 900  CONTINUE
      CALL GVSTTE ('?SYM003')
      RETURN



 905  CONTINUE
      CALL GVSTT6 ('?SYM004')
      RETURN



 910  CONTINUE
      CALL GVSTTE ('?SYM005')
      GOTO 10



 920  CONTINUE
      CALL GVSTTE ('?SYM006')
      CALL GVSTT6 (LINE)
      NUMSYM=NUMSYM-1
      GOTO 10



 930  CONTINUE
      CALL GVSTTE ('?SYM007')
      CALL GVSTT6 (LINE)
      SCLFND=.FALSE.
      GOTO 10



 940  CONTINUE
      CALL GVSTTE ('?SYM008')
      CALL GVSTT6 (LINE)
      NUMSYM=NUMSYM-1
      GOTO 10

      RETURN
      END
      SUBROUTINE RCRYST1



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SYMINC.INC'
      INTEGER       GVFLEN
      REAL          GVFLDF
      CHARACTER*12  SPCSAV
      LOGICAL       CONVENTIONAL



      IF (ABS(CELDIM(1)-1.0) .LT.0.1.AND.ABS(CELDIM(2)-1.0) .LT.0.1.AND.
     +    ABS(CELDIM(3)-1.0) .LT.1.0.AND.ABS(CELDIM(4)-90.0).LT.0.1.AND.
     +    ABS(CELDIM(5)-90.0).LT.0.1.AND.ABS(CELDIM(6)-90.0).LT.0.1)THEN
         CALL PDBMES ('CUBANG')
         WIFPAR(1503)=1
         SYMHAS=.FALSE.
         RETURN
      END IF



      IF (CELDIM(1).LT.2.0.OR.CELDIM(2).LT.2.0.OR.
     +    CELDIM(3).LT.2.0) THEN
         CALL PDBMES ('VECOUTRAN')
         RETURN
      END IF



      IF (CELDIM(4).LT.25.0.OR.CELDIM(4).GT.155.0.OR.
     +     CELDIM(5).LT.25.0.OR.CELDIM(5).GT.155.0.OR.
     +     CELDIM(6).LT.25.0.OR.CELDIM(6).GT.155.0) THEN
         CALL PDBMES ('ANGOUTRAN')
         RETURN
      END IF



      CALL SYMCLS (CELDIM,CLASS)




      IF (GVFLEN(SPCNAM).EQ.0) THEN
         IF (CLASS.NE.'TRICLINIC') THEN
            CALL PDBMES ('P1WRONG')
            IF (SYMZ.LT.1.OR.SYMZ.GT.96) SYMZ=1
         ELSE
            CALL PDBMES ('P1')
            SYMZ=1
         END IF
         CALL GVSSTX (SPCNAM,'P 1         ')
         CALL SYMCLG (SPCNAM,SPCNAMB,SPCNUM,CLASS2)
      ELSE
         CALL GVSSTX (SPCSAV,SPCNAM)
         CALL GVSRDB (SPCNAM)
         IF (SPCNAM(1:1).EQ.' ') THEN
            CALL GVSSTX (SPCNAM(1:11),SPCNAM(2:12))
            SPCNAM(12:12)=' '
         ENDIF
         IF (SPCNAM.NE.SPCSAV) THEN
            CALL PDBMES ('SPCFORM')
         END IF
         IF (SPCNAM(2:2).NE.' ') THEN
            SPCNAM=SPCNAM(1:1)//' '//SPCNAM(2:11)
            CALL PDBMES ('SPCNOSPACE')
         END IF
         IF (SPCNAM.EQ.'I 23        ') THEN
            CALL PDBMES ('SPCERR')
            CALL GVSSTX (SPCNAM,'I 2 3')
         ELSE IF (SPCNAM.EQ.'R 32        ') THEN
            CALL PDBMES ('SPCERR')
            CALL GVSSTX (SPCNAM,'R 3 2')
         END IF
         IF (SPCNAM.EQ.'P 21        '.AND.CELDIM(4).EQ.90.0.AND.
     +        CELDIM(5).EQ.90.0.AND.CELDIM(6).NE.90.0) THEN
            CALL PDBMES ('P21SETT')
            CALL GVSSTX (SPCNAM,'P 1 1 21')
            CALL SYMCLG (SPCNAM,SPCNAMB,SPCNUM,CLASS2)
         ELSE
            CALL GVSSTX (SPCSAV,SPCNAM)
            CALL SYMCLG (SPCNAM,SPCNAMB,SPCNUM,CLASS2)
            IF (SPCSAV.NE.SPCNAM) THEN
               CALL PDBMES ('SPCSPCERR')
            END IF
            IF (CLASS2.EQ.'UNKNOWN') THEN
               CALL PDBMES ('SPCUNKNOWN')
               CALL GVSSTX (SPCNAM,'P 1')
            ELSE IF (SPCNAMB.NE.SPCNAM) THEN
               IF (SPCNAM.EQ.'B 2         '.AND.CELDIM(4).EQ.90.0.AND.
     +              CELDIM(5).EQ.90.0.AND.CELDIM(6).NE.90.0) THEN
                  CALL PDBMES ('B2SPC')
               ELSE IF (SPCNAM.EQ.'B 2         ') THEN
                  CALL PDBMES ('B2ERR')
                  CALL GVSSTX (SPCNAM,'P 1')
               ELSE
                  CALL PDBMES ('NONSTDSPC')
               END IF
            ELSE IF (CLASS.EQ.'TRIGONAL'.AND.CLASS2.EQ.'TRIGONAL') THEN
               IF (SPCNAM.EQ.'R 3 2       ') THEN
                  CALL PDBMES ('RHOMBO')
                  CALL GVSSTX (SPCSAV,SPCNAM)
                  CALL GVSSTX (SPCNAM,'Z 3 2')
               ELSE IF (SPCNAM.EQ.'R 3         ') THEN
                  CALL PDBMES ('RHOMBO')
                  CALL GVSSTX (SPCSAV,SPCNAM)
                  CALL GVSSTX (SPCNAM,'Z 3')
               ELSE
                  CALL PDBMES ('RHOMBO')
                  CALL GVSSTX (SPCSAV,SPCNAM)
                  CALL GVSSTX (SPCNAM,'P 1')
               END IF
            ELSE IF (CLASS.NE.CLASS2) THEN
               IF (CLASS.NE.'HEXAGONAL'.OR.CLASS2.NE.'TRIGONAL') THEN
                  CALL PDBMES ('UNEQCLASS')
               END IF
            END IF
         END IF
      END IF



      CALL CEL001 (CELDIM(1),CELDIM(2),CELDIM(3),CELDIM(4),CELDIM(5),
     + CELDIM(6),SYMICL)
      CALL CEL002 (CELDIM(1),CELDIM(2),CELDIM(3),CELDIM(4),CELDIM(5),
     + CELDIM(6),SYMCEL)



      CONVENTIONAL=.TRUE.
      IF (CELDIM(4).LT.60.OR.CELDIM(4).GT.120.OR.
     +     CELDIM(5).LT.60.OR.CELDIM(5).GT.120.OR.
     +     CELDIM(6).LT.60.OR.CELDIM(6).GT.120) THEN
         IF (SPCNAM(1:1).EQ.'P') THEN
            CALL PDBMES ('NONSTDANG')
            CONVENTIONAL=.FALSE.
         END IF
      END IF
      CELFND=.TRUE.



      IF (CLASS.EQ.'TRICLINIC') THEN
         IF (CELDIM(4).LE.90.AND.CELDIM(5).LE.90.AND.
     +        CELDIM(6).LE.90) THEN
            CONTINUE
         ELSE IF (CELDIM(4).GE.90.AND.CELDIM(5).GE.90.AND.
     +        CELDIM(6).GE.90) THEN
            CONTINUE
         ELSE
            CALL PDBMES ('TRICONV')
            CONVENTIONAL=.FALSE.
         END IF
      ELSE IF (CELDIM(4).GE.89.95.AND.CELDIM(5).GE.89.95.AND.
     +    CELDIM(6).GE.89.95) THEN
         CONTINUE
      ELSE IF (CLASS.NE.'TRIGONAL') THEN
         CALL PDBMES ('OTHACONV')
         CONVENTIONAL=.FALSE.
      END IF
      IF (CLASS.EQ.'ORTHORHOMBIC') THEN
         IF (CELDIM(1).LE.CELDIM(2).AND.CELDIM(2).LE.CELDIM(3)) THEN
            CONTINUE
         ELSE IF (SPCNAM.EQ.'P 2 2 2     '.OR.
     +       SPCNAM.EQ.'P 21 21 21  ') THEN
            CALL PDBMES ('ORTLCONV')
            CONVENTIONAL=.FALSE.
         END IF
      END IF




      CALL CELRED (CELDIM,SPCNAM,RCELDIM,CELTRR)
      CALL CELCON (RCELDIM,CCELDIM,BRAVAIS,CCLASS,CELTRC)
      CALL GVS3X3 (CELTR,CELTRC,CELTRR)
      IF (CCLASS.EQ.'TRIGONAL'.AND.CLASS.EQ.'HEXAGONAL') THEN
         CONTINUE
      ELSE IF (CCLASS.EQ.'TRIGONAL'.AND.CLASS.EQ.'TRIGONAL'
     +        .AND.CLASS2.EQ.'TRIGONAL') THEN
         CALL PDBMES ('TRIGSOLV')
      ELSE IF (CCLASS.NE.CLASS) THEN
         NEWCLS=.TRUE.
         CALL PDBMES ('CONVCLAS')
         WIFPAR(1507)=1
      ELSE IF (GVFLDF(CELDIM,CCELDIM,6).GT.0.05) THEN
         IF (.NOT.CONVENTIONAL) THEN
            CALL PDBMES ('CONVCELL')
         ELSE
            IF (SPCNAM.NE.'P 2 2 21    '.AND.
     +          SPCNAM.NE.'P 21 21 2   ') THEN
               CALL PDBMES ('CONVPRB')
            END IF
         END IF
      END IF
    
      RETURN
      END
      SUBROUTINE RSCALE



















      IMPLICIT      NONE
      INCLUDE       'SYMINC.INC'
      LOGICAL       GVFIMU
      REAL          GVFRTD, GVFDET, IVOL, GVFMAX
      INTEGER       IERR

      SCLFND=.FALSE.



      IF ((SYMTRN(1).NE.0.).OR.(SYMTRN(2).NE.0.)
     +    .OR.(SYMTRN(3).NE.0.)) THEN
         IF (GVFMAX(SYMTRN,3).GT.3) THEN
            CALL PDBMES ('SCALTRERR')
            CALL GVSMVV (SYMTRN,SYMSCL)
         ELSE
            CALL PDBMES ('SCALTRANS')
         END IF
      END IF



      IF (GVFIMU(SYMSCL)) THEN
         CALL PDBMES ('SCALEUNIT')
         RETURN
      ELSE IF (ABS(SYMSCL(1,1)).GT.0.5.OR.
     +         ABS(SYMSCL(2,1)).GT.0.5.OR.
     +         ABS(SYMSCL(3,1)).GT.0.5.OR.
     +         ABS(SYMSCL(1,2)).GT.0.5.OR.
     +         ABS(SYMSCL(2,2)).GT.0.5.OR.
     +         ABS(SYMSCL(3,2)).GT.0.5.OR.
     +         ABS(SYMSCL(1,3)).GT.0.5.OR.
     +         ABS(SYMSCL(2,3)).GT.0.5.OR.
     +         ABS(SYMSCL(3,3)).GT.0.5) THEN
         CALL PDBMES ('SCLLARGE')
         RETURN
      ELSE
         IVOL=GVFDET(SYMSCL)
         IF (IVOL.GT.0.5) THEN
            CALL PDBMES ('SCALESMALL')
            RETURN
         ELSE IF (IVOL.EQ.0.) THEN
            CALL PDBMES ('SCALESING')
            RETURN
         ELSE IF (IVOL.LT.0.) THEN
            CALL PDBMES ('SCALENEG')

         END IF
      END IF



      CALL GVSMI2 (SYMINV,SYMSCL,3,IERR)
      CALL GVSMV3 (SYMIVV,SYMINV,SYMTRN)
      SYMIVV(1)=-SYMIVV(1)
      SYMIVV(2)=-SYMIVV(2)
      SYMIVV(3)=-SYMIVV(3)



      CALL CEL004 (SYMSCL,CELDIMS(1),CELDIMS(2),CELDIMS(3),
     +     CELDIMS(4),CELDIMS(5),CELDIMS(6))
      CELDIMS(4)=GVFRTD(CELDIMS(4))
      CELDIMS(5)=GVFRTD(CELDIMS(5))
      CELDIMS(6)=GVFRTD(CELDIMS(6))
      IF (CELDIMS(4).LT.25.OR.CELDIMS(4).GT.155.OR.
     +     CELDIMS(5).LT.25.OR.CELDIMS(5).GT.155.OR.
     +     CELDIMS(6).LT.25.OR.CELDIMS(6).GT.155) THEN
         CALL PDBMES ('SCALEICELL')
         RETURN
      END IF
      SCLFND=.TRUE.
      RETURN
      END
      SUBROUTINE SYMAGR



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'SYMINC.INC'
      LOGICAL       ROUNDING, L(6)
      INTEGER       I, I_90, NROFF, I_ZERO, I_NONZERO, ISIGN,
     +              I_FACTOR10, J, K, IERR, MISTYPED
      REAL          TMP, TMP1(3,3), TMP2(3,3), GVFGTA, RCEL(6),
     +              RCELS(6), GVFLDF
      CHARACTER     CLASS_C*12, CLASSS*12, STR*4



      IF (SCLFND.AND.CELFND) THEN



         CALL CELROT



         IF (GVFLDF(CELDIM,CELDIMS,6).GT.0.05) THEN
            FIXLST(1)=1.0



            SYMALT=.TRUE.
            CALL GVSCPR (SYMAL1, SYMSCL, 9)
            CALL GVSCPR (SYMAL2, SYMCEL, 9)



            ROUNDING=.TRUE.
            DO 25 I=4,6
               IF (ABS(CELDIM(I)-CELDIMS(I)).GT.0.05) THEN
                  IF (ABS(CELDIM(I)-CELDIMS(I)).GT.3.OR.
     +                 (CELDIM(I).NE.90.AND.CELDIM(I).NE.120)) THEN
                     ROUNDING=.FALSE.
                  END IF
               END IF
 25         CONTINUE
            DO 26 I=1,3
               IF (ABS(CELDIM(I)-CELDIMS(I)).GT.0.05) THEN
                  IF (ABS(CELDIMS(I)-CELDIM(I)).GT.0.3) THEN
                     ROUNDING=.FALSE.
                  END IF
               END IF
 26         CONTINUE
            IF (ROUNDING) THEN
               CALL PDBMES ('CELLROUND')
               GOTO 850
            ELSE



               CALL SYMCLS (CELDIM,CLASS_C)
               CALL SYMCLS (CELDIMS,CLASSS)
               IF ((CLASS2.EQ.CLASS_C.AND.CLASS2.NE.CLASSS).OR.
     +             (CLASS2.EQ.'TRIGONAL'.AND.CLASS_C.EQ.'HEXAGONAL'.AND.
     +              CLASSS.NE.'HEXAGONAL')) THEN
                  CALL PDBMES ('CCLASS')
                  SYMALT=.FALSE.
                  GOTO 800
               END IF
               IF ((CLASS2.EQ.CLASSS.AND.CLASS2.NE.CLASS_C).OR.
     +             (CLASS2.EQ.'TRIGONAL'.AND.CLASSS.EQ.'HEXAGONAL'.AND.
     +              CLASS_C.NE.'HEXAGONAL')) THEN
                  CALL PDBMES ('SCLASS')
                  SYMALT=.FALSE.
                  GOTO 850
               END IF
               IF (GVFLDF(CELDIM,CELDIMS,6).GT.0.05.AND.
     +              GVFLDF(CELDIM,CELDIMS,3).LE.0.05) THEN
                  I_90=0
                  DO 29 I=4,6
                     IF (CELDIM(I).EQ.90.AND.CELDIMS(I).NE.90) THEN
                        I_90=I_90+1
                     END IF
 29               CONTINUE
                  IF (I_90.EQ.1) THEN
                     CALL PDBMES ('CANGLE90')
                     GOTO 850
                  END IF
                  I_90=0
                  DO 31 I=4,6
                     IF (CELDIM(I).NE.90.AND.CELDIMS(I).EQ.90) THEN
                        I_90=I_90+1
                     END IF
 31               CONTINUE
                  IF (I_90.EQ.1) THEN
                     CALL PDBMES ('SANGLE90')
                     GOTO 800
                  END IF
               END IF
               NROFF=0
               I_ZERO=0
               I_NONZERO=0
               ISIGN=0
               I_FACTOR10=0
               DO 28 I=1,3
                  DO 27 J=1,3
                     IF (ABS(SYMSCL(I,J)-SYMCEL(I,J)).GE.0.00001) THEN
                        NROFF=NROFF+1
                        IF (SYMSCL(I,J).EQ.0) THEN
                           I_ZERO=I_ZERO+1
                        ELSE IF (SYMCEL(I,J).EQ.0) THEN
                           I_NONZERO=I_NONZERO+1
                        ELSE
                           TMP=SYMSCL(I,J)/SYMCEL(I,J)
                           IF (ABS(TMP+1.).LT.0.01) THEN
                              ISIGN=ISIGN+1
                           ELSE IF (ABS(SYMCEL(I,J)+SYMICL(I,J))
     +                             .LT.2.E-6) THEN
                              ISIGN=ISIGN+1
                           ELSE IF (ABS(TMP-10.).LT.0.01) THEN
                              I_FACTOR10=I_FACTOR10+1
                           ELSE IF (ABS(TMP-0.1).LT.0.001) THEN
                              I_FACTOR10=I_FACTOR10+1
                           END IF
                        END IF
                     END IF
 27               CONTINUE
 28            CONTINUE
               IF (NROFF.EQ.0) THEN
                  CALL PDBMES ('INACCSC')
                  GOTO 800
               ELSE IF (NROFF.EQ.ISIGN) THEN
                  CALL PDBMES ('SIGNERRSC')
                  SYMALT=.FALSE.
                  GOTO 850
               ELSE IF (NROFF.EQ.I_ZERO) THEN
                  CALL PDBMES ('ZEROERRSC')
                  GOTO 800
               ELSE IF (NROFF.EQ.I_NONZERO) THEN
                  CALL PDBMES ('NZEROERRSC')
                  GOTO 800
               ELSE IF (NROFF.EQ.I_FACTOR10) THEN
                  CALL PDBMES ('FACERRSC')
                  GOTO 800
               ELSE
                  IF (CELDIMS(4).LT.60.OR.CELDIMS(4).GT.120.OR.
     +                 CELDIMS(5).LT.60.OR.CELDIMS(5).GT.120.OR.
     +                 CELDIMS(6).LT.60.OR.CELDIMS(6).GT.120) THEN
                     IF (CELDIM(4).LT.60.OR.CELDIM(4).GT.120.OR.
     +                    CELDIM(5).LT.60.OR.CELDIM(5).GT.120.OR.
     +                    CELDIM(6).LT.60.OR.CELDIM(6).GT.120) THEN
                        CALL PDBMES ('ERRSC')
                        GOTO 800
                     ELSE
                        CALL PDBMES ('SCALEARAN')
                        SYMALT=.FALSE.
                        GOTO 800
                     END IF
                  END IF
               END IF



               MISTYPED=0
               CALL CELREC (RCEL,CELDIM)
               CALL CELREC (RCELS,CELDIMS)
               DO 750 I=1,6
                  L(I)=(ABS(RCEL(I)/RCELS(I)-1).LT.0.005)
 750           CONTINUE
               IF (L(1).AND.L(2).AND..NOT.L(3).AND.L(6)) THEN
                  MISTYPED=3
               ELSE IF (L(2).AND.L(3).AND..NOT.L(1).AND.L(4)) THEN
                  MISTYPED=1
               ELSE IF (L(1).AND.L(3).AND..NOT.L(2).AND.L(5)) THEN
                  MISTYPED=2
               END IF
               IF (MISTYPED.GT.0) THEN




                  K=0
                  DO 770 I=1,3
                     IF (I.NE.MISTYPED) THEN
                        K=K+1
                        DO 760 J=1,3
                           TMP1(J,K)=SYMSCL(I,J)
                           TMP2(J,K)=SYMCEL(I,J)
 760                    CONTINUE
                     END IF
 770              CONTINUE
                  CALL GVSCP3 (TMP1(1,3),TMP1(1,1),TMP1(1,2))
                  CALL GVSCP3 (TMP2(1,3),TMP2(1,1),TMP2(1,2))
                  CALL GVSTPS (TMP1,3)
                  CALL GVSTPS (TMP2,3)
                  CALL GVSMIV (TMP2,3,IERR)
                  CALL GVS3X3 (MPRIME,TMP2,TMP1)
                  IF (GVFGTA(MPRIME).GT.0.1) THEN
                     MPRIMS=1
                  ELSE
                     CALL GVSMTU (MPRIME,3)
                     MPRIMS=0
                  END IF
                  SYMALT=.FALSE.
                  IF (MISTYPED.EQ.1) THEN
                     CALL PDBMES ('MISTYP1')
                  ELSE IF (MISTYPED.EQ.2) THEN
                     CALL PDBMES ('MISTYP2')
                  ELSE IF (MISTYPED.EQ.3) THEN
                     CALL PDBMES ('MISTYP3')
                  END IF
                  GOTO 800
               END IF



               CALL PDBMES ('ERRSC')
               GOTO 800
            END IF
         ELSE
            CALL MATCMP (IERR,SYMICL,SYMINV,0.1)
            IF (IERR.NE.0) THEN
               CALL PDBMES ('SCALORIEN')



               SYMALT=.FALSE.
            END IF
         END IF
      ELSE
         CALL GVSMTU (MPRIME, 3)
         IF (.NOT.SCLREAD) CALL PDBMES ('NOSCAL')
         IF (.NOT.CELREAD) THEN
            CALL PDBMES ('NOCELL')
            CALL GVSSTX (SPCNAM,'P 1')
         END IF
         IF (CELFND) THEN
            GOTO 800
         ELSE IF (SCLFND) THEN
            GOTO 850
         ELSE
            CALL PDBMES ('NOUNIT')
            SYMHAS=.FALSE.
            SYMINV(1,1)=1000.
            SYMINV(2,2)=1000.
            SYMINV(3,3)=1000.
            CALL GVSMI2 (SYMSCL,SYMINV,3,IERR)
            CELDIM(1)=1000.
            CELDIM(2)=1000.
            CELDIM(3)=1000.
            CELDIM(4)=90.
            CELDIM(5)=90.
            CELDIM(6)=90.
         END IF
      END IF



      IF (NUMSYM.GT.1.AND.WIFPAR(642).EQ.0) THEN
         WRITE (STR,'(I4)',ERR=998) NUMSYM-1
         CALL GVST6C (STR,'?SYM095',.TRUE.)
      END IF
      RETURN




 800  CONTINUE
      IF (MPRIMS.EQ.-1) MPRIMS=-2
      CALL GVSNX3 (SYMCEL,MPRIME)
      CALL GVSMI2 (SYMICL,SYMCEL,3,IERR)
      CALL GVSMTM (SYMINV,SYMICL,3)
      CALL GVSMTM (SYMSCL,SYMCEL,3)
      CALL PDBMES ('CORRSCAL')
      RETURN




 850  CONTINUE
      CALL GVSMTM (SYMICL,SYMINV,3)
      CALL GVSMTM (SYMCEL,SYMSCL,3)
      CALL GVSCPR (CELDIM,CELDIMS,6)
 998  CONTINUE

      RETURN
      END
