# this file is based on the detRunSummary.d file: it uses the same tables restricted to the 
# master detrend runs which have been accepted

TABLE detRun LEFT JOIN detRunSummary ON detRun.det_id = detRunSummary.det_id
TITLE Master Detrend Frames
FILE  masterDetrendFrames.php
MENU  ipp.detrend.dat

# the following WHERE clauses are added to all queries joined by AND
WHERE (detRunSummary.accept = 1 or detRun.mode = 'register')
WHERE detRun.state = 'stop'

ARGS  ARG1 detRunSummary.det_id=$detRunSummary.det_id

ARGS  ARG2 detInputExp.det_id=$detRunSummary.det_id
ARGS  ARG2 detInputExp.iteration=$detRunSummary.iteration

ARGS  ARG3 detProcessedExp.det_id=$detRunSummary.det_id

ARGS  ARG4 detResidExp.det_id=$detRunSummary.det_id
ARGS  ARG4 detResidExp.iteration=$detRunSummary.iteration

ARGS  ARG5 det_id=$det_id

#     field                    width format  name          show         link to                   extras
FIELD detRun.det_id,           5,    %s,     det ID,       value,       detRunSummary.php,        ARG1
FIELD detRunSummary.iteration, 3,    %s,     iter
FIELD detRun.det_type,        12,    %s,     type
FIELD detRun.state,            5,    %s,     state
# FIELD detRun.mode,             5,    %s,     mode
# FIELD detRunSummary.accept,    5,    %s,     accept
FIELD *,                       5,    %s,     choose,       value=input, detInputExp.php,          ARG2
FIELD *,                       5,    %s,     choose,       value=proc,  detProcessedExp.php,      ARG3
FIELD *,                       5,    %s,     choose,       value=stack, detStackedImfile.php,  ARG5
FIELD *,                       5,    %s,     choose,       value=resid, detResidExp.php,          ARG4
FIELD mode,         	       5,    %s,     mode
FIELD filter,       	      10,    %s,     filter     
FIELD registered,             19,   %s,      registered 
FIELD use_begin,              19,   %s,      use_begin  
FIELD use_end,                19,   %s,      use_end    
FIELD detRunSummary.bg,        8,   %.2f,    bg
FIELD detRunSummary.bg_stdev,  8,   %.2f,    bg_stdev
# FIELD airmass_min,             5,   %.2f,    min_airmass    
# FIELD airmass_max,             5,   %.2f,    max     
# FIELD exp_time_min,            5,   %.2f,    min_exp_time   
# FIELD exp_time_max,            5,   %.2f,    max 
# FIELD ccd_temp_min,            5,   %.2f,    min_ccd_temp   
# FIELD ccd_temp_max,            5,   %.2f,    max    
# FIELD posang_min,              5,   %.2f,    min_posang     
# FIELD posang_max,              5,   %.2f,    max      
# FIELD bg_mean_stdev, 20,   bg_mean_stdev

# this file illustrates a simple inner join to generate the output table
# assuming no other dynamic restrictions are added, this generates the following query:
# SELECT detRunSummary.det_id,detRunSummary.iteration,detRunSummary.iteration,detRun.det_type,detRunSummary.bg,detRunSummary.bg_stdev \
# FROM detRunSummary, detRun \
# WHERE detRunSummary.accept = 1 AND detRun.det_id = detRunSummary.det_id AND detRun.iteration = detRunSummary.iteration \
# LIMIT 20
