#!/usr/bin/perl

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

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

  while (<FILE_IN>)
    {
    s{\s*(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*}
    {<atom element=\"C\" x=\"\2\" y=\"\3\" z=\"\4\"/>\n}g;

    printf FILE_OUT;
    }

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

  close FILE_IN;
  close FILE_OUT;
  }
