#!/usr/bin/perl

use warnings;
use strict;

sub p() {
    # p is for Perl is so much fun!
    $_ = <>;
    print $_;
    return $_;
}

p;                              # title

my ($natoms) =
  p =~/^.{27}(...)/;            # lattice type

p;                              # mode
p;                              # lattice constants

for (1 .. $natoms) {
    p;                          # first position
    $_ = p;
    my ($mult) = 
      $_ =~ /^.{15}(..)/;       # multiplicity

    p for (1 .. $mult-1);       # further positions

    p;                          # name
    p for (1 .. 3);             # LOCROT
}

my ($nsym) =
      <> =~ /^(....)/;          # symmetries

print qq(   1 SYMMETRY OPERATION FOR W2W\n);

my $f1 = qq(%2d%2d%2d%11.8f\n);
my $f2 = qq(%8d\n);

printf $f1, 1, 0, 0, 0;
printf $f1, 0, 1, 0, 0;
printf $f1, 0, 0, 1, 0;
printf $f2, 1;

for (my $i=2; $i<=$nsym; $i++) {
    # symmetry matrix + vector
    my ($a, $b, $c) = (scalar <>, scalar <>, scalar <>);
    <>;                         # number

    my ($a1, $a2, $a3, $a4) = $a =~ m[(..)(..)(..)(.*)];
    my ($b1, $b2, $b3, $b4) = $b =~ m[(..)(..)(..)(.*)];
    my ($c1, $c2, $c3, $c4) = $c =~ m[(..)(..)(..)(.*)];

    unless ($a1==1 and $a2==0 and $a3==0 and $a4==0 and
            $b1==0 and $b2==1 and $b3==0 and $b4==0 and
            $c1==0 and $c2==0 and $c3==1 and $c4==0)
    {                           # re-print sym op
        print $a, $b, $c;
        printf $f2, $i;
    } else {                    # we found the identity
        $i--;
        next;
    }
}
