#!/usr/local/bin/perl -w # # Copyright (C) 2008 Smithsonian Astrophysical Observatory # # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # # ########################################################################### # Script: rdb2ciao.pl # Version: 1.0 # Date: 08 October 2008 # # Version 1.1 # Date: 15 April 2010 # Changes: script renamed tsv2ciao.pl; line 66 edited to # account for lack of line of dashes in TSV (as compared to RDB); # commented out lines for writing null values since it is not working # (neither for RDB nor TSV format input files). # # This script converts a save file from the Chandra Source Catalog # GUI browser to a format useable by the CIAO Data Model. # # For more information, refer to the CSC website # http://cxc.harvard.edu/csc/ # use strict; # print usage if ($#ARGV < 1){ #print "usage: ./rdb2ciao.pl input output null_value\n"; print "usage: ./rdb2ciao.pl input output"; exit; } # get the input, output, and null value from command line my $input = shift; my $outfile = shift; #my $null = shift; # open the input file open(INFILE, "<$input") or die "Could not open file '$input' for reading.\n"; open (OUTFILE, ">$outfile") or die "Could not open file '$outfile' for writing.\n"; my $count = 0; my $querystamp; while (my $line = ) { chomp $line; # ignore any line which begins with '#' if ($line =~ /^#/) { next; } if ($count < 1 ) { print OUTFILE "# $line\n" ; $count++; } else { # add null value to empty cells in remaining lines # null at beginning #$line =~ s/^\t/$null\t/g; # null at end #$line =~ s/\t$/\t$null/g; # nulls in the middle #$line =~ s/(?=\t\t)\t/\t$null/g; print OUTFILE "$line\n"; } } close (INFILE); close (OUTFILE); __END__