TABLE detResidExp, rawExp, detInputExp
TITLE detResidExp
FILE  detResidExp.php
MENU  ipp.detrend.dat

# the following WHERE clauses are added to all queries joined by AND
WHERE detResidExp.exp_id = rawExp.exp_id
WHERE detResidExp.exp_id = detInputExp.exp_id
WHERE detResidExp.iteration = detInputExp.iteration

# define image names to be used below
# IMAGE VAR basename filerule camera class_id
IMAGE JPEG2 $detResidExp.path_base PPIMAGE.JPEG2 $rawExp.camera NONE

# define the arguments supplied to the links below (if any)
ARGS  ARG1 exp_id=$detResidExp.exp_id

ARGS  ARG2 detResidImfile.det_id=$detResidExp.det_id
ARGS  ARG2 detResidImfile.iteration=$detResidExp.iteration
ARGS  ARG2 detResidImfile.exp_id=$detResidExp.exp_id
ARGS  ARG2 camera=$rawExp.camera
ARGS  ARG2 basename=$detResidExp.path_base

OP    OP1  $detResidExp.bin_stdev > 0.0 ? $detResidExp.bg / $detResidExp.bin_stdev : NAN

#     field                   size  format  name       show         link to              linkargs
FIELD detResidExp.det_id,        7, %s,     Det ID,    value
FIELD rawExp.camera,            10, %s,     camera,    value
FIELD detResidExp.exp_id, 	 5, %s,     Exp ID,    value,       rawImfile.php,       ARG1
FIELD rawExp.exp_name, 	         5, %s,     Exp Name,  value,       rawImfile.php,       ARG1
FIELD detResidExp.iteration,     5, %s,     iter,      value
FIELD detInputExp.include,       3, %t,     used,      value
FIELD detResidExp.accept,        3, %t,     keep,      value
FIELD detResidExp.fault,         4, %d,     fault,     value
FIELD *,    	                 8, %s,     image,     image=JPEG2, detResidImfile.php,  ARG2
FIELD detResidExp.bg,            8, %.3f,   backgnd,   value
FIELD detResidExp.bg_mean_stdev, 8, %.3f,   [stdev],   value
FIELD detResidExp.bg_stdev,      8, %.3f,   stdev,     value
FIELD detResidExp.bin_stdev,     8, %.3f,   bin stdev, value
FIELD *,                         8, %s,     S/N,       op=OP1
FIELD detResidExp.fringe_0,      8, %.3f,   fringe,    value
FIELD detResidExp.fringe_1,      8, %.3f,   fringe err, value
FIELD detResidExp.fringe_2,      8, %.3f,   fringe stdev, value
FIELD detResidExp.user_1,        8, %.3f,   dfringe,    value
FIELD detResidExp.user_2,        8, %.3f,   dfringe err, value
FIELD detResidExp.user_3,        8, %.3f,   dfringe stdev, value
FIELD rawExp.dateobs,           19, %T,     obs date,  value
FIELD rawExp.filter,            10, %s,     filter,    value
FIELD rawExp.exp_time,           8, %.2f,   exptime,   value
FIELD rawExp.ccd_temp,           8, %.2f,   ccd temp,  value
FIELD rawExp.airmass,            8, %.4f,   airmass,   value
FIELD detResidExp.path_base,    20, %s,     path_base, none

TD_CLASS det_drop $detInputExp.include == 1 && $detResidExp.accept == 0
TD_CLASS det_off  $detInputExp.include == 0 && $detResidExp.accept == 0
TD_CLASS det_add  $detInputExp.include == 0 && $detResidExp.accept == 1
