#! /usr/bin/perl

use FileHandle;

$infile = $ARGV[0];
$outfile = $ARGV[1];
$Gt = $ARGV[2];

$lp = '(';
$rp = ')';

open(INFILE,"<$infile");
open(OUTFILE,">$outfile");

write OUTFILE;





while(defined($line=<INFILE>))
{
    $line =~ s/\s//g;
#    print "$line\n";
    @ldat = split /\(/ , $line , 2;
#    print "ldat[0] = $ldat[0]\n";
#    print "ldat[1] = $ldat[1]\n";

    $vnd = $ldat[0];
    @vns = split /\(/ , $vnd;
#    print "vn = $vn\n";
    $vn = $vns[0];
    $DDat = $ldat[1];
    if ($DDat =~ /\[(\S*)\]/)
    { 
       $Ddat = $1;
    }  
#    print "Ddat = $Ddat\n";
    @ddat = split /,/ , $Ddat;
    $rnk = @ddat;
    $rnk = $rnk/2;
#    print "rank = $rnk\n";
    $i = 0;
    $descents = "[";
    $ffnd = 0;
    foreach $dd (@ddat)
    {
      $i = $i+1;
      
      if ($dd =~ /C\-/)
      {
        if ($ffnd == 1) 
        {
          $descents = $descents . ",$i" ;
        }
        else
        {
          $descents = $descents . "$i";
          $ffnd = 1;
        }
      }
      if ($i >= $rnk) 
      {
	  last;
      }
    }
    $descents = $descents . "]";
#    print "descents = $descents\n";
    @SWRD = split /\)/ , $line;
    $s = @SWRD;
    $swd = $SWRD[$s-1];
#    print "swd = $swd\n";
    if ($swd =~ /e/)
    {
       $ln = 0;
       $sw = '[]';
    }
    else
    {
      @Swd = split /,/ , $swd ;
      $ln = @Swd;
      $ln = $ln /2;
      $sw = "[";
      for ($j=0 ; $j < $ln ; ++$j)
      {
         if ($j == 0)
         {
	     $sw = $sw . $Swd[$j];
	 }
         else
         {
             $sw = $sw . "," . $Swd[$j];
         }
      }
    $sw = $sw . "]"
    }
    print OUTFILE "$vn : $ln : $descents : $sw\n";
}   
close(INFILE);
close(OUTFILE);




format OUTFILE =
// Vertex data 
//
// Each of the lines below corresponds to an element w of W as it appears in
// the W-graph. The individual datums in each line are separated by colons.
// They to be interpreted as follows:
//   datum[1] := an integer i identifying the atlas index of w
//   datum[2] := length of w
//   datum[3] := list of indexes of simple roots that are left descents of w
//   datum[4] := reduced expression for w (presented as a sequence of
//               simple roots)
/////////////////////////////////////////////////////////////////////////////
.
