#!/usr/bin/perl
#

$debug = 1;

for ($year = 1996; $year <= 1997; $year++) {

  if ($debug > 0) {
    printf "next year is %d \n", $year;
  }

  $dir = sprintf "year_%04d", $year;

  $cmd = "mkdir $dir";
  $ret = `$cmd`;

  $url = "http://www.astro.uiuc.edu/stardial/archive/jpg/RA/2115/2006/0825.jpg";
  $url = "http://www.astro.uiuc.edu/stardial/archive/jpg/RA/2115/";


  $infile = sprintf "files_%s", $year;
  open(INFILE, "$infile") || die("can't open file $infile");
  while (<INFILE>) {
    $line = " " . $_;
    chomp($line);
    @words = split(/\s+/, $line);
    $num = $words[2];
    $size = $words[5];
    $size =~ s/K//g;
    if ($debug > 0) {
      printf "  year %04d  num ..%s..  size %5.1f \n", $year, $num, $size;
    }

    if ($size > 10) {
      $cmd = sprintf "wget $url/$year/$num";
      if ($debug > 0) {
        printf "cmd is ..%s.. \n", $cmd;
      }
      $ret = `$cmd`;
      if ($debug > 0) {
        printf "ret is ..%s.. \n", $ret;
      }

      $cmd = "mv $num $dir ";
      $ret = `$cmd`;

    }
    
    
  }
  close(INFILE);


}


exit 0;
