anchor.diff:  sLVtemp = sLV 
   call make_primitive(sLVtemp,aTypTemp,aBasTemp,.false.,eps)
   if(nAt/=size(aTypTemp)) then;
  -   write(17,'(/,"ERROR: The input structure wasn''t primitive")')
  -   write(17,'("atom type: ",20(i2,1x))') aTypTemp(:)
  -   write(17,'("number of atoms: ",i2,5x," size of aTyp:",i2)') nAt, size(aTypTemp)
  +   ! write(17,'(/,"ERROR: The input structure wasn''t primitive")')
  +   ! write(17,'("atom type: ",20(i2,1x))') aTypTemp(:)
  +   ! write(17,'("number of atoms: ",i2,5x," size of aTyp:",i2)') nAt, size(aTypTemp)
      stop "ERROR: input structure for get_gspace_representation was not primitive";endif
   aTypTemp = 1; pLVtemp = sLV
   call make_primitive(pLVtemp,aTypTemp,aBasTemp,.false.,eps)
  -write(17,'("Parent lattice (columns): ",/,3(3(f7.3,1x),/))') (pLVtemp(iAt,:),iAt=1,3)
  -write(17,'("Parent lattice (in): ",/,3(3(f7.3,1x),/))') (pLV(iAt,:),iAt=1,3)
  -write(17,'("Superlattice (columns): ",/,3(3(f7.3,1x),/))') (sLV(iAt,:),iAt=1,3)
  +! write(17,'("Parent lattice (columns): ",/,3(3(f7.3,1x),/))') (pLVtemp(iAt,:),iAt=1,3)
  +! write(17,'("Parent lattice (in): ",/,3(3(f7.3,1x),/))') (pLV(iAt,:),iAt=1,3)
  +! write(17,'("Superlattice (columns): ",/,3(3(f7.3,1x),/))') (sLV(iAt,:),iAt=1,3)
   call matrix_inverse(pLVtemp,parLattTest,err)
   if(err) stop "Parent lattice of input superstructure is wrong"
   T = matmul(parLattTest,pLV)
   if(.not. equal(T,nint(T),eps)) stop "Input for get_gspace_representation is inconsistent"
  -write(17,'("Size of supercell: ",i3)') abs(nint(determinant(sLV)/determinant(pLV)))
  -write(17,'("d-set: ",/,200(3(f7.3,1x),/))') (dset(:,iAt),iAt=1,size(dset,2))
  +! write(17,'("Size of supercell: ",i3)') abs(nint(determinant(sLV)/determinant(pLV)))
  +! write(17,'("d-set: ",/,200(3(f7.3,1x),/))') (dset(:,iAt),iAt=1,size(dset,2))
   !** Calls to enumlib routines **
     ! This call generates a list of permutations for the d-set under symmetry operations
     ! of the parent lattice (need this for d-g table permutations)
  
positive.code:       trow(nuq,:) = row
     endif
  enddo
  write(17,'("Unique HNF entries after rotations:")')
  do i = 1,nuq
     write(17,'("row #:",i3,3x,6(i2,1x))') i,trow(i,:)
  enddo
  allocate(HNF(3,3,nuq))
  HNF = 0
  do iuq = 1,nuq
     HNF(1,1,iuq) = trow(iuq,1); HNF(2,1,iuq) = trow(iuq,2); HNF(2,2,iuq) = trow(iuq,3)
     HNF(3,1,iuq) = trow(iuq,4); HNF(3,2,iuq) = trow(iuq,5); HNF(3,3,iuq) = trow(iuq,6)
     write(17,'("HNF #: ",i3,/,3(3(i2,1x),/))') iuq,(HNF(iAt,:,iuq),iAt=1,3)
  enddo
  
  call SmithNormalForm(S,L,SNF,R)
  write(17,'("Integer transform of superlattice: ",/,3(3(i2,1x),/))') (S(iAt,:),iAt=1,3)
  write(17,'("SNF: ",/,3(3(i2,1x),/))') (SNF(iAt,:),iAt=1,3)
  close(17)
  END SUBROUTINE get_HNF_of_derivative_structure
  
  
  
negative.code: 
  nD = size(dset,2)
  
  ! open(17,file="debug_get_HNF.out")
  ! write(17,'(3/,"<<< Finding the g-space representation >>>",2/)')
  
  ! do iAt = 1, nAt
  !    write(17,'("Atom #: ",i2," position: ",3(f7.3,1x))') iAt, aBas(:,iAt)
  ! enddo
  
  allocate(aTypTemp(nAt),aBasTemp(3,nAt))
  aTypTemp = aTyp; aBasTemp = aBas
  pLVtemp = sLV 
  call make_primitive(pLVtemp,aTypTemp,aBasTemp,.false.,eps)
  if(nAt/=size(aTypTemp)) then; ! the structure was reduced by make_primitive
     ! write(17,'(/,"ERROR: The input structure wasn''t primitive")')
     ! write(17,'("atom type: ",20(i2,1x))') aTypTemp(:)
     ! write(17,'("number of atoms: ",i2,5x," size of aTyp:",i2)') nAt, size(aTypTemp)
     stop "ERROR: input structure for get_HNF_of_derivative_structure was not primitive";endif
  
  ! Now make every atom the same and apply make_primitive to find the parent cell
  aTypTemp = 1; pLVtemp = sLV
  call make_primitive(pLVtemp,aTypTemp,aBasTemp,.false.,eps)
  ! write(17,'("Parent lattice of input superlattice (columns): ",/,3(3(f8.4,1x),/))') (pLVtemp(iAt,:),iAt=1,3)
  
  call matrix_inverse(pLVtemp,parLattTest,err)
  if(err) stop "Problem inverting parent lattice basis"
  