//Classification
if DPR.CATG=="CALIB" and DPR.TYPE=="BIAS" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "BIAS_BLUE";
  REFLEX.CATG = "BIAS_BLUE";
  PACK.DIR = "DET";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="BIAS" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "BIAS_RED";
  REFLEX.CATG = "BIAS_RED";
  PACK.DIR = "DET";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and (
    ( DPR.TYPE=="BIAS,DETCHAR" and TPL.ID=="UVES_blue_tec_ccdflat" )
  ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "CCDTEST_BLUE";
  REFLEX.CATG = "BIAS_DETCHAR_BLUE";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and (
    ( DPR.TYPE=="BIAS,DETCHAR" and TPL.ID=="UVES_red_tec_ccdflat" )
  ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "CCDTEST_RED";
  REFLEX.CATG = "BIAS_DETCHAR_RED";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and (
    ( DPR.TYPE=="LAMP,FLAT,DETCHAR" and DPR.TECH=="IMAGE" and TPL.ID=="UVES_blue_tec_ccdflat" )
  ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "CCDTEST_BLUE";
  REFLEX.CATG = "SCREEN_FLAT_DETCHAR_BLUE";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and (
    ( DPR.TYPE=="LAMP,FLAT,DETCHAR" and DPR.TECH=="IMAGE" and TPL.ID=="UVES_red_tec_ccdflat" )
  ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "CCDTEST_RED";
  REFLEX.CATG = "SCREEN_FLAT_DETCHAR_RED";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="DARK" and DPR.TECH=="IMAGE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "DARK_BLUE";
  REFLEX.CATG = "DARK_BLUE";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="DARK" and DPR.TECH=="IMAGE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "DARK_RED";
  REFLEX.CATG = "DARK_RED";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="PARASITIC" and DPR.TECH=="IMAGE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "PDARK_BLUE";
  REFLEX.CATG = "PDARK_BLUE";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="PARASITIC" and DPR.TECH=="IMAGE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "PDARK_RED";
  REFLEX.CATG = "PDARK_RED";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,FMTCHK" and DPR.TECH=="ECHELLE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "FMTCHK_ECH_BLUE";
  REFLEX.CATG = "ARC_LAMP_FORM_BLUE";
  PACK.DIR = "SPEC_OTHER";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,FMTCHK" and DPR.TECH=="ECHELLE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "FMTCHK_ECH_RED";
  REFLEX.CATG = "ARC_LAMP_FORM_RED";
  PACK.DIR = "SPEC_OTHER";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,ORDERDEF" and DPR.TECH=="ECHELLE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "ORDERDEF_ECH_BLUE";
  REFLEX.CATG = "ORDER_FLAT_BLUE";
  PACK.DIR = "SPEC_OTHER";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,ORDERDEF" and DPR.TECH=="ECHELLE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "ORDERDEF_ECH_RED";
  REFLEX.CATG = "ORDER_FLAT_RED";
  PACK.DIR = "SPEC_OTHER";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,FLAT" and DPR.TECH=="ECHELLE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "EFLAT_ECH_BLUE";
  REFLEX.CATG = "FLAT_BLUE";
  PACK.DIR = "SPEC_FLAT";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,DFLAT" and DPR.TECH=="ECHELLE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "DFLAT_ECH_BLUE";
  REFLEX.CATG = "DFLAT_BLUE";
  PACK.DIR = "SPEC_FLAT";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,FLAT" and DPR.TECH=="ECHELLE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "EFLAT_ECH_RED";
  REFLEX.CATG = "FLAT_RED";
  PACK.DIR = "SPEC_FLAT";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,WAVE" and DPR.TECH=="ECHELLE" and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "WAVE_ECH_BLUE";
  REFLEX.CATG = "ARC_LAMP_BLUE";
  PACK.DIR = "SPEC_ARC";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,WAVE" and DPR.TECH=="ECHELLE" and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "WAVE_ECH_RED";
  REFLEX.CATG = "ARC_LAMP_RED";
  PACK.DIR = "SPEC_ARC";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,TFLAT" and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3"
   ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "TFLAT_ECH_BLUE";
  REFLEX.CATG = "TFLAT_BLUE";
  PACK.DIR = "SPEC_FLAT";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="LAMP,TFLAT" and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3"
    ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "TFLAT_ECH_RED";
  REFLEX.CATG = "TFLAT_RED";
  PACK.DIR = "SPEC_FLAT";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="STD" and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3"
   ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "STD_ECH_BLUE";
  REFLEX.CATG = "STANDARD_BLUE";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="CALIB" and DPR.TYPE=="STD" and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3"
   ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "STD_ECH_RED";
  REFLEX.CATG = "STANDARD_RED";
  PACK.DIR = "NONE";
  CATG = "CALIB";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT" or
      DPR.TYPE=="OBJECT,POINT" or
      DPR.TYPE=="OBJECT,POINT,POINT"
   ) and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL"
   ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_POINT_ECH_BLUE";
  REFLEX.CATG = "SCI_POINT_BLUE";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
  REFLEX.TARGET = "T";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT" or
      DPR.TYPE=="OBJECT,POINT" or
      DPR.TYPE=="OBJECT,POINT,POINT"
   ) and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL"
   ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_POINT_ECH_RED";
  REFLEX.CATG = "SCI_POINT_RED";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
  REFLEX.TARGET = "T";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT,EXTENDED" or
      DPR.TYPE=="OBJECT,EXTENDED,EXTENDED"
   ) and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL"
   ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_EXTENDED_ECH_BLUE";
  REFLEX.CATG = "SCI_EXTND_BLUE";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT,EXTENDED" or
      DPR.TYPE=="OBJECT,EXTENDED,EXTENDED"
   ) and (
      DPR.TECH=="ECHELLE" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL"
   ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_EXTENDED_ECH_RED";
  REFLEX.CATG = "SCI_EXTND_RED";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT,POINT" or
      DPR.TYPE=="OBJECT,POINT,POINT"
   ) and (
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#1" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#2" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#3"
   ) and DET.CHIPS==1 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_SLIC_ECH_BLUE";
  REFLEX.CATG = "SCI_SLICER_BLUE";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
}

