#! /bin/sh
#!perl -w # --*- Perl -*--
eval 'exec perl -x $0 ${1+"$@"}'
    if 0;
#------------------------------------------------------------------------------
#$Author: antanas $
#$Date: 2019-12-05 21:08:48 +0200 (Thu, 05 Dec 2019) $ 
#$Revision: 7546 $
#$URL: svn://www.crystallography.net/cod-tools/tags/v2.10/scripts/ssg_symop_matrices $
#------------------------------------------------------------------------------
#*
#* Parse superspace group symmetry operators as described in the CIF
#* _space_group_symop_ssg_operation_algebraic data items and produce
#* symmetry matrices for them.
#*
#* USAGE:
#*   $0 < input.symop
#*   $0 input.symop
#*   $0 input1.symop input*.symop
#**

use strict;
use warnings;
use COD::SOptions qw( getOptions );
use COD::SUsage qw( usage );
use COD::Spacegroups::Symop::SSGParse qw( symop_from_string );
use COD::ToolsVersion;

#* OPTIONS:
#*   --help, --usage
#*                     Output a short usage message (this message) and exit.
#*   --version
#*                     Output version information and exit.
#**
@ARGV = getOptions(
    "--help,--usage" => sub { usage; exit },
    '--version'      => sub { print 'cod-tools version ',
                              $COD::ToolsVersion::Version, "\n";
                              exit }
);

while(<>) {
    next if /^#/;
    next if /^\s*$/;
    chomp;
    my $matrix = symop_from_string( $_ );
    print "# $_\n";
    print_matrix( $matrix );
}

sub print_matrix
{
    my ($m) = @_;

    print "[\n";
    for (@$m) {
        print "   [ ";
        my $prefix = "";
        for (@$_) {
            printf "%s%2s", $prefix, $_;
            $prefix = ", ";
        }
        print " ]\n";
    }
    print "]\n\n";

    return;
}
