#!/usr/bin/perl

foreach (@ARGV)
  {
  open FILE_IN, "<$_" or die "Unable to read file $_";

  s/.cc1//;
  open FILE_OUT, ">$_.xml" or die "Unable to write file $_.xml";
  printf FILE_OUT "<gml>\n<molecule name=\"$_\">\n";

  <FILE_IN>;
  while (<FILE_IN>)
    {
    s{\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s.*}
    {<atom element=\"\1\" x=\"\3\" y=\"\4\" z=\"\5\"/>\n}sg;

    printf FILE_OUT;
    }

  printf FILE_OUT "</molecule>\n</gml>\n";

  close FILE_IN;
  close FILE_OUT;
  }