if DPR.CATG=="SCIENCE" and (
      DPR.TYPE=="OBJECT,POINT" or
      DPR.TYPE=="OBJECT,POINT,POINT"
   ) and (
      DPR.TECH=="ECHELLE,SLIC#1" or
      DPR.TECH=="ECHELLE,SLIC#2" or
      DPR.TECH=="ECHELLE,SLIC#3" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#1" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#2" or
      DPR.TECH=="ECHELLE,ABSORPTION-CELL,SLIC#3"
   ) and DET.CHIPS==2 and INSTRUME=="UVES" then
{
  RAW.TYPE = "SCI_SLIC_ECH_RED";
  REFLEX.CATG = "SCI_SLICER_RED";
  PACK.DIR = "NONE";
  CATG = "SCIENCE";
}

if PRO.CATG=="EXTCOEFF_TABLE" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "EXTCOEFF_TABLE";
}

if PRO.CATG=="LINE_REFER_TABLE" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "LINE_REFER_TABLE";
}

if PRO.CATG=="FLUX_STD_TABLE" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "FLUX_STD_TABLE";
}

if PRO.CATG=="MASTER_RESPONSE_BLUE" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "MASTER_RESPONSE_BLUE";
}

if PRO.CATG=="MASTER_RESPONSE_REDL" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "MASTER_RESPONSE_REDL";
}

if PRO.CATG=="MASTER_RESPONSE_REDU" and INSTRUME=="UVES" then
{
  REFLEX.CATG = "MASTER_RESPONSE_REDU";
}

//Selection of actions and grouping

select execute(BIAS_BLUE) from inputFiles where RAW.TYPE=="BIAS_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(BIAS_RED) from inputFiles where RAW.TYPE=="BIAS_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(CCDTEST_BLUE) from inputFiles where RAW.TYPE=="CCDTEST_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(CCDTEST_RED) from inputFiles where RAW.TYPE=="CCDTEST_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(DARK_BLUE) from inputFiles where RAW.TYPE=="DARK_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(DARK_RED) from inputFiles where RAW.TYPE=="DARK_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(PDARK_BLUE) from inputFiles where RAW.TYPE=="PDARK_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(PDARK_RED) from inputFiles where RAW.TYPE=="PDARK_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,TPL.START as (TPL_A,tpl);
select execute(FMTCHK_ECH_BLUE) from inputFiles where RAW.TYPE=="FMTCHK_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT1.WLEN,ARCFILE;
select execute(FMTCHK_ECH_RED) from inputFiles where RAW.TYPE=="FMTCHK_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT2.WLEN,ARCFILE;
select execute(ORDERDEF_ECH_BLUE) from inputFiles where RAW.TYPE=="ORDERDEF_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT1.WLEN,ARCFILE;
select execute(ORDERDEF_ECH_RED) from inputFiles where RAW.TYPE=="ORDERDEF_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT2.WLEN,ARCFILE;
select execute(EFLAT_ECH_BLUE) from inputFiles where RAW.TYPE=="EFLAT_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,TPL.START as (TPL_A,tpl);
select execute(EFLAT_ECH_RED) from inputFiles where RAW.TYPE=="EFLAT_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,TPL.START as (TPL_A,tpl);
select execute(DFLAT_ECH_BLUE) from inputFiles where RAW.TYPE=="DFLAT_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,TPL.START as (TPL_A,tpl);
select execute(WAVE_ECH_BLUE) from inputFiles where RAW.TYPE=="WAVE_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,ARCFILE;
select execute(WAVE_ECH_RED) from inputFiles where RAW.TYPE=="WAVE_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,ARCFILE;
select execute(TFLAT_ECH_BLUE) from inputFiles where RAW.TYPE=="TFLAT_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,TPL.START as (TPL_A,tpl);
select execute(TFLAT_ECH_RED) from inputFiles where RAW.TYPE=="TFLAT_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,TPL.START as (TPL_A,tpl);
select execute(STD_ECH_BLUE) from inputFiles where RAW.TYPE=="STD_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT1.WLEN,OBS.TARG.NAME,ARCFILE;
select execute(STD_ECH_RED) from inputFiles where RAW.TYPE=="STD_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT2.WLEN,OBS.TARG.NAME,ARCFILE;
select execute(STD_TELL_BLUE) from inputFiles where RAW.TYPE=="STD_TELL_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT1.WLEN,OBS.TARG.NAME,ARCFILE;
select execute(STD_TELL_RED) from inputFiles where RAW.TYPE=="STD_TELL_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.GRAT2.WLEN,OBS.TARG.NAME,ARCFILE;
select execute(SCI_POINT_ECH_BLUE) from inputFiles where RAW.TYPE=="SCI_POINT_ECH_BLUE"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,ARCFILE;
select execute(SCI_POINT_ECH_RED) from inputFiles where RAW.TYPE=="SCI_POINT_ECH_RED"
  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,ARCFILE;
//There is no support for SLICER or EXTENDED data so far
//select execute(SCI_EXTENDED_ECH_BLUE) from inputFiles where RAW.TYPE=="SCI_EXTENDED_ECH_BLUE"
//  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,ARCFILE;
//select execute(SCI_EXTENDED_ECH_RED) from inputFiles where RAW.TYPE=="SCI_EXTENDED_ECH_RED"
//  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,ARCFILE;
//select execute(SCI_SLIC_ECH_BLUE) from inputFiles where RAW.TYPE=="SCI_SLIC_ECH_BLUE"
//  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT1.WLEN,INS.SLIT2.WID,ARCFILE;
//select execute(SCI_SLIC_ECH_RED) from inputFiles where RAW.TYPE=="SCI_SLIC_ECH_RED"
//  group by DET.CHIPS,DET.WIN1.BINX,DET.WIN1.BINY,DET.READ.SPEED,INS.MODE,INS.SLIT1.NAME,INS.GRAT2.WLEN,INS.SLIT3.WID,ARCFILE;

//Definitions of actions 
action BIAS_BLUE
{
  recipe uves_cal_mbias;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_BIAS_BLUE_WKF { PRO.CATG="MASTER_BIAS_BLUE_WKF"; PRO.EXT="tpl_0000.fits";}
}

action BIAS_RED
{
  recipe uves_cal_mbias;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_BIAS_REDL_WKF { PRO.CATG="MASTER_BIAS_REDL_WKF"; PRO.EXT="tpl_0000.fits";}
  product MASTER_BIAS_REDU_WKF { PRO.CATG="MASTER_BIAS_REDU_WKF"; PRO.EXT="tpl_0001.fits";}
}

