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__ = "Archive to FITS converter" 00012 __author__ = "S. Tuvi <stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online" 00013 __date__ = "02/27/2003" 00014 __version__ = "$Revision: 2.2 $" 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-a or --archive to specify an input archive file (*.ldf)" 00026 print "\t-f or --fits to specify the output FITS file (append .gz to the filename for compression)" 00027 print "\t-r or --runreport to specify an input run report filename (ie. 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 runReportFile='' 00036 try: 00037 opts, args = getopt.getopt(sys.argv[1:], "ha:f:vr:", 00038 ["help", "archive=", "fits=", "verbose", "runreport="]) 00039 except getopt.GetoptError: 00040 # print help information and exit: 00041 __usage() 00042 sys.exit(2) 00043 for o, a in opts: 00044 if o in ("-h", "--help"): 00045 __usage() 00046 sys.exit() 00047 if o in ("-a", "--archive"): 00048 archiveFile = a 00049 if o in ("-f", "--fits"): 00050 fitsFile = a 00051 if o in ("-v", "--verbose"): 00052 verbose = 1 00053 if o in ("-r", "--runreport"): 00054 runReportFile = a 00055 00056 if archiveFile == '': 00057 print "\nERROR: Missing archive file parameter" 00058 __usage() 00059 sys.exit(2) 00060 00061 if fitsFile == '': 00062 print "\nERROR: Missing FITS file parameter" 00063 __usage() 00064 sys.exit(2) 00065 00066 if runReportFile == '': 00067 print "\nERROR: Missing Run Report file parameter" 00068 __usage() 00069 sys.exit(2) 00070 00071 import rcArchiver 00072 arch = rcArchiver.rcArchiver(fileName=archiveFile, mode=rcArchiver.MODE_READONLY) 00073 00074 import rcReportGen 00075 reportGen = rcReportGen.rcReportGen(fileName=runReportFile) 00076 reportGen.initialize() 00077 reportGen.readReportXML() 00078 00079 import rcFitsWriter 00080 fits = rcFitsWriter.rcFitsWriter(fileName=fitsFile, format=rcFitsWriter.FORMAT_BYTE, reportGen=reportGen) 00081 00082 cnt=0 00083 while(True): 00084 dat = arch.read() 00085 if dat == None: break 00086 cnt+=1 00087 if verbose and (cnt % 100) == 0: print "Progress line:", cnt 00088 fits.write(dat) 00089 if verbose and (cnt % 100) != 0: print "Progress line:", cnt 00090 00091 arch.close() 00092 fits.close() 00093 00094 if verbose: print "Conversion completed successfully!"