
my $gml = shift; # "fichier entrée."
my $net = shift; # "fichier sortie."

my $verticeCount = 0;

use POSIX qw(setlocale LC_ALL LC_CTYPE);

# sauvegarde la "locale" initial
my $old_locale = setlocale(LC_CTYPE);
my $new_locale = setlocale(LC_CTYPE, "ISO-8859-1");
$new_locale = setlocale(LC_CTYPE);

use locale;


my @nodes = (); # "1 motY", "2 motX", ...
my @edges = ();

open(GML, "<$gml") or die "Echec open $gml : $!\n";


while(my $l=<GML>){
    
    # "Récupère les nodes"
    if ($l =~ /\<node.*\>([\w]+)\<\/data\>/)
    {
        push @nodes, ++$verticeCount . " \"$1\"" . "\n"; 
    }

    # "Récupère les edges"
    if ($l =~ /\<edge.*\"(\d+)\".*\"(\d+)\".*\>(\d+)\<.*/)
    {
        push @edges, "$1 $2 $3\n"; 
        #print "F : , $1, $2, $3, \n";
    }
    
} 
close GML;


open(NET, ">$net") or die "Echec open $net : $!\n";
print NET '*Vertices ', "$verticeCount\n";
print NET @nodes;
print NET '*Edges', "\n";
print NET @edges;
close NET;

setlocale(LC_CTYPE, $old_locale);