action CCDTEST_BLUE
{
  recipe uves_cal_lingain;
}

action CCDTEST_RED
{
  recipe uves_cal_lingain;
}

action DARK_BLUE
{
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_mdark;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_DARK_BLUE_WKF { PRO.CATG="MASTER_DARK_BLUE_WKF"; PRO.EXT="tpl_0000.fits";}
}

action DARK_RED
{
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_mdark;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_DARK_REDL_WKF { PRO.CATG="MASTER_DARK_REDL_WKF"; PRO.EXT="tpl_0000.fits";}
  product MASTER_DARK_REDU_WKF { PRO.CATG="MASTER_DARK_REDU_WKF"; PRO.EXT="tpl_0001.fits";}
}

action FMTCHK_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as LINE_REFER_TABLE from calibFiles where
    PRO.CATG=="LINE_REFER_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FORM_BLUE from calibFiles where
    PRO.CATG=="MASTER_FORM_BLUE"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_predict;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product ORDER_GUESS_TAB_BLUE_WKF { PRO.CATG="ORDER_GUESS_TAB_BLUE_WKF"; PRO.EXT="0001.fits";}
  product LINE_GUESS_TAB_BLUE_WKF { PRO.CATG="LINE_GUESS_TAB_BLUE_WKF"; PRO.EXT="0003.fits";}
}

action FMTCHK_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as LINE_REFER_TABLE from calibFiles where
    PRO.CATG=="LINE_REFER_TABLE" and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FORM_REDL from calibFiles where
    PRO.CATG=="MASTER_FORM_REDL"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FORM_REDU from calibFiles where
    PRO.CATG=="MASTER_FORM_REDU"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  recipe uves_cal_predict;
  
  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product ORDER_GUESS_TAB_REDL_WKF { PRO.CATG="ORDER_GUESS_TAB_REDL_WKF"; PRO.EXT="0001.fits";}
  product LINE_GUESS_TAB_REDL_WKF { PRO.CATG="LINE_GUESS_TAB_REDL_WKF"; PRO.EXT="0003.fits";}
  product ORDER_GUESS_TAB_REDU_WKF { PRO.CATG="ORDER_GUESS_TAB_REDU_WKF"; PRO.EXT="0005.fits";}
  product LINE_GUESS_TAB_REDU_WKF { PRO.CATG="LINE_GUESS_TAB_REDU_WKF"; PRO.EXT="0007.fits";}
}

action ORDERDEF_ECH_BLUE
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_GUESS_TAB_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_GUESS_TAB_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_orderpos;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product ORDER_TABLE_BLUE_WKF { PRO.CATG="ORDER_TABLE_BLUE_WKF"; PRO.EXT="0000.fits";}
}

action ORDERDEF_ECH_RED
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_GUESS_TAB_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_GUESS_TAB_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_GUESS_TAB_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_GUESS_TAB_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_orderpos;
  product ORDER_TABLE_REDL_WKF { PRO.CATG="ORDER_TABLE_REDL_WKF"; PRO.EXT="0000.fits";}
  product ORDER_TABLE_REDU_WKF { PRO.CATG="ORDER_TABLE_REDU_WKF"; PRO.EXT="0003.fits";}
}

action EFLAT_ECH_BLUE
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_mflat;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_FLAT_BLUE_WKF { PRO.CATG="MASTER_FLAT_BLUE_WKF"; PRO.EXT="tpl_0000.fits";}
}

action EFLAT_ECH_RED
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_mflat;
  product MASTER_FLAT_REDL_WKF { PRO.CATG="MASTER_FLAT_REDL_WKF"; PRO.EXT="tpl_0000.fits";}
  product MASTER_FLAT_REDU_WKF { PRO.CATG="MASTER_FLAT_REDU_WKF"; PRO.EXT="tpl_0002.fits";}
}

action DFLAT_ECH_BLUE
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_mflat;

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product MASTER_DFLAT_BLUE_WKF { PRO.CATG="MASTER_DFLAT_BLUE_WKF"; PRO.EXT="tpl_0000.fits";}
}

action WAVE_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as LINE_REFER_TABLE from calibFiles where
    PRO.CATG=="LINE_REFER_TABLE" and inputFile.INSTRUME==INSTRUME;

