Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

fits2ldf.py

00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2002
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "FITS to Archive converter"
00012 __author__   = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = ("$Date: 2004/08/24 23:15:11 $").split(' ')[1]
00014 __version__  = "$Revision: 2.1 $"
00015 __credits__  = "SLAC"
00016 
00017 import LATTE.copyright_SLAC
00018 
00019 import sys
00020 import getopt
00021 
00022 def __usage():
00023   print "\n%s Usage:" % (sys.argv[0])
00024   print "\t-h or --help for Help"
00025   print "\t-f or --fits to specify the input FITS file"
00026   print "\t-a or --archive to specify to output archive file"
00027   print "\t-r or --runreport to specify an output run report filename (eg. rcReport.out)"
00028   print "\t-v or --verbose to specify progress messages during the conversion"
00029 
00030 
00031 if __name__ == '__main__':
00032   archiveFile=''
00033   fitsFile=''
00034   verbose=0
00035   try:
00036     opts, args = getopt.getopt(sys.argv[1:], "ha:f:vr:",
00037                                ["help", "archive=", "fits=", "verbose", "runreport="])
00038   except getopt.GetoptError:
00039     # print help information and exit:
00040     __usage()
00041     sys.exit(2)
00042   for o, a in opts:
00043     if o in ("-h", "--help"):
00044       __usage()
00045       sys.exit()
00046     if o in ("-a", "--archive"):
00047       archiveFile = a
00048     if o in ("-f", "--fits"):
00049       fitsFile = a
00050     if o in ("-v", "--verbose"):
00051       verbose = 1
00052     if o in ("-r", "--runreport"):
00053       runReportFile = a
00054 
00055   if archiveFile == '':
00056     print "\nERROR: Missing archive file parameter"
00057     __usage()
00058     sys.exit(2)
00059 
00060   if fitsFile == '':
00061     print "\nERROR: Missing FITS file parameter"
00062     __usage()
00063     sys.exit(2)
00064 
00065   import rcArchiver
00066   arch = rcArchiver.rcArchiver(fileName=archiveFile, mode=rcArchiver.MODE_CREATE)
00067 
00068   import rcReportGen
00069   reportGen = rcReportGen.rcReportGen(fileName=runReportFile)
00070   reportGen.initialize()
00071 
00072   import rcFitsWriter
00073   fits = rcFitsWriter.rcFitsWriter(fileName=fitsFile, mode=rcFitsWriter.MODE_READONLY,
00074                                    format=rcFitsWriter.FORMAT_BYTE, reportGen=reportGen)
00075 
00076   cnt=0
00077   while(1):
00078     dat = fits.read()
00079     if dat == None: break
00080     cnt+=1
00081     if verbose and (cnt % 100) == 0: print "Progress line:", cnt
00082     arch.write(dat)
00083   if verbose and (cnt % 100) != 0: print "Progress line:", cnt
00084 
00085   arch.close()
00086   fits.close()
00087 
00088   reportGen.writeReportXML()
00089 
00090   if verbose: print "Conversion completed successfully!"

Generated on Fri Jul 21 13:26:27 2006 for LATTE R04-12-00 by doxygen 1.4.3