#!/bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2021-07-30 20:10:23 +0300 (Fri, 30 Jul 2021) $
#$Revision: 8841 $
#$URL: svn+ssh://www.crystallography.net/home/coder/svn-repositories/cod-tools/tags/v3.8.0/tools/duplicate_space_groups $
#------------------------------------------------------------------------------
#*
# Find and print out duplicated space group definitions in COD::Spacegroups::Lookup::COD.
#**

use strict;
use warnings;
use COD::Spacegroups::Lookup::COD;
use COD::Spacegroups::Lookup qw( make_symop_hash make_symop_key );

# Identify the spacegroup from the symmetry operators:

my %symop_lookup_table = make_symop_hash( [
    \@COD::Spacegroups::Lookup::COD::table,
    \@COD::Spacegroups::Lookup::COD::extra_settings
] );

for my $sg ( @COD::Spacegroups::Lookup::COD::table,
             @COD::Spacegroups::Lookup::COD::extra_settings ) {
    my @symops = @{$sg->{symops}};
    my $key = make_symop_key( \@symops );

    if( exists $symop_lookup_table{$key} ) {
        my $estimated_sg = $symop_lookup_table{$key};
        if( $sg->{universal_h_m} ne $estimated_sg->{universal_h_m} ) {
            printf "%-20s\t%s\n",
                $sg->{universal_h_m},
                $estimated_sg->{universal_h_m};
        }
    } else {
        print STDERR "$0:: WARNING, space group could not be identified\n"
    }
}
