anchor.diff:  logical err
   real(dp), allocatable :: rgp(:,:)
   logical, allocatable :: skip(:)
  +integer OpIndxInSuperCellList, RowInDxGTable
  +
  +open(19,file="debug_get_rotation_perms_lists.out")
   
   ! Number of HNFs (superlattices); Index of the superlattices; Number of d-vectors in d set
   nH = size(HNF,3); n = determinant(HNF(:,:,1)); nD = size(RPList(1)%v,2) 
  
positive.code: allocate(dRPList%perm(nOp,nD),dRPList%v(3,nD,nOp),STAT=status)
  if(status/=0)stop "Allocation failed in get_dvector_permutations: dRPList"
  
  
  call matrix_inverse(pLV,inv_pLV,err)
  if (err) stop "Bad parent lattice vectors in input to get_dvector_permutations"
  
  dRPList%nL = nOp
  !print *,"numops",nOp,"nD",nD
  !print*,"shape(pd)",shape(pd),"shape(rd)",shape(rd)
  !!DEBUG  do ix = 1,3
  !!DEBUG      write(*,'("pLV, pLVinv:",20(f8.4,1x))') pLV(ix,:),inv_pLV(ix,:)
  !!DEBUG   enddo
  
  do iOp = 1, nOp ! Try each operation in turn and see how the d-vectors are permuted for each
     rd = matmul(rot(:,:,iOp),pd)+spread(shift(:,iOp),2,nD) ! Rotate each d and add the shift
  !!DEBUG   do ix = 1,3
  !!DEBUG      write(*,'(i2,":  pd/rd:",20(f8.4,1x))') iOp,pd(ix,:),rd(ix,:)
  !!DEBUG   enddo
  !!DEBUG   do ix = 1,3
  !!DEBUG      write(*,'(i2,": ",3(f7.3,1x))') iOp,rot(ix,:,iOp) !nint(rot(iD,:,iOp))
  !!DEBUG   enddo
  !!DEBUG!   write(*,'("S:",3i3,/)') nint(shift(:,iOp))
  !!DEBUG   write(*,'("S:",3(f7.3,1x),/)') shift(:,iOp)
     tRD = rd
     do iD = 1, nD
        call bring_into_cell(rd(:,iD),inv_pLV,pLV,eps)
     enddo
  !!DEBUG  do ix = 1,3
  !!DEBUG      write(*,'(i2,":  postrot pd/rd:",20(f8.4,1x))') iOp,pd(ix,:),rd(ix,:)
  !!DEBUG   enddo
   
     dRPList%v(:,:,iOp) = rd(:,:) - tRD(:,:)
     call map_dvector_permutation(rd,pd,dRPList%perm(iOp,:),eps)
  enddo
  
negative.code:       enddo
     enddo
  enddo ! loop over iH (superlattices)
  close(19)
  ENDSUBROUTINE get_rotation_perms_lists
  
  !***************************************************************************************************
  