;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Lance Simms, Stanford University 2009
;pro create_star_window_db_xrg.pro
;
;PURPOSE:
;  To create a database that contains the residuals from the fit to a guide
;  star at different clocking speeds of the HxRG detectors
;
;INPUTS:
;  DETSTR: string
;     The name of the detector used ('H1RG-022', 'H2RG-32-147', 'H4RG-007')
;  ELECSTR: string
;     The name of the electronics used ('ASIC', 'LEACH')
;  OBJECT: string
;     The name of the object that will be used for the TableName.  Available
;     options are :
;        1) SAO59392
;        2) VBELyn
;
;KEYWORDS: 
;  OVERWRITE: int
;     0 - don't overwrite the table if it already exists
;     1 - overwrite the table 
;EFFECTS:
;  The MySQL database will be updated with the new table.
;
;CALLING SEQUENCE:
;  Create_Star_Window_DB_xRG, DetStr, ElecStr, Object
;
;EXAMPLES
;  PIXEL RATE EXPERIMENTS:
;    Create_Star_Window_DB_xRG, 'H1RG-022', 'ASIC', 'SAO59392', /OverWrite
;  PHOTOMETRY ON VBELYN
;    Create_Star_Window_DB_xRG, 'H2RG-32-147', 'ASIC', 'VBELynVBELyn'
;
pro Create_Star_Window_DB_xRG, DetStr, ElecStr, ObjectName, $
    OverWrite=OverWrite

If N_Elements(OverWrite) eq 0 then OverWrite=0

Date = ''
Common KeyParams, KeyStr
;Include all of the keywords from the KeywordStruct file

@KeywordStruct_xRG.pro
@PlotSettings_xRG.pro

;Single Hit Cosmic Ray Database
openmysql, MySQLLun, 'WindowStarPhotometry', MyQLErr

;Format the strings in the table name
TableName = KeyStr.DetStr+'_'+KeyStr.ElecStr+'_'+KeyStr.ObjectName
strreplace, TableName, '-','_'
strreplace, TableName, '-','_'

if OverWrite eq 1 then $
   mysqlcmd, MySQLLun, 'DROP TABLE ' +TableName+';'

Command = 'CREATE TABLE '+TableName+'('+$
        'FRAMENUM SMALLINT, WINDOWNUM TINYINT,'+$
        'XC FLOAT, YC FLOAT, XCM FLOAT, YCM FLOAT,'+$
        'SHARP FLOAT, ROUND FLOAT, RESIDUAL FLOAT,'+$
        'MAG FLOAT, FINDFLUX FLOAT, APERFLUX FLOAT,'+$
        'PEAK FLOAT, G1 FLOAT , G2 FLOAT,'+ $
        'SIGX FLOAT, SIGY FLOAT, SKY FLOAT, FWHMX FLOAT, FWHMY FLOAT,'+$
        'DTK DATETIME, FRACSEC FLOAT, FILENAME VARCHAR(80));'

mysqlcmd, MySQLLun, Command, Answer, NumLines

end  
