10 my $bandwidthfile = shift @ARGV;
 
  11 my $originsfile = shift @ARGV;
 
  16 # Create a parser for the country database
 
  17 my $countries = XML::TreeBuilder->new;
 
  19 # Parse the country database
 
  20 $countries->parsefile("lib/countries.xml");
 
  22 # Load the per-country bandwidth details
 
  23 my $bandwidth = YAML::LoadFile($bandwidthfile);
 
  25 # Fill in country table and work out which clusters each can use
 
  26 foreach my $country ($countries->look_down("_tag" => "country"))
 
  28     my $code = $country->look_down("_tag" => "countryCode")->as_text;
 
  29     my $name = $country->look_down("_tag" => "countryName")->as_text;
 
  30     my $population = $country->look_down("_tag" => "population")->as_text;
 
  31     my $bandwidth = $bandwidth->{$code} || 0;
 
  32     my $continent = $country->look_down("_tag" => "continent")->as_text;
 
  33     my $west = $country->look_down("_tag" => "west")->as_text;
 
  34     my $north = $country->look_down("_tag" => "north")->as_text;
 
  35     my $east = $country->look_down("_tag" => "east")->as_text;
 
  36     my $south = $country->look_down("_tag" => "south")->as_text;
 
  37     my $lat = centre_lat($south, $north);
 
  38     my $lon = centre_lon($west, $east);
 
  41         code => $code, name => $name,
 
  42         country => $code, continent => $continent,
 
  43         bandwidth => $bandwidth, lat => $lat, lon => $lon
 
  48 YAML::DumpFile($originsfile, $origins);
 
  53 # Find the centre value between two latitudes
 
  60     return ( $south + $north ) / 2;
 
  64 # Find the centre value between two longitudes
 
  74         $lon = ( $west + $east ) / 2;
 
  78         $lon = ( $west + $east + 360 ) / 2;
 
  81     $lon = $lon - 360 if $lon > 180;