      program read_ssg_datafile
* read data for (3+d)-dimensional superspace groups (d=1,2,3)
      implicit none
      integer i,j,k,m,n,imax,nmod,iclass
* 
* number of Bravais classes
      integer nclasses
* for each Bravais class:
*   number of modulation q vectors
      integer iclass_nmod(322)
*   class number 
      integer iclass_number(322)
*   basic space group of lattice
      integer iclass_spacegroup(322)
*   number of different stars of q
      integer iclass_nstars(322)
*   number of modulation q vectors for each star
      integer iclass_nmodstar(3,322)
*   class number label: 1.1, 1.2, 1.3, etc.
      character class_nlabel(322)*5
*   class label
      character class_label(322)*50
*   q vectors
      integer iclass_qvec(3,3,3,322)
*   number of centering translations
      integer iclass_ncentering(322)
*   centering translations: d integers followed by a common denominator
      integer iclass_centering(7,16,322)
*
* number of superspace groups
      integer ngroups
* for each superspace group
*   group number
      integer igroup_number(16697)
*   Bravais class
      integer igroup_class(16697)
*   basic space group
      integer igroup_spacegroup(16697)
*   group number label: 1.1.1.1, 2,1,1,1, etc.
      character group_nlabel(16697)*13
*   group label
      character group_label(16697)*60
*   number of operators
      integer igroup_nops(16697)
*   (d+1)x(d+1) augmented matrix for each operator in supercentered setting
*   common denominator in element (d+1,d+1)
      integer igroup_ops(7,7,48,16697)
*   number of reflection conditions
      integer igroup_nconditions(16697)
*   matrix representation of righthand side
      integer igroup_condition1(6,6,50,16697)
*   vector representation of lefthand side
      integer igroup_condition2(7,50,16697)

      imax=0
* open data file
      open(30,file='ssg_datafile.txt')
* skip heading
      read(30,*)
      read(30,*)
      read(30,*)
* read number of Bravais classes
      read(30,*)nclasses
* read each Bravais class
      do m=1,nclasses
        read(30,*)n,iclass_nmod(m),iclass_number(m),
     $       iclass_spacegroup(m),iclass_nstars(m),
     $       (iclass_nmodstar(i,m),i=1,iclass_nstars(m))
        nmod=iclass_nmod(m)
        if(n.ne.m)then
          stop 'Read error in read_ssg_datafile'
        endif
        read(30,*)class_nlabel(m),class_label(m)
        read(30,*)(((iclass_qvec(i,j,k,m),i=1,3),j=1,3),
     $       k=1,iclass_nmod(m))
        read(30,*)iclass_ncentering(m)
        if(iclass_ncentering(m).gt.imax)imax=iclass_ncentering(m)
        read(30,*)((iclass_centering(i,j,m),i=1,nmod+4),
     $       j=1,iclass_ncentering(m))
      enddo
* read number of superspace groups
      read(30,*)ngroups
* read each superspace group
      do m=1,ngroups
        write(6,'(i5)')m
        read(30,*)n,igroup_number(m),igroup_class(m),
     $       igroup_spacegroup(m)
        if(n.ne.m)then
          stop 'Read error in read_ssg_datafile'
        endif
        iclass=igroup_class(m)
        nmod=iclass_nmod(iclass)
        read(30,*)group_nlabel(m),group_label(m)
        read(30,*)igroup_nops(m)
        read(30,*)(((igroup_ops(i,j,k,m),i=1,nmod+4),j=1,nmod+4),
     $       k=1,igroup_nops(m))
        read(30,*)igroup_nconditions(m)
        if(igroup_nconditions(m).gt.imax)imax=igroup_nconditions(m)
        if(igroup_nconditions(m).gt.0)then
        read(30,*)(((igroup_condition1(i,j,k,m),i=1,nmod+3),j=1,nmod+3),
     $       (igroup_condition2(j,k,m),j=1,nmod+4),
     $       k=1,igroup_nconditions(m))
        endif
      enddo
      write(6,*)imax
      end
