anchor.diff:     ! 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
  +   !stop "ERROR: input structure for get_gspace_representation was not primitive";endif
  +  write(*,'(A)') "WARNING: 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)
  
positive.code: 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"
  if (nD/=size(aTypTemp))then;print*,"Number of parent lattice sites in " !//trim(adjustl(sfname))
     print *,"isn't the same as the structure being checked";
     print *,"size(aTypTemp)",size(aTypTemp),"nD",nD;stop;endif
  ! If we pass this test, the two cell bases are equivalent even if not equal. From this point on, use
  ! the one from the struct_enum.out file. (that one is pLV, not pLVtemp)
  
  
  allocate(dsetStruc(3,size(aTypTemp))); dsetStruc = aBasTemp
  call matrix_inverse(pLV,pLVinv,err) 
  if(err) stop "matrix inverse failed in get_HNF_of_derivative_structure"
  ! write(17,'("d-set: ",/,200(3(f8.4,1x),/))') (dsetStruc(:,iAt),iAt=1,size(dsetStruc,2))
  
negative.code: real(dp) :: testsite(3), diff(3)
  
  nAt = size(aBas,2)
  if(nAt/=size(aTyp)) stop "Input to get_HNF_of_derivative_structure is inconsistent"
  
  nD = size(dset,2)
  
  if (present(fixedOcc)) then; fixedOcc_ => fixedOcc
                         else; allocate(fixedOcc_(0))
                         endif
  
  ! open(17,file="debug_get_HNF.out")
  ! write(17,'(3/,"<<< Finding the g-space representation >>>",2/)')
  