#convert_tee.pl
#convert MRT data format to Soon-Tee data format

require 'getcwd.pl';

#$TH = $ARGV[0];
#if ($TH eq "") {print "enter threashold, like TH0.1, TH0.15, TH0.2\n"; exit(0);}
#$HD = $ARGV[1];
#if ($HD eq "") {print "enter update frequency, like HD1,HD10,HD28\n"; exit(0);}
#$AS = $ARGV[2];
#if ($HD eq "") {print "enter AS , like AS2914,AS3333\n"; exit(0);}

#$out_fn = $ARGV[3];
#if ($out_fn eq "") {print "enter output file\n"; exit(0);}


#$current_dir = &getcwd;
#$wholepath_out = $current_dir ."/" . $out_fn;
#system("touch $wholepath_out");

#my $th_dir = $TH . "_" . $HD;

#chdir($TH);
#chdir($th_dir);
#chdir($AS);

$current_dir = &getcwd;
opendir(DIR,$current_dir);
@dirs = readdir(DIR);
foreach $dir (@dirs)
{
    unless (-d $dir) {next;}
    if ($dir eq "." or $dir eq "..") {next;}
    chdir($dir);
    chdir("AS3333");
    chdir("2001");
    system("perl /home/amy/BGP/helper_prog/convert_to_soon_format.pl 2001 2001.amy");
    system("/home/amy/BGP/helper_prog/convert 2001.amy 2001.tee");
    system("rm 2001.amy");
    chdir("..");
    chdir(2002);
    
    $current_dir2 = &getcwd;
    print ( "current dir is $current_dir2\n");

    opendir(DIR2, $current_dir2);
    @dirs2 = readdir(DIR2);
    foreach $dir2 (@dirs2)
    {

        #print (" the lowest level file is $dir2 \n");

	if (-d $dir2) {next;}
	if ($dir2 eq "." or $dir2 eq "..") {next;}
        if ($dir2 =~ /^20020/ and $dir !~ /tee$/)
        {
            $newamyfile = $dir2 . ".amy";
            $newteefile = $dir2 . ".tee";	 
            system("perl /home/amy/BGP/helper_prog/convert_to_soon_format.pl $dir2 $newamyfile");
            system("/home/amy/BGP/helper_prog/convert $newamyfile $newteefile");
            system("rm $newamyfile");
        }
  
    }
    closedir(DIR2);
    chdir("..");
    chdir("..");
    chdir("..");
}

closedir(DIR);


