anchor.diff:     deallocate(ilabeling1)
   enddo f1loop
   close(13)
  -
  -CONTAINS
  -function checkForEquiatomic(n,nD1,k,labeling) result(equiatomic)
  -integer, intent(in)  :: n, nD1, k
  -character(len=*), intent(in):: labeling
  -logical              :: equiatomic
  -integer              :: equiN
  -integer, allocatable :: integerLab(:)
  -integer              :: j, i
  -equiatomic = .false.
  -if (mod(n*nD1,k)== 0) then ! necessary but not sufficient condition for equiatomic.
  -   equiatomic = .true.
  -   equiN = n*nD1/k
  -   allocate(integerLab(n*nD1))
  -   do j = 1, n*nD1
  -      read(labeling(j:j),'(i1)') integerLab(j)
  -   enddo
  -   do i = 0,k-1
  -      if (count(integerLab==i)/=equiN) then ! can't be equiatomic
  -         equiatomic = .false.
  -         exit
  -      endif
  -   enddo
  -endif
  -endfunction checkForEquiatomic
  +write(*,'("The labelings in the two lists have 1-1 correspondence.")')
   
   endprogram compare_two_struct_enum
  
positive.code:                        & i9,")")') iStr2, strN2
           cycle
        endif
        do i = 0, k-1
           if (count(ilabeling2==i)/=count(ilabeling1==i)) then
              write(13,'("Concentrations don''t match for color ",i1)') i
              cycle compareloop
           endif
        enddo
        write(13,'("Concentrations match for structures ",2(i6,1x))') strN, strN2
  
  !! Aug 12 This block of 30 lines was moved from above. We only need to check for L1/=L2 after everything else matches.
     ! We do this even though there are no duplicates to remove. The routine also generates the vectors subscripts for the label permutations and we need these to generate the list of equivalent labelings
  
  ! dRotList1 is used in following two calls because, at this point, we've established that they would be the same, and it's more efficient to find dRotList1 outside of the compare loop
     call remove_duplicate_lattices(HNFin,LatDim2,pLV2,rot,shift,dset2,dRotList1,HNFout,fixOp,&
                                    LattRotList2,sLVlist,degen_list,eps)
     open(17,file="debug_rotation_permutations.out")
     ! Get the list of label permutations
     call get_rotation_perms_lists(pLV2,HNFout,L2,SNF,fixOp,LattRotList2,dRotList1,eps)
     write(17,'("Rots Indx:",/,8(24(i3,1x),/))') LattRotList2(1)%RotIndx(:)
     write(17,'("Permutation group (trans+rot):")')
     nP = size(LattRotList2(1)%perm,1)
  
negative.code:       write(17,'("Perm #",i3,":",1x,200(i2,1x))') ip,LattRotList2(1)%perm(ip,:)
     enddo
     call find_equivalent_labelings(ilabeling2,LattRotList2,qLabel,rotProdLab)
     if (any(L1/=L2)) then ! We must find the automorphism that connects the two different groups and adjust ilabeling2 accordingly
        print*,"L1/=L2"
        if (associated(g1)) deallocate(g1); if (associated(g2)) deallocate(g2)
        !1) build the member list
        call make_member_list(diag,g1) ! This routine allocates g1
        ! do i = 1,3
        !    write(*,'("g1: ",20(i2,1x))') g1(i,:)
        ! enddo
        ! print*
        !2) find the group automorphism
        call matrix_inverse(real(L2(:,:,1),dp),L2inv,err)
        if (err) stop "L2inv is not defined"
        ! do i = 1,3
        !    write(*,'(" L1:  ",3(i2,1x))') L1(i,:,1)
        ! enddo
        ! do i = 1,3
        !    write(*,'(" L2:  ",3(i2,1x))') L2(i,:,1)
        ! enddo
  
        T = matmul(L1(:,:,1),L2inv)
         ! do i = 1,3
         !    write(*,'(" T:  ",3(f7.3,1x))') T(i,:)
         ! enddo
        allocate(g2(3,size(g1,2)))
        !g2 = -1
        g2 = nint(matmul(T,g1))
        g2 = modulo(g2,spread(diag,2,n))
        !if (any(g2==-1)) stop "Bug in group member mapping"
        ! do i = 1,3
        !    write(*,'("g2: ",20(i2,1x))') g2(i,:)
        ! enddo
        ! print*
  
        ! Next, find the rearrangement between the two groups (the automorphism)
        if (allocated(automorphism)) deallocate(automorphism)
        allocate(automorphism(n2))
        call find_permutation_of_group(g1,g2,automorphism)
        write(13,"('automorphism')")
        write(13,"(20i1)") automorphism
        ! 3) Apply the automorphism to every permuted labeling (qLabels)
        do j = 1,size(qLabel,1)
           do i = 0, n*nD2-1, n ! Each block of 'n' needs a copy of the automorphism
              qLabel(j,1+i:n+i) = qLabel(j,automorphism+i)
           enddo
        enddo
        !4) proceed as normal
     endif
     foundLab = .false.
     ! We need to loop over all permutations (to get the full orbit) because we do not know
     ! which member of the orbit is the representative.
     ! We also need to check the complement of each labeling because any of the complements may appear
     ! in either list. GLWH 2019, see email chain, subject: "Monk?", with Rod Forcade starting May 16 2019
     do jL = 1, size(qlabel,1)
        !ilabeling2 = qLabel(jL,:)
        ! if(all(ilabeling2==ilabeling1)) then
        !    foundLab = .true.
        !    write(13,'("MATCH  Perm #: ",i3)') jl
        !    if (match/=0) then
        !       write(13,'("Additional match found: ",i6," == ",i6)') strN, strN2
        !        write(13,'("In file 2, structure ",i6)') strN2
        !        write(13,'("was equivalent to ",i6)') match
        !        write(13,'("in file 1")')
        !       stop "BUG! Found more than one match in struct_enum.out file"
        !    endif
        !    match = strN2
        !    exit
        ! endif
        do iLP = 1, nLP ! Loop over all complements of the labels (stored in 'labPerms').
           do i = 0,k-1 ! Loop over each color to make the complement of the label
              where  (qLabel(jL,:)==i) ilabeling2 = labPerms(iLP,i+1)
           enddo
           if(all(ilabeling1==ilabeling2)) then
              foundLab = .true.
              if (match/=0) then
                 write(13,'("Additional match found: ",i6," == ",i6)') strN, strN2
                 write(13,'("In file 2, structure ",i6)') strN2
                 write(13,'("was also equivalent to ",i6)') match
                 write(13,'("in file 1")')
                 stop "BUG! Found more than one match in struct_enum.out file"
              endif
              match = strN2
              exit !iLP loop over complements
           endif
        enddo !iLP loop
        if (foundLab) exit ! loop over permutations. Some labelings are invariant under some permutations. So without the exit, we will find a duplicate
     enddo ! jL Loop over permutations
     if(.not. foundLab) then
        write(13,'("Labeling didn''t match for str #:",i8)') strN
     else
        write(13,'("Structure number:",i8," in file2 is a match to ",i8," in file1!")') strN2, strN
     endif
     !if (match/=0) exit
     enddo compareloop
     close(f2)
     if(match==0) then
        write(13,'("Match for str #:",i8," in file 1 was not found in file 2")') strN
        stop "Match not found!"
     else
        write(13,'("Structure number:",i8," is a match to # ",i9," in file 2.")') strN, match
     endif
  