      subroutine space (bra,nsy,spcgrp,ispa,icomp)                      SPAC001
C-----------------------------------------------------------------------SPAC002
C   this subroutine decodes and checks the space group symbol SPCGRP.   SPAC003
C   Returns system, bravais symbol, and complains on invalid symbols.   SPAC004
c   Code is property of the PhysiSoft Corporation, Bernhard Rupp, 1989  SPAC005
c ----------------------------------------------------------------------SPAC006
c     This program module is part of the PhysiSoft X-ray Library        SPAC007
c     and may not be sold or reproduced for commercial purposes.        SPAC008
c     Although it has been tested carefully, there is no warranty       SPAC009
c     regarding accuracy or freedom from side-effects.                  SPAC010
c ----------------------------------------------------------------------SPAC011
                                                                        SPAC012
C-----declararion                                                       SPAC013
      character spcgrp*10,s(11),sym*4,bra,sys$*12,icomp*4               SPAC014
      logical exists                                                    SPAC015
      dimension sym(5),sys$(8)                                          SPAC016
                                                                        SPAC017
      data (sys$(i),i=1,8)/'cubic','tetragonal','hexagonal',            SPAC018
     &'rhombohedral','orthorhombic','monoclinic','triclinic'            SPAC019
     *,'trigonal'/                                                      SPAC020
                                                                        SPAC021
C-----set s and sym to blank                                            SPAC022
 0001 do 3001 i=1,11                                                    SPAC023
         s(i)=' '                                                       SPAC024
         if(i.gt.5) goto 3001                                           SPAC025
         sym(i)='    '                                                  SPAC026
 3001 continue                                                          SPAC027
                                                                        SPAC028
C-----begin inquire spacegroup                                          SPAC029
      if (nsy.ne.99) then                                               SPAC030
         write(*,'(/a$)')'  Please enter space group symbol : '         SPAC031
         read (*,'(11a1)')  (s(i),i=1,11)                               SPAC032
         do 1001 i=1,11                                                 SPAC033
 1001       call upstrg (s(i),1)                                        SPAC034
         write(spcgrp,'(10a1)') (s(i),i=1,10)                           SPAC035
      else                                                              SPAC036
         read (spcgrp,'(10a1)') (s(i),i=1,10)                           SPAC037
      end if                                                            SPAC038
                                                                        SPAC039
c --- we check first the bravais symbol --                              SPAC040
      bra=s(1)                                                          SPAC041
c --- if it is empty, call help --                                      SPAC042
      if (bra.eq.' ') then                                              SPAC043
         call help (ihelp,icomp)                                        SPAC044
         goto 0001                                                      SPAC045
      endif                                                             SPAC046
c --- if it is garbage or not proper format we complain --              SPAC047
      call brachk(s(1),exists)                                          SPAC048
      if (.not.exists.or.(s(1).ne.' '.and.s(2).ne.' ')) then            SPAC049
         write (*,'(a,a,a)')                                            SPAC050
     &   '  No such Bravais symbol exists - ',s(1),s(2)                 SPAC051
         call help (ihelp,icomp)                                        SPAC052
         goto 0001                                                      SPAC053
      endif                                                             SPAC054
                                                                        SPAC055
C-----write symbol groups                                               SPAC056
      k=3                                                               SPAC057
      j=1                                                               SPAC058
      do 3003 i=k,11                                                    SPAC059
         if(s(i).eq.' ') then                                           SPAC060
            l=i-1                                                       SPAC061
            if ((1+l-k).gt.4) goto 9001                                 SPAC062
            write(sym(j),'(4a1)') (s(m),m=k,l)                          SPAC063
            k=i+1                                                       SPAC064
            j=j+1                                                       SPAC065
            if ((i+1).gt.11) goto 9001                                  SPAC066
            if(s(i+1).eq.' ') goto 9001                                 SPAC067
         endif                                                          SPAC068
 3003 continue                                                          SPAC069
 9001 continue                                                          SPAC070
                                                                        SPAC071
c --- search for invalid symbol group --                                SPAC072
      do 1002 i=1,j-1                                                   SPAC073
         call symchk (sym(i),exists)                                    SPAC074
         if (.not.exists) then                                          SPAC075
            write (*,*) ' Symbol group ',sym(i),' invalid '             SPAC076
            call help (ihelp,icomp)                                     SPAC077
            goto 0001                                                   SPAC078
         end if                                                         SPAC079
 1002 continue                                                          SPAC080
                                                                        SPAC081
c       NSY 1= Cubic, 2 Tetragonal,3 Hexagonal, 4 Rhombohedral,         SPAC082
c       5 orthorhombic, 6 Monoclinic, 7 Triclinic, 8 Trigonal           SPAC083
                                                                        SPAC084
c --- find system --                                                    SPAC085
      if(s(3).eq.'-') s(3)=s(4)                                         SPAC086
      if(s(3).eq.'3'.and.bra.eq.'R') then                               SPAC087
         nsy=4                                                          SPAC088
      elseif(s(3).eq.'3'.and.bra.ne.'R') then                           SPAC089
         nsy=8                                                          SPAC090
      elseif(s(3).eq.'6') then                                          SPAC091
         nsy=3                                                          SPAC092
      elseif(s(3).eq.'4'.and.sym(2).ne.'3') then                        SPAC093
         nsy=2                                                          SPAC094
      elseif(sym(2).eq.'3') then                                        SPAC095
         nsy=1                                                          SPAC096
      elseif((sym(1).eq.'1'.or.sym(1).eq.'-1').and.sym(2).eq.'    ')thenSPAC097
         nsy=7                                                          SPAC098
      elseif(sym(2).eq.'    ') then                                     SPAC099
         nsy=6                                                          SPAC100
      else                                                              SPAC101
         nsy=5                                                          SPAC102
      endif                                                             SPAC103
                                                                        SPAC104
c --- let's also better check for possible inconsistencies --           SPAC105
      call syschk (bra,nsy,exists)                                      SPAC106
      if (.not.exists) then                                             SPAC107
         write (*,*)' Sorry, incorrect combination of Bravais symbol '  SPAC108
     &   ,bra, ' with system - ',sys$(nsy)                              SPAC109
         call help (ihelp,icomp)                                        SPAC110
         goto 0001                                                      SPAC111
      endif                                                             SPAC112
                                                                        SPAC113
c --- final check for allowed symbol and return number of spcgrp --     SPAC114
      call spsymc (spcgrp,ispa)                                         SPAC115
                                                                        SPAC116
c --- and ?                                                             SPAC117
      if (ispa.eq.0) then                                               SPAC118
         write (*,'(/a,a)')'  Not a valid space group symbol - ',spcgrp SPAC119
         call help (ihelp,icomp)                                        SPAC120
         goto 0001                                                      SPAC121
      end if                                                            SPAC122
      return                                                            SPAC123
      end                                                               SPAC124
