| 1 | #!/usr/bin/perl -w
|
|---|
| 2 | #
|
|---|
| 3 | # Go through list of input files
|
|---|
| 4 | # Extract run and field from input filename
|
|---|
| 5 | # If a $run-$field directory doesn't yet exist, create it
|
|---|
| 6 | # Move the file to that directory
|
|---|
| 7 | @filelist = @ARGV;
|
|---|
| 8 |
|
|---|
| 9 | die( "Give file list as arg!\n") unless (length($ARGV[0]) > 0);
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 | foreach $file (@filelist) {
|
|---|
| 13 | # Extract run and rerun, at the same time skipping non-SDSS filenames
|
|---|
| 14 | if ($file =~ /fpC-([0-9]{6})-([ugriz])[1-6]-([0-9]{4})\.fit/) {
|
|---|
| 15 | $run = $1;
|
|---|
| 16 | $filter = $2;
|
|---|
| 17 | $field = $3;
|
|---|
| 18 | # For the run number, I want to strip leading 0s
|
|---|
| 19 | $run =~ s/^0+//;
|
|---|
| 20 | $targetdir = "$filter/$run-$field";
|
|---|
| 21 | print "$targetdir\n";
|
|---|
| 22 |
|
|---|
| 23 | # Test if directory exists and is writeable to; if exists but not writeable, die
|
|---|
| 24 | if (-e $targetdir) {
|
|---|
| 25 | die("$targetdir exists, but is not a directory\n") unless
|
|---|
| 26 | -d $targetdir;
|
|---|
| 27 | die("$targetdir exists, but I cannot write to it\n") unless
|
|---|
| 28 | -w $targetdir;
|
|---|
| 29 | } else {
|
|---|
| 30 | # If it doesn't exist, create it - but first assume that
|
|---|
| 31 | # the parent needs to be created, too
|
|---|
| 32 | $filterdir = $filter;
|
|---|
| 33 | if (-e $filterdir) {
|
|---|
| 34 | die("$filterdir exists, but is not a directory\n") unless
|
|---|
| 35 | -d $filterdir;
|
|---|
| 36 | die("$filterdir exists, but I cannot write to it\n") unless
|
|---|
| 37 | -w $filterdir;
|
|---|
| 38 | } else {
|
|---|
| 39 | mkdir $filterdir or die("Cannot create per-filter directory $filterdir\n");
|
|---|
| 40 | }
|
|---|
| 41 | mkdir $targetdir or die ("Cannot create $targetdir\n");
|
|---|
| 42 | }
|
|---|
| 43 | if (system("mv $file $targetdir/") != 0) {
|
|---|
| 44 | die ("Could not write $file to $targetdir");
|
|---|
| 45 | }
|
|---|
| 46 | }
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | exit 0;
|
|---|