// Only neede by DFO
//  minRet = 0; maxRet = 1;
//  select file as LINE_INTMON_TABLE from calibFiles where
//    PRO.CATG=="LINE_INTMON_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN 
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_GUESS_TAB_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_GUESS_TAB_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_wavecal {
  "--tolerance=10.0";
  "--degree=4";
  }

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product LINE_TABLE_BLUE_WKF { PRO.CATG="LINE_TABLE_BLUE_WKF"; PRO.EXT="0000.fits";}
}

action WAVE_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as LINE_REFER_TABLE from calibFiles where
    PRO.CATG=="LINE_REFER_TABLE" and inputFile.INSTRUME==INSTRUME;

// Only neede by DFO
//  minRet = 0; maxRet = 1;
//  select file as LINE_INTMON_TABLE from calibFiles where
//    PRO.CATG=="LINE_INTMON_TABLE" and inputFile.INSTRUME==INSTRUME
//  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_GUESS_TAB_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_GUESS_TAB_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_GUESS_TAB_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_GUESS_TAB_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_wavecal {
  "--tolerance=10.0";
  "--degree=4";
  }
  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product LINE_TABLE_REDL_WKF { PRO.CATG="LINE_TABLE_REDL_WKF"; PRO.EXT="0000.fits";}
  product LINE_TABLE_REDU_WKF { PRO.CATG="LINE_TABLE_REDU_WKF"; PRO.EXT="0004.fits";}
}

action STD_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as FLUX_STD_TABLE from calibFiles where
    PRO.CATG=="FLUX_STD_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_response {
  "--reduce.tiltcorr=false";
  }

  //The _WKF suffix is used to avoid association of already existing calibration frames
  //All the associations should go through virtual products
  product INSTR_RESPONSE_BLUE_WKF { PRO.CATG="INSTR_RESPONSE_BLUE_WKF"; PRO.EXT="0000.fits";}
}

action STD_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as FLUX_STD_TABLE from calibFiles where
    PRO.CATG=="FLUX_STD_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED  and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  recipe uves_cal_response {
  "--reduce.tiltcorr=false";
  }
  product INSTR_RESPONSE_REDL_WKF { PRO.CATG="INSTR_RESPONSE_REDL_WKF"; PRO.EXT="0000.fits";}
  product INSTR_RESPONSE_REDU_WKF { PRO.CATG="INSTR_RESPONSE_REDU_WKF"; PRO.EXT="0001.fits";}
}

action STD_TELL_BLUE
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY  and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_BLUE_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_BLUE_WKF"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME
  ;

  recipe uves_obs_scired {
  "--reduce.tiltcorr=true";
  }
}

action STD_TELL_RED
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINYand inputFile.INS.MODE==INS.MODE  and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDL_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.)) and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDU_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.)) and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME
  ;
  recipe uves_obs_scired {
  "--reduce.tiltcorr=true";
  "--reduce.extract.kappa=20";
  }
}

action TFLAT_ECH_BLUE
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) )
    and INS.SLIT2.WID==1.00 and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as REF_TFLAT_BLUE from calibFiles where
    PRO.CATG=="REF_TFLAT_BLUE"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INS.SLIT1.NAME==INS.SLIT1.NAME and inputFile.INSTRUME==INSTRUME
  ;
  recipe uves_cal_tflat {
  "--reduce.tiltcorr=false";
  }
}

action TFLAT_ECH_RED
{
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) )
    and INS.SLIT3.WID==1.00 and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as REF_TFLAT_REDL from calibFiles where
    PRO.CATG=="REF_TFLAT_REDL"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INS.SLIT1.NAME==INS.SLIT1.NAME and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 0; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) )
    and INS.SLIT3.WID==1.00 and inputFile.INSTRUME==INSTRUME
  ;
  minRet = 1; maxRet = 1;
  select file as REF_TFLAT_REDU from calibFiles where
    PRO.CATG=="REF_TFLAT_REDU"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INS.SLIT1.NAME==INS.SLIT1.NAME and inputFile.INSTRUME==INSTRUME
  ;
  recipe uves_cal_tflat {
  "--reduce.tiltcorr=false";
  }
}

action SCI_EXTENDED_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

   minRet = 1; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;    

  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_BLUE_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_BLUE_WKF"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_BLUE from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_BLUE"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;


  recipe uves_obs_scired {
    "--reduce.backsub.mmethod=minimum";
    "--reduce.tiltcorr=true";
    "--reduce.extract.method=2d";
  }
}

action SCI_EXTENDED_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_REDL_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDL_WKF"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDU_WKF"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;



  recipe uves_obs_scired {
    "--reduce.backsub.mmethod=minimum";
    "--reduce.tiltcorr=true";
    "--reduce.extract.method=2d";
  }
}

action SCI_POINT_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0 or (inputFile.INS.SLIT2.WID >= 2.1 and INS.SLIT2.WID==1.00))
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_BLUE_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_BLUE_WKF"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_BLUE from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_BLUE"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;

  recipe uves_obs_scired {
  "--reduce.tiltcorr=true";
  }
}

action SCI_POINT_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0 or (inputFile.INS.SLIT3.WID >= 2.1 and INS.SLIT3.WID==1.00))
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0 or (inputFile.INS.SLIT3.WID >= 2.1 and INS.SLIT3.WID==1.00))
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_REDL_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN  and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_REDU_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_REDU_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN  and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDL from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDL"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))    
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDU from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDU"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;


  recipe uves_obs_scired {
  "--reduce.tiltcorr=true";
  }
}

action SCI_SLIC_ECH_BLUE
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_BLUE_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
   minRet = 1; maxRet = 1;
  select file as MASTER_DARK_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_FLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_DFLAT_BLUE_WKF from calibFiles where
    PRO.CATG=="MASTER_DFLAT_BLUE_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.INS.SLIT2.WID==INS.SLIT2.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_BLUE_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_BLUE_WKF"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_BLUE from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_BLUE"
    and inputFile.INS.GRAT1.WLEN==INS.GRAT1.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;




  recipe uves_obs_scired {
    "--reduce.extract.method=average";
    "--reduce.tiltcorr=true";
  }
}

action SCI_SLIC_ECH_RED
{
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as ORDER_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="ORDER_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDL_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as LINE_TABLE_REDU_WKF from calibFiles where
    PRO.CATG=="LINE_TABLE_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_BIAS_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_BIAS_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

   minRet = 1; maxRet = 1;
  select file as MASTER_DARK_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;

  minRet = 1; maxRet = 1;
  select file as MASTER_DARK_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_DARK_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDL_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 1; maxRet = 1;
  select file as MASTER_FLAT_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_FLAT_REDU_WKF"
    and inputFile.DET.CHIPS==DET.CHIPS and inputFile.DET.WIN1.BINX==DET.WIN1.BINX and inputFile.DET.WIN1.BINY==DET.WIN1.BINY and inputFile.DET.READ.SPEED==DET.READ.SPEED and inputFile.INS.MODE==INS.MODE and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.INS.SLIT3.WID==INS.SLIT3.WID or inputFile.MJD-OBS < 51818.0)
    and ( OBS.ID==inputFile.OBS.ID or (MJD-OBS < inputFile.MJD-OBS or MJD-OBS >= inputFile.MJD-OBS) ) and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_REDL_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as INSTR_RESPONSE_REDU_WKF from calibFiles where
    PRO.CATG=="INSTR_RESPONSE_REDU_WKF"
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and (inputFile.MJD-OBS - MJD-OBS) < 0.5 and (inputFile.MJD-OBS - MJD-OBS) > -0.5 and inputFile.INSTRUME==INSTRUME;

  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDL_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDL_WKF"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as MASTER_RESPONSE_REDU_WKF from calibFiles where
    PRO.CATG=="MASTER_RESPONSE_REDU_WKF"
    and ((inputFile.MJD-OBS < 54997. and MJD-OBS < 54997.) or (inputFile.MJD-OBS > 54997. and MJD-OBS > 54997.))
    and inputFile.INS.GRAT2.WLEN==INS.GRAT2.WLEN and inputFile.INSTRUME==INSTRUME;
    
  minRet = 0; maxRet = 1;
  select file as EXTCOEFF_TABLE from calibFiles where
    PRO.CATG=="EXTCOEFF_TABLE" and inputFile.INSTRUME==INSTRUME;



  recipe uves_obs_scired {
    "--reduce.extract.method=average";
    "--reduce.tiltcorr=true";
  }
}

