#!/usr/bin/perl # Routine to sort the LSPN calib/ directory be referencing the DATE-OBS # in the FITS headers. #============================================================================ # Loop through the header files in the current directory: opendir(CAL,".") || die "Could not open directory for reading ($!)"; foreach $file (sort readdir(CAL)) { next if ($file !~ /hdr$/); # Only interested in FITS headers # Now we'll open the header by piping it through 'brkstrm', # looking for the 'DATE-OBS' line: open(HDR,"brkstrm < $file |") || die "Could not open brkstrm pipe for $file ($!)\n"; $line = ; # First line is not the one we're looking for. $line = while ($line !~ /^DATE-OBS/); $line =~ /^DATE-OBS=\s*'(.*)\/(.*)\/(.*)\s*'/; $day = $1; $month = $2; $year = 1900 + $3; close(HDR); # Done with this now. $datadir = "$year/$month/$day"; # We do need to create these directories if they don't already # exists, so we better check before copying: mkdir "$year" if (! -d "$year"); mkdir "$year/$month" if (! -d "$year/$month"); mkdir "$year/$month/$day" if (! -d "$year/$month/$day"); # We'll need to replace the file extension with ".*": $file =~ s/\.hdr/.*/; # And now we're ready to move: system "mv $file $datadir"; # On to the next file.... } closedir(CAL);