#!/usr/bin/perl # Routine to adjust the comments in the *centers.lbl files to indicate that # given coordinates are 1-based. To do this, we'll just be rewriting the # label DESCRIPTION field and the DESCRIPTION of two of the columns. # # Descends recursively through directories starting with cwd. # #============================================================================= use File::Find; # Run: find({wanted=>\&fixit},"."); # That's it for the main routine. #---------------------------------------------------------------------------- sub fixit # Routine to fix the "*_centers.lbl" files DESCRIPTION fields for the TABLE # object and two of the COLUMN objects. All other files are ignored. We # are CDed to the local directory when this routine is called. { my ($filename, $line); my $TMPFILE = "zzzTMP"; $filename = $_; return if ($filename !~ /_centers\.lbl$/); # Open files: open (OLD, "varlen -rmcr $filename |") || die "Could not open $File::Find::name pipe for reading ($!)."; open (NEW, "| fixlen -c > $TMPFILE") || die "Could not open $file::Find::dir/$TMPFILE pipe for writing ($!)."; # First we loop through the label looking for the first DESCRIPTION, which # will be the TABLE description: $line =; while ($line !~ /\s*DESCRIPTION\s*=/) { printf NEW $line; $line = ; } # Now we want to read past all of the DESCRIPTION. Regardless of file type, # it takes at least one more line. We'll loop until we find a closing quote, # assuming that the file is syntactically correct, of course: $line = ; while ($line !~ /\"/) { $line = ; } # We now output the new DESCRIPTION, which depends on the file name: if ($filename =~ /^comet/) { printf NEW " DESCRIPTION = \"(x,y) position of the center\n"; printf NEW " of comet 9P/Tempel 1 on the archived reduced CCD images.\n"; printf NEW " The first pixel is (1,1).\"\n"; } else { printf NEW " DESCRIPTION = \"(x,y) positions of the centers\n"; printf NEW " of standard stars in the Landolt star field on the archived\n"; printf NEW " reduced CCD images. The first pixel is (1,1).\"\n"; } # That takes care of the TABLE description. Now we need to find the two # columns that need their descriptions updated. We'll look for them by # name, stopping when we find the name "X_CENTER": $line = ; while ($line !~ /^\s*NAME\s*=\s*"X_CENTER"/) { printf NEW $line; $line=; } printf NEW $line; # Now we want the next DESCRIPTION field: $line = ; while ($line !~ /^\s*DESCRIPTION\s*=/) { printf NEW $line; $line = ; } # As before, we want to delete this DESCRIPTION and replace it with a new # one. It may run one or two lines: if ($line !~ /^\s*DESCRIPTION\s*=\s*".*"\s*$/) { $line = ; if ($line !~ /^\s*[^"=]*"\s*$/) { printf STDERR "Couldn't find end of X_CENTER.DESCRIPTION in"; printf STDERR "$File::Find::name.\n"; close(OLD); close(NEW); return; } } # Now we add our new DESCRIPTION: $line = " DESCRIPTION = \"x-coordinate of the center\n"; printf NEW $line; if ($filename =~ /^comet/) { $line = " of the comet. First pixel is (1,1).\"\n"; } else { $line = " of the star. First pixel is (1,1).\"\n"; } printf NEW $line; # And we repeat the entire process for the Y_CENTER column: $line = ; while ($line !~ /^\s*NAME\s*=\s*"Y_CENTER"/) { printf NEW $line; $line=; } printf NEW $line; # Now we want the next DESCRIPTION field: $line = ; while ($line !~ /^\s*DESCRIPTION\s*=/) { printf NEW $line; $line = ; } # As before, we want to delete this DESCRIPTION and replace it with a new # one. It may run one or two lines: if ($line !~ /^\s*DESCRIPTION\s*=\s*".*"\s*$/) { $line = ; if ($line !~ /^\s*[^"=]*"\s*$/) { printf STDERR "Couldn't find end of Y_CENTER.DESCRIPTION in"; printf STDERR "$File::Find::name.\n"; close(OLD); close(NEW); return; } } # Now we add our new DESCRIPTION: $line = " DESCRIPTION = \"y-coordinate of the center\n"; printf NEW $line; if ($filename =~ /^comet/) { $line = " of the comet. First pixel is (1,1).\"\n"; } else { $line = " of the star. First pixel is (1,1).\"\n"; } printf NEW $line; # And now we loop to the end of the label: while ($line=) { printf NEW $line; } # And we're done: close(OLD); close(NEW); rename $TMPFILE, $filename; return; }