stdtoMACSYMA.txt
Perl script to convert from std format to MACSYMA format
For information about the data base of lattices, see:
Index File and
Abbreviations.
We suggest that you:
o download this file
o copy it to a new file called stdtoMACSYMA.perl,
o delete everything up to and including the line "cut 1 here",
o delete the line "cut 2 here" and everything after it,
o then make the file executable.
o To use it, type (for example) stdtoMACSYMA.perl E8.std >out.mac
then load "out.mac" into MACSYMA.
------- cut 1 here -------
#!/usr/common/bin/perl
# stdtoMACSYMA.perl Perl script to make MACSYMA readable
# version of gram matrix from standard library file
# Last modified Jan 13 1998
if ( $#ARGV != 0 )
{ die "Useage: stdtoMACSYMA.perl file.std >out.mac then do
cat out.mac | macsyma local
or
macsyma local
batch(\"out.mac\");
then type: determinant(a); etc " }
# check file name ends in .std
if ( ! $ARGV[0] =~ /\.std$/) { die "filename doesn't end with .std! "}
# check if file exists
if ( ! -f $ARGV[0] ) { die "$ARGV[0] does not exist! " }
# open lattice file ($1)
open(LATTICE,$ARGV[0]);
# states: 0 = neutral, 1 means have just read "^%GRAM",
# 2 means reading Gram matrix
$state = "0";
# set up empty list to hold Gram matrix
@gramlist = ();
# read all input lines
while () {
chop; # delete newline at end
$_ =~ s/^ *//; # delete leading blanks
@line = split; # break up into a list
if ( $#line < 0 ) {next } # skip if empty line
if ($line[0] =~ /^%/) { $state = "0" } #reset state to 0 if find %
if ($line[0] =~ /^%GRAM$/) { # look for line beginning %GRAM
$state = "1"; # sets state to 1, getting ready
# for reading dimensions on next line
next; }
if ($state =~ "1") { $d1 = $line[0]; # state = 1,
# so read dimensions of array
$d2 = $line[1];
$state = "2"; # and set state to 2
next;
}
if ($state =~ "2" && $line[0] !~ /^%/) { # reading Gram matrix
$t1 = $#line; # get no of entries on the current line
# add then to gram matrix
push( @gramlist, @line) }
}
# print in MACSYMA format, calling the gram matrix "a"
# print LHS
print("a : matrix(\n");
### case 1, Gram matrix given in square form:
if ( $d1 == $d2 ) # square Gram matrix
{ # start bracket 1
$at = 0;
# print row i (but not the last one)
for ($i = 0; $i < $d1 - 1; $i = $i + 1) {
# print element j (but not the last one)
print("[\n");
for ($j = 0; $j < $d1 - 1; $j = $j + 1) {
print($gramlist[$at],",\n");
$at = $at + 1; };
# print last elt in row
print($gramlist[$at],"],\n");
$at = $at + 1;
}
# print last row
$i = $d1 - 1;
print("[\n");
# print element j (but not the last one)
for ($j = 0; $j < $d1 - 1; $j = $j + 1) {
print($gramlist[$at],",\n");
$at = $at + 1; };
# print last elt in row
print($gramlist[$at],"])\$\n");
} # end bracket 1
else
### case 2 , Gram matrix given in triangular form
{ # start bracket 2
# print row i
for ($i = 0; $i < $d1 ; $i = $i + 1) {
print("[\n"); # opening bracket for row i
# print column j
# print elements j = 0 .. i
for ($j = 0; $j <= $i ; $j = $j + 1) {
$at = $i * ($i + 1)/2 + $j;
print($gramlist[$at],"\n");
# follow it by a comma unless at end of line
if ($j < $d1 - 1 ) {print(",\n"); } else { print("]\n");}
};
# print elements j = i+1 .. $d1-1
for ($j = $i + 1; $j < $d1 ; $j = $j + 1) {
$at = $j * ($j + 1)/2 + $i;
print($gramlist[$at],"\n");
# follow it by a comma unless at end of line
if ($j < $d1 - 1 ) {print(",\n"); } else { print("]\n");}
};
# print closing comma
if ( $i < $d1 - 1 ) { print(",\n"); } else { print(")\$\n"); }
};
} # end bracket 2
---------- cut 2 here -------