#!/usr/bin/perl

$directory=$ARGV[0];
print"$directory\n";
  my @file_name = ();
  opendir (my $dir_fn, $directory)
  or die "impossible to open directory $directory\n";
  my @file_dir = grep { !/^\.\.?$/ } readdir($dir_fn);
  closedir ($dir_fn);
  
foreach my $name (@file_dir) {
    if ( -f "$directory/$name" ) {
#       print"$name\n";
       @file_ext=split(/\./,$name);
       if ( -f "$file_ext[0].md5"){}
	else{
#       print "$file_ext[0], $file_ext[1]\n";
         $input_file = "$directory/$file_ext[0]".".fits";
	 $output_file = $file_ext[0].".md5";
         system "md5sum $input_file > $output_file";
        }
     }
   